@leafer-ui/interaction-web 1.1.0 → 1.1.2
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 +4 -4
- package/src/Interaction.ts +12 -18
- package/src/WheelEventHelper.ts +0 -47
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/interaction-web",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "@leafer-ui/interaction-web",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.1.
|
|
26
|
-
"@leafer-ui/core": "1.1.
|
|
25
|
+
"@leafer/core": "1.1.2",
|
|
26
|
+
"@leafer-ui/core": "1.1.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.1.
|
|
29
|
+
"@leafer/interface": "1.1.2"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/Interaction.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { MathHelper } from '@leafer/core'
|
|
|
3
3
|
import { InteractionBase, InteractionHelper, Cursor } from '@leafer-ui/core'
|
|
4
4
|
|
|
5
5
|
import { PointerEventHelper } from './PointerEventHelper'
|
|
6
|
-
import { WheelEventHelper } from './WheelEventHelper'
|
|
7
6
|
import { KeyEventHelper } from './KeyEventHelper'
|
|
8
7
|
|
|
9
8
|
|
|
@@ -14,7 +13,7 @@ interface IGestureEvent extends IClientPointData, UIEvent {
|
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
|
|
17
|
-
const {
|
|
16
|
+
const { pathCanDrag } = InteractionHelper
|
|
18
17
|
|
|
19
18
|
export class Interaction extends InteractionBase {
|
|
20
19
|
|
|
@@ -281,15 +280,12 @@ export class Interaction extends InteractionBase {
|
|
|
281
280
|
// wheel
|
|
282
281
|
protected onWheel(e: WheelEvent): void {
|
|
283
282
|
this.preventDefaultWheel(e)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const eventBase = InteractionHelper.getBase(e)
|
|
292
|
-
scale !== 1 ? this.zoom(getZoomEventData(local, scale, eventBase)) : this.move(getMoveEventData(local, wheel.getMove ? wheel.getMove(e, wheel) : WheelEventHelper.getMove(e, wheel), eventBase))
|
|
283
|
+
this.wheel({
|
|
284
|
+
...InteractionHelper.getBase(e),
|
|
285
|
+
...this.getLocal(e),
|
|
286
|
+
deltaX: e.deltaX,
|
|
287
|
+
deltaY: e.deltaY
|
|
288
|
+
})
|
|
293
289
|
}
|
|
294
290
|
|
|
295
291
|
|
|
@@ -306,16 +302,14 @@ export class Interaction extends InteractionBase {
|
|
|
306
302
|
if (this.useMultiTouch) return
|
|
307
303
|
this.preventDefaultWheel(e)
|
|
308
304
|
|
|
309
|
-
const local = this.getLocal(e)
|
|
310
305
|
const eventBase = InteractionHelper.getBase(e)
|
|
311
|
-
|
|
312
|
-
const changeAngle = e.rotation - this.lastGestureRotation
|
|
306
|
+
Object.assign(eventBase, this.getLocal(e))
|
|
313
307
|
|
|
314
|
-
|
|
315
|
-
|
|
308
|
+
const scale = (e.scale / this.lastGestureScale)
|
|
309
|
+
const rotation = (e.rotation - this.lastGestureRotation) / Math.PI * 180 * (MathHelper.within(this.config.wheel.rotateSpeed, 0, 1) / 4 + 0.1)
|
|
316
310
|
|
|
317
|
-
this.zoom(
|
|
318
|
-
this.rotate(
|
|
311
|
+
this.zoom({ ...eventBase, scale: scale * scale })
|
|
312
|
+
this.rotate({ ...eventBase, rotation })
|
|
319
313
|
|
|
320
314
|
this.lastGestureScale = e.scale
|
|
321
315
|
this.lastGestureRotation = e.rotation
|
package/src/WheelEventHelper.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { IPointData, IWheelConfig } from '@leafer/interface'
|
|
2
|
-
import { MathHelper, Platform } from '@leafer/core'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const WheelEventHelper = {
|
|
6
|
-
|
|
7
|
-
getMove(e: WheelEvent, config: IWheelConfig): IPointData {
|
|
8
|
-
let { moveSpeed } = config
|
|
9
|
-
let { deltaX, deltaY } = e
|
|
10
|
-
if (e.shiftKey && !deltaX) { // Window
|
|
11
|
-
deltaX = deltaY
|
|
12
|
-
deltaY = 0
|
|
13
|
-
}
|
|
14
|
-
if (deltaX > 50) deltaX = Math.max(50, deltaX / 3)
|
|
15
|
-
if (deltaY > 50) deltaY = Math.max(50, deltaY / 3)
|
|
16
|
-
return { x: -deltaX * moveSpeed * 2, y: -deltaY * moveSpeed * 2 }
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
getScale(e: WheelEvent, config: IWheelConfig): number {
|
|
20
|
-
|
|
21
|
-
let zoom: boolean
|
|
22
|
-
let scale = 1
|
|
23
|
-
let { zoomMode, zoomSpeed } = config
|
|
24
|
-
|
|
25
|
-
const delta = e.deltaY || e.deltaX
|
|
26
|
-
|
|
27
|
-
if (zoomMode) {
|
|
28
|
-
// mac 触摸板滚动手势的deltaY是整数, 鼠标滚动/触摸板缩放的deltaY有小数点, firfox鼠标滚动为整数,为18或19的倍数
|
|
29
|
-
// windows 始终是整数
|
|
30
|
-
zoom = (zoomMode === 'mouse') ? true : (!e.deltaX && (Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta))
|
|
31
|
-
if (e.shiftKey || e.metaKey || e.ctrlKey) zoom = true
|
|
32
|
-
} else {
|
|
33
|
-
zoom = !e.shiftKey && (e.metaKey || e.ctrlKey)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (zoom) {
|
|
37
|
-
zoomSpeed = MathHelper.within(zoomSpeed, 0, 1)
|
|
38
|
-
const min = e.deltaY ? config.delta.y : config.delta.x
|
|
39
|
-
scale = 1 - delta / (min * 4) * zoomSpeed // zoomSpeed
|
|
40
|
-
if (scale < 0.5) scale = 0.5
|
|
41
|
-
if (scale >= 1.5) scale = 1.5
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return scale
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}
|