@leafer/selector 1.0.0-alpha.1 → 1.0.0-alpha.21

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,11 +1,13 @@
1
1
  {
2
2
  "name": "@leafer/selector",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.21",
4
4
  "description": "@leafer/selector",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
7
7
  "main": "src/index.ts",
8
- "files": ["src"],
8
+ "files": [
9
+ "src"
10
+ ],
9
11
  "repository": {
10
12
  "type": "git",
11
13
  "url": "https://github.com/leaferjs/leafer.git"
@@ -17,11 +19,11 @@
17
19
  "leaferjs"
18
20
  ],
19
21
  "dependencies": {
20
- "@leafer/event": "1.0.0-alpha.1",
21
- "@leafer/math": "1.0.0-alpha.1",
22
- "@leafer/list": "1.0.0-alpha.1"
22
+ "@leafer/event": "1.0.0-alpha.21",
23
+ "@leafer/math": "1.0.0-alpha.21",
24
+ "@leafer/list": "1.0.0-alpha.21"
23
25
  },
24
26
  "devDependencies": {
25
- "@leafer/interface": "1.0.0-alpha.1"
27
+ "@leafer/interface": "1.0.0-alpha.21"
26
28
  }
27
29
  }
package/src/PathFinder.ts CHANGED
@@ -24,7 +24,7 @@ export class PathFinder {
24
24
 
25
25
  public getHitPointPath(hitPoint: IPointData, hitRadius: number, options?: ISelectPathOptions): ISelectPathResult {
26
26
  const through = options ? options.through : false
27
- this.exclude = options ? options.exclude : undefined
27
+ this.exclude = options ? options.exclude : null
28
28
 
29
29
  this.isStop = false
30
30
  this.point = { x: hitPoint.x, y: hitPoint.y, radiusX: hitRadius, radiusY: hitRadius }
@@ -69,17 +69,14 @@ export class PathFinder {
69
69
  const { point } = this, len = children.length
70
70
  for (let i = len - 1; i > -1; i--) {
71
71
  child = children[i]
72
- if (child.__interactionOff) continue
72
+ if (child.__.hittable) {
73
+ if (hitRadiusPoint(child.__world, point)) {
74
+ if (child.__isBranch && child.__.hitChildren) this.eachThroughFind(child.children)
73
75
 
74
- if (hitRadiusPoint(child.__world, point)) {
75
- if (child.__isBranch) {
76
- child.__childrenInteractionOff || this.eachThroughFind(child.children)
76
+ if (this.exclude && this.exclude.has(child)) continue
77
+ if (child.__hitWorld(point)) this.throughPath.push(child)
77
78
  }
78
-
79
- if (this.exclude && this.exclude.has(child)) continue
80
- if (child.__hitWorld(point)) this.throughPath.push(child)
81
79
  }
82
-
83
80
  }
84
81
  }
85
82
 
@@ -88,23 +85,23 @@ export class PathFinder {
88
85
  const { point } = this, len = children.length
89
86
  for (let i = len - 1; i > -1; i--) {
90
87
  child = children[i]
91
- if (child.__interactionOff) continue
88
+ if (child.__.hittable) {
89
+ if (hitRadiusPoint(child.__world, point)) {
90
+ if (child.__isBranch) {
92
91
 
93
- if (hitRadiusPoint(child.__world, point)) {
94
- if (child.__isBranch) {
92
+ if (child.__.hitChildren) this.eachFind(child.children)
95
93
 
96
- child.__childrenInteractionOff || this.eachFind(child.children)
94
+ if (child.__isBranchLeaf) { // 填充了背景色的Group, 如画板/Frame元素
95
+ if (!this.isStop) this.hitChild(child, point)
96
+ }
97
97
 
98
- if (child.__isBranchLeaf) { // 填充了背景色的Group, 如画板/Frame元素
99
- if (!this.isStop) this.hitChild(child, point)
98
+ } else {
99
+ this.hitChild(child, point)
100
100
  }
101
-
102
- } else {
103
- this.hitChild(child, point)
104
101
  }
105
- }
106
102
 
107
- if (this.isStop) break
103
+ if (this.isStop) break
104
+ }
108
105
  }
109
106
  }
110
107
 
@@ -117,15 +114,15 @@ export class PathFinder {
117
114
  }
118
115
 
119
116
  protected clear(): void {
120
- this.point = undefined
121
- this.leaf = undefined
122
- this.throughPath = undefined
123
- this.exclude = undefined
117
+ this.point = null
118
+ this.leaf = null
119
+ this.throughPath = null
120
+ this.exclude = null
124
121
  }
125
122
 
126
123
  public destroy(): void {
127
- this.target = undefined
128
- this.selector = undefined
124
+ this.target = null
125
+ this.selector = null
129
126
  }
130
127
 
131
128
  }
package/src/Selector.ts CHANGED
@@ -13,38 +13,22 @@ interface IFind {
13
13
  export class Selector implements ISelector {
14
14
 
15
15
  public target: ILeaf
16
- protected pathFinder: PathFinder
17
-
18
16
  public defaultPath: ILeafList
19
17
 
20
- protected eventIds: IEventListenerId[]
18
+ protected pathFinder: PathFinder
21
19
 
22
20
  protected innerIdList: ILeafMap = {}
23
21
  protected idList: ILeafMap = {}
24
22
  protected classNameList: ILeafArrayMap = {}
25
23
  protected tagNameList: ILeafArrayMap = {}
26
24
 
25
+ protected __eventIds: IEventListenerId[]
26
+
27
27
  constructor(target: ILeaf) {
28
28
  this.target = target
29
29
  this.defaultPath = new LeafList(target)
30
30
  this.pathFinder = new PathFinder(target, this)
31
- this.listenEvents()
32
- }
33
-
34
- protected listenEvents(): void {
35
- this.eventIds = [
36
- this.target.on__(ChildEvent.REMOVE, this.onRemoveChild, this)
37
- ]
38
- }
39
-
40
- protected removeListenEvents(): void {
41
- this.target.off__(this.eventIds)
42
- }
43
-
44
- protected onRemoveChild(event: ChildEvent): void {
45
- const target = event.target as ILeaf
46
- if (this.idList[target.id]) this.idList[target.id] = undefined
47
- if (this.innerIdList[target.id]) this.innerIdList[target.innerId] = undefined
31
+ this.__listenEvents()
48
32
  }
49
33
 
50
34
  public getHitPointPath(hitPoint: IPointData, hitRadius: number, options?: ISelectPathOptions): ISelectPathResult {
@@ -128,17 +112,34 @@ export class Selector implements ISelector {
128
112
  }
129
113
  }
130
114
 
115
+ protected __onRemoveChild(event: ChildEvent): void {
116
+ const target = event.target as ILeaf
117
+ if (this.idList[target.id]) this.idList[target.id] = null
118
+ if (this.innerIdList[target.id]) this.innerIdList[target.innerId] = null
119
+ }
120
+
121
+
122
+ protected __listenEvents(): void {
123
+ this.__eventIds = [
124
+ this.target.on__(ChildEvent.REMOVE, this.__onRemoveChild, this)
125
+ ]
126
+ }
127
+
128
+ protected __removeListenEvents(): void {
129
+ this.target.off__(this.__eventIds)
130
+ }
131
+
131
132
  public destroy(): void {
132
133
  if (this.target) {
133
- this.removeListenEvents()
134
+ this.__removeListenEvents()
134
135
  this.pathFinder.destroy()
135
136
 
136
- this.target = undefined
137
- this.pathFinder = undefined
138
- this.innerIdList = undefined
139
- this.idList = undefined
140
- this.classNameList = undefined
141
- this.tagNameList = undefined
137
+ this.target = null
138
+ this.pathFinder = null
139
+ this.innerIdList = null
140
+ this.idList = null
141
+ this.classNameList = null
142
+ this.tagNameList = null
142
143
  }
143
144
  }
144
145