@leafer/selector 1.0.0-rc.21 → 1.0.0-rc.22

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/selector",
3
- "version": "1.0.0-rc.21",
3
+ "version": "1.0.0-rc.22",
4
4
  "description": "@leafer/selector",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,9 +22,9 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.0-rc.21"
25
+ "@leafer/core": "1.0.0-rc.22"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.21"
28
+ "@leafer/interface": "1.0.0-rc.22"
29
29
  }
30
30
  }
package/src/Picker.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ILeaf, ILeafList, IPointData, IRadiusPointData, IPickResult, IPickOptions, ISelector } from '@leafer/interface'
1
+ import { ILeaf, ILeafList, IPointData, IRadiusPointData, IPickResult, IPickOptions, ISelector, IPickBottom } from '@leafer/interface'
2
2
  import { BoundsHelper, LeafList, LeafHelper } from '@leafer/core'
3
3
 
4
4
 
@@ -9,7 +9,7 @@ export class Picker {
9
9
  protected target: ILeaf
10
10
  protected selector: ISelector
11
11
 
12
- protected findList: ILeaf[]
12
+ protected findList: ILeafList
13
13
  protected exclude: ILeafList
14
14
 
15
15
  protected point: IRadiusPointData
@@ -29,13 +29,13 @@ export class Picker {
29
29
  this.exclude = options.exclude || null
30
30
 
31
31
  this.point = { x: hitPoint.x, y: hitPoint.y, radiusX: hitRadius, radiusY: hitRadius }
32
- this.findList = options.findList || []
32
+ this.findList = new LeafList(options.findList)
33
33
 
34
34
  // path
35
- if (!options.findList) this.eachFind(target.children, target.__onlyHitMask)
35
+ if (!options.findList) this.hitBranch(target) // 包含through元素
36
36
 
37
- const list = this.findList
38
- const leaf = this.getBestMatchLeaf()
37
+ const { list } = this.findList
38
+ const leaf = this.getBestMatchLeaf(list, options.bottomList, ignoreHittable)
39
39
  const path = ignoreHittable ? this.getPath(leaf) : this.getHitablePath(leaf)
40
40
 
41
41
  this.clear()
@@ -43,22 +43,29 @@ export class Picker {
43
43
  return through ? { path, target: leaf, throughPath: list.length ? this.getThroughPath(list) : path } : { path, target: leaf }
44
44
  }
45
45
 
46
- public getBestMatchLeaf(): ILeaf {
47
- const { findList: targets } = this
48
- if (targets.length > 1) {
46
+ public getBestMatchLeaf(list: ILeaf[], bottomList: IPickBottom[], ignoreHittable: boolean): ILeaf {
47
+ if (list.length) {
49
48
  let find: ILeaf
50
- this.findList = []
49
+ this.findList = new LeafList()
51
50
  const { x, y } = this.point
52
51
  const point = { x, y, radiusX: 0, radiusY: 0 }
53
- for (let i = 0, len = targets.length; i < len; i++) {
54
- find = targets[i]
55
- if (LeafHelper.worldHittable(find)) {
52
+ for (let i = 0, len = list.length; i < len; i++) {
53
+ find = list[i]
54
+ if (ignoreHittable || LeafHelper.worldHittable(find)) {
56
55
  this.hitChild(find, point)
57
- if (this.findList.length) return this.findList[0]
56
+ if (this.findList.length) return this.findList.list[0]
58
57
  }
59
58
  }
60
59
  }
61
- return targets[0]
60
+
61
+ if (bottomList) { // 底部虚拟元素
62
+ for (let i = 0, len = bottomList.length; i < len; i++) {
63
+ this.hitChild(bottomList[i].target, this.point, bottomList[i].proxy)
64
+ if (this.findList.length) return this.findList.list[0]
65
+ }
66
+ }
67
+
68
+ return list[0]
62
69
  }
63
70
 
64
71
  public getPath(leaf: ILeaf): LeafList {
@@ -104,6 +111,9 @@ export class Picker {
104
111
  return throughPath
105
112
  }
106
113
 
114
+ protected hitBranch(branch: ILeaf): void {
115
+ this.eachFind(branch.children, branch.__onlyHitMask)
116
+ }
107
117
 
108
118
  protected eachFind(children: ILeaf[], hitMask: boolean): void {
109
119
  let child: ILeaf, hit: boolean
@@ -124,9 +134,9 @@ export class Picker {
124
134
  }
125
135
  }
126
136
 
127
- protected hitChild(child: ILeaf, point: IRadiusPointData): void {
137
+ protected hitChild(child: ILeaf, point: IRadiusPointData, proxy?: ILeaf): void {
128
138
  if (this.exclude && this.exclude.has(child)) return
129
- if (child.__hitWorld(point)) this.findList.push(child)
139
+ if (child.__hitWorld(point)) this.findList.add(proxy || child)
130
140
  }
131
141
 
132
142
  protected clear(): void {
package/types/index.d.ts CHANGED
@@ -1,20 +1,21 @@
1
- import { ILeaf, ISelector, ILeafList, IRadiusPointData, IPointData, IPickOptions, IPickResult, ISelectorProxy, ISelectorConfig, ILeafMap, IEventListenerId, IFindMethod } from '@leafer/interface';
1
+ import { ILeaf, ISelector, ILeafList, IRadiusPointData, IPointData, IPickOptions, IPickResult, IPickBottom, ISelectorProxy, ISelectorConfig, ILeafMap, IEventListenerId, IFindMethod } from '@leafer/interface';
2
2
  import { LeafList, ChildEvent, PropertyEvent } from '@leafer/core';
3
3
 
4
4
  declare class Picker {
5
5
  protected target: ILeaf;
6
6
  protected selector: ISelector;
7
- protected findList: ILeaf[];
7
+ protected findList: ILeafList;
8
8
  protected exclude: ILeafList;
9
9
  protected point: IRadiusPointData;
10
10
  constructor(target: ILeaf, selector: ISelector);
11
11
  getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult;
12
- getBestMatchLeaf(): ILeaf;
12
+ getBestMatchLeaf(list: ILeaf[], bottomList: IPickBottom[], ignoreHittable: boolean): ILeaf;
13
13
  getPath(leaf: ILeaf): LeafList;
14
14
  getHitablePath(leaf: ILeaf): LeafList;
15
15
  getThroughPath(list: ILeaf[]): LeafList;
16
+ protected hitBranch(branch: ILeaf): void;
16
17
  protected eachFind(children: ILeaf[], hitMask: boolean): void;
17
- protected hitChild(child: ILeaf, point: IRadiusPointData): void;
18
+ protected hitChild(child: ILeaf, point: IRadiusPointData, proxy?: ILeaf): void;
18
19
  protected clear(): void;
19
20
  destroy(): void;
20
21
  }