@leafer/selector 1.7.0 → 1.9.0
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 +3 -3
- package/src/Picker.ts +34 -9
- package/src/Selector.ts +4 -0
- package/types/index.d.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/selector",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
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.
|
|
25
|
+
"@leafer/core": "1.9.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.
|
|
28
|
+
"@leafer/interface": "1.9.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/Picker.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ILeaf, ILeafList, IPointData, IRadiusPointData, IPickResult, IPickOptions, ISelector, IPickBottom } from '@leafer/interface'
|
|
1
|
+
import { ILeaf, ILeafList, IPointData, IRadiusPointData, IPickResult, IPickOptions, ISelector, IPickBottom, IPicker } from '@leafer/interface'
|
|
2
2
|
import { BoundsHelper, LeafList, LeafHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
const { hitRadiusPoint } = BoundsHelper
|
|
6
6
|
|
|
7
|
-
export class Picker {
|
|
7
|
+
export class Picker implements IPicker {
|
|
8
8
|
|
|
9
9
|
protected target?: ILeaf
|
|
10
10
|
protected selector: ISelector
|
|
@@ -32,7 +32,7 @@ export class Picker {
|
|
|
32
32
|
this.findList = new LeafList(options.findList)
|
|
33
33
|
|
|
34
34
|
// path
|
|
35
|
-
if (!options.findList) this.hitBranch(target) // 包含through元素
|
|
35
|
+
if (!options.findList) this.hitBranch(target.isBranchLeaf ? { children: [target] } as ILeaf : target) // 包含through元素
|
|
36
36
|
|
|
37
37
|
const { list } = this.findList
|
|
38
38
|
const leaf = this.getBestMatchLeaf(list, options.bottomList, ignoreHittable)
|
|
@@ -43,29 +43,40 @@ 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 hitPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): boolean {
|
|
47
|
+
return !!this.getByPoint(hitPoint, hitRadius, options).target // 后期需进行优化 !!!
|
|
48
|
+
}
|
|
49
|
+
|
|
46
50
|
public getBestMatchLeaf(list: ILeaf[], bottomList: IPickBottom[], ignoreHittable: boolean): ILeaf {
|
|
51
|
+
const findList = this.findList = new LeafList()
|
|
52
|
+
|
|
47
53
|
if (list.length) {
|
|
48
54
|
let find: ILeaf
|
|
49
|
-
this.findList = new LeafList()
|
|
50
55
|
const { x, y } = this.point
|
|
51
56
|
const point = { x, y, radiusX: 0, radiusY: 0 }
|
|
52
57
|
for (let i = 0, len = list.length; i < len; i++) {
|
|
53
58
|
find = list[i]
|
|
54
59
|
if (ignoreHittable || LeafHelper.worldHittable(find)) {
|
|
55
60
|
this.hitChild(find, point)
|
|
56
|
-
if (
|
|
61
|
+
if (findList.length) {
|
|
62
|
+
if (find.isBranchLeaf && list.some(item => item !== find && LeafHelper.hasParent(item, find))) {
|
|
63
|
+
findList.reset()
|
|
64
|
+
break // Frame / Box 同时碰撞到子元素时,忽略自身,优先选中子元素
|
|
65
|
+
}
|
|
66
|
+
return findList.list[0]
|
|
67
|
+
}
|
|
57
68
|
}
|
|
58
69
|
}
|
|
59
70
|
}
|
|
60
71
|
|
|
61
|
-
if (bottomList) { //
|
|
72
|
+
if (bottomList) { // 底部虚拟元素,一般为编辑器的虚拟框
|
|
62
73
|
for (let i = 0, len = bottomList.length; i < len; i++) {
|
|
63
74
|
this.hitChild(bottomList[i].target, this.point, bottomList[i].proxy)
|
|
64
|
-
if (
|
|
75
|
+
if (findList.length) return findList.list[0]
|
|
65
76
|
}
|
|
66
77
|
}
|
|
67
78
|
|
|
68
|
-
return list[0]
|
|
79
|
+
return ignoreHittable ? list[0] : list.find(item => LeafHelper.worldHittable(item))
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
public getPath(leaf: ILeaf): LeafList {
|
|
@@ -138,7 +149,21 @@ export class Picker {
|
|
|
138
149
|
if (this.exclude && this.exclude.has(child)) return
|
|
139
150
|
if (child.__hitWorld(point)) {
|
|
140
151
|
const { parent } = child
|
|
141
|
-
if (parent && parent.__hasMask && !child.__.mask
|
|
152
|
+
if (parent && parent.__hasMask && !child.__.mask) {
|
|
153
|
+
|
|
154
|
+
let findMasks: ILeaf[] = [], item: ILeaf
|
|
155
|
+
const { children } = parent
|
|
156
|
+
|
|
157
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
158
|
+
item = children[i]
|
|
159
|
+
if (item.__.mask) findMasks.push(item)
|
|
160
|
+
if (item === child) {
|
|
161
|
+
if (findMasks && !findMasks.every(value => value.__hitWorld(point))) return // 遮罩上层的元素,与遮罩相交的区域才能响应事件
|
|
162
|
+
break
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
}
|
|
142
167
|
this.findList.add(proxy || child)
|
|
143
168
|
}
|
|
144
169
|
}
|
package/src/Selector.ts
CHANGED
|
@@ -26,6 +26,10 @@ export class Selector implements ISelector {
|
|
|
26
26
|
return picker.getByPoint(hitPoint, hitRadius, options)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
public hitPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): boolean {
|
|
30
|
+
return this.picker.hitPoint(hitPoint, hitRadius, options)
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
// @leafer-in/find will rewrite
|
|
30
34
|
public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] {
|
|
31
35
|
return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need('find')
|
package/types/index.d.ts
CHANGED
|
@@ -9,11 +9,12 @@ declare class Selector implements ISelector {
|
|
|
9
9
|
finder?: IFinder;
|
|
10
10
|
constructor(target: ILeaf, userConfig?: ISelectorConfig);
|
|
11
11
|
getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult;
|
|
12
|
+
hitPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): boolean;
|
|
12
13
|
getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[];
|
|
13
14
|
destroy(): void;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
declare class Picker {
|
|
17
|
+
declare class Picker implements IPicker {
|
|
17
18
|
protected target?: ILeaf;
|
|
18
19
|
protected selector: ISelector;
|
|
19
20
|
protected findList: ILeafList;
|
|
@@ -21,6 +22,7 @@ declare class Picker {
|
|
|
21
22
|
protected point: IRadiusPointData;
|
|
22
23
|
constructor(target: ILeaf, selector: ISelector);
|
|
23
24
|
getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult;
|
|
25
|
+
hitPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): boolean;
|
|
24
26
|
getBestMatchLeaf(list: ILeaf[], bottomList: IPickBottom[], ignoreHittable: boolean): ILeaf;
|
|
25
27
|
getPath(leaf: ILeaf): LeafList;
|
|
26
28
|
getHitablePath(leaf: ILeaf): LeafList;
|