@leafer-ui/hit 1.0.0-rc.1 → 1.0.0-rc.10

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.0.0-rc.1",
3
+ "version": "1.0.0-rc.10",
4
4
  "description": "@leafer-ui/hit",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -21,8 +21,11 @@
21
21
  "leafer-ui",
22
22
  "leaferjs"
23
23
  ],
24
+ "dependencies": {
25
+ "@leafer-ui/draw": "1.0.0-rc.10"
26
+ },
24
27
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-rc.1",
26
- "@leafer-ui/interface": "1.0.0-rc.1"
28
+ "@leafer/interface": "1.0.0-rc.10",
29
+ "@leafer-ui/interface": "1.0.0-rc.10"
27
30
  }
28
31
  }
package/src/LeafHit.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { IRadiusPointData } from '@leafer/interface'
2
+ import { Leaf, PointHelper, BoundsHelper } from '@leafer-ui/draw'
3
+
4
+
5
+ const { toInnerRadiusPointOf, copy, setRadius } = PointHelper
6
+ const inner = {} as IRadiusPointData
7
+
8
+ Leaf.prototype.__hitWorld = function (point: IRadiusPointData): boolean {
9
+ if (this.__layout.hitCanvasChanged || !this.__hitCanvas) {
10
+ this.__updateHitCanvas()
11
+ this.__layout.hitCanvasChanged = false
12
+ }
13
+
14
+ if (this.__.hitRadius) {
15
+ copy(inner, point), point = inner
16
+ setRadius(point, this.__.hitRadius)
17
+ }
18
+
19
+ toInnerRadiusPointOf(point, this.__world, inner)
20
+
21
+ if (this.__.hitBox) {
22
+ if (BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner)) return true
23
+ }
24
+
25
+ return this.__hit(inner)
26
+ }
package/src/RectHit.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { IRadiusPointData } from '@leafer/interface'
2
+ import { Rect, UI, BoundsHelper } from '@leafer-ui/draw'
3
+
4
+
5
+ const ui = new UI()
6
+
7
+ // hit
8
+
9
+ Rect.prototype.__updateHitCanvas = function () {
10
+ if (this.stroke || this.cornerRadius) ui.__updateHitCanvas.call(this)
11
+ }
12
+
13
+ Rect.prototype.__hitFill = function (inner: IRadiusPointData, windingRule?: string): boolean {
14
+ return this.__hitCanvas ? ui.__hitFill.call(this, inner, windingRule) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner)
15
+ }
package/src/UIHit.ts CHANGED
@@ -1,54 +1,47 @@
1
1
  import { IRadiusPointData } from '@leafer/interface'
2
-
3
- import { IUIHitModule } from '@leafer-ui/interface'
4
- import { Platform } from '@leafer/core'
5
-
6
-
7
- export const UIHit: IUIHitModule = {
8
-
9
- __updateHitCanvas(): void {
10
- if (!this.__hitCanvas) this.__hitCanvas = this.leafer.hitCanvasManager.getPathType(this)
11
- const h = this.__hitCanvas
12
- this.__drawHitPath(h)
13
- h.setStrokeOptions(this.__)
14
- },
15
-
16
- __hit(inner: IRadiusPointData): boolean {
17
- const { __hitCanvas: h } = this
18
- if (Platform.name === 'miniapp') this.__drawHitPath(h) // fix: 小程序需要实时更新
19
-
20
- const { fill, hitFill, windingRule } = this.__
21
- const needHitFill = (fill && hitFill === 'path') || hitFill === 'all'
22
- const isHitFill = h.hitFill(inner, windingRule)
23
- if (needHitFill && isHitFill) return true
24
-
25
- const { stroke, hitStroke, strokeWidth, strokeAlign } = this.__
26
- const needHitStroke = (stroke && hitStroke === 'path') || hitStroke === 'all'
27
- const radiusWidth = inner.radiusX * 2
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
2
+ import { UI, Platform } from '@leafer-ui/draw'
3
+
4
+
5
+ UI.prototype.__updateHitCanvas = function (): void {
6
+ if (!this.__hitCanvas) this.__hitCanvas = this.leafer.hitCanvasManager.getPathType(this)
7
+ const h = this.__hitCanvas
8
+ this.__drawHitPath(h)
9
+ h.setStrokeOptions(this.__)
10
+ }
11
+
12
+ UI.prototype.__hit = function (inner: IRadiusPointData): boolean {
13
+ if (Platform.name === 'miniapp') this.__drawHitPath(this.__hitCanvas) // fix: 小程序需要实时更新
14
+
15
+ const { fill, hitFill, windingRule } = this.__
16
+ const needHitFill = (fill && hitFill === 'path') || hitFill === 'all'
17
+ const isHitFill = this.__hitFill(inner, windingRule)
18
+ if (needHitFill && isHitFill) return true
19
+
20
+ const { stroke, hitStroke, __strokeWidth, strokeAlign } = this.__
21
+ const needHitStroke = (stroke && hitStroke === 'path') || hitStroke === 'all'
22
+ const radiusWidth = inner.radiusX * 2
23
+
24
+ let hitWidth = radiusWidth
25
+
26
+ if (needHitStroke) {
27
+ switch (strokeAlign) {
28
+ case 'inside':
29
+ hitWidth += __strokeWidth * 2
30
+ if (!needHitFill && (isHitFill && this.__hitStroke(inner, hitWidth))) return true
31
+ hitWidth = radiusWidth
32
+ break
33
+ case 'center':
34
+ hitWidth += __strokeWidth
35
+ break
36
+ case 'outside':
37
+ hitWidth += __strokeWidth * 2
38
+ if (!needHitFill) {
39
+ if (!isHitFill && this.__hitStroke(inner, hitWidth)) return true
36
40
  hitWidth = radiusWidth
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
- }
41
+ }
42
+ break
49
43
  }
50
-
51
- return hitWidth ? h.hitStroke(inner, hitWidth) : false
52
44
  }
53
45
 
54
- }
46
+ return hitWidth ? this.__hitStroke(inner, hitWidth) : false
47
+ }
package/src/index.ts CHANGED
@@ -1 +1,22 @@
1
- export { UIHit } from "./UIHit"
1
+ export * from './LeafHit'
2
+ export * from './UIHit'
3
+ export * from './RectHit'
4
+
5
+ import { IFindMethod, IPointData, IPickOptions, IPickResult } from '@leafer/interface'
6
+ import { IFindUIMethod, IUI } from '@leafer-ui/interface'
7
+ import { UI, Group } from '@leafer-ui/draw'
8
+
9
+
10
+ UI.prototype.find = function (condition: number | string | IFindUIMethod, options?: any): IUI[] {
11
+ return this.leafer ? this.leafer.selector.getBy(condition as IFindMethod, this, false, options) as IUI[] : []
12
+ }
13
+
14
+ UI.prototype.findOne = function (condition: number | string | IFindUIMethod, options?: any): IUI {
15
+ return this.leafer ? this.leafer.selector.getBy(condition as IFindMethod, this, true, options) as IUI : null
16
+ }
17
+
18
+ Group.prototype.pick = function (hitPoint: IPointData, options?: IPickOptions): IPickResult {
19
+ this.__layout.update()
20
+ if (!options) options = {}
21
+ return this.leafer ? this.leafer.selector.getByPoint(hitPoint, options.hitRadius || 0, { ...options, target: this }) : null
22
+ }
package/types/index.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- import { IUIHitModule } from '@leafer-ui/interface';
2
1
 
3
- declare const UIHit: IUIHitModule;
4
-
5
- export { UIHit };
2
+ export { }