@leafer/selector
Advanced tools
+3
-3
| { | ||
| "name": "@leafer/selector", | ||
| "version": "1.8.0", | ||
| "version": "1.9.0", | ||
| "description": "@leafer/selector", | ||
@@ -25,7 +25,7 @@ "author": "Chao (Leafer) Wan", | ||
| "dependencies": { | ||
| "@leafer/core": "1.8.0" | ||
| "@leafer/core": "1.9.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@leafer/interface": "1.8.0" | ||
| "@leafer/interface": "1.9.0" | ||
| } | ||
| } |
+34
-9
@@ -1,2 +0,2 @@ | ||
| import { ILeaf, ILeafList, IPointData, IRadiusPointData, IPickResult, IPickOptions, ISelector, IPickBottom } from '@leafer/interface' | ||
| import { ILeaf, ILeafList, IPointData, IRadiusPointData, IPickResult, IPickOptions, ISelector, IPickBottom, IPicker } from '@leafer/interface' | ||
| import { BoundsHelper, LeafList, LeafHelper } from '@leafer/core' | ||
@@ -7,3 +7,3 @@ | ||
| export class Picker { | ||
| export class Picker implements IPicker { | ||
@@ -36,3 +36,3 @@ protected target?: ILeaf | ||
| // path | ||
| if (!options.findList) this.hitBranch(target) // 包含through元素 | ||
| if (!options.findList) this.hitBranch(target.isBranchLeaf ? { children: [target] } as ILeaf : target) // 包含through元素 | ||
@@ -48,6 +48,11 @@ const { list } = this.findList | ||
| public hitPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): boolean { | ||
| return !!this.getByPoint(hitPoint, hitRadius, options).target // 后期需进行优化 !!! | ||
| } | ||
| public getBestMatchLeaf(list: ILeaf[], bottomList: IPickBottom[], ignoreHittable: boolean): ILeaf { | ||
| const findList = this.findList = new LeafList() | ||
| if (list.length) { | ||
| let find: ILeaf | ||
| this.findList = new LeafList() | ||
| const { x, y } = this.point | ||
@@ -59,3 +64,9 @@ const point = { x, y, radiusX: 0, radiusY: 0 } | ||
| this.hitChild(find, point) | ||
| if (this.findList.length) return this.findList.list[0] | ||
| if (findList.length) { | ||
| if (find.isBranchLeaf && list.some(item => item !== find && LeafHelper.hasParent(item, find))) { | ||
| findList.reset() | ||
| break // Frame / Box 同时碰撞到子元素时,忽略自身,优先选中子元素 | ||
| } | ||
| return findList.list[0] | ||
| } | ||
| } | ||
@@ -65,10 +76,10 @@ } | ||
| if (bottomList) { // 底部虚拟元素 | ||
| if (bottomList) { // 底部虚拟元素,一般为编辑器的虚拟框 | ||
| for (let i = 0, len = bottomList.length; i < len; i++) { | ||
| this.hitChild(bottomList[i].target, this.point, bottomList[i].proxy) | ||
| if (this.findList.length) return this.findList.list[0] | ||
| if (findList.length) return findList.list[0] | ||
| } | ||
| } | ||
| return list[0] | ||
| return ignoreHittable ? list[0] : list.find(item => LeafHelper.worldHittable(item)) | ||
| } | ||
@@ -146,3 +157,17 @@ | ||
| const { parent } = child | ||
| if (parent && parent.__hasMask && !child.__.mask && !parent.children.some(item => item.__.mask && item.__hitWorld(point))) return | ||
| if (parent && parent.__hasMask && !child.__.mask) { | ||
| let findMasks: ILeaf[] = [], item: ILeaf | ||
| const { children } = parent | ||
| for (let i = 0, len = children.length; i < len; i++) { | ||
| item = children[i] | ||
| if (item.__.mask) findMasks.push(item) | ||
| if (item === child) { | ||
| if (findMasks && !findMasks.every(value => value.__hitWorld(point))) return // 遮罩上层的元素,与遮罩相交的区域才能响应事件 | ||
| break | ||
| } | ||
| } | ||
| } | ||
| this.findList.add(proxy || child) | ||
@@ -149,0 +174,0 @@ } |
+4
-0
@@ -29,2 +29,6 @@ import { ILeaf, ISelector, ISelectorProxy, IPickResult, IPickOptions, IPointData, ISelectorConfig, IFinder, IFindMethod, IFindCondition, IPicker } from '@leafer/interface' | ||
| public hitPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): boolean { | ||
| return this.picker.hitPoint(hitPoint, hitRadius, options) | ||
| } | ||
| // @leafer-in/find will rewrite | ||
@@ -31,0 +35,0 @@ public getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[] { |
+3
-1
@@ -12,2 +12,3 @@ import { ISelector, ILeaf, ISelectorProxy, ISelectorConfig, IPicker, IFinder, IPointData, IPickOptions, IPickResult, IFindCondition, IFindMethod, ILeafList, IRadiusPointData, IPickBottom } from '@leafer/interface'; | ||
| getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult; | ||
| hitPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): boolean; | ||
| getBy(condition: number | string | IFindCondition | IFindMethod, branch?: ILeaf, one?: boolean, options?: any): ILeaf | ILeaf[]; | ||
@@ -17,3 +18,3 @@ destroy(): void; | ||
| declare class Picker { | ||
| declare class Picker implements IPicker { | ||
| protected target?: ILeaf; | ||
@@ -26,2 +27,3 @@ protected selector: ISelector; | ||
| getByPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): IPickResult; | ||
| hitPoint(hitPoint: IPointData, hitRadius: number, options?: IPickOptions): boolean; | ||
| getBestMatchLeaf(list: ILeaf[], bottomList: IPickBottom[], ignoreHittable: boolean): ILeaf; | ||
@@ -28,0 +30,0 @@ getPath(leaf: ILeaf): LeafList; |
11909
15.51%211
13.44%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated