@leafer-ui/interaction 1.0.0-rc.18 → 1.0.0-rc.20
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 +6 -5
- package/src/Dragger.ts +20 -14
- package/src/HitCanvasManager.ts +17 -9
- package/src/Interaction.ts +64 -43
- package/src/config.ts +1 -0
- package/src/index.ts +25 -1
- package/types/index.d.ts +17 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/interaction",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.20",
|
|
4
4
|
"description": "@leafer-ui/interaction",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.0.0-rc.
|
|
26
|
-
"@leafer-ui/draw": "1.0.0-rc.
|
|
27
|
-
"@leafer-ui/event": "1.0.0-rc.
|
|
25
|
+
"@leafer/core": "1.0.0-rc.20",
|
|
26
|
+
"@leafer-ui/draw": "1.0.0-rc.20",
|
|
27
|
+
"@leafer-ui/event": "1.0.0-rc.20"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@leafer/interface": "1.0.0-rc.
|
|
30
|
+
"@leafer/interface": "1.0.0-rc.20",
|
|
31
|
+
"@leafer-ui/interface": "1.0.0-rc.20"
|
|
31
32
|
}
|
|
32
33
|
}
|
package/src/Dragger.ts
CHANGED
|
@@ -56,7 +56,7 @@ export class Dragger {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
if (!this.moving && canDrag) {
|
|
59
|
-
if (this.moving = interaction.
|
|
59
|
+
if (this.moving = interaction.canMove(this.downData) || interaction.isHoldRightKey || interaction.isMobileDragEmpty) interaction.emit(MoveEvent.START, this.dragData)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (!this.moving) {
|
|
@@ -109,7 +109,7 @@ export class Dragger {
|
|
|
109
109
|
const list = this.getList()
|
|
110
110
|
if (list.length && running) {
|
|
111
111
|
const { moveX, moveY } = this.dragData
|
|
112
|
-
list.forEach(leaf => leaf.moveWorld(moveX, moveY))
|
|
112
|
+
list.forEach(leaf => leaf.draggable && leaf.moveWorld(moveX, moveY))
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -141,7 +141,7 @@ export class Dragger {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
public dragEnd(data: IPointerEvent, speed?: number): void {
|
|
144
|
-
if (!this.
|
|
144
|
+
if (!this.dragging && !this.moving) return
|
|
145
145
|
|
|
146
146
|
const { moveX, moveY } = this.dragData
|
|
147
147
|
if (this.interaction.config.move.dragAnimate && this.canAnimate && this.moving && (Math.abs(moveX) > 1 || Math.abs(moveY) > 1)) {
|
|
@@ -165,12 +165,19 @@ export class Dragger {
|
|
|
165
165
|
if (throughPath) endDragData.throughPath = throughPath
|
|
166
166
|
endDragData.path = path
|
|
167
167
|
|
|
168
|
-
if (this.moving)
|
|
168
|
+
if (this.moving) {
|
|
169
|
+
this.moving = false
|
|
170
|
+
interaction.emit(MoveEvent.END, endDragData)
|
|
171
|
+
}
|
|
172
|
+
|
|
169
173
|
if (this.dragging) {
|
|
174
|
+
const dropList = this.getList()
|
|
175
|
+
|
|
176
|
+
this.dragging = false
|
|
170
177
|
interaction.emit(DragEvent.END, endDragData)
|
|
171
178
|
|
|
172
|
-
this.swipe(data, endDragData)
|
|
173
|
-
this.drop(data)
|
|
179
|
+
this.swipe(data, downData, dragData, endDragData)
|
|
180
|
+
this.drop(data, dropList, this.dragEnterPath)
|
|
174
181
|
}
|
|
175
182
|
|
|
176
183
|
this.autoMoveCancel()
|
|
@@ -185,24 +192,23 @@ export class Dragger {
|
|
|
185
192
|
}
|
|
186
193
|
|
|
187
194
|
|
|
188
|
-
protected swipe(data: IPointerEvent, endDragData: IDragEvent): void {
|
|
189
|
-
const { interaction
|
|
195
|
+
protected swipe(data: IPointerEvent, downData: IPointerEvent, dragData: IDragEvent, endDragData: IDragEvent): void {
|
|
196
|
+
const { interaction } = this
|
|
190
197
|
if (PointHelper.getDistance(downData, data) > interaction.config.pointer.swipeDistance) {
|
|
191
|
-
const swipeData = getSwipeEventData(downData,
|
|
198
|
+
const swipeData = getSwipeEventData(downData, dragData, endDragData)
|
|
192
199
|
this.interaction.emit(swipeData.type, swipeData)
|
|
193
200
|
}
|
|
194
201
|
}
|
|
195
202
|
|
|
196
|
-
protected drop(data: IPointerEvent): void {
|
|
197
|
-
const dropData = getDropEventData(data,
|
|
198
|
-
dropData.path =
|
|
203
|
+
protected drop(data: IPointerEvent, dropList: ILeafList, dragEnterPath: ILeafList): void {
|
|
204
|
+
const dropData = getDropEventData(data, dropList, DragEvent.data)
|
|
205
|
+
dropData.path = dragEnterPath
|
|
199
206
|
this.interaction.emit(DropEvent.DROP, dropData)
|
|
200
|
-
this.interaction.emit(DragEvent.LEAVE, data,
|
|
207
|
+
this.interaction.emit(DragEvent.LEAVE, data, dragEnterPath)
|
|
201
208
|
}
|
|
202
209
|
|
|
203
210
|
protected dragReset(): void {
|
|
204
211
|
DragEvent.list = DragEvent.data = this.dragableList = this.dragData = this.downData = this.dragOverPath = this.dragEnterPath = null
|
|
205
|
-
this.dragging = this.moving = false
|
|
206
212
|
}
|
|
207
213
|
|
|
208
214
|
|
package/src/HitCanvasManager.ts
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IHitCanvasManager, ILeaf, IHitCanvas, ILeafList, ILeaferCanvasConfig } from '@leafer/interface'
|
|
2
2
|
import { CanvasManager, LeafList, Creator } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export class HitCanvasManager extends CanvasManager implements IHitCanvasManager {
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
protected imageTypeList: ILeafList = new LeafList()
|
|
7
|
+
public maxTotal = 1000 // 最多缓存多少张画布
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
protected pathList: ILeafList = new LeafList()
|
|
10
|
+
protected pixelList: ILeafList = new LeafList()
|
|
11
|
+
|
|
12
|
+
public getPixelType(leaf: ILeaf, config: ILeaferCanvasConfig): IHitCanvas {
|
|
13
|
+
this.__autoClear()
|
|
14
|
+
this.pixelList.add(leaf)
|
|
15
|
+
return Creator.hitCanvas(config)
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
public getPathType(leaf: ILeaf): IHitCanvas {
|
|
16
|
-
this.
|
|
19
|
+
this.__autoClear()
|
|
20
|
+
this.pathList.add(leaf)
|
|
17
21
|
return Creator.hitCanvas()
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
public clearImageType(): void {
|
|
21
|
-
this.__clearLeafList(this.
|
|
25
|
+
this.__clearLeafList(this.pixelList)
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
public clearPathType(): void {
|
|
25
|
-
this.__clearLeafList(this.
|
|
29
|
+
this.__clearLeafList(this.pathList)
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
protected __clearLeafList(leafList: ILeafList): void {
|
|
@@ -37,6 +41,10 @@ export class HitCanvasManager extends CanvasManager implements IHitCanvasManager
|
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
|
|
44
|
+
protected __autoClear(): void {
|
|
45
|
+
if (this.pathList.length + this.pixelList.length > this.maxTotal) this.clear()
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
public clear(): void {
|
|
41
49
|
this.clearPathType()
|
|
42
50
|
this.clearImageType()
|
package/src/Interaction.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IUIEvent, IPointerEvent, ILeaf, IInteraction, IInteractionConfig, ILeafList, IMoveEvent, IZoomEvent, IRotateEvent, ISelector, IBounds, IEventListenerId, IInteractionCanvas, ITimer, IKeepTouchData, IKeyEvent, IPickOptions, ICursorType, IBooleanMap } from '@leafer/interface'
|
|
2
2
|
import { LeaferEvent, ResizeEvent, LeafList, Bounds, PointHelper, DataHelper } from '@leafer/core'
|
|
3
3
|
|
|
4
|
+
import { IApp } from '@leafer-ui/interface'
|
|
4
5
|
import { PointerEvent, DropEvent, KeyEvent, PointerButton, Keyboard } from '@leafer-ui/event'
|
|
5
6
|
|
|
6
7
|
import { Transformer } from './Transformer'
|
|
@@ -21,9 +22,13 @@ export class InteractionBase implements IInteraction {
|
|
|
21
22
|
public running: boolean
|
|
22
23
|
|
|
23
24
|
public get dragging(): boolean { return this.dragger.dragging }
|
|
24
|
-
public get
|
|
25
|
+
public get moveMode(): boolean { return this.config.move.drag || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty }
|
|
26
|
+
|
|
27
|
+
public get isDragEmpty(): boolean { return this.config.move.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData)) }
|
|
28
|
+
public get isMobileDragEmpty(): boolean { return this.config.move.dragEmpty && !this.config.pointer.hover && this.downData && this.isTreePath(this.downData) }
|
|
29
|
+
public get isHoldMiddleKey(): boolean { return this.config.move.holdMiddleKey && this.downData && PointerButton.middle(this.downData) }
|
|
25
30
|
public get isHoldRightKey(): boolean { return this.config.move.holdRightKey && this.downData && PointerButton.right(this.downData) }
|
|
26
|
-
public get
|
|
31
|
+
public get isHoldSpaceKey(): boolean { return this.config.move.holdSpaceKey && Keyboard.isHoldSpaceKey() }
|
|
27
32
|
|
|
28
33
|
public config: IInteractionConfig = config
|
|
29
34
|
|
|
@@ -33,12 +38,10 @@ export class InteractionBase implements IInteraction {
|
|
|
33
38
|
public shrinkCanvasBounds: IBounds
|
|
34
39
|
|
|
35
40
|
public downData: IPointerEvent
|
|
36
|
-
protected oldDownData?: IPointerEvent // 通过updateDownData强制更新下来的数据
|
|
37
41
|
public hoverData: IPointerEvent
|
|
38
42
|
public focusData: ILeaf
|
|
39
43
|
|
|
40
44
|
public downTime: number
|
|
41
|
-
protected downed: boolean
|
|
42
45
|
|
|
43
46
|
protected overPath: LeafList
|
|
44
47
|
protected enterPath: LeafList
|
|
@@ -90,24 +93,22 @@ export class InteractionBase implements IInteraction {
|
|
|
90
93
|
PointerButton.defaultLeft(data)
|
|
91
94
|
|
|
92
95
|
this.updateDownData(data)
|
|
93
|
-
|
|
96
|
+
this.checkPath(data, useDefaultPath)
|
|
94
97
|
|
|
95
98
|
this.downTime = Date.now()
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.emit(PointerEvent.DOWN, data)
|
|
100
|
+
this.emit(PointerEvent.BEFORE_DOWN, data) // downData maybe changed
|
|
101
|
+
this.emit(PointerEvent.DOWN, data)
|
|
100
102
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
103
|
+
if (PointerButton.left(data)) {
|
|
104
|
+
this.tapWait()
|
|
105
|
+
this.longPressWait(data)
|
|
106
|
+
} else if (PointerButton.right(data)) {
|
|
107
|
+
this.waitMenuTap = true
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
this.dragger.setDragData(data) // must after down event
|
|
110
|
-
this.updateCursor(data)
|
|
111
|
+
if (!this.isHoldRightKey) this.updateCursor(data)
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
public pointerMove(data?: IPointerEvent): void {
|
|
@@ -119,20 +120,17 @@ export class InteractionBase implements IInteraction {
|
|
|
119
120
|
|
|
120
121
|
const hit = this.canvas.bounds.hitPoint(data)
|
|
121
122
|
if (hit || downData) {
|
|
122
|
-
if (hit && !downData && PointerButton.left(data)) {
|
|
123
|
-
this.pointerDown(data, true) // 从外部拖拽内容进入,需要先模拟down事件
|
|
124
|
-
this.dragger.canDragOut = false
|
|
125
|
-
}
|
|
126
123
|
this.pointerMoveReal(data)
|
|
127
124
|
if (downData) this.dragger.checkDragOut(data)
|
|
128
125
|
}
|
|
129
126
|
}
|
|
130
127
|
|
|
131
128
|
public pointerMoveReal(data: IPointerEvent): void {
|
|
129
|
+
const { dragHover, dragDistance } = this.config.pointer
|
|
132
130
|
this.emit(PointerEvent.BEFORE_MOVE, data, this.defaultPath)
|
|
133
131
|
|
|
134
132
|
if (this.downData) {
|
|
135
|
-
const canDrag = PointHelper.getDistance(this.downData, data) >
|
|
133
|
+
const canDrag = PointHelper.getDistance(this.downData, data) > dragDistance
|
|
136
134
|
if (canDrag) {
|
|
137
135
|
if (this.waitTap) this.pointerWaitCancel()
|
|
138
136
|
this.waitMenuTap = false
|
|
@@ -143,11 +141,11 @@ export class InteractionBase implements IInteraction {
|
|
|
143
141
|
|
|
144
142
|
if (!this.dragger.moving) {
|
|
145
143
|
this.updateHoverData(data)
|
|
146
|
-
|
|
144
|
+
this.checkPath(data)
|
|
147
145
|
|
|
148
146
|
this.emit(PointerEvent.MOVE, data)
|
|
149
147
|
|
|
150
|
-
if (!(this.dragging && !
|
|
148
|
+
if (!(this.dragging && !dragHover)) this.pointerHover(data)
|
|
151
149
|
|
|
152
150
|
if (this.dragger.dragging) {
|
|
153
151
|
this.dragger.dragOverOrOut(data)
|
|
@@ -159,35 +157,39 @@ export class InteractionBase implements IInteraction {
|
|
|
159
157
|
}
|
|
160
158
|
|
|
161
159
|
public pointerUp(data?: IPointerEvent): void {
|
|
162
|
-
const { downData
|
|
160
|
+
const { downData } = this
|
|
163
161
|
if (!data) data = downData
|
|
164
162
|
if (!downData) return
|
|
163
|
+
|
|
165
164
|
PointerButton.defaultLeft(data)
|
|
166
165
|
|
|
167
166
|
this.findPath(data)
|
|
167
|
+
const upData = { ...data, path: data.path.clone() }
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
this.downed = false
|
|
171
|
-
this.emit(PointerEvent.BEFORE_UP, data)
|
|
172
|
-
this.emit(PointerEvent.UP, data)
|
|
173
|
-
if (oldDownData) this.emit(PointerEvent.UP, oldDownData, undefined, data.path) // oldDownPath必须触发up
|
|
174
|
-
this.emit(PointerEvent.UP, downData, undefined, data.path) // downPath必须触发up
|
|
169
|
+
data.path.addList(downData.path.list) // downPath必须触发
|
|
175
170
|
|
|
176
|
-
|
|
171
|
+
this.checkPath(data)
|
|
177
172
|
|
|
173
|
+
this.downData = null // must before pointer.up event
|
|
174
|
+
this.emit(PointerEvent.BEFORE_UP, data)
|
|
175
|
+
this.emit(PointerEvent.UP, data)
|
|
176
|
+
|
|
177
|
+
this.touchLeave(data)
|
|
178
|
+
|
|
179
|
+
if (!data.isCancel) {
|
|
178
180
|
this.tap(data)
|
|
179
181
|
this.menuTap(data)
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
this.dragger.dragEnd(data)
|
|
183
185
|
|
|
184
|
-
this.
|
|
185
|
-
|
|
186
|
-
this.updateCursor(data)
|
|
186
|
+
this.updateCursor(upData)
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
public pointerCancel(): void {
|
|
190
|
-
this.
|
|
190
|
+
const data = { ...this.dragger.dragData }
|
|
191
|
+
data.isCancel = true
|
|
192
|
+
this.pointerUp(data)
|
|
191
193
|
}
|
|
192
194
|
|
|
193
195
|
|
|
@@ -257,8 +259,10 @@ export class InteractionBase implements IInteraction {
|
|
|
257
259
|
|
|
258
260
|
// helper
|
|
259
261
|
protected pointerHover(data: IPointerEvent): void {
|
|
260
|
-
this.
|
|
261
|
-
|
|
262
|
+
if (this.config.pointer.hover) {
|
|
263
|
+
this.pointerOverOrOut(data)
|
|
264
|
+
this.pointerEnterOrLeave(data)
|
|
265
|
+
}
|
|
262
266
|
}
|
|
263
267
|
|
|
264
268
|
protected pointerOverOrOut(data: IPointerEvent): void {
|
|
@@ -348,14 +352,31 @@ export class InteractionBase implements IInteraction {
|
|
|
348
352
|
return find.path
|
|
349
353
|
}
|
|
350
354
|
|
|
355
|
+
public isRootPath(data: IPointerEvent): boolean {
|
|
356
|
+
return data && (data.path.list[0] as ILeaf).isLeafer
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
public isTreePath(data: IPointerEvent): boolean {
|
|
360
|
+
const app = this.target.app as IApp
|
|
361
|
+
if (!app || !app.isApp) return false
|
|
362
|
+
return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree)) // 当dragEmpty为true时,在手机端(pointer.hover为false)可以拖动tree层(编辑器选中的元素除外)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
protected checkPath(data: IPointerEvent, useDefaultPath?: boolean): void {
|
|
366
|
+
if (useDefaultPath || this.canMove(data)) data.path = this.defaultPath
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
public canMove(data: IPointerEvent): boolean { // moveMode and path can move
|
|
370
|
+
return this.moveMode && data && data.path.list.every(item => !item.isOutside)
|
|
371
|
+
}
|
|
372
|
+
|
|
351
373
|
|
|
352
374
|
public isDrag(leaf: ILeaf): boolean {
|
|
353
375
|
return this.dragger.getList().has(leaf)
|
|
354
376
|
}
|
|
355
377
|
|
|
356
378
|
public isPress(leaf: ILeaf): boolean {
|
|
357
|
-
|
|
358
|
-
return this.downed && ((downData && downData.path.has(leaf)) || (oldDownData && oldDownData.path.has(leaf)))
|
|
379
|
+
return this.downData && this.downData.path.has(leaf)
|
|
359
380
|
}
|
|
360
381
|
|
|
361
382
|
public isHover(leaf: ILeaf): boolean {
|
|
@@ -376,12 +397,12 @@ export class InteractionBase implements IInteraction {
|
|
|
376
397
|
}
|
|
377
398
|
|
|
378
399
|
|
|
379
|
-
public updateDownData(data?: IPointerEvent, options?: IPickOptions): void {
|
|
400
|
+
public updateDownData(data?: IPointerEvent, options?: IPickOptions, merge?: boolean): void {
|
|
380
401
|
const { downData } = this
|
|
381
|
-
if (!data && downData) data =
|
|
402
|
+
if (!data && downData) data = downData
|
|
382
403
|
if (!data) return
|
|
383
|
-
this.oldDownData = downData
|
|
384
404
|
this.findPath(data, options)
|
|
405
|
+
if (merge && downData) data.path.addList(downData.path.list)
|
|
385
406
|
this.downData = data
|
|
386
407
|
}
|
|
387
408
|
|
|
@@ -393,7 +414,7 @@ export class InteractionBase implements IInteraction {
|
|
|
393
414
|
}
|
|
394
415
|
|
|
395
416
|
public updateCursor(data?: IPointerEvent): void {
|
|
396
|
-
if (this.config.cursor.stop) return
|
|
417
|
+
if (this.config.cursor.stop || !this.config.pointer.hover) return
|
|
397
418
|
|
|
398
419
|
if (!data) {
|
|
399
420
|
this.updateHoverData()
|
|
@@ -402,7 +423,7 @@ export class InteractionBase implements IInteraction {
|
|
|
402
423
|
|
|
403
424
|
if (this.dragger.moving) {
|
|
404
425
|
return this.setCursor('grabbing')
|
|
405
|
-
} else if (this.
|
|
426
|
+
} else if (this.canMove(data)) {
|
|
406
427
|
return this.setCursor(this.downData ? 'grabbing' : 'grab')
|
|
407
428
|
} else if (!data) return
|
|
408
429
|
|
package/src/config.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,4 +2,28 @@ export { InteractionBase } from './Interaction'
|
|
|
2
2
|
export { InteractionHelper } from './InteractionHelper'
|
|
3
3
|
export { MultiTouchHelper } from './MultiTouchHelper'
|
|
4
4
|
export { Cursor } from './Cursor'
|
|
5
|
-
export { HitCanvasManager } from './HitCanvasManager'
|
|
5
|
+
export { HitCanvasManager } from './HitCanvasManager'
|
|
6
|
+
|
|
7
|
+
import { IPointData, IRadiusPointData, IWindingRule } from '@leafer/interface'
|
|
8
|
+
import { LeaferCanvasBase, tempBounds } from '@leafer/core'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const canvas = LeaferCanvasBase.prototype
|
|
12
|
+
|
|
13
|
+
canvas.hitFill = function (point: IPointData, fillRule?: IWindingRule): boolean {
|
|
14
|
+
return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
canvas.hitStroke = function (point: IPointData, strokeWidth?: number): boolean {
|
|
18
|
+
this.strokeWidth = strokeWidth
|
|
19
|
+
return this.context.isPointInStroke(point.x, point.y)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
canvas.hitPixel = function (radiusPoint: IRadiusPointData, offset?: IPointData, scale = 1): boolean { // 画布必须有alpha通道
|
|
23
|
+
let { x, y, radiusX, radiusY } = radiusPoint
|
|
24
|
+
if (offset) x -= offset.x, y -= offset.y
|
|
25
|
+
tempBounds.set(x - radiusX, y - radiusY, radiusX * 2, radiusY * 2).scale(scale).ceil()
|
|
26
|
+
const { data } = this.context.getImageData(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height)
|
|
27
|
+
for (let i = 0, len = data.length; i < len; i += 4) { if (data[i + 3] > 0) return true }
|
|
28
|
+
return data[3] > 0
|
|
29
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer, IDragEvent, IPointerEvent, ILeafList, IFunction, IInteraction, ILeaf, IInteractionCanvas, ISelector, IInteractionConfig, ICursorType, IBounds, IEventListenerId, IBooleanMap, IUIEvent, IKeepTouchData, IKeyEvent, IPickOptions, IPointData, IEvent, IObject, IDropEvent, ISwipeEvent, IMultiTouchData, ICursorTypeMap, IHitCanvasManager,
|
|
1
|
+
import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer, IDragEvent, IPointerEvent, ILeafList, IFunction, IInteraction, ILeaf, IInteractionCanvas, ISelector, IInteractionConfig, ICursorType, IBounds, IEventListenerId, IBooleanMap, IUIEvent, IKeepTouchData, IKeyEvent, IPickOptions, IPointData, IEvent, IObject, IDropEvent, ISwipeEvent, IMultiTouchData, ICursorTypeMap, IHitCanvasManager, ILeaferCanvasConfig, IHitCanvas } from '@leafer/interface';
|
|
2
2
|
import { LeafList, CanvasManager } from '@leafer/core';
|
|
3
3
|
|
|
4
4
|
declare class Transformer {
|
|
@@ -45,8 +45,8 @@ declare class Dragger {
|
|
|
45
45
|
dragEnd(data: IPointerEvent, speed?: number): void;
|
|
46
46
|
protected dragEndReal(data?: IPointerEvent): void;
|
|
47
47
|
protected animate(func?: IFunction, off?: 'off'): void;
|
|
48
|
-
protected swipe(data: IPointerEvent, endDragData: IDragEvent): void;
|
|
49
|
-
protected drop(data: IPointerEvent): void;
|
|
48
|
+
protected swipe(data: IPointerEvent, downData: IPointerEvent, dragData: IDragEvent, endDragData: IDragEvent): void;
|
|
49
|
+
protected drop(data: IPointerEvent, dropList: ILeafList, dragEnterPath: ILeafList): void;
|
|
50
50
|
protected dragReset(): void;
|
|
51
51
|
checkDragOut(data: IPointerEvent): void;
|
|
52
52
|
protected autoMoveOnDragOut(data: IPointerEvent): void;
|
|
@@ -60,19 +60,20 @@ declare class InteractionBase implements IInteraction {
|
|
|
60
60
|
selector: ISelector;
|
|
61
61
|
running: boolean;
|
|
62
62
|
get dragging(): boolean;
|
|
63
|
+
get moveMode(): boolean;
|
|
63
64
|
get isDragEmpty(): boolean;
|
|
65
|
+
get isMobileDragEmpty(): boolean;
|
|
66
|
+
get isHoldMiddleKey(): boolean;
|
|
64
67
|
get isHoldRightKey(): boolean;
|
|
65
|
-
get
|
|
68
|
+
get isHoldSpaceKey(): boolean;
|
|
66
69
|
config: IInteractionConfig;
|
|
67
70
|
cursor: ICursorType | ICursorType[];
|
|
68
71
|
get hitRadius(): number;
|
|
69
72
|
shrinkCanvasBounds: IBounds;
|
|
70
73
|
downData: IPointerEvent;
|
|
71
|
-
protected oldDownData?: IPointerEvent;
|
|
72
74
|
hoverData: IPointerEvent;
|
|
73
75
|
focusData: ILeaf;
|
|
74
76
|
downTime: number;
|
|
75
|
-
protected downed: boolean;
|
|
76
77
|
protected overPath: LeafList;
|
|
77
78
|
protected enterPath: LeafList;
|
|
78
79
|
protected waitMenuTap: boolean;
|
|
@@ -110,12 +111,16 @@ declare class InteractionBase implements IInteraction {
|
|
|
110
111
|
protected touchLeave(data: IPointerEvent): void;
|
|
111
112
|
protected tap(data: IPointerEvent): void;
|
|
112
113
|
findPath(data: IPointerEvent, options?: IPickOptions): ILeafList;
|
|
114
|
+
isRootPath(data: IPointerEvent): boolean;
|
|
115
|
+
isTreePath(data: IPointerEvent): boolean;
|
|
116
|
+
protected checkPath(data: IPointerEvent, useDefaultPath?: boolean): void;
|
|
117
|
+
canMove(data: IPointerEvent): boolean;
|
|
113
118
|
isDrag(leaf: ILeaf): boolean;
|
|
114
119
|
isPress(leaf: ILeaf): boolean;
|
|
115
120
|
isHover(leaf: ILeaf): boolean;
|
|
116
121
|
isFocus(leaf: ILeaf): boolean;
|
|
117
122
|
cancelHover(): void;
|
|
118
|
-
updateDownData(data?: IPointerEvent, options?: IPickOptions): void;
|
|
123
|
+
updateDownData(data?: IPointerEvent, options?: IPickOptions, merge?: boolean): void;
|
|
119
124
|
updateHoverData(data?: IPointerEvent): void;
|
|
120
125
|
updateCursor(data?: IPointerEvent): void;
|
|
121
126
|
setCursor(cursor: ICursorType | ICursorType[]): void;
|
|
@@ -158,13 +163,15 @@ declare class Cursor {
|
|
|
158
163
|
}
|
|
159
164
|
|
|
160
165
|
declare class HitCanvasManager extends CanvasManager implements IHitCanvasManager {
|
|
161
|
-
|
|
162
|
-
protected
|
|
163
|
-
|
|
166
|
+
maxTotal: number;
|
|
167
|
+
protected pathList: ILeafList;
|
|
168
|
+
protected pixelList: ILeafList;
|
|
169
|
+
getPixelType(leaf: ILeaf, config: ILeaferCanvasConfig): IHitCanvas;
|
|
164
170
|
getPathType(leaf: ILeaf): IHitCanvas;
|
|
165
171
|
clearImageType(): void;
|
|
166
172
|
clearPathType(): void;
|
|
167
173
|
protected __clearLeafList(leafList: ILeafList): void;
|
|
174
|
+
protected __autoClear(): void;
|
|
168
175
|
clear(): void;
|
|
169
176
|
}
|
|
170
177
|
|