@leafer-in/viewport 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/dist/viewport.cjs +189 -156
- package/dist/viewport.esm.js +183 -155
- package/dist/viewport.esm.min.js +1 -1
- package/dist/viewport.esm.min.js.map +1 -1
- package/dist/viewport.js +158 -171
- package/dist/viewport.min.cjs +1 -1
- package/dist/viewport.min.cjs.map +1 -1
- package/dist/viewport.min.js +1 -1
- package/dist/viewport.min.js.map +1 -1
- package/package.json +4 -4
- package/src/interaction/Dragger.ts +4 -4
package/dist/viewport.cjs
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
var core = require(
|
|
3
|
+
var core = require("@leafer-ui/core");
|
|
4
4
|
|
|
5
5
|
function addViewport(leafer, mergeConfig, custom) {
|
|
6
6
|
addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig);
|
|
7
|
-
if (leafer.isApp || custom)
|
|
8
|
-
|
|
9
|
-
leafer.__eventIds.push(leafer.on_(core.MoveEvent.BEFORE_MOVE, (e) => {
|
|
7
|
+
if (leafer.isApp || custom) return;
|
|
8
|
+
leafer.__eventIds.push(leafer.on_(core.MoveEvent.BEFORE_MOVE, e => {
|
|
10
9
|
leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
|
|
11
|
-
}), leafer.on_(core.ZoomEvent.BEFORE_ZOOM,
|
|
12
|
-
const { zoomLayer
|
|
10
|
+
}), leafer.on_(core.ZoomEvent.BEFORE_ZOOM, e => {
|
|
11
|
+
const {zoomLayer: zoomLayer} = leafer;
|
|
13
12
|
const changeScale = leafer.getValidScale(e.scale);
|
|
14
|
-
if (changeScale !== 1)
|
|
15
|
-
zoomLayer.scaleOfWorld(e, changeScale);
|
|
13
|
+
if (changeScale !== 1) zoomLayer.scaleOfWorld(e, changeScale);
|
|
16
14
|
}));
|
|
17
15
|
}
|
|
16
|
+
|
|
18
17
|
function addViewportConfig(leafer, mergeConfig) {
|
|
19
18
|
const viewportConfig = {
|
|
20
|
-
wheel: {
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
wheel: {
|
|
20
|
+
preventDefault: true
|
|
21
|
+
},
|
|
22
|
+
touch: {
|
|
23
|
+
preventDefault: true
|
|
24
|
+
},
|
|
25
|
+
pointer: {
|
|
26
|
+
preventDefaultMenu: true
|
|
27
|
+
}
|
|
23
28
|
};
|
|
24
|
-
if (mergeConfig)
|
|
25
|
-
core.DataHelper.assign(viewportConfig, mergeConfig);
|
|
29
|
+
if (mergeConfig) core.DataHelper.assign(viewportConfig, mergeConfig);
|
|
26
30
|
core.DataHelper.assign(leafer.config, viewportConfig, leafer.userConfig);
|
|
27
31
|
}
|
|
28
32
|
|
|
@@ -33,24 +37,29 @@ function custom(leafer) {
|
|
|
33
37
|
function design(leafer) {
|
|
34
38
|
addViewport(leafer, {
|
|
35
39
|
zoom: {
|
|
36
|
-
min:
|
|
40
|
+
min: .01,
|
|
37
41
|
max: 256
|
|
38
42
|
},
|
|
39
43
|
move: {
|
|
40
44
|
holdSpaceKey: true,
|
|
41
|
-
holdMiddleKey: true
|
|
45
|
+
holdMiddleKey: true
|
|
42
46
|
}
|
|
43
47
|
});
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
function document(leafer) {
|
|
47
51
|
addViewport(leafer, {
|
|
48
|
-
zoom: {
|
|
49
|
-
|
|
52
|
+
zoom: {
|
|
53
|
+
min: 1
|
|
54
|
+
},
|
|
55
|
+
move: {
|
|
56
|
+
scroll: "limit"
|
|
57
|
+
}
|
|
50
58
|
});
|
|
51
59
|
}
|
|
52
60
|
|
|
53
|
-
const debug = core.Debug.get(
|
|
61
|
+
const debug = core.Debug.get("LeaferTypeCreator");
|
|
62
|
+
|
|
54
63
|
const LeaferTypeCreator = {
|
|
55
64
|
list: {},
|
|
56
65
|
register(name, fn) {
|
|
@@ -62,78 +71,92 @@ const LeaferTypeCreator = {
|
|
|
62
71
|
fn && fn(leafer);
|
|
63
72
|
}
|
|
64
73
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
register(
|
|
69
|
-
|
|
74
|
+
|
|
75
|
+
const {list: list, register: register} = LeaferTypeCreator;
|
|
76
|
+
|
|
77
|
+
register("viewport", addViewport);
|
|
78
|
+
|
|
79
|
+
register("custom", custom);
|
|
80
|
+
|
|
81
|
+
register("design", design);
|
|
82
|
+
|
|
83
|
+
register("document", document);
|
|
70
84
|
|
|
71
85
|
const MultiTouchHelper = {
|
|
72
86
|
getData(list) {
|
|
73
87
|
const a = list[0], b = list[1];
|
|
74
88
|
const lastCenter = core.PointHelper.getCenter(a.from, b.from);
|
|
75
89
|
const center = core.PointHelper.getCenter(a.to, b.to);
|
|
76
|
-
const move = {
|
|
90
|
+
const move = {
|
|
91
|
+
x: center.x - lastCenter.x,
|
|
92
|
+
y: center.y - lastCenter.y
|
|
93
|
+
};
|
|
77
94
|
const lastDistance = core.PointHelper.getDistance(a.from, b.from);
|
|
78
95
|
const distance = core.PointHelper.getDistance(a.to, b.to);
|
|
79
96
|
const scale = distance / lastDistance;
|
|
80
97
|
const rotation = core.PointHelper.getRotation(a.from, b.from, a.to, b.to);
|
|
81
|
-
return {
|
|
98
|
+
return {
|
|
99
|
+
move: move,
|
|
100
|
+
scale: scale,
|
|
101
|
+
rotation: rotation,
|
|
102
|
+
center: center
|
|
103
|
+
};
|
|
82
104
|
}
|
|
83
105
|
};
|
|
84
106
|
|
|
85
107
|
const WheelEventHelper = {
|
|
86
108
|
getMove(event, config) {
|
|
87
|
-
let { moveSpeed
|
|
88
|
-
let { deltaX, deltaY } = event;
|
|
109
|
+
let {moveSpeed: moveSpeed} = config;
|
|
110
|
+
let {deltaX: deltaX, deltaY: deltaY} = event;
|
|
89
111
|
if (event.shiftKey && !deltaX) {
|
|
90
112
|
deltaX = deltaY;
|
|
91
113
|
deltaY = 0;
|
|
92
114
|
}
|
|
93
|
-
if (deltaX > 50)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
115
|
+
if (deltaX > 50) deltaX = Math.max(50, deltaX / 3);
|
|
116
|
+
if (deltaY > 50) deltaY = Math.max(50, deltaY / 3);
|
|
117
|
+
return {
|
|
118
|
+
x: -deltaX * moveSpeed * 2,
|
|
119
|
+
y: -deltaY * moveSpeed * 2
|
|
120
|
+
};
|
|
98
121
|
},
|
|
99
122
|
getScale(event, config) {
|
|
100
123
|
let zoom;
|
|
101
124
|
let scale = 1;
|
|
102
|
-
let { zoomMode, zoomSpeed } = config;
|
|
125
|
+
let {zoomMode: zoomMode, zoomSpeed: zoomSpeed} = config;
|
|
103
126
|
const delta = event.deltaY || event.deltaX;
|
|
104
127
|
if (zoomMode) {
|
|
105
|
-
zoom =
|
|
106
|
-
if (event.shiftKey || event.metaKey || event.ctrlKey)
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
128
|
+
zoom = zoomMode === "mouse" ? true : !event.deltaX && (core.Platform.intWheelDeltaY ? Math.abs(delta) > 17 : Math.ceil(delta) !== delta);
|
|
129
|
+
if (event.shiftKey || event.metaKey || event.ctrlKey) zoom = true;
|
|
130
|
+
} else {
|
|
110
131
|
zoom = !event.shiftKey && (event.metaKey || event.ctrlKey);
|
|
111
132
|
}
|
|
112
133
|
if (zoom) {
|
|
113
134
|
zoomSpeed = core.MathHelper.within(zoomSpeed, 0, 1);
|
|
114
135
|
const min = event.deltaY ? config.delta.y : config.delta.x;
|
|
115
136
|
scale = 1 - delta / (min * 4) * zoomSpeed;
|
|
116
|
-
if (scale <
|
|
117
|
-
|
|
118
|
-
if (scale >= 1.5)
|
|
119
|
-
scale = 1.5;
|
|
137
|
+
if (scale < .5) scale = .5;
|
|
138
|
+
if (scale >= 1.5) scale = 1.5;
|
|
120
139
|
}
|
|
121
140
|
return scale;
|
|
122
141
|
}
|
|
123
142
|
};
|
|
124
143
|
|
|
125
144
|
class Transformer {
|
|
126
|
-
get transforming() {
|
|
145
|
+
get transforming() {
|
|
146
|
+
return !!(this.moveData || this.zoomData || this.rotateData);
|
|
147
|
+
}
|
|
127
148
|
constructor(interaction) {
|
|
128
149
|
this.interaction = interaction;
|
|
129
150
|
}
|
|
130
151
|
move(data) {
|
|
131
|
-
const { interaction
|
|
132
|
-
if (!data.moveType)
|
|
133
|
-
data.moveType = 'move';
|
|
152
|
+
const {interaction: interaction} = this;
|
|
153
|
+
if (!data.moveType) data.moveType = "move";
|
|
134
154
|
if (!this.moveData) {
|
|
135
155
|
this.setPath(data);
|
|
136
|
-
this.moveData = Object.assign(Object.assign({}, data), {
|
|
156
|
+
this.moveData = Object.assign(Object.assign({}, data), {
|
|
157
|
+
moveX: 0,
|
|
158
|
+
moveY: 0
|
|
159
|
+
});
|
|
137
160
|
interaction.emit(core.MoveEvent.START, this.moveData);
|
|
138
161
|
}
|
|
139
162
|
data.path = this.moveData.path;
|
|
@@ -142,10 +165,12 @@ class Transformer {
|
|
|
142
165
|
this.transformEndWait();
|
|
143
166
|
}
|
|
144
167
|
zoom(data) {
|
|
145
|
-
const { interaction
|
|
168
|
+
const {interaction: interaction} = this;
|
|
146
169
|
if (!this.zoomData) {
|
|
147
170
|
this.setPath(data);
|
|
148
|
-
this.zoomData = Object.assign(Object.assign({}, data), {
|
|
171
|
+
this.zoomData = Object.assign(Object.assign({}, data), {
|
|
172
|
+
scale: 1
|
|
173
|
+
});
|
|
149
174
|
interaction.emit(core.ZoomEvent.START, this.zoomData);
|
|
150
175
|
}
|
|
151
176
|
data.path = this.zoomData.path;
|
|
@@ -154,10 +179,12 @@ class Transformer {
|
|
|
154
179
|
this.transformEndWait();
|
|
155
180
|
}
|
|
156
181
|
rotate(data) {
|
|
157
|
-
const { interaction
|
|
182
|
+
const {interaction: interaction} = this;
|
|
158
183
|
if (!this.rotateData) {
|
|
159
184
|
this.setPath(data);
|
|
160
|
-
this.rotateData = Object.assign(Object.assign({}, data), {
|
|
185
|
+
this.rotateData = Object.assign(Object.assign({}, data), {
|
|
186
|
+
rotation: 0
|
|
187
|
+
});
|
|
161
188
|
interaction.emit(core.RotateEvent.START, this.rotateData);
|
|
162
189
|
}
|
|
163
190
|
data.path = this.rotateData.path;
|
|
@@ -166,8 +193,8 @@ class Transformer {
|
|
|
166
193
|
this.transformEndWait();
|
|
167
194
|
}
|
|
168
195
|
setPath(data) {
|
|
169
|
-
const { interaction
|
|
170
|
-
const { path
|
|
196
|
+
const {interaction: interaction} = this;
|
|
197
|
+
const {path: path} = interaction.selector.getByPoint(data, interaction.hitRadius);
|
|
171
198
|
data.path = path;
|
|
172
199
|
interaction.cancelHover();
|
|
173
200
|
}
|
|
@@ -178,13 +205,10 @@ class Transformer {
|
|
|
178
205
|
}, this.interaction.p.transformTime);
|
|
179
206
|
}
|
|
180
207
|
transformEnd() {
|
|
181
|
-
const { interaction, moveData, zoomData, rotateData } = this;
|
|
182
|
-
if (moveData)
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
interaction.emit(core.ZoomEvent.END, zoomData);
|
|
186
|
-
if (rotateData)
|
|
187
|
-
interaction.emit(core.RotateEvent.END, rotateData);
|
|
208
|
+
const {interaction: interaction, moveData: moveData, zoomData: zoomData, rotateData: rotateData} = this;
|
|
209
|
+
if (moveData) interaction.emit(core.MoveEvent.END, moveData);
|
|
210
|
+
if (zoomData) interaction.emit(core.ZoomEvent.END, zoomData);
|
|
211
|
+
if (rotateData) interaction.emit(core.RotateEvent.END, rotateData);
|
|
188
212
|
this.reset();
|
|
189
213
|
}
|
|
190
214
|
reset() {
|
|
@@ -196,103 +220,99 @@ class Transformer {
|
|
|
196
220
|
}
|
|
197
221
|
|
|
198
222
|
const leafer = core.Leafer.prototype;
|
|
199
|
-
|
|
200
|
-
|
|
223
|
+
|
|
224
|
+
const bounds = new core.Bounds;
|
|
225
|
+
|
|
226
|
+
leafer.initType = function(type) {
|
|
201
227
|
LeaferTypeCreator.run(type, this);
|
|
202
228
|
};
|
|
203
|
-
|
|
204
|
-
|
|
229
|
+
|
|
230
|
+
leafer.getValidMove = function(moveX, moveY) {
|
|
231
|
+
const {scroll: scroll, disabled: disabled} = this.app.config.move;
|
|
205
232
|
if (scroll) {
|
|
206
|
-
const type = scroll === true ?
|
|
207
|
-
if (type.includes(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
else
|
|
212
|
-
Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0;
|
|
213
|
-
if (type.includes('limit')) {
|
|
214
|
-
const { x, y, width, height } = bounds.set(this.__world).addPoint(this.zoomLayer);
|
|
233
|
+
const type = scroll === true ? "" : scroll;
|
|
234
|
+
if (type.includes("x")) moveX = moveX || moveY, moveY = 0; else if (type.includes("y")) moveY = moveY || moveX,
|
|
235
|
+
moveX = 0; else Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0;
|
|
236
|
+
if (type.includes("limit")) {
|
|
237
|
+
const {x: x, y: y, width: width, height: height} = bounds.set(this.__world).addPoint(this.zoomLayer);
|
|
215
238
|
const right = x + width - this.width, bottom = y + height - this.height;
|
|
216
|
-
if (x >= 0 && right <= 0)
|
|
217
|
-
moveX =
|
|
218
|
-
else if (moveX
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
else if (moveX < 0 && right + moveX < 0)
|
|
223
|
-
moveX = -right;
|
|
224
|
-
if (y >= 0 && bottom <= 0)
|
|
225
|
-
moveY = 0;
|
|
226
|
-
else if (moveY > 0) {
|
|
227
|
-
if (y + moveY > 0)
|
|
228
|
-
moveY = -y;
|
|
229
|
-
}
|
|
230
|
-
else if (moveY < 0 && bottom + moveY < 0)
|
|
231
|
-
moveY = -bottom;
|
|
239
|
+
if (x >= 0 && right <= 0) moveX = 0; else if (moveX > 0) {
|
|
240
|
+
if (x + moveX > 0) moveX = -x;
|
|
241
|
+
} else if (moveX < 0 && right + moveX < 0) moveX = -right;
|
|
242
|
+
if (y >= 0 && bottom <= 0) moveY = 0; else if (moveY > 0) {
|
|
243
|
+
if (y + moveY > 0) moveY = -y;
|
|
244
|
+
} else if (moveY < 0 && bottom + moveY < 0) moveY = -bottom;
|
|
232
245
|
}
|
|
233
246
|
}
|
|
234
|
-
return {
|
|
247
|
+
return {
|
|
248
|
+
x: disabled ? 0 : moveX,
|
|
249
|
+
y: disabled ? 0 : moveY
|
|
250
|
+
};
|
|
235
251
|
};
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
else if (max && absScale > max)
|
|
241
|
-
changeScale = max / scaleX;
|
|
252
|
+
|
|
253
|
+
leafer.getValidScale = function(changeScale) {
|
|
254
|
+
const {scaleX: scaleX} = this.zoomLayer.__, {min: min, max: max, disabled: disabled} = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale);
|
|
255
|
+
if (min && absScale < min) changeScale = min / scaleX; else if (max && absScale > max) changeScale = max / scaleX;
|
|
242
256
|
return disabled ? 1 : changeScale;
|
|
243
257
|
};
|
|
244
258
|
|
|
245
259
|
function getMoveEventData(move, event) {
|
|
246
|
-
return Object.assign(Object.assign({}, event), {
|
|
260
|
+
return Object.assign(Object.assign({}, event), {
|
|
261
|
+
moveX: move.x,
|
|
262
|
+
moveY: move.y
|
|
263
|
+
});
|
|
247
264
|
}
|
|
265
|
+
|
|
248
266
|
function getRotateEventData(rotation, event) {
|
|
249
|
-
return Object.assign(Object.assign({}, event), {
|
|
267
|
+
return Object.assign(Object.assign({}, event), {
|
|
268
|
+
rotation: rotation
|
|
269
|
+
});
|
|
250
270
|
}
|
|
271
|
+
|
|
251
272
|
function getZoomEventData(scale, event) {
|
|
252
|
-
return Object.assign(Object.assign({}, event), {
|
|
273
|
+
return Object.assign(Object.assign({}, event), {
|
|
274
|
+
scale: scale
|
|
275
|
+
});
|
|
253
276
|
}
|
|
277
|
+
|
|
254
278
|
const interaction = core.InteractionBase.prototype;
|
|
255
|
-
|
|
279
|
+
|
|
280
|
+
interaction.createTransformer = function() {
|
|
256
281
|
this.transformer = new Transformer(this);
|
|
257
282
|
};
|
|
258
|
-
|
|
283
|
+
|
|
284
|
+
interaction.move = function(data) {
|
|
259
285
|
this.transformer.move(data);
|
|
260
286
|
};
|
|
261
|
-
|
|
287
|
+
|
|
288
|
+
interaction.zoom = function(data) {
|
|
262
289
|
this.transformer.zoom(data);
|
|
263
290
|
};
|
|
264
|
-
|
|
291
|
+
|
|
292
|
+
interaction.rotate = function(data) {
|
|
265
293
|
this.transformer.rotate(data);
|
|
266
294
|
};
|
|
267
|
-
|
|
295
|
+
|
|
296
|
+
interaction.transformEnd = function() {
|
|
268
297
|
this.transformer.transformEnd();
|
|
269
298
|
};
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (data.deltaX > 0)
|
|
275
|
-
|
|
276
|
-
else
|
|
277
|
-
negDeltaSpeed && (data.deltaX *= negDeltaSpeed);
|
|
278
|
-
if (data.deltaY > 0)
|
|
279
|
-
posDeltaSpeed && (data.deltaY *= posDeltaSpeed);
|
|
280
|
-
else
|
|
281
|
-
negDeltaSpeed && (data.deltaY *= negDeltaSpeed);
|
|
299
|
+
|
|
300
|
+
interaction.wheel = function(data) {
|
|
301
|
+
const {wheel: wheel, pointer: pointer} = this.config, {posDeltaSpeed: posDeltaSpeed, negDeltaSpeed: negDeltaSpeed} = wheel;
|
|
302
|
+
if (wheel.disabled) return;
|
|
303
|
+
if (data.deltaX > 0) posDeltaSpeed && (data.deltaX *= posDeltaSpeed); else negDeltaSpeed && (data.deltaX *= negDeltaSpeed);
|
|
304
|
+
if (data.deltaY > 0) posDeltaSpeed && (data.deltaY *= posDeltaSpeed); else negDeltaSpeed && (data.deltaY *= negDeltaSpeed);
|
|
282
305
|
const scale = wheel.getScale ? wheel.getScale(data, wheel) : WheelEventHelper.getScale(data, wheel);
|
|
283
|
-
if (scale !== 1)
|
|
284
|
-
this.zoom(getZoomEventData(scale, data));
|
|
285
|
-
else {
|
|
306
|
+
if (scale !== 1) this.zoom(getZoomEventData(scale, data)); else {
|
|
286
307
|
const move = wheel.getMove ? wheel.getMove(data, wheel) : WheelEventHelper.getMove(data, wheel);
|
|
287
|
-
if (pointer.snap)
|
|
288
|
-
core.PointHelper.round(move);
|
|
308
|
+
if (pointer.snap) core.PointHelper.round(move);
|
|
289
309
|
this.move(getMoveEventData(move, data));
|
|
290
310
|
}
|
|
291
311
|
};
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const { move, rotation, scale, center } = MultiTouchHelper.getData(list);
|
|
312
|
+
|
|
313
|
+
interaction.multiTouch = function(data, list) {
|
|
314
|
+
if (this.config.multiTouch.disabled) return;
|
|
315
|
+
const {move: move, rotation: rotation, scale: scale, center: center} = MultiTouchHelper.getData(list);
|
|
296
316
|
Object.assign(data, center);
|
|
297
317
|
data.multiTouch = true;
|
|
298
318
|
this.pointerWaitCancel();
|
|
@@ -302,70 +322,83 @@ interaction.multiTouch = function (data, list) {
|
|
|
302
322
|
};
|
|
303
323
|
|
|
304
324
|
const dragger = core.Dragger.prototype;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
325
|
+
|
|
326
|
+
const {abs: abs} = Math;
|
|
327
|
+
|
|
328
|
+
dragger.checkDragEndAnimate = function(data, speed) {
|
|
329
|
+
const {moveX: moveX, moveY: moveY} = this.dragData;
|
|
330
|
+
const absMoveX = abs(moveX), absMoveY = abs(moveY), minMove = speed ? 1 : .1;
|
|
331
|
+
const dragAnimate = this.canAnimate && this.moving && (absMoveX > minMove || absMoveY > minMove) && this.interaction.m.dragAnimate;
|
|
310
332
|
if (dragAnimate) {
|
|
311
|
-
const inertia = data.pointerType ===
|
|
312
|
-
speed = speed ?
|
|
313
|
-
if (absMoveX * speed > maxMove)
|
|
314
|
-
speed = maxMove / absMoveX;
|
|
315
|
-
else if (absMoveY * speed > maxMove)
|
|
316
|
-
speed = maxMove / absMoveY;
|
|
333
|
+
const inertia = data.pointerType === "touch" ? 3 : 1, maxMove = 70;
|
|
334
|
+
speed = speed ? core.isNumber(dragAnimate) ? dragAnimate : .95 : inertia;
|
|
335
|
+
if (absMoveX * speed > maxMove) speed = maxMove / absMoveX; else if (absMoveY * speed > maxMove) speed = maxMove / absMoveY;
|
|
317
336
|
data = Object.assign({}, data);
|
|
318
337
|
core.PointHelper.move(data, moveX * speed, moveY * speed);
|
|
319
338
|
this.drag(data);
|
|
320
|
-
this.animate(() => {
|
|
339
|
+
this.animate(() => {
|
|
340
|
+
this.dragEnd(data, 1);
|
|
341
|
+
});
|
|
321
342
|
}
|
|
322
343
|
return dragAnimate;
|
|
323
344
|
};
|
|
324
|
-
|
|
345
|
+
|
|
346
|
+
dragger.animate = function(func, off) {
|
|
325
347
|
const animateWait = func || this.animateWait;
|
|
326
|
-
if (animateWait)
|
|
327
|
-
this.interaction.target.nextRender(animateWait, null, off);
|
|
348
|
+
if (animateWait) this.interaction.target.nextRender(animateWait, null, off);
|
|
328
349
|
this.animateWait = func;
|
|
329
350
|
};
|
|
330
|
-
|
|
331
|
-
|
|
351
|
+
|
|
352
|
+
dragger.checkDragOut = function(data) {
|
|
353
|
+
const {interaction: interaction} = this;
|
|
332
354
|
this.autoMoveCancel();
|
|
333
|
-
if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data))
|
|
334
|
-
this.autoMoveOnDragOut(data);
|
|
355
|
+
if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data)) this.autoMoveOnDragOut(data);
|
|
335
356
|
};
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const {
|
|
339
|
-
|
|
340
|
-
|
|
357
|
+
|
|
358
|
+
dragger.autoMoveOnDragOut = function(data) {
|
|
359
|
+
const {interaction: interaction, downData: downData, canDragOut: canDragOut} = this;
|
|
360
|
+
const {autoDistance: autoDistance, dragOut: dragOut} = interaction.m;
|
|
361
|
+
if (!dragOut || !canDragOut || !autoDistance) return;
|
|
341
362
|
const bounds = interaction.shrinkCanvasBounds;
|
|
342
|
-
const { x, y } = bounds;
|
|
363
|
+
const {x: x, y: y} = bounds;
|
|
343
364
|
const right = core.BoundsHelper.maxX(bounds);
|
|
344
365
|
const bottom = core.BoundsHelper.maxY(bounds);
|
|
345
|
-
const moveX = data.x < x ? autoDistance :
|
|
346
|
-
const moveY = data.y < y ? autoDistance :
|
|
366
|
+
const moveX = data.x < x ? autoDistance : right < data.x ? -autoDistance : 0;
|
|
367
|
+
const moveY = data.y < y ? autoDistance : bottom < data.y ? -autoDistance : 0;
|
|
347
368
|
let totalX = 0, totalY = 0;
|
|
348
369
|
this.autoMoveTimer = setInterval(() => {
|
|
349
370
|
totalX += moveX;
|
|
350
371
|
totalY += moveY;
|
|
351
372
|
core.PointHelper.move(downData, moveX, moveY);
|
|
352
373
|
core.PointHelper.move(this.dragData, moveX, moveY);
|
|
353
|
-
interaction.move(Object.assign(Object.assign({}, data), {
|
|
374
|
+
interaction.move(Object.assign(Object.assign({}, data), {
|
|
375
|
+
moveX: moveX,
|
|
376
|
+
moveY: moveY,
|
|
377
|
+
totalX: totalX,
|
|
378
|
+
totalY: totalY,
|
|
379
|
+
moveType: "drag"
|
|
380
|
+
}));
|
|
354
381
|
interaction.pointerMoveReal(data);
|
|
355
382
|
}, 10);
|
|
356
383
|
};
|
|
357
|
-
|
|
384
|
+
|
|
385
|
+
dragger.autoMoveCancel = function() {
|
|
358
386
|
if (this.autoMoveTimer) {
|
|
359
387
|
clearInterval(this.autoMoveTimer);
|
|
360
388
|
this.autoMoveTimer = 0;
|
|
361
389
|
}
|
|
362
390
|
};
|
|
363
391
|
|
|
364
|
-
core.Plugin.add(
|
|
392
|
+
core.Plugin.add("viewport");
|
|
365
393
|
|
|
366
394
|
exports.LeaferTypeCreator = LeaferTypeCreator;
|
|
395
|
+
|
|
367
396
|
exports.MultiTouchHelper = MultiTouchHelper;
|
|
397
|
+
|
|
368
398
|
exports.Transformer = Transformer;
|
|
399
|
+
|
|
369
400
|
exports.WheelEventHelper = WheelEventHelper;
|
|
401
|
+
|
|
370
402
|
exports.addViewport = addViewport;
|
|
403
|
+
|
|
371
404
|
exports.addViewportConfig = addViewportConfig;
|