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