react-pic-gallery 1.5.2 → 1.5.6
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/react-pic-gallery.es.js +1077 -1296
- package/dist/react-pic-gallery.umd.js +7 -11
- package/package.json +6 -2
|
@@ -17,7 +17,7 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import React, {
|
|
20
|
+
import React, { Component, useState, useEffect, useCallback } from "react";
|
|
21
21
|
var jsxRuntime = { exports: {} };
|
|
22
22
|
var reactJsxRuntime_production_min = {};
|
|
23
23
|
/*
|
|
@@ -130,14 +130,12 @@ var extendStatics = function(d, b) {
|
|
|
130
130
|
d2.__proto__ = b2;
|
|
131
131
|
} || function(d2, b2) {
|
|
132
132
|
for (var p2 in b2)
|
|
133
|
-
if (
|
|
133
|
+
if (b2.hasOwnProperty(p2))
|
|
134
134
|
d2[p2] = b2[p2];
|
|
135
135
|
};
|
|
136
136
|
return extendStatics(d, b);
|
|
137
137
|
};
|
|
138
138
|
function __extends(d, b) {
|
|
139
|
-
if (typeof b !== "function" && b !== null)
|
|
140
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
141
139
|
extendStatics(d, b);
|
|
142
140
|
function __() {
|
|
143
141
|
this.constructor = d;
|
|
@@ -156,28 +154,183 @@ var __assign = function() {
|
|
|
156
154
|
};
|
|
157
155
|
return __assign.apply(this, arguments);
|
|
158
156
|
};
|
|
159
|
-
function
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
157
|
+
function __rest(s, e) {
|
|
158
|
+
var t = {};
|
|
159
|
+
for (var p2 in s)
|
|
160
|
+
if (Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0)
|
|
161
|
+
t[p2] = s[p2];
|
|
162
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
163
|
+
for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++) {
|
|
164
|
+
if (e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i]))
|
|
165
|
+
t[p2[i]] = s[p2[i]];
|
|
167
166
|
}
|
|
168
|
-
return
|
|
167
|
+
return t;
|
|
169
168
|
}
|
|
169
|
+
var initialState = {
|
|
170
|
+
wrapperComponent: null,
|
|
171
|
+
contentComponent: null,
|
|
172
|
+
previousScale: 1,
|
|
173
|
+
scale: 1,
|
|
174
|
+
positionX: 0,
|
|
175
|
+
positionY: 0,
|
|
176
|
+
options: {
|
|
177
|
+
disabled: false,
|
|
178
|
+
transformEnabled: true,
|
|
179
|
+
minPositionX: null,
|
|
180
|
+
maxPositionX: null,
|
|
181
|
+
minPositionY: null,
|
|
182
|
+
maxPositionY: null,
|
|
183
|
+
minScale: 1,
|
|
184
|
+
maxScale: 8,
|
|
185
|
+
limitToBounds: true,
|
|
186
|
+
limitToWrapper: false,
|
|
187
|
+
centerContent: true,
|
|
188
|
+
wrapperClass: "",
|
|
189
|
+
contentClass: ""
|
|
190
|
+
},
|
|
191
|
+
wheel: {
|
|
192
|
+
disabled: false,
|
|
193
|
+
step: 5,
|
|
194
|
+
wheelEnabled: true,
|
|
195
|
+
touchPadEnabled: true,
|
|
196
|
+
limitsOnWheel: false
|
|
197
|
+
},
|
|
198
|
+
pan: {
|
|
199
|
+
disabled: false,
|
|
200
|
+
panAnimationType: "linear",
|
|
201
|
+
lockAxisX: false,
|
|
202
|
+
lockAxisY: false,
|
|
203
|
+
velocity: true,
|
|
204
|
+
velocityEqualToMove: true,
|
|
205
|
+
velocitySensitivity: 2,
|
|
206
|
+
velocityActiveScale: 1,
|
|
207
|
+
velocityMinSpeed: 1,
|
|
208
|
+
velocityBaseTime: 1600,
|
|
209
|
+
velocityAnimationType: "easeOutQuart",
|
|
210
|
+
padding: true,
|
|
211
|
+
paddingSize: 30,
|
|
212
|
+
panReturnAnimationTime: 400,
|
|
213
|
+
panReturnAnimationType: "easeOut",
|
|
214
|
+
disableOnTarget: []
|
|
215
|
+
},
|
|
216
|
+
pinch: {
|
|
217
|
+
disabled: false
|
|
218
|
+
},
|
|
219
|
+
zoomIn: {
|
|
220
|
+
disabled: false,
|
|
221
|
+
step: 20,
|
|
222
|
+
animation: true,
|
|
223
|
+
animationType: "easeOut",
|
|
224
|
+
animationTime: 200
|
|
225
|
+
},
|
|
226
|
+
zoomOut: {
|
|
227
|
+
disabled: false,
|
|
228
|
+
step: 20,
|
|
229
|
+
animation: true,
|
|
230
|
+
animationType: "easeOut",
|
|
231
|
+
animationTime: 200
|
|
232
|
+
},
|
|
233
|
+
doubleClick: {
|
|
234
|
+
disabled: false,
|
|
235
|
+
step: 20,
|
|
236
|
+
mode: "zoomIn",
|
|
237
|
+
animation: true,
|
|
238
|
+
animationType: "easeOut",
|
|
239
|
+
animationTime: 200
|
|
240
|
+
},
|
|
241
|
+
reset: {
|
|
242
|
+
disabled: false,
|
|
243
|
+
animation: true,
|
|
244
|
+
animationType: "easeOut",
|
|
245
|
+
animationTime: 200
|
|
246
|
+
},
|
|
247
|
+
scalePadding: {
|
|
248
|
+
disabled: false,
|
|
249
|
+
size: 0.2,
|
|
250
|
+
animationTime: 200,
|
|
251
|
+
animationType: "easeOut"
|
|
252
|
+
}
|
|
253
|
+
};
|
|
170
254
|
var roundNumber = function(num, decimal) {
|
|
171
255
|
return Number(num.toFixed(decimal));
|
|
172
256
|
};
|
|
173
257
|
var checkIsNumber = function(num, defaultValue) {
|
|
174
258
|
return typeof num === "number" ? num : defaultValue;
|
|
175
259
|
};
|
|
176
|
-
var
|
|
260
|
+
var boundLimiter = function(value, minBound, maxBound, isActive) {
|
|
261
|
+
if (!isActive)
|
|
262
|
+
return roundNumber(value, 2);
|
|
263
|
+
if (value < minBound)
|
|
264
|
+
return roundNumber(minBound, 2);
|
|
265
|
+
if (value > maxBound)
|
|
266
|
+
return roundNumber(maxBound, 2);
|
|
267
|
+
return roundNumber(value, 2);
|
|
268
|
+
};
|
|
269
|
+
var calculateBoundingArea = function(wrapperWidth, newContentWidth, diffWidth, wrapperHeight, newContentHeight, diffHeight, limitToWrapper) {
|
|
270
|
+
var scaleWidthFactor = wrapperWidth > newContentWidth ? diffWidth * (limitToWrapper ? 1 : 0.5) : 0;
|
|
271
|
+
var scaleHeightFactor = wrapperHeight > newContentHeight ? diffHeight * (limitToWrapper ? 1 : 0.5) : 0;
|
|
272
|
+
var minPositionX = wrapperWidth - newContentWidth - scaleWidthFactor;
|
|
273
|
+
var maxPositionX = scaleWidthFactor;
|
|
274
|
+
var minPositionY = wrapperHeight - newContentHeight - scaleHeightFactor;
|
|
275
|
+
var maxPositionY = scaleHeightFactor;
|
|
276
|
+
return {
|
|
277
|
+
minPositionX,
|
|
278
|
+
maxPositionX,
|
|
279
|
+
minPositionY,
|
|
280
|
+
maxPositionY
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
var getDistance = function(firstPoint, secondPoint) {
|
|
284
|
+
return Math.sqrt(Math.pow(firstPoint.pageX - secondPoint.pageX, 2) + Math.pow(firstPoint.pageY - secondPoint.pageY, 2));
|
|
285
|
+
};
|
|
286
|
+
var deleteUndefinedProps = function(value) {
|
|
287
|
+
var newObject = __assign({}, value);
|
|
288
|
+
Object.keys(newObject).forEach(function(key) {
|
|
289
|
+
return newObject[key] === void 0 && delete newObject[key];
|
|
290
|
+
});
|
|
291
|
+
return newObject;
|
|
292
|
+
};
|
|
293
|
+
var handleCallback = function(callback, props) {
|
|
177
294
|
if (callback && typeof callback === "function") {
|
|
178
|
-
callback(
|
|
295
|
+
callback(props);
|
|
179
296
|
}
|
|
180
297
|
};
|
|
298
|
+
var handleWheelStop = function(previousEvent, event, stateProvider) {
|
|
299
|
+
var scale = stateProvider.scale, _a = stateProvider.options, maxScale = _a.maxScale, minScale = _a.minScale;
|
|
300
|
+
if (!previousEvent)
|
|
301
|
+
return false;
|
|
302
|
+
if (scale < maxScale || scale > minScale)
|
|
303
|
+
return true;
|
|
304
|
+
if (Math.sign(previousEvent.deltaY) !== Math.sign(event.deltaY))
|
|
305
|
+
return true;
|
|
306
|
+
if (previousEvent.deltaY > 0 && previousEvent.deltaY < event.deltaY)
|
|
307
|
+
return true;
|
|
308
|
+
if (previousEvent.deltaY < 0 && previousEvent.deltaY > event.deltaY)
|
|
309
|
+
return true;
|
|
310
|
+
if (Math.sign(previousEvent.deltaY) !== Math.sign(event.deltaY))
|
|
311
|
+
return true;
|
|
312
|
+
return false;
|
|
313
|
+
};
|
|
314
|
+
var mergeProps = function(initialState2, dynamicProps) {
|
|
315
|
+
return Object.keys(initialState2).reduce(function(acc, curr) {
|
|
316
|
+
if (typeof dynamicProps[curr] === "object" && dynamicProps[curr] !== null) {
|
|
317
|
+
acc[curr] = __assign(__assign({}, initialState2[curr]), dynamicProps[curr]);
|
|
318
|
+
} else {
|
|
319
|
+
acc[curr] = dynamicProps[curr] === void 0 ? initialState2[curr] : dynamicProps[curr];
|
|
320
|
+
}
|
|
321
|
+
return acc;
|
|
322
|
+
}, {});
|
|
323
|
+
};
|
|
324
|
+
function getWindowScaleY(wrapper) {
|
|
325
|
+
if (!wrapper)
|
|
326
|
+
return 0;
|
|
327
|
+
return window.innerHeight / wrapper.offsetHeight;
|
|
328
|
+
}
|
|
329
|
+
function getWindowScaleX(wrapper) {
|
|
330
|
+
if (!wrapper)
|
|
331
|
+
return 0;
|
|
332
|
+
return window.innerWidth / wrapper.offsetWidth;
|
|
333
|
+
}
|
|
181
334
|
var easeOut = function(t) {
|
|
182
335
|
return -Math.cos(t * Math.PI) / 2 + 0.5;
|
|
183
336
|
};
|
|
@@ -220,7 +373,7 @@ var easeOutQuint = function(t) {
|
|
|
220
373
|
var easeInOutQuint = function(t) {
|
|
221
374
|
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
|
|
222
375
|
};
|
|
223
|
-
var
|
|
376
|
+
var availableAnimations = {
|
|
224
377
|
easeOut,
|
|
225
378
|
linear,
|
|
226
379
|
easeInQuad,
|
|
@@ -236,69 +389,98 @@ var animations = {
|
|
|
236
389
|
easeOutQuint,
|
|
237
390
|
easeInOutQuint
|
|
238
391
|
};
|
|
239
|
-
|
|
240
|
-
if (
|
|
241
|
-
cancelAnimationFrame(animation);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
var handleCancelAnimation = function(contextInstance) {
|
|
245
|
-
if (!contextInstance.mounted)
|
|
392
|
+
function handleDisableAnimation() {
|
|
393
|
+
if (!this.mounted)
|
|
246
394
|
return;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
395
|
+
if (this.animation) {
|
|
396
|
+
cancelAnimationFrame(this.animation);
|
|
397
|
+
}
|
|
398
|
+
this.animate = false;
|
|
399
|
+
this.animation = false;
|
|
400
|
+
this.velocity = false;
|
|
401
|
+
}
|
|
402
|
+
function animate(animationName, animationTime, callback) {
|
|
403
|
+
var _this = this;
|
|
404
|
+
if (!this.mounted)
|
|
254
405
|
return;
|
|
255
406
|
var startTime = new Date().getTime();
|
|
256
407
|
var lastStep = 1;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (!
|
|
260
|
-
return
|
|
261
|
-
}
|
|
408
|
+
handleDisableAnimation.call(this);
|
|
409
|
+
this.animation = function() {
|
|
410
|
+
if (!_this.animation || !_this.mounted)
|
|
411
|
+
return;
|
|
262
412
|
var frameTime = new Date().getTime() - startTime;
|
|
263
413
|
var animationProgress = frameTime / animationTime;
|
|
264
|
-
var animationType =
|
|
414
|
+
var animationType = availableAnimations[animationName];
|
|
265
415
|
var step = animationType(animationProgress);
|
|
266
416
|
if (frameTime >= animationTime) {
|
|
267
417
|
callback(lastStep);
|
|
268
|
-
|
|
269
|
-
} else
|
|
418
|
+
_this.animation = null;
|
|
419
|
+
} else {
|
|
270
420
|
callback(step);
|
|
271
|
-
requestAnimationFrame(
|
|
421
|
+
requestAnimationFrame(_this.animation);
|
|
272
422
|
}
|
|
273
423
|
};
|
|
274
|
-
requestAnimationFrame(
|
|
424
|
+
requestAnimationFrame(this.animation);
|
|
275
425
|
}
|
|
276
|
-
function
|
|
277
|
-
var
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
var setTransformState = contextInstance.setTransformState;
|
|
281
|
-
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
426
|
+
function animateComponent(_a) {
|
|
427
|
+
var _this = this;
|
|
428
|
+
var targetState = _a.targetState, speed = _a.speed, type = _a.type;
|
|
429
|
+
var _b = this.stateProvider, scale = _b.scale, positionX = _b.positionX, positionY = _b.positionY;
|
|
282
430
|
var scaleDiff = targetState.scale - scale;
|
|
283
431
|
var positionXDiff = targetState.positionX - positionX;
|
|
284
432
|
var positionYDiff = targetState.positionY - positionY;
|
|
285
|
-
if (
|
|
286
|
-
|
|
433
|
+
if (speed === 0) {
|
|
434
|
+
this.stateProvider.previousScale = this.stateProvider.scale;
|
|
435
|
+
this.stateProvider.scale = targetState.scale;
|
|
436
|
+
this.stateProvider.positionX = targetState.positionX;
|
|
437
|
+
this.stateProvider.positionY = targetState.positionY;
|
|
438
|
+
this.applyTransformation();
|
|
287
439
|
} else {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
440
|
+
animate.call(this, type, speed, function(step) {
|
|
441
|
+
_this.stateProvider.previousScale = _this.stateProvider.scale;
|
|
442
|
+
_this.stateProvider.scale = scale + scaleDiff * step;
|
|
443
|
+
_this.stateProvider.positionX = positionX + positionXDiff * step;
|
|
444
|
+
_this.stateProvider.positionY = positionY + positionYDiff * step;
|
|
445
|
+
_this.applyTransformation();
|
|
293
446
|
});
|
|
294
447
|
}
|
|
295
448
|
}
|
|
296
|
-
function
|
|
297
|
-
var
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
449
|
+
function checkZoomBounds(zoom, minScale, maxScale, zoomPadding, enablePadding) {
|
|
450
|
+
var scalePadding = enablePadding ? zoomPadding : 0;
|
|
451
|
+
var minScaleWithPadding = minScale - scalePadding;
|
|
452
|
+
if (!isNaN(maxScale) && zoom >= maxScale)
|
|
453
|
+
return maxScale;
|
|
454
|
+
if (!isNaN(minScale) && zoom <= minScaleWithPadding)
|
|
455
|
+
return minScaleWithPadding;
|
|
456
|
+
return zoom;
|
|
457
|
+
}
|
|
458
|
+
function checkPositionBounds(positionX, positionY, bounds, limitToBounds, paddingValue, wrapperComponent) {
|
|
459
|
+
var minPositionX = bounds.minPositionX, minPositionY = bounds.minPositionY, maxPositionX = bounds.maxPositionX, maxPositionY = bounds.maxPositionY;
|
|
460
|
+
var paddingX = wrapperComponent ? paddingValue * wrapperComponent.offsetWidth / 100 : 0;
|
|
461
|
+
var paddingY = wrapperComponent ? paddingValue * wrapperComponent.offsetHeight / 100 : 0;
|
|
462
|
+
var x = boundLimiter(positionX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
|
|
463
|
+
var y = boundLimiter(positionY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
|
|
464
|
+
return {
|
|
465
|
+
x,
|
|
466
|
+
y
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function getDelta(event, customDelta) {
|
|
470
|
+
var deltaY = event ? event.deltaY < 0 ? 1 : -1 : 0;
|
|
471
|
+
var delta = checkIsNumber(customDelta, deltaY);
|
|
472
|
+
return delta;
|
|
473
|
+
}
|
|
474
|
+
function wheelMousePosition(event, contentComponent, scale) {
|
|
475
|
+
var contentRect = contentComponent.getBoundingClientRect();
|
|
476
|
+
var mouseX = (event.clientX - contentRect.left) / scale;
|
|
477
|
+
var mouseY = (event.clientY - contentRect.top) / scale;
|
|
478
|
+
if (isNaN(mouseX) || isNaN(mouseY))
|
|
479
|
+
console.error("No mouse or touch offset found");
|
|
480
|
+
return {
|
|
481
|
+
mouseX,
|
|
482
|
+
mouseY
|
|
483
|
+
};
|
|
302
484
|
}
|
|
303
485
|
function getComponentsSizes(wrapperComponent, contentComponent, newScale) {
|
|
304
486
|
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
@@ -318,1330 +500,920 @@ function getComponentsSizes(wrapperComponent, contentComponent, newScale) {
|
|
|
318
500
|
newDiffHeight
|
|
319
501
|
};
|
|
320
502
|
}
|
|
321
|
-
|
|
322
|
-
var
|
|
323
|
-
var scaleHeightFactor = wrapperHeight > newContentHeight ? diffHeight * (centerZoomedOut ? 1 : 0.5) : 0;
|
|
324
|
-
var minPositionX = wrapperWidth - newContentWidth - scaleWidthFactor;
|
|
325
|
-
var maxPositionX = scaleWidthFactor;
|
|
326
|
-
var minPositionY = wrapperHeight - newContentHeight - scaleHeightFactor;
|
|
327
|
-
var maxPositionY = scaleHeightFactor;
|
|
328
|
-
return {
|
|
329
|
-
minPositionX,
|
|
330
|
-
maxPositionX,
|
|
331
|
-
minPositionY,
|
|
332
|
-
maxPositionY
|
|
333
|
-
};
|
|
334
|
-
};
|
|
335
|
-
var calculateBounds = function(contextInstance, newScale) {
|
|
336
|
-
var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
337
|
-
var centerZoomedOut = contextInstance.setup.centerZoomedOut;
|
|
338
|
-
if (!wrapperComponent || !contentComponent) {
|
|
339
|
-
throw new Error("Components are not mounted");
|
|
340
|
-
}
|
|
341
|
-
var _a = getComponentsSizes(wrapperComponent, contentComponent, newScale), wrapperWidth = _a.wrapperWidth, wrapperHeight = _a.wrapperHeight, newContentWidth = _a.newContentWidth, newDiffWidth = _a.newDiffWidth, newContentHeight = _a.newContentHeight, newDiffHeight = _a.newDiffHeight;
|
|
342
|
-
var bounds = getBounds(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, Boolean(centerZoomedOut));
|
|
343
|
-
return bounds;
|
|
344
|
-
};
|
|
345
|
-
var handleCalculateBounds = function(contextInstance, newScale) {
|
|
346
|
-
var bounds = calculateBounds(contextInstance, newScale);
|
|
347
|
-
contextInstance.bounds = bounds;
|
|
348
|
-
return bounds;
|
|
349
|
-
};
|
|
350
|
-
function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, paddingValueX, paddingValueY, wrapperComponent) {
|
|
351
|
-
var minPositionX = bounds.minPositionX, minPositionY = bounds.minPositionY, maxPositionX = bounds.maxPositionX, maxPositionY = bounds.maxPositionY;
|
|
352
|
-
var paddingX = 0;
|
|
353
|
-
var paddingY = 0;
|
|
354
|
-
if (wrapperComponent) {
|
|
355
|
-
paddingX = paddingValueX;
|
|
356
|
-
paddingY = paddingValueY;
|
|
357
|
-
}
|
|
358
|
-
var x = boundLimiter(positionX, minPositionX - paddingX, maxPositionX + paddingX, limitToBounds);
|
|
359
|
-
var y = boundLimiter(positionY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
|
|
360
|
-
return {
|
|
361
|
-
x,
|
|
362
|
-
y
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
var boundLimiter = function(value, minBound, maxBound, isActive) {
|
|
366
|
-
if (!isActive)
|
|
367
|
-
return roundNumber(value, 2);
|
|
368
|
-
if (value < minBound)
|
|
369
|
-
return roundNumber(minBound, 2);
|
|
370
|
-
if (value > maxBound)
|
|
371
|
-
return roundNumber(maxBound, 2);
|
|
372
|
-
return roundNumber(value, 2);
|
|
373
|
-
};
|
|
374
|
-
function handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds) {
|
|
375
|
-
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
503
|
+
function handleCalculatePositions(mouseX, mouseY, newScale, bounds, limitToBounds) {
|
|
504
|
+
var _a = this.stateProvider, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY, transformEnabled = _a.options.transformEnabled;
|
|
376
505
|
var scaleDifference = newScale - scale;
|
|
377
|
-
if (typeof mouseX !== "number" || typeof mouseY !== "number")
|
|
378
|
-
console.error("Mouse X and Y position were not provided!");
|
|
506
|
+
if (typeof mouseX !== "number" || typeof mouseY !== "number")
|
|
507
|
+
return console.error("Mouse X and Y position were not provided!");
|
|
508
|
+
if (!transformEnabled)
|
|
379
509
|
return {
|
|
380
|
-
|
|
381
|
-
|
|
510
|
+
newPositionX: positionX,
|
|
511
|
+
newPositionY: positionY
|
|
382
512
|
};
|
|
383
|
-
}
|
|
384
513
|
var calculatedPositionX = positionX - mouseX * scaleDifference;
|
|
385
514
|
var calculatedPositionY = positionY - mouseY * scaleDifference;
|
|
386
|
-
var newPositions =
|
|
515
|
+
var newPositions = checkPositionBounds(calculatedPositionX, calculatedPositionY, bounds, limitToBounds, 0, null);
|
|
387
516
|
return newPositions;
|
|
388
517
|
}
|
|
389
|
-
function
|
|
390
|
-
var scalePadding = enablePadding ? zoomPadding : 0;
|
|
391
|
-
var minScaleWithPadding = minScale - scalePadding;
|
|
392
|
-
if (!isNaN(maxScale) && zoom >= maxScale)
|
|
393
|
-
return maxScale;
|
|
394
|
-
if (!isNaN(minScale) && zoom <= minScaleWithPadding)
|
|
395
|
-
return minScaleWithPadding;
|
|
396
|
-
return zoom;
|
|
397
|
-
}
|
|
398
|
-
var isPanningStartAllowed = function(contextInstance, event) {
|
|
399
|
-
var excluded = contextInstance.setup.panning.excluded;
|
|
400
|
-
var isInitialized = contextInstance.isInitialized, wrapperComponent = contextInstance.wrapperComponent;
|
|
401
|
-
var target = event.target;
|
|
402
|
-
var isWrapperChild = wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.contains(target);
|
|
403
|
-
var isAllowed = isInitialized && target && isWrapperChild;
|
|
404
|
-
if (!isAllowed)
|
|
405
|
-
return false;
|
|
406
|
-
var isExcluded = isExcludedNode(target, excluded);
|
|
407
|
-
if (isExcluded)
|
|
408
|
-
return false;
|
|
409
|
-
return true;
|
|
410
|
-
};
|
|
411
|
-
var isPanningAllowed = function(contextInstance) {
|
|
412
|
-
var isInitialized = contextInstance.isInitialized, isPanning = contextInstance.isPanning, setup = contextInstance.setup;
|
|
413
|
-
var disabled = setup.panning.disabled;
|
|
414
|
-
var isAllowed = isInitialized && isPanning && !disabled;
|
|
415
|
-
if (!isAllowed)
|
|
416
|
-
return false;
|
|
417
|
-
return true;
|
|
418
|
-
};
|
|
419
|
-
var handlePanningSetup = function(contextInstance, event) {
|
|
420
|
-
var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY;
|
|
421
|
-
contextInstance.isPanning = true;
|
|
422
|
-
var x = event.clientX;
|
|
423
|
-
var y = event.clientY;
|
|
424
|
-
contextInstance.startCoords = {
|
|
425
|
-
x: x - positionX,
|
|
426
|
-
y: y - positionY
|
|
427
|
-
};
|
|
428
|
-
};
|
|
429
|
-
var handleTouchPanningSetup = function(contextInstance, event) {
|
|
518
|
+
function getClientPosition(event) {
|
|
430
519
|
var touches = event.touches;
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
var x = touches[0].clientX;
|
|
436
|
-
var y = touches[0].clientY;
|
|
437
|
-
contextInstance.startCoords = {
|
|
438
|
-
x: x - positionX,
|
|
439
|
-
y: y - positionY
|
|
520
|
+
if (touches && touches.length === 1) {
|
|
521
|
+
return {
|
|
522
|
+
clientX: touches[0].clientX,
|
|
523
|
+
clientY: touches[0].clientY
|
|
440
524
|
};
|
|
441
525
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
526
|
+
if (!touches) {
|
|
527
|
+
return {
|
|
528
|
+
clientX: event.clientX,
|
|
529
|
+
clientY: event.clientY
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
function handlePanning(event) {
|
|
535
|
+
var _a = this.stateProvider, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY, _b = _a.options, limitToBounds = _b.limitToBounds, minScale = _b.minScale, _c = _a.pan, lockAxisX = _c.lockAxisX, lockAxisY = _c.lockAxisY, padding = _c.padding, paddingSize = _c.paddingSize, wrapperComponent = _a.wrapperComponent;
|
|
536
|
+
if (!this.startCoords)
|
|
537
|
+
return;
|
|
538
|
+
var _d = this.startCoords, x = _d.x, y = _d.y;
|
|
539
|
+
var positions = getClientPosition(event);
|
|
540
|
+
if (!positions)
|
|
541
|
+
return console.error("Cannot find mouse client positions");
|
|
542
|
+
var clientX = positions.clientX, clientY = positions.clientY;
|
|
543
|
+
var mouseX = clientX - x;
|
|
544
|
+
var mouseY = clientY - y;
|
|
545
|
+
var newPositionX = lockAxisX ? positionX : mouseX;
|
|
546
|
+
var newPositionY = lockAxisY ? positionY : mouseY;
|
|
547
|
+
var paddingValue = padding && scale >= minScale ? paddingSize : 0;
|
|
548
|
+
if (newPositionX === positionX && newPositionY === positionY)
|
|
549
|
+
return;
|
|
550
|
+
var calculatedPosition = checkPositionBounds(newPositionX, newPositionY, this.bounds, limitToBounds, paddingValue, wrapperComponent);
|
|
551
|
+
handlePaddingAnimation.call(this, calculatedPosition.x, calculatedPosition.y);
|
|
552
|
+
}
|
|
553
|
+
function handlePanningAnimation() {
|
|
554
|
+
var _a = this.stateProvider, scale = _a.scale, minScale = _a.options.minScale, _b = _a.pan, disabled = _b.disabled, padding = _b.padding, panReturnAnimationTime = _b.panReturnAnimationTime, panReturnAnimationType = _b.panReturnAnimationType;
|
|
555
|
+
var isDisabled = disabled || scale < minScale || !padding;
|
|
556
|
+
if (isDisabled)
|
|
448
557
|
return;
|
|
449
|
-
var
|
|
558
|
+
var targetState = handlePanToBounds.call(this);
|
|
559
|
+
animateComponent.call(this, {
|
|
560
|
+
targetState,
|
|
561
|
+
speed: panReturnAnimationTime,
|
|
562
|
+
type: panReturnAnimationType
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
function handlePanToBounds() {
|
|
566
|
+
var _a = this.stateProvider, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale, _b = _a.options, disabled = _b.disabled, limitToBounds = _b.limitToBounds, limitToWrapper = _b.limitToWrapper;
|
|
567
|
+
var wrapperComponent = this.state.wrapperComponent;
|
|
568
|
+
if (disabled)
|
|
569
|
+
return;
|
|
570
|
+
var _c = this.bounds, maxPositionX = _c.maxPositionX, minPositionX = _c.minPositionX, maxPositionY = _c.maxPositionY, minPositionY = _c.minPositionY;
|
|
450
571
|
var xChanged = positionX > maxPositionX || positionX < minPositionX;
|
|
451
572
|
var yChanged = positionY > maxPositionY || positionY < minPositionY;
|
|
452
|
-
var
|
|
453
|
-
var
|
|
454
|
-
var
|
|
573
|
+
var mouseX = positionX > maxPositionX ? wrapperComponent.offsetWidth : this.stateProvider.minPositionX || 0;
|
|
574
|
+
var mouseY = positionY > maxPositionY ? wrapperComponent.offsetHeight : this.stateProvider.minPositionY || 0;
|
|
575
|
+
var mousePosX = mouseX;
|
|
576
|
+
var mousePosY = mouseY;
|
|
577
|
+
var _d = handleCalculatePositions.call(this, mousePosX, mousePosY, scale, this.bounds, limitToBounds || limitToWrapper), x = _d.x, y = _d.y;
|
|
455
578
|
return {
|
|
456
579
|
scale,
|
|
457
580
|
positionX: xChanged ? x : positionX,
|
|
458
581
|
positionY: yChanged ? y : positionY
|
|
459
582
|
};
|
|
460
583
|
}
|
|
461
|
-
function
|
|
462
|
-
var
|
|
463
|
-
|
|
464
|
-
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
465
|
-
var hasPositionXChanged = newPositionX !== positionX;
|
|
466
|
-
var hasPositionYChanged = newPositionY !== positionY;
|
|
467
|
-
var hasNewPosition = !hasPositionXChanged || !hasPositionYChanged;
|
|
468
|
-
if (!wrapperComponent || hasNewPosition || !bounds) {
|
|
584
|
+
function handlePaddingAnimation(positionX, positionY) {
|
|
585
|
+
var padding = this.stateProvider.pan.padding;
|
|
586
|
+
if (!padding)
|
|
469
587
|
return;
|
|
588
|
+
this.stateProvider.positionX = positionX;
|
|
589
|
+
this.stateProvider.positionY = positionY;
|
|
590
|
+
this.applyTransformation();
|
|
591
|
+
}
|
|
592
|
+
function handleCalculateZoom(delta, step, disablePadding, getTarget, isBtnFunction) {
|
|
593
|
+
var _a = this.stateProvider, scale = _a.scale, _b = _a.options, maxScale = _b.maxScale, minScale = _b.minScale, _c = _a.scalePadding, size = _c.size, disabled = _c.disabled, wrapperComponent = _a.wrapperComponent;
|
|
594
|
+
var targetScale = null;
|
|
595
|
+
if (isBtnFunction) {
|
|
596
|
+
var scaleFactor = window.innerWidth * 1e-4;
|
|
597
|
+
var zoomFactor = delta < 0 ? 30 : 20;
|
|
598
|
+
targetScale = scale + (step - step * scaleFactor) * delta * (scale / zoomFactor);
|
|
599
|
+
} else {
|
|
600
|
+
var wrapperToWindowScale = 2 - window.innerWidth / wrapperComponent.offsetWidth;
|
|
601
|
+
var scaleFactor = Math.max(0.2, Math.min(0.99, wrapperToWindowScale));
|
|
602
|
+
var zoomFactor = 20;
|
|
603
|
+
targetScale = scale + step * delta * ((scale - scale * scaleFactor) / zoomFactor);
|
|
470
604
|
}
|
|
471
|
-
|
|
472
|
-
|
|
605
|
+
if (getTarget)
|
|
606
|
+
return targetScale;
|
|
607
|
+
var paddingEnabled = disablePadding ? false : !disabled;
|
|
608
|
+
var newScale = checkZoomBounds(roundNumber(targetScale, 3), minScale, maxScale, size, paddingEnabled);
|
|
609
|
+
return newScale;
|
|
473
610
|
}
|
|
474
|
-
|
|
475
|
-
var
|
|
476
|
-
var
|
|
477
|
-
var
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
611
|
+
function handleCalculateBounds(newScale, limitToWrapper) {
|
|
612
|
+
var _a = this.stateProvider, wrapperComponent = _a.wrapperComponent, contentComponent = _a.contentComponent;
|
|
613
|
+
var _b = getComponentsSizes(wrapperComponent, contentComponent, newScale), wrapperWidth = _b.wrapperWidth, wrapperHeight = _b.wrapperHeight, newContentWidth = _b.newContentWidth, newDiffWidth = _b.newDiffWidth, newContentHeight = _b.newContentHeight, newDiffHeight = _b.newDiffHeight;
|
|
614
|
+
var bounds = calculateBoundingArea(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, limitToWrapper);
|
|
615
|
+
this.bounds = bounds;
|
|
616
|
+
return bounds;
|
|
617
|
+
}
|
|
618
|
+
function handleWheelZoom(event) {
|
|
619
|
+
var _a = this.stateProvider, scale = _a.scale, contentComponent = _a.contentComponent, limitToBounds = _a.options.limitToBounds, _b = _a.scalePadding, size = _b.size, disabled = _b.disabled, _c = _a.wheel, step = _c.step, limitsOnWheel = _c.limitsOnWheel;
|
|
620
|
+
event.preventDefault();
|
|
621
|
+
event.stopPropagation();
|
|
622
|
+
var delta = getDelta(event, null);
|
|
623
|
+
var newScale = handleCalculateZoom.call(this, delta, step, !event.ctrlKey);
|
|
624
|
+
if (scale === newScale)
|
|
625
|
+
return;
|
|
626
|
+
var bounds = handleCalculateBounds.call(this, newScale, !limitsOnWheel);
|
|
627
|
+
var _d = wheelMousePosition(event, contentComponent, scale), mouseX = _d.mouseX, mouseY = _d.mouseY;
|
|
628
|
+
var isLimitedToBounds = limitToBounds && (disabled || size === 0 || limitsOnWheel);
|
|
629
|
+
var _e = handleCalculatePositions.call(this, mouseX, mouseY, newScale, bounds, isLimitedToBounds), x = _e.x, y = _e.y;
|
|
630
|
+
this.bounds = bounds;
|
|
631
|
+
this.stateProvider.previousScale = scale;
|
|
632
|
+
this.stateProvider.scale = newScale;
|
|
633
|
+
this.stateProvider.positionX = x;
|
|
634
|
+
this.stateProvider.positionY = y;
|
|
635
|
+
this.applyTransformation();
|
|
636
|
+
}
|
|
637
|
+
function handleZoomToPoint(isDisabled, scale, mouseX, mouseY, event) {
|
|
638
|
+
var _a = this.stateProvider, contentComponent = _a.contentComponent, _b = _a.options, disabled = _b.disabled, minScale = _b.minScale, maxScale = _b.maxScale, limitToBounds = _b.limitToBounds, limitToWrapper = _b.limitToWrapper;
|
|
639
|
+
if (disabled || isDisabled)
|
|
640
|
+
return;
|
|
641
|
+
var newScale = checkZoomBounds(roundNumber(scale, 2), minScale, maxScale, null, null);
|
|
642
|
+
var bounds = handleCalculateBounds.call(this, newScale, limitToWrapper);
|
|
643
|
+
var mousePosX = mouseX;
|
|
644
|
+
var mousePosY = mouseY;
|
|
645
|
+
if (event) {
|
|
646
|
+
var mousePosition = wheelMousePosition(event, contentComponent, scale);
|
|
647
|
+
mousePosX = mousePosition.mouseX;
|
|
648
|
+
mousePosY = mousePosition.mouseY;
|
|
484
649
|
}
|
|
485
|
-
var
|
|
486
|
-
var mouseY = clientY - startCoords.y;
|
|
487
|
-
var newPositionX = lockAxisX ? positionX : mouseX;
|
|
488
|
-
var newPositionY = lockAxisY ? positionY : mouseY;
|
|
650
|
+
var _c = handleCalculatePositions.call(this, mousePosX, mousePosY, newScale, bounds, limitToBounds), x = _c.x, y = _c.y;
|
|
489
651
|
return {
|
|
490
|
-
|
|
491
|
-
|
|
652
|
+
scale: newScale,
|
|
653
|
+
positionX: x,
|
|
654
|
+
positionY: y
|
|
492
655
|
};
|
|
493
|
-
};
|
|
494
|
-
var getPaddingValue = function(contextInstance, size) {
|
|
495
|
-
var setup = contextInstance.setup, transformState = contextInstance.transformState;
|
|
496
|
-
var scale = transformState.scale;
|
|
497
|
-
var minScale = setup.minScale;
|
|
498
|
-
if (size > 0 && scale >= minScale) {
|
|
499
|
-
return size;
|
|
500
|
-
}
|
|
501
|
-
return 0;
|
|
502
|
-
};
|
|
503
|
-
var isVelocityCalculationAllowed = function(contextInstance) {
|
|
504
|
-
var mounted = contextInstance.mounted;
|
|
505
|
-
var _a = contextInstance.setup, disabled = _a.disabled, velocityAnimation = _a.velocityAnimation;
|
|
506
|
-
var scale = contextInstance.transformState.scale;
|
|
507
|
-
var disabledVelocity = velocityAnimation.disabled;
|
|
508
|
-
var isAllowed = !disabledVelocity || scale > 1 || !disabled || mounted;
|
|
509
|
-
if (!isAllowed)
|
|
510
|
-
return false;
|
|
511
|
-
return true;
|
|
512
|
-
};
|
|
513
|
-
var isVelocityAllowed = function(contextInstance) {
|
|
514
|
-
var mounted = contextInstance.mounted, velocity = contextInstance.velocity, bounds = contextInstance.bounds;
|
|
515
|
-
var _a = contextInstance.setup, disabled = _a.disabled, velocityAnimation = _a.velocityAnimation;
|
|
516
|
-
var scale = contextInstance.transformState.scale;
|
|
517
|
-
var disabledVelocity = velocityAnimation.disabled;
|
|
518
|
-
var isAllowed = !disabledVelocity || scale > 1 || !disabled || mounted;
|
|
519
|
-
if (!isAllowed)
|
|
520
|
-
return false;
|
|
521
|
-
if (!velocity || !bounds)
|
|
522
|
-
return false;
|
|
523
|
-
return true;
|
|
524
|
-
};
|
|
525
|
-
function getVelocityMoveTime(contextInstance, velocity) {
|
|
526
|
-
var velocityAnimation = contextInstance.setup.velocityAnimation;
|
|
527
|
-
var equalToMove = velocityAnimation.equalToMove, animationTime = velocityAnimation.animationTime, sensitivity = velocityAnimation.sensitivity;
|
|
528
|
-
if (equalToMove) {
|
|
529
|
-
return animationTime * velocity * sensitivity;
|
|
530
|
-
}
|
|
531
|
-
return animationTime;
|
|
532
656
|
}
|
|
533
|
-
function
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
return maxTarget;
|
|
539
|
-
if (calculatedPosition < maxPosition)
|
|
540
|
-
return maxPosition;
|
|
541
|
-
return calculatedPosition;
|
|
542
|
-
}
|
|
543
|
-
if (startPosition < minPosition && currentPosition < minPosition) {
|
|
544
|
-
var calculatedPosition = minPosition + (newPosition - minPosition) * step;
|
|
545
|
-
if (calculatedPosition < minTarget)
|
|
546
|
-
return minTarget;
|
|
547
|
-
if (calculatedPosition > minPosition)
|
|
548
|
-
return minPosition;
|
|
549
|
-
return calculatedPosition;
|
|
550
|
-
}
|
|
657
|
+
function handlePaddingAnimation$1() {
|
|
658
|
+
var _a = this.stateProvider, scale = _a.scale, wrapperComponent = _a.wrapperComponent, _b = _a.options, minScale = _b.minScale, limitToBounds = _b.limitToBounds, _c = _a.scalePadding, disabled = _c.disabled, animationTime = _c.animationTime, animationType = _c.animationType;
|
|
659
|
+
var isDisabled = disabled || scale >= minScale;
|
|
660
|
+
if (scale >= 1 || limitToBounds) {
|
|
661
|
+
handlePanningAnimation.call(this);
|
|
551
662
|
}
|
|
552
|
-
if (
|
|
553
|
-
return
|
|
554
|
-
|
|
663
|
+
if (isDisabled)
|
|
664
|
+
return;
|
|
665
|
+
var mouseX = wrapperComponent.offsetWidth / 2;
|
|
666
|
+
var mouseY = wrapperComponent.offsetHeight / 2;
|
|
667
|
+
var targetState = handleZoomToPoint.call(this, false, minScale, mouseX, mouseY, null);
|
|
668
|
+
animateComponent.call(this, {
|
|
669
|
+
targetState,
|
|
670
|
+
speed: animationTime,
|
|
671
|
+
type: animationType
|
|
672
|
+
});
|
|
555
673
|
}
|
|
556
|
-
function
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
674
|
+
function handleDoubleClick(event) {
|
|
675
|
+
event.preventDefault();
|
|
676
|
+
event.stopPropagation();
|
|
677
|
+
var _a = this.stateProvider, contentComponent = _a.contentComponent, scale = _a.scale, _b = _a.doubleClick, disabled = _b.disabled, mode = _b.mode, step = _b.step, animationTime = _b.animationTime, animationType = _b.animationType;
|
|
678
|
+
if (mode === "reset") {
|
|
679
|
+
return resetTransformations.call(this, event, animationTime);
|
|
560
680
|
}
|
|
561
|
-
|
|
681
|
+
var delta = mode === "zoomOut" ? -1 : 1;
|
|
682
|
+
var newScale = handleCalculateZoom.call(this, delta, step, void 0, void 0, true);
|
|
683
|
+
var _c = wheelMousePosition(event, contentComponent, scale), mouseX = _c.mouseX, mouseY = _c.mouseY;
|
|
684
|
+
var targetState = handleZoomToPoint.call(this, disabled, newScale, mouseX, mouseY);
|
|
685
|
+
if (targetState.scale === scale)
|
|
686
|
+
return;
|
|
687
|
+
var targetScale = handleCalculateZoom.call(this, delta, step, true, void 0, true);
|
|
688
|
+
var time = getButtonAnimationTime(targetScale, newScale, animationTime);
|
|
689
|
+
animateComponent.call(this, {
|
|
690
|
+
targetState,
|
|
691
|
+
speed: time,
|
|
692
|
+
type: animationType
|
|
693
|
+
});
|
|
562
694
|
}
|
|
563
|
-
function
|
|
564
|
-
var
|
|
565
|
-
|
|
695
|
+
function handleZoomControls(customDelta, customStep) {
|
|
696
|
+
var _a = this.stateProvider, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY, wrapperComponent = _a.wrapperComponent, zoomIn = _a.zoomIn, zoomOut = _a.zoomOut;
|
|
697
|
+
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
698
|
+
var wrapperHeight = wrapperComponent.offsetHeight;
|
|
699
|
+
var mouseX = (wrapperWidth / 2 - positionX) / scale;
|
|
700
|
+
var mouseY = (wrapperHeight / 2 - positionY) / scale;
|
|
701
|
+
var newScale = handleCalculateZoom.call(this, customDelta, customStep, void 0, void 0, true);
|
|
702
|
+
var isZoomIn = newScale > scale;
|
|
703
|
+
var animationSpeed = isZoomIn ? zoomIn.animationTime : zoomOut.animationTime;
|
|
704
|
+
var animationType = isZoomIn ? zoomIn.animationType : zoomOut.animationType;
|
|
705
|
+
var isDisabled = isZoomIn ? zoomIn.disabled : zoomOut.disabled;
|
|
706
|
+
var targetState = handleZoomToPoint.call(this, isDisabled, newScale, mouseX, mouseY);
|
|
707
|
+
if (targetState.scale === scale)
|
|
566
708
|
return;
|
|
567
|
-
|
|
568
|
-
var
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
var distanceX = position.x - lastMousePosition.x;
|
|
575
|
-
var distanceY = position.y - lastMousePosition.y;
|
|
576
|
-
var velocityX = distanceX / sizeMultiplier;
|
|
577
|
-
var velocityY = distanceY / sizeMultiplier;
|
|
578
|
-
var interval = now - velocityTime;
|
|
579
|
-
var speed = distanceX * distanceX + distanceY * distanceY;
|
|
580
|
-
var velocity = Math.sqrt(speed) / interval;
|
|
581
|
-
contextInstance.velocity = {
|
|
582
|
-
velocityX,
|
|
583
|
-
velocityY,
|
|
584
|
-
total: velocity
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
contextInstance.lastMousePosition = position;
|
|
588
|
-
contextInstance.velocityTime = now;
|
|
709
|
+
var targetScale = handleCalculateZoom.call(this, customDelta, customStep, true, void 0, true);
|
|
710
|
+
var time = getButtonAnimationTime(targetScale, newScale, animationSpeed);
|
|
711
|
+
animateComponent.call(this, {
|
|
712
|
+
targetState,
|
|
713
|
+
speed: time,
|
|
714
|
+
type: animationType
|
|
715
|
+
});
|
|
589
716
|
}
|
|
590
|
-
function
|
|
591
|
-
var
|
|
592
|
-
var
|
|
593
|
-
if (
|
|
717
|
+
function resetTransformations(animationSpeed) {
|
|
718
|
+
var _a = this.props.defaultValues, defaultScale = _a.defaultScale, defaultPositionX = _a.defaultPositionX, defaultPositionY = _a.defaultPositionY;
|
|
719
|
+
var _b = this.stateProvider, scale = _b.scale, positionX = _b.positionX, positionY = _b.positionY, reset = _b.reset, _c = _b.options, disabled = _c.disabled, limitToBounds = _c.limitToBounds, centerContent = _c.centerContent, limitToWrapper = _c.limitToWrapper;
|
|
720
|
+
if (disabled || reset.disabled)
|
|
721
|
+
return;
|
|
722
|
+
if (scale === defaultScale && positionX === defaultPositionX && positionY === defaultPositionY)
|
|
594
723
|
return;
|
|
724
|
+
var speed = typeof animationSpeed === "number" ? animationSpeed : reset.animationTime;
|
|
725
|
+
var targetScale = checkIsNumber(defaultScale, initialState.scale);
|
|
726
|
+
var newPositionX = checkIsNumber(defaultPositionX, initialState.positionX);
|
|
727
|
+
var newPositionY = checkIsNumber(defaultPositionY, initialState.positionY);
|
|
728
|
+
if (limitToBounds && !limitToWrapper || centerContent) {
|
|
729
|
+
var bounds = handleCalculateBounds.call(this, targetScale, limitToWrapper);
|
|
730
|
+
newPositionX = bounds.minPositionX;
|
|
731
|
+
newPositionY = bounds.minPositionY;
|
|
595
732
|
}
|
|
596
|
-
var
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
var finalAnimationTime = Math.max(moveAnimationTime, alignAnimationTime);
|
|
606
|
-
var paddingValueX = getPaddingValue(contextInstance, sizeX);
|
|
607
|
-
var paddingValueY = getPaddingValue(contextInstance, sizeY);
|
|
608
|
-
var paddingX = paddingValueX * wrapperComponent.offsetWidth / 100;
|
|
609
|
-
var paddingY = paddingValueY * wrapperComponent.offsetHeight / 100;
|
|
610
|
-
var maxTargetX = maxPositionX + paddingX;
|
|
611
|
-
var minTargetX = minPositionX - paddingX;
|
|
612
|
-
var maxTargetY = maxPositionY + paddingY;
|
|
613
|
-
var minTargetY = minPositionY - paddingY;
|
|
614
|
-
var startState = contextInstance.transformState;
|
|
615
|
-
var startTime = new Date().getTime();
|
|
616
|
-
handleSetupAnimation(contextInstance, animationType, finalAnimationTime, function(step) {
|
|
617
|
-
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
618
|
-
var frameTime = new Date().getTime() - startTime;
|
|
619
|
-
var animationProgress = frameTime / alignAnimationTime;
|
|
620
|
-
var alignAnimation = animations[alignmentAnimation.animationType];
|
|
621
|
-
var alignStep = 1 - alignAnimation(Math.min(1, animationProgress));
|
|
622
|
-
var customStep = 1 - step;
|
|
623
|
-
var newPositionX = positionX + velocityX * customStep;
|
|
624
|
-
var newPositionY = positionY + velocityY * customStep;
|
|
625
|
-
var currentPositionX = getVelocityPosition(newPositionX, startState.positionX, positionX, lockAxisX, limitToBounds, minPositionX, maxPositionX, minTargetX, maxTargetX, alignStep);
|
|
626
|
-
var currentPositionY = getVelocityPosition(newPositionY, startState.positionY, positionY, lockAxisY, limitToBounds, minPositionY, maxPositionY, minTargetY, maxTargetY, alignStep);
|
|
627
|
-
if (positionX !== newPositionX || positionY !== newPositionY) {
|
|
628
|
-
contextInstance.setTransformState(scale, currentPositionX, currentPositionY);
|
|
629
|
-
}
|
|
733
|
+
var targetState = {
|
|
734
|
+
scale: targetScale,
|
|
735
|
+
positionX: newPositionX,
|
|
736
|
+
positionY: newPositionY
|
|
737
|
+
};
|
|
738
|
+
animateComponent.call(this, {
|
|
739
|
+
targetState,
|
|
740
|
+
speed,
|
|
741
|
+
type: reset.animationType
|
|
630
742
|
});
|
|
631
743
|
}
|
|
632
|
-
function
|
|
633
|
-
|
|
634
|
-
handleCancelAnimation(contextInstance);
|
|
635
|
-
handleCalculateBounds(contextInstance, scale);
|
|
636
|
-
if (event.touches) {
|
|
637
|
-
handleTouchPanningSetup(contextInstance, event);
|
|
638
|
-
} else {
|
|
639
|
-
handlePanningSetup(contextInstance, event);
|
|
640
|
-
}
|
|
744
|
+
function getButtonAnimationTime(targetScale, newScale, time) {
|
|
745
|
+
return time * (newScale / targetScale);
|
|
641
746
|
}
|
|
642
|
-
function
|
|
643
|
-
var
|
|
644
|
-
|
|
645
|
-
if (!startCoords)
|
|
646
|
-
return;
|
|
647
|
-
var _b = getPanningClientPosition(contextInstance, clientX, clientY), x = _b.x, y = _b.y;
|
|
648
|
-
var paddingValueX = getPaddingValue(contextInstance, sizeX);
|
|
649
|
-
var paddingValueY = getPaddingValue(contextInstance, sizeY);
|
|
650
|
-
handleCalculateVelocity(contextInstance, {
|
|
651
|
-
x,
|
|
652
|
-
y
|
|
653
|
-
});
|
|
654
|
-
handleNewPosition(contextInstance, x, y, paddingValueX, paddingValueY);
|
|
747
|
+
function round(number, decimal) {
|
|
748
|
+
var roundNumber2 = Math.pow(10, decimal);
|
|
749
|
+
return Math.round(number * roundNumber2) / roundNumber2;
|
|
655
750
|
}
|
|
656
|
-
function
|
|
657
|
-
|
|
658
|
-
var velocityDisabled = contextInstance.setup.panning.velocityDisabled;
|
|
659
|
-
var velocity = contextInstance.velocity, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
660
|
-
contextInstance.isPanning = false;
|
|
661
|
-
contextInstance.animate = false;
|
|
662
|
-
contextInstance.animation = null;
|
|
663
|
-
var wrapperRect = wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.getBoundingClientRect();
|
|
664
|
-
var contentRect = contentComponent === null || contentComponent === void 0 ? void 0 : contentComponent.getBoundingClientRect();
|
|
665
|
-
var wrapperWidth = (wrapperRect === null || wrapperRect === void 0 ? void 0 : wrapperRect.width) || 0;
|
|
666
|
-
var wrapperHeight = (wrapperRect === null || wrapperRect === void 0 ? void 0 : wrapperRect.height) || 0;
|
|
667
|
-
var contentWidth = (contentRect === null || contentRect === void 0 ? void 0 : contentRect.width) || 0;
|
|
668
|
-
var contentHeight = (contentRect === null || contentRect === void 0 ? void 0 : contentRect.height) || 0;
|
|
669
|
-
var isZoomed = wrapperWidth < contentWidth || wrapperHeight < contentHeight;
|
|
670
|
-
var shouldAnimate = !velocityDisabled && velocity && (velocity === null || velocity === void 0 ? void 0 : velocity.total) > 0.1 && isZoomed;
|
|
671
|
-
if (shouldAnimate) {
|
|
672
|
-
handleVelocityPanning(contextInstance);
|
|
673
|
-
} else {
|
|
674
|
-
handleAlignToBounds(contextInstance);
|
|
675
|
-
}
|
|
676
|
-
}
|
|
751
|
+
function getCurrentDistance(event) {
|
|
752
|
+
return getDistance(event.touches[0], event.touches[1]);
|
|
677
753
|
}
|
|
678
|
-
function
|
|
679
|
-
|
|
680
|
-
var _a = contextInstance.setup, minScale = _a.minScale, alignmentAnimation = _a.alignmentAnimation;
|
|
681
|
-
var disabled = alignmentAnimation.disabled, sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, animationTime = alignmentAnimation.animationTime, animationType = alignmentAnimation.animationType;
|
|
682
|
-
var isDisabled = disabled || scale < minScale || !sizeX && !sizeY;
|
|
683
|
-
if (isDisabled)
|
|
684
|
-
return;
|
|
685
|
-
var targetState = handlePanToBounds(contextInstance);
|
|
686
|
-
if (targetState) {
|
|
687
|
-
animate(contextInstance, targetState, animationTime, animationType);
|
|
688
|
-
}
|
|
754
|
+
function checkIfInfinite(number) {
|
|
755
|
+
return number === Infinity || number === -Infinity;
|
|
689
756
|
}
|
|
690
|
-
function
|
|
691
|
-
var
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
var isDisabled = disabled || scale >= minScale;
|
|
696
|
-
if (scale >= 1 || limitToBounds) {
|
|
697
|
-
handleAlignToBounds(contextInstance);
|
|
698
|
-
}
|
|
699
|
-
if (isDisabled || !wrapperComponent || !contextInstance.mounted)
|
|
757
|
+
function calculatePinchZoom(currentDistance, pinchStartDistance) {
|
|
758
|
+
var _a = this.stateProvider, _b = _a.options, minScale = _b.minScale, maxScale = _b.maxScale, _c = _a.scalePadding, size = _c.size, disabled = _c.disabled;
|
|
759
|
+
if (typeof pinchStartDistance !== "number" || typeof currentDistance !== "number")
|
|
760
|
+
return console.error("Pinch touches distance was not provided");
|
|
761
|
+
if (currentDistance < 0)
|
|
700
762
|
return;
|
|
701
|
-
var
|
|
702
|
-
var
|
|
703
|
-
|
|
704
|
-
if (targetState) {
|
|
705
|
-
animate(contextInstance, targetState, animationTime, animationType);
|
|
706
|
-
}
|
|
763
|
+
var touchProportion = currentDistance / pinchStartDistance;
|
|
764
|
+
var scaleDifference = touchProportion * this.pinchStartScale;
|
|
765
|
+
return checkZoomBounds(roundNumber(scaleDifference, 2), minScale, maxScale, size, !disabled);
|
|
707
766
|
}
|
|
708
|
-
function
|
|
709
|
-
var
|
|
710
|
-
var
|
|
711
|
-
var
|
|
712
|
-
var
|
|
767
|
+
function calculateMidpoint(event, scale, contentComponent) {
|
|
768
|
+
var contentRect = contentComponent.getBoundingClientRect();
|
|
769
|
+
var touches = event.touches;
|
|
770
|
+
var firstPointX = round(touches[0].clientX - contentRect.left, 5);
|
|
771
|
+
var firstPointY = round(touches[0].clientY - contentRect.top, 5);
|
|
772
|
+
var secondPointX = round(touches[1].clientX - contentRect.left, 5);
|
|
773
|
+
var secondPointY = round(touches[1].clientY - contentRect.top, 5);
|
|
713
774
|
return {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
positionY: y
|
|
775
|
+
mouseX: (firstPointX + secondPointX) / 2 / scale,
|
|
776
|
+
mouseY: (firstPointY + secondPointY) / 2 / scale
|
|
717
777
|
};
|
|
718
778
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
return void 0;
|
|
728
|
-
},
|
|
729
|
-
contextInstance: null
|
|
730
|
-
});
|
|
731
|
-
var initialSetup = {
|
|
732
|
-
disabled: false,
|
|
733
|
-
minPositionX: null,
|
|
734
|
-
maxPositionX: null,
|
|
735
|
-
minPositionY: null,
|
|
736
|
-
maxPositionY: null,
|
|
737
|
-
minScale: 1,
|
|
738
|
-
maxScale: 8,
|
|
739
|
-
limitToBounds: true,
|
|
740
|
-
centerZoomedOut: false,
|
|
741
|
-
centerOnInit: false,
|
|
742
|
-
wheel: {
|
|
743
|
-
step: 0.2,
|
|
744
|
-
disabled: false,
|
|
745
|
-
wheelDisabled: false,
|
|
746
|
-
touchPadDisabled: false,
|
|
747
|
-
activationKeys: [],
|
|
748
|
-
excluded: []
|
|
749
|
-
},
|
|
750
|
-
panning: {
|
|
751
|
-
disabled: false,
|
|
752
|
-
velocityDisabled: false,
|
|
753
|
-
lockAxisX: false,
|
|
754
|
-
lockAxisY: false,
|
|
755
|
-
activationKeys: [],
|
|
756
|
-
excluded: []
|
|
757
|
-
},
|
|
758
|
-
pinch: {
|
|
759
|
-
step: 5,
|
|
760
|
-
disabled: false,
|
|
761
|
-
excluded: []
|
|
762
|
-
},
|
|
763
|
-
doubleClick: {
|
|
764
|
-
disabled: false,
|
|
765
|
-
step: 0.7,
|
|
766
|
-
mode: "zoomIn",
|
|
767
|
-
animationType: "easeOut",
|
|
768
|
-
animationTime: 200,
|
|
769
|
-
excluded: []
|
|
770
|
-
},
|
|
771
|
-
zoomAnimation: {
|
|
772
|
-
disabled: false,
|
|
773
|
-
size: 0.4,
|
|
774
|
-
animationTime: 200,
|
|
775
|
-
animationType: "easeOut"
|
|
776
|
-
},
|
|
777
|
-
alignmentAnimation: {
|
|
778
|
-
disabled: false,
|
|
779
|
-
sizeX: 100,
|
|
780
|
-
sizeY: 100,
|
|
781
|
-
animationTime: 200,
|
|
782
|
-
velocityAlignmentTime: 400,
|
|
783
|
-
animationType: "easeOut"
|
|
784
|
-
},
|
|
785
|
-
velocityAnimation: {
|
|
786
|
-
disabled: false,
|
|
787
|
-
sensitivity: 1,
|
|
788
|
-
animationTime: 400,
|
|
789
|
-
animationType: "easeOut",
|
|
790
|
-
equalToMove: true
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
var createState = function(props) {
|
|
794
|
-
var _a, _b, _c, _d;
|
|
795
|
-
return {
|
|
796
|
-
previousScale: (_a = props.initialScale) !== null && _a !== void 0 ? _a : initialState.scale,
|
|
797
|
-
scale: (_b = props.initialScale) !== null && _b !== void 0 ? _b : initialState.scale,
|
|
798
|
-
positionX: (_c = props.initialPositionX) !== null && _c !== void 0 ? _c : initialState.positionX,
|
|
799
|
-
positionY: (_d = props.initialPositionY) !== null && _d !== void 0 ? _d : initialState.positionY
|
|
800
|
-
};
|
|
801
|
-
};
|
|
802
|
-
var createSetup = function(props) {
|
|
803
|
-
var newSetup = __assign({}, initialSetup);
|
|
804
|
-
Object.keys(props).forEach(function(key) {
|
|
805
|
-
var validValue = typeof props[key] !== "undefined";
|
|
806
|
-
var validParameter = typeof initialSetup[key] !== "undefined";
|
|
807
|
-
if (validParameter && validValue) {
|
|
808
|
-
var dataType = Object.prototype.toString.call(initialSetup[key]);
|
|
809
|
-
var isObject = dataType === "[object Object]";
|
|
810
|
-
var isArray = dataType === "[object Array]";
|
|
811
|
-
if (isObject) {
|
|
812
|
-
newSetup[key] = __assign(__assign({}, initialSetup[key]), props[key]);
|
|
813
|
-
} else if (isArray) {
|
|
814
|
-
newSetup[key] = __spreadArray(__spreadArray([], initialSetup[key]), props[key]);
|
|
815
|
-
} else {
|
|
816
|
-
newSetup[key] = props[key];
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
});
|
|
820
|
-
return newSetup;
|
|
821
|
-
};
|
|
822
|
-
var handleCalculateButtonZoom = function(contextInstance, delta, step) {
|
|
823
|
-
var scale = contextInstance.transformState.scale;
|
|
824
|
-
var wrapperComponent = contextInstance.wrapperComponent, setup = contextInstance.setup;
|
|
825
|
-
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation;
|
|
826
|
-
var size = zoomAnimation.size;
|
|
827
|
-
if (!wrapperComponent) {
|
|
828
|
-
throw new Error("Wrapper is not mounted");
|
|
829
|
-
}
|
|
830
|
-
var targetScale = scale * Math.exp(delta * step);
|
|
831
|
-
var newScale = checkZoomBounds(roundNumber(targetScale, 3), minScale, maxScale, size, false);
|
|
832
|
-
return newScale;
|
|
833
|
-
};
|
|
834
|
-
function handleZoomToViewCenter(contextInstance, delta, step, animationTime, animationType) {
|
|
835
|
-
var wrapperComponent = contextInstance.wrapperComponent;
|
|
836
|
-
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
837
|
-
if (!wrapperComponent)
|
|
838
|
-
return console.error("No WrapperComponent found");
|
|
839
|
-
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
840
|
-
var wrapperHeight = wrapperComponent.offsetHeight;
|
|
841
|
-
var mouseX = (wrapperWidth / 2 - positionX) / scale;
|
|
842
|
-
var mouseY = (wrapperHeight / 2 - positionY) / scale;
|
|
843
|
-
var newScale = handleCalculateButtonZoom(contextInstance, delta, step);
|
|
844
|
-
var targetState = handleZoomToPoint(contextInstance, newScale, mouseX, mouseY);
|
|
845
|
-
if (!targetState) {
|
|
846
|
-
return console.error("Error during zoom event. New transformation state was not calculated.");
|
|
779
|
+
function handleZoomPinch(event) {
|
|
780
|
+
var _a = this.stateProvider, scale = _a.scale, _b = _a.options, limitToBounds = _b.limitToBounds, limitToWrapper = _b.limitToWrapper, _c = _a.scalePadding, disabled = _c.disabled, size = _c.size, limitsOnWheel = _a.wheel.limitsOnWheel, pinch = _a.pinch;
|
|
781
|
+
var contentComponent = this.state.contentComponent;
|
|
782
|
+
if (pinch.disabled || this.stateProvider.options.disabled)
|
|
783
|
+
return;
|
|
784
|
+
if (event.cancelable) {
|
|
785
|
+
event.preventDefault();
|
|
786
|
+
event.stopPropagation();
|
|
847
787
|
}
|
|
848
|
-
|
|
849
|
-
}
|
|
850
|
-
function resetTransformations(contextInstance, animationTime, animationType) {
|
|
851
|
-
var setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
|
|
852
|
-
var limitToBounds = setup.limitToBounds;
|
|
853
|
-
var initialTransformation = createState(contextInstance.props);
|
|
854
|
-
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
855
|
-
if (!wrapperComponent)
|
|
788
|
+
if (this.pinchStartDistance === null)
|
|
856
789
|
return;
|
|
857
|
-
var
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
};
|
|
864
|
-
if (scale === initialTransformation.scale && positionX === initialTransformation.positionX && positionY === initialTransformation.positionY) {
|
|
790
|
+
var _d = calculateMidpoint(event, scale, contentComponent), mouseX = _d.mouseX, mouseY = _d.mouseY;
|
|
791
|
+
if (checkIfInfinite(mouseX) || checkIfInfinite(mouseY))
|
|
792
|
+
return;
|
|
793
|
+
var currentDistance = getCurrentDistance(event);
|
|
794
|
+
var newScale = calculatePinchZoom.call(this, currentDistance, this.pinchStartDistance);
|
|
795
|
+
if (checkIfInfinite(newScale) || newScale === scale)
|
|
865
796
|
return;
|
|
797
|
+
var bounds = handleCalculateBounds.call(this, newScale, limitToWrapper);
|
|
798
|
+
var isLimitedToBounds = limitToBounds && (disabled || size === 0 || limitsOnWheel);
|
|
799
|
+
var _e = handleCalculatePositions.call(this, mouseX, mouseY, newScale, bounds, isLimitedToBounds), x = _e.x, y = _e.y;
|
|
800
|
+
this.lastDistance = currentDistance;
|
|
801
|
+
this.stateProvider.positionX = x;
|
|
802
|
+
this.stateProvider.positionY = y;
|
|
803
|
+
this.stateProvider.scale = newScale;
|
|
804
|
+
this.stateProvider.previousScale = scale;
|
|
805
|
+
this.applyTransformation();
|
|
806
|
+
}
|
|
807
|
+
var throttleTime = 30;
|
|
808
|
+
function velocityTimeSpeed(speed, animationTime) {
|
|
809
|
+
var velocityEqualToMove = this.stateProvider.pan.velocityEqualToMove;
|
|
810
|
+
if (velocityEqualToMove) {
|
|
811
|
+
return animationTime - animationTime / Math.max(1, speed);
|
|
866
812
|
}
|
|
867
|
-
|
|
813
|
+
return animationTime;
|
|
868
814
|
}
|
|
869
|
-
function
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
return initialState;
|
|
874
|
-
var wrapperRect = wrapperComponent.getBoundingClientRect();
|
|
875
|
-
var nodeRect = getOffset(node);
|
|
876
|
-
var nodeLeft = nodeRect.x;
|
|
877
|
-
var nodeTop = nodeRect.y;
|
|
878
|
-
var nodeWidth = node.offsetWidth;
|
|
879
|
-
var nodeHeight = node.offsetHeight;
|
|
880
|
-
var scaleX = wrapperComponent.offsetWidth / nodeWidth;
|
|
881
|
-
var scaleY = wrapperComponent.offsetHeight / nodeHeight;
|
|
882
|
-
var newScale = checkZoomBounds(customZoom || Math.min(scaleX, scaleY), minScale, maxScale, 0, false);
|
|
883
|
-
var offsetX = (wrapperRect.width - nodeWidth * newScale) / 2;
|
|
884
|
-
var offsetY = (wrapperRect.height - nodeHeight * newScale) / 2;
|
|
885
|
-
var newPositionX = (wrapperRect.left - nodeLeft) * newScale + offsetX;
|
|
886
|
-
var newPositionY = (wrapperRect.top - nodeTop) * newScale + offsetY;
|
|
887
|
-
var bounds = calculateBounds(contextInstance, newScale);
|
|
888
|
-
var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, 0, 0, wrapperComponent), x = _b.x, y = _b.y;
|
|
889
|
-
return {
|
|
890
|
-
positionX: x,
|
|
891
|
-
positionY: y,
|
|
892
|
-
scale: newScale
|
|
893
|
-
};
|
|
815
|
+
function handleEnableVelocity() {
|
|
816
|
+
this.setState({
|
|
817
|
+
startAnimation: false
|
|
818
|
+
});
|
|
894
819
|
}
|
|
895
|
-
function
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
while (el) {
|
|
900
|
-
offsetLeft += el.offsetLeft;
|
|
901
|
-
offsetTop += el.offsetTop;
|
|
902
|
-
el = el.offsetParent;
|
|
903
|
-
}
|
|
904
|
-
return {
|
|
905
|
-
x: offsetLeft,
|
|
906
|
-
y: offsetTop
|
|
907
|
-
};
|
|
820
|
+
function handleFireVelocity() {
|
|
821
|
+
this.setState({
|
|
822
|
+
startAnimation: true
|
|
823
|
+
});
|
|
908
824
|
}
|
|
909
|
-
function
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
return
|
|
825
|
+
function animateVelocity() {
|
|
826
|
+
var _this = this;
|
|
827
|
+
var _a = this.stateProvider, positionX = _a.positionX, positionY = _a.positionY, limitToBounds = _a.options.limitToBounds, _b = _a.pan, velocityBaseTime = _b.velocityBaseTime, lockAxisX = _b.lockAxisX, lockAxisY = _b.lockAxisY, velocityAnimationType = _b.velocityAnimationType, panReturnAnimationTime = _b.panReturnAnimationTime, panReturnAnimationType = _b.panReturnAnimationType, padding = _b.padding, paddingSize = _b.paddingSize, wrapperComponent = _a.wrapperComponent;
|
|
828
|
+
if (!this.mounted)
|
|
829
|
+
return;
|
|
830
|
+
if (!this.velocity || !this.bounds)
|
|
831
|
+
return handleDisableAnimation.call(this);
|
|
832
|
+
var _c = this.bounds, maxPositionX = _c.maxPositionX, minPositionX = _c.minPositionX, maxPositionY = _c.maxPositionY, minPositionY = _c.minPositionY;
|
|
833
|
+
var _d = this.velocity, velocityX = _d.velocityX, velocityY = _d.velocityY, velocity = _d.velocity;
|
|
834
|
+
var animationTime = velocityTimeSpeed.call(this, velocity, velocityBaseTime);
|
|
835
|
+
if (!animationTime) {
|
|
836
|
+
handlePanningAnimation.call(this);
|
|
837
|
+
return;
|
|
916
838
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
var
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
var
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
if (
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
animationType = "easeOut";
|
|
943
|
-
}
|
|
944
|
-
handleZoomToViewCenter(contextInstance, -1, step, animationTime, animationType);
|
|
945
|
-
};
|
|
946
|
-
};
|
|
947
|
-
var setTransform = function(contextInstance) {
|
|
948
|
-
return function(newPositionX, newPositionY, newScale, animationTime, animationType) {
|
|
949
|
-
if (animationTime === void 0) {
|
|
950
|
-
animationTime = 300;
|
|
951
|
-
}
|
|
952
|
-
if (animationType === void 0) {
|
|
953
|
-
animationType = "easeOut";
|
|
839
|
+
var targetX = velocityX;
|
|
840
|
+
var targetY = velocityY;
|
|
841
|
+
var newAnimationTime = animationTime > panReturnAnimationTime ? animationTime : panReturnAnimationTime;
|
|
842
|
+
var paddingValue = padding ? paddingSize : 0;
|
|
843
|
+
var paddingX = wrapperComponent ? paddingValue * wrapperComponent.offsetWidth / 100 : 0;
|
|
844
|
+
var paddingY = wrapperComponent ? paddingValue * wrapperComponent.offsetHeight / 100 : 0;
|
|
845
|
+
var maxTargetX = maxPositionX + paddingX;
|
|
846
|
+
var minTargetX = minPositionX - paddingX;
|
|
847
|
+
var maxTargetY = maxPositionY + paddingY;
|
|
848
|
+
var minTargetY = minPositionY - paddingY;
|
|
849
|
+
var startPosition = checkPositionBounds(positionX, positionY, this.bounds, limitToBounds, paddingValue, wrapperComponent);
|
|
850
|
+
var startTime = new Date().getTime();
|
|
851
|
+
animate.call(this, velocityAnimationType, newAnimationTime, function(step) {
|
|
852
|
+
var frameTime = new Date().getTime() - startTime;
|
|
853
|
+
var animationProgress = frameTime / panReturnAnimationTime;
|
|
854
|
+
var returnAnimation = availableAnimations[panReturnAnimationType];
|
|
855
|
+
var customReturnStep = returnAnimation(animationProgress);
|
|
856
|
+
if (frameTime > panReturnAnimationTime || customReturnStep > 1 || customReturnStep === Infinity || customReturnStep === -Infinity)
|
|
857
|
+
customReturnStep = 1;
|
|
858
|
+
var currentPositionX = getPosition(lockAxisX, targetX, step, customReturnStep, minPositionX, maxPositionX, limitToBounds, positionX, startPosition.x, minTargetX, maxTargetX);
|
|
859
|
+
var currentPositionY = getPosition(lockAxisY, targetY, step, customReturnStep, minPositionY, maxPositionY, limitToBounds, positionY, startPosition.y, minTargetY, maxTargetY);
|
|
860
|
+
if (positionX !== currentPositionX || positionY !== currentPositionY) {
|
|
861
|
+
_this.stateProvider.positionX = currentPositionX;
|
|
862
|
+
_this.stateProvider.positionY = currentPositionY;
|
|
863
|
+
_this.applyTransformation();
|
|
954
864
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
function calculateVelocityStart(event) {
|
|
868
|
+
var _this = this;
|
|
869
|
+
var _a = this.stateProvider, scale = _a.scale, disabled = _a.options.disabled, _b = _a.pan, velocity = _b.velocity, velocitySensitivity = _b.velocitySensitivity, velocityActiveScale = _b.velocityActiveScale, velocityMinSpeed = _b.velocityMinSpeed, wrapperComponent = _a.wrapperComponent;
|
|
870
|
+
if (!velocity || velocityActiveScale >= scale || disabled)
|
|
871
|
+
return;
|
|
872
|
+
handleEnableVelocity.call(this);
|
|
873
|
+
var now = Date.now();
|
|
874
|
+
if (this.lastMousePosition) {
|
|
875
|
+
var position_1 = getClientPosition(event);
|
|
876
|
+
if (!position_1)
|
|
877
|
+
return console.error("No mouse or touch position detected");
|
|
878
|
+
var clientX = position_1.clientX, clientY = position_1.clientY;
|
|
879
|
+
var distanceX = clientX - this.lastMousePosition.clientX;
|
|
880
|
+
var distanceY = clientY - this.lastMousePosition.clientY;
|
|
881
|
+
var interval = now - this.velocityTime;
|
|
882
|
+
var wrapperToWindowScaleX = 2 - wrapperComponent.offsetWidth / window.innerWidth;
|
|
883
|
+
var wrapperToWindowScaleY = 2 - wrapperComponent.offsetHeight / window.innerHeight;
|
|
884
|
+
var scaledX = 20 * Math.max(velocityMinSpeed, Math.min(2, wrapperToWindowScaleX));
|
|
885
|
+
var scaledY = 20 * Math.max(velocityMinSpeed, Math.min(2, wrapperToWindowScaleY));
|
|
886
|
+
var velocityX = distanceX / interval * velocitySensitivity * scale * scaledX;
|
|
887
|
+
var velocityY = distanceY / interval * velocitySensitivity * scale * scaledY;
|
|
888
|
+
var speed = distanceX * distanceX + distanceY * distanceY;
|
|
889
|
+
var velocity_1 = Math.sqrt(speed) / interval * velocitySensitivity;
|
|
890
|
+
if (this.velocity && velocity_1 < this.velocity.velocity && this.throttle)
|
|
959
891
|
return;
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
};
|
|
965
|
-
animate(contextInstance, targetState, animationTime, animationType);
|
|
966
|
-
};
|
|
967
|
-
};
|
|
968
|
-
var resetTransform = function(contextInstance) {
|
|
969
|
-
return function(animationTime, animationType) {
|
|
970
|
-
if (animationTime === void 0) {
|
|
971
|
-
animationTime = 200;
|
|
972
|
-
}
|
|
973
|
-
if (animationType === void 0) {
|
|
974
|
-
animationType = "easeOut";
|
|
975
|
-
}
|
|
976
|
-
resetTransformations(contextInstance, animationTime, animationType);
|
|
977
|
-
};
|
|
978
|
-
};
|
|
979
|
-
var centerView = function(contextInstance) {
|
|
980
|
-
return function(scale, animationTime, animationType) {
|
|
981
|
-
if (animationTime === void 0) {
|
|
982
|
-
animationTime = 200;
|
|
983
|
-
}
|
|
984
|
-
if (animationType === void 0) {
|
|
985
|
-
animationType = "easeOut";
|
|
986
|
-
}
|
|
987
|
-
var transformState = contextInstance.transformState, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
988
|
-
if (wrapperComponent && contentComponent) {
|
|
989
|
-
var targetState = getCenterPosition(scale || transformState.scale, wrapperComponent, contentComponent);
|
|
990
|
-
animate(contextInstance, targetState, animationTime, animationType);
|
|
991
|
-
}
|
|
992
|
-
};
|
|
993
|
-
};
|
|
994
|
-
var zoomToElement = function(contextInstance) {
|
|
995
|
-
return function(node, scale, animationTime, animationType) {
|
|
996
|
-
if (animationTime === void 0) {
|
|
997
|
-
animationTime = 600;
|
|
998
|
-
}
|
|
999
|
-
if (animationType === void 0) {
|
|
1000
|
-
animationType = "easeOut";
|
|
1001
|
-
}
|
|
1002
|
-
handleCancelAnimation(contextInstance);
|
|
1003
|
-
var wrapperComponent = contextInstance.wrapperComponent;
|
|
1004
|
-
var target = typeof node === "string" ? document.getElementById(node) : node;
|
|
1005
|
-
if (wrapperComponent && isValidZoomNode(target) && target && wrapperComponent.contains(target)) {
|
|
1006
|
-
var targetState = calculateZoomToNode(contextInstance, target, scale);
|
|
1007
|
-
animate(contextInstance, targetState, animationTime, animationType);
|
|
1008
|
-
}
|
|
1009
|
-
};
|
|
1010
|
-
};
|
|
1011
|
-
var getContext = function(contextInstance) {
|
|
1012
|
-
return {
|
|
1013
|
-
instance: contextInstance,
|
|
1014
|
-
state: contextInstance.transformState,
|
|
1015
|
-
zoomIn: zoomIn(contextInstance),
|
|
1016
|
-
zoomOut: zoomOut(contextInstance),
|
|
1017
|
-
setTransform: setTransform(contextInstance),
|
|
1018
|
-
resetTransform: resetTransform(contextInstance),
|
|
1019
|
-
centerView: centerView(contextInstance),
|
|
1020
|
-
zoomToElement: zoomToElement(contextInstance)
|
|
1021
|
-
};
|
|
1022
|
-
};
|
|
1023
|
-
var passiveSupported = false;
|
|
1024
|
-
function makePassiveEventOption() {
|
|
1025
|
-
try {
|
|
1026
|
-
var options = {
|
|
1027
|
-
get passive() {
|
|
1028
|
-
passiveSupported = true;
|
|
1029
|
-
return false;
|
|
1030
|
-
}
|
|
892
|
+
this.velocity = {
|
|
893
|
+
velocityX,
|
|
894
|
+
velocityY,
|
|
895
|
+
velocity: velocity_1
|
|
1031
896
|
};
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
897
|
+
if (this.throttle)
|
|
898
|
+
clearTimeout(this.throttle);
|
|
899
|
+
this.throttle = setTimeout(function() {
|
|
900
|
+
if (_this.mounted)
|
|
901
|
+
_this.throttle = false;
|
|
902
|
+
}, throttleTime);
|
|
1036
903
|
}
|
|
904
|
+
var position = getClientPosition(event);
|
|
905
|
+
this.lastMousePosition = position;
|
|
906
|
+
this.velocityTime = now;
|
|
1037
907
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
908
|
+
function getPosition(isLocked, target, step, panReturnStep, minBound, maxBound, limitToBounds, offset, startPosition, minTarget, maxTarget) {
|
|
909
|
+
if (limitToBounds) {
|
|
910
|
+
if (startPosition > minBound && offset > maxBound) {
|
|
911
|
+
var newPosition = startPosition - (startPosition - maxBound) * panReturnStep;
|
|
912
|
+
if (newPosition > maxTarget)
|
|
913
|
+
return maxTarget;
|
|
914
|
+
if (newPosition < maxBound)
|
|
915
|
+
return maxBound;
|
|
916
|
+
return newPosition;
|
|
917
|
+
}
|
|
918
|
+
if (startPosition < minBound && offset < minBound) {
|
|
919
|
+
var newPosition = startPosition - (startPosition - minBound) * panReturnStep;
|
|
920
|
+
if (newPosition < minTarget)
|
|
921
|
+
return minTarget;
|
|
922
|
+
if (newPosition > minBound)
|
|
923
|
+
return minBound;
|
|
924
|
+
return newPosition;
|
|
925
|
+
}
|
|
1055
926
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
var getCenterPosition = function(scale, wrapperComponent, contentComponent) {
|
|
1061
|
-
var contentWidth = contentComponent.offsetWidth * scale;
|
|
1062
|
-
var contentHeight = contentComponent.offsetHeight * scale;
|
|
1063
|
-
var centerPositionX = (wrapperComponent.offsetWidth - contentWidth) / 2;
|
|
1064
|
-
var centerPositionY = (wrapperComponent.offsetHeight - contentHeight) / 2;
|
|
1065
|
-
return {
|
|
1066
|
-
scale,
|
|
1067
|
-
positionX: centerPositionX,
|
|
1068
|
-
positionY: centerPositionY
|
|
1069
|
-
};
|
|
1070
|
-
};
|
|
1071
|
-
var isWheelAllowed = function(contextInstance, event) {
|
|
1072
|
-
var _a = contextInstance.setup.wheel, disabled = _a.disabled, wheelDisabled = _a.wheelDisabled, touchPadDisabled = _a.touchPadDisabled, excluded = _a.excluded;
|
|
1073
|
-
var isInitialized = contextInstance.isInitialized, isPanning = contextInstance.isPanning;
|
|
1074
|
-
var target = event.target;
|
|
1075
|
-
var isAllowed = isInitialized && !isPanning && !disabled && target;
|
|
1076
|
-
if (!isAllowed)
|
|
1077
|
-
return false;
|
|
1078
|
-
if (wheelDisabled && !event.ctrlKey)
|
|
1079
|
-
return false;
|
|
1080
|
-
if (touchPadDisabled && event.ctrlKey)
|
|
1081
|
-
return false;
|
|
1082
|
-
var isExcluded = isExcludedNode(target, excluded);
|
|
1083
|
-
if (isExcluded)
|
|
1084
|
-
return false;
|
|
1085
|
-
return true;
|
|
1086
|
-
};
|
|
1087
|
-
function getDelta(event, customDelta) {
|
|
1088
|
-
var deltaY = event ? event.deltaY < 0 ? 1 : -1 : 0;
|
|
1089
|
-
var delta = checkIsNumber(customDelta, deltaY);
|
|
1090
|
-
return delta;
|
|
927
|
+
if (isLocked)
|
|
928
|
+
return startPosition;
|
|
929
|
+
var offsetPosition = offset + target * step;
|
|
930
|
+
return boundLimiter(offsetPosition, minBound, maxBound, limitToBounds);
|
|
1091
931
|
}
|
|
1092
|
-
function
|
|
1093
|
-
|
|
1094
|
-
var mouseX = 0;
|
|
1095
|
-
var mouseY = 0;
|
|
1096
|
-
if ("clientX" in event) {
|
|
1097
|
-
mouseX = (event.clientX - contentRect.left) / scale;
|
|
1098
|
-
mouseY = (event.clientY - contentRect.top) / scale;
|
|
1099
|
-
} else {
|
|
1100
|
-
var touch = event.touches[0];
|
|
1101
|
-
mouseX = (touch.clientX - contentRect.left) / scale;
|
|
1102
|
-
mouseY = (touch.clientY - contentRect.top) / scale;
|
|
1103
|
-
}
|
|
1104
|
-
if (isNaN(mouseX) || isNaN(mouseY))
|
|
1105
|
-
console.error("No mouse or touch offset found");
|
|
1106
|
-
return {
|
|
1107
|
-
x: mouseX,
|
|
1108
|
-
y: mouseY
|
|
1109
|
-
};
|
|
932
|
+
function makePassiveEventOption(passive) {
|
|
933
|
+
return passive;
|
|
1110
934
|
}
|
|
1111
|
-
var
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
}
|
|
1119
|
-
var targetScale = scale + delta * (scale - scale * step) * step;
|
|
1120
|
-
if (getTarget)
|
|
1121
|
-
return targetScale;
|
|
1122
|
-
var paddingEnabled = disablePadding ? false : !disabled;
|
|
1123
|
-
var newScale = checkZoomBounds(roundNumber(targetScale, 3), minScale, maxScale, size, paddingEnabled);
|
|
1124
|
-
return newScale;
|
|
1125
|
-
};
|
|
1126
|
-
var handleWheelZoomStop = function(contextInstance, event) {
|
|
1127
|
-
var previousWheelEvent = contextInstance.previousWheelEvent;
|
|
1128
|
-
var scale = contextInstance.transformState.scale;
|
|
1129
|
-
var _a = contextInstance.setup, maxScale = _a.maxScale, minScale = _a.minScale;
|
|
1130
|
-
if (!previousWheelEvent)
|
|
1131
|
-
return false;
|
|
1132
|
-
if (scale < maxScale || scale > minScale)
|
|
1133
|
-
return true;
|
|
1134
|
-
if (Math.sign(previousWheelEvent.deltaY) !== Math.sign(event.deltaY))
|
|
1135
|
-
return true;
|
|
1136
|
-
if (previousWheelEvent.deltaY > 0 && previousWheelEvent.deltaY < event.deltaY)
|
|
1137
|
-
return true;
|
|
1138
|
-
if (previousWheelEvent.deltaY < 0 && previousWheelEvent.deltaY > event.deltaY)
|
|
1139
|
-
return true;
|
|
1140
|
-
if (Math.sign(previousWheelEvent.deltaY) !== Math.sign(event.deltaY))
|
|
1141
|
-
return true;
|
|
1142
|
-
return false;
|
|
1143
|
-
};
|
|
1144
|
-
var isPinchStartAllowed = function(contextInstance, event) {
|
|
1145
|
-
var _a = contextInstance.setup.pinch, disabled = _a.disabled, excluded = _a.excluded;
|
|
1146
|
-
var isInitialized = contextInstance.isInitialized;
|
|
1147
|
-
var target = event.target;
|
|
1148
|
-
var isAllowed = isInitialized && !disabled && target;
|
|
1149
|
-
if (!isAllowed)
|
|
1150
|
-
return false;
|
|
1151
|
-
var isExcluded = isExcludedNode(target, excluded);
|
|
1152
|
-
if (isExcluded)
|
|
1153
|
-
return false;
|
|
1154
|
-
return true;
|
|
1155
|
-
};
|
|
1156
|
-
var isPinchAllowed = function(contextInstance) {
|
|
1157
|
-
var disabled = contextInstance.setup.pinch.disabled;
|
|
1158
|
-
var isInitialized = contextInstance.isInitialized, pinchStartDistance = contextInstance.pinchStartDistance;
|
|
1159
|
-
var isAllowed = isInitialized && !disabled && pinchStartDistance;
|
|
1160
|
-
if (!isAllowed)
|
|
1161
|
-
return false;
|
|
1162
|
-
return true;
|
|
1163
|
-
};
|
|
1164
|
-
var calculateTouchMidPoint = function(event, scale, contentComponent) {
|
|
1165
|
-
var contentRect = contentComponent.getBoundingClientRect();
|
|
1166
|
-
var touches = event.touches;
|
|
1167
|
-
var firstPointX = roundNumber(touches[0].clientX - contentRect.left, 5);
|
|
1168
|
-
var firstPointY = roundNumber(touches[0].clientY - contentRect.top, 5);
|
|
1169
|
-
var secondPointX = roundNumber(touches[1].clientX - contentRect.left, 5);
|
|
1170
|
-
var secondPointY = roundNumber(touches[1].clientY - contentRect.top, 5);
|
|
1171
|
-
return {
|
|
1172
|
-
x: (firstPointX + secondPointX) / 2 / scale,
|
|
1173
|
-
y: (firstPointY + secondPointY) / 2 / scale
|
|
1174
|
-
};
|
|
1175
|
-
};
|
|
1176
|
-
var getTouchDistance = function(event) {
|
|
1177
|
-
return Math.sqrt(Math.pow(event.touches[0].pageX - event.touches[1].pageX, 2) + Math.pow(event.touches[0].pageY - event.touches[1].pageY, 2));
|
|
1178
|
-
};
|
|
1179
|
-
var calculatePinchZoom = function(contextInstance, currentDistance) {
|
|
1180
|
-
var pinchStartScale = contextInstance.pinchStartScale, pinchStartDistance = contextInstance.pinchStartDistance, setup = contextInstance.setup;
|
|
1181
|
-
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation;
|
|
1182
|
-
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
1183
|
-
if (!pinchStartScale || pinchStartDistance === null || !currentDistance) {
|
|
1184
|
-
throw new Error("Pinch touches distance was not provided");
|
|
1185
|
-
}
|
|
1186
|
-
if (currentDistance < 0) {
|
|
1187
|
-
return contextInstance.transformState.scale;
|
|
1188
|
-
}
|
|
1189
|
-
var touchProportion = currentDistance / pinchStartDistance;
|
|
1190
|
-
var scaleDifference = touchProportion * pinchStartScale;
|
|
1191
|
-
return checkZoomBounds(roundNumber(scaleDifference, 2), minScale, maxScale, size, !disabled);
|
|
935
|
+
var propsList = ["previousScale", "scale", "positionX", "positionY", "defaultPositionX", "defaultPositionY", "defaultScale", "onWheelStart", "onWheel", "onWheelStop", "onPanningStart", "onPanning", "onPanningStop", "onPinchingStart", "onPinching", "onPinchingStop", "onZoomChange", "options", "wheel", "scalePadding", "pan", "pinch", "zoomIn", "zoomOut", "doubleClick", "reset"];
|
|
936
|
+
var getValidPropsFromObject = function(props) {
|
|
937
|
+
return Object.keys(props).reduce(function(acc, key) {
|
|
938
|
+
if (propsList.includes(key)) {
|
|
939
|
+
acc[key] = props[key];
|
|
940
|
+
}
|
|
941
|
+
return acc;
|
|
942
|
+
}, {});
|
|
1192
943
|
};
|
|
1193
|
-
var
|
|
944
|
+
var Context = React.createContext({});
|
|
945
|
+
var wheelStopEventTimer = null;
|
|
946
|
+
var wheelStopEventTime = 180;
|
|
947
|
+
var wheelAnimationTimer = null;
|
|
1194
948
|
var wheelAnimationTime = 100;
|
|
1195
|
-
var
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
handleCancelAnimation(contextInstance);
|
|
1199
|
-
handleCallback(getContext(contextInstance), event, onWheelStart);
|
|
1200
|
-
handleCallback(getContext(contextInstance), event, onZoomStart);
|
|
1201
|
-
}
|
|
1202
|
-
};
|
|
1203
|
-
var handleWheelZoom = function(contextInstance, event) {
|
|
1204
|
-
var _a = contextInstance.props, onWheel = _a.onWheel, onZoom = _a.onZoom;
|
|
1205
|
-
var contentComponent = contextInstance.contentComponent, setup = contextInstance.setup, transformState = contextInstance.transformState;
|
|
1206
|
-
var scale = transformState.scale;
|
|
1207
|
-
var limitToBounds = setup.limitToBounds, centerZoomedOut = setup.centerZoomedOut, zoomAnimation = setup.zoomAnimation, wheel = setup.wheel;
|
|
1208
|
-
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
1209
|
-
var step = wheel.step;
|
|
1210
|
-
if (!contentComponent) {
|
|
1211
|
-
throw new Error("Component not mounted");
|
|
1212
|
-
}
|
|
1213
|
-
event.preventDefault();
|
|
1214
|
-
event.stopPropagation();
|
|
1215
|
-
var delta = getDelta(event, null);
|
|
1216
|
-
var newScale = handleCalculateWheelZoom(contextInstance, delta, step, !event.ctrlKey);
|
|
1217
|
-
if (scale === newScale)
|
|
1218
|
-
return;
|
|
1219
|
-
var bounds = handleCalculateBounds(contextInstance, newScale);
|
|
1220
|
-
var mousePosition = getMousePosition(event, contentComponent, scale);
|
|
1221
|
-
var isPaddingDisabled = disabled || size === 0 || centerZoomedOut;
|
|
1222
|
-
var isLimitedToBounds = limitToBounds && isPaddingDisabled;
|
|
1223
|
-
var _b = handleCalculateZoomPositions(contextInstance, mousePosition.x, mousePosition.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
|
|
1224
|
-
contextInstance.previousWheelEvent = event;
|
|
1225
|
-
contextInstance.setTransformState(newScale, x, y);
|
|
1226
|
-
handleCallback(getContext(contextInstance), event, onWheel);
|
|
1227
|
-
handleCallback(getContext(contextInstance), event, onZoom);
|
|
1228
|
-
};
|
|
1229
|
-
var handleWheelStop = function(contextInstance, event) {
|
|
1230
|
-
var _a = contextInstance.props, onWheelStop = _a.onWheelStop, onZoomStop = _a.onZoomStop;
|
|
1231
|
-
cancelTimeout(contextInstance.wheelAnimationTimer);
|
|
1232
|
-
contextInstance.wheelAnimationTimer = setTimeout(function() {
|
|
1233
|
-
if (!contextInstance.mounted)
|
|
1234
|
-
return;
|
|
1235
|
-
handleAlignToScaleBounds(contextInstance, event.x, event.y);
|
|
1236
|
-
contextInstance.wheelAnimationTimer = null;
|
|
1237
|
-
}, wheelAnimationTime);
|
|
1238
|
-
var hasStoppedZooming = handleWheelZoomStop(contextInstance, event);
|
|
1239
|
-
if (hasStoppedZooming) {
|
|
1240
|
-
cancelTimeout(contextInstance.wheelStopEventTimer);
|
|
1241
|
-
contextInstance.wheelStopEventTimer = setTimeout(function() {
|
|
1242
|
-
if (!contextInstance.mounted)
|
|
1243
|
-
return;
|
|
1244
|
-
contextInstance.wheelStopEventTimer = null;
|
|
1245
|
-
handleCallback(getContext(contextInstance), event, onWheelStop);
|
|
1246
|
-
handleCallback(getContext(contextInstance), event, onZoomStop);
|
|
1247
|
-
}, wheelStopEventTime);
|
|
1248
|
-
}
|
|
1249
|
-
};
|
|
1250
|
-
var handlePinchStart = function(contextInstance, event) {
|
|
1251
|
-
var distance = getTouchDistance(event);
|
|
1252
|
-
contextInstance.pinchStartDistance = distance;
|
|
1253
|
-
contextInstance.lastDistance = distance;
|
|
1254
|
-
contextInstance.pinchStartScale = contextInstance.transformState.scale;
|
|
1255
|
-
contextInstance.isPanning = false;
|
|
1256
|
-
handleCancelAnimation(contextInstance);
|
|
1257
|
-
};
|
|
1258
|
-
var handlePinchZoom = function(contextInstance, event) {
|
|
1259
|
-
var contentComponent = contextInstance.contentComponent, pinchStartDistance = contextInstance.pinchStartDistance;
|
|
1260
|
-
var scale = contextInstance.transformState.scale;
|
|
1261
|
-
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, centerZoomedOut = _a.centerZoomedOut, zoomAnimation = _a.zoomAnimation;
|
|
1262
|
-
var disabled = zoomAnimation.disabled, size = zoomAnimation.size;
|
|
1263
|
-
if (pinchStartDistance === null || !contentComponent)
|
|
1264
|
-
return;
|
|
1265
|
-
var midPoint = calculateTouchMidPoint(event, scale, contentComponent);
|
|
1266
|
-
if (!isFinite(midPoint.x) || !isFinite(midPoint.y))
|
|
1267
|
-
return;
|
|
1268
|
-
var currentDistance = getTouchDistance(event);
|
|
1269
|
-
var newScale = calculatePinchZoom(contextInstance, currentDistance);
|
|
1270
|
-
if (newScale === scale)
|
|
1271
|
-
return;
|
|
1272
|
-
var bounds = handleCalculateBounds(contextInstance, newScale);
|
|
1273
|
-
var isPaddingDisabled = disabled || size === 0 || centerZoomedOut;
|
|
1274
|
-
var isLimitedToBounds = limitToBounds && isPaddingDisabled;
|
|
1275
|
-
var _b = handleCalculateZoomPositions(contextInstance, midPoint.x, midPoint.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
|
|
1276
|
-
contextInstance.pinchMidpoint = midPoint;
|
|
1277
|
-
contextInstance.lastDistance = currentDistance;
|
|
1278
|
-
contextInstance.setTransformState(newScale, x, y);
|
|
1279
|
-
};
|
|
1280
|
-
var handlePinchStop = function(contextInstance) {
|
|
1281
|
-
var pinchMidpoint = contextInstance.pinchMidpoint;
|
|
1282
|
-
contextInstance.velocity = null;
|
|
1283
|
-
contextInstance.lastDistance = null;
|
|
1284
|
-
contextInstance.pinchMidpoint = null;
|
|
1285
|
-
contextInstance.pinchStartScale = null;
|
|
1286
|
-
contextInstance.pinchStartDistance = null;
|
|
1287
|
-
handleAlignToScaleBounds(contextInstance, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.x, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.y);
|
|
1288
|
-
};
|
|
1289
|
-
function handleDoubleClick(contextInstance, event) {
|
|
1290
|
-
var _a = contextInstance.setup.doubleClick, disabled = _a.disabled, mode = _a.mode, step = _a.step, animationTime = _a.animationTime, animationType = _a.animationType;
|
|
1291
|
-
if (disabled)
|
|
1292
|
-
return;
|
|
1293
|
-
if (mode === "reset") {
|
|
1294
|
-
return resetTransformations(contextInstance, animationTime, animationType);
|
|
1295
|
-
}
|
|
1296
|
-
var scale = contextInstance.transformState.scale;
|
|
1297
|
-
var contentComponent = contextInstance.contentComponent;
|
|
1298
|
-
if (!contentComponent)
|
|
1299
|
-
return console.error("No ContentComponent found");
|
|
1300
|
-
var delta = mode === "zoomOut" ? -1 : 1;
|
|
1301
|
-
var newScale = handleCalculateButtonZoom(contextInstance, delta, step);
|
|
1302
|
-
var mousePosition = getMousePosition(event, contentComponent, scale);
|
|
1303
|
-
var targetState = handleZoomToPoint(contextInstance, newScale, mousePosition.x, mousePosition.y);
|
|
1304
|
-
if (!targetState) {
|
|
1305
|
-
return console.error("Error during zoom event. New transformation state was not calculated.");
|
|
1306
|
-
}
|
|
1307
|
-
animate(contextInstance, targetState, animationTime, animationType);
|
|
1308
|
-
}
|
|
1309
|
-
var isDoubleClickAllowed = function(contextInstance, event) {
|
|
1310
|
-
var isInitialized = contextInstance.isInitialized, setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
|
|
1311
|
-
var _a = setup.doubleClick, disabled = _a.disabled, excluded = _a.excluded;
|
|
1312
|
-
var target = event.target;
|
|
1313
|
-
var isWrapperChild = wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.contains(target);
|
|
1314
|
-
var isAllowed = isInitialized && target && isWrapperChild && !disabled;
|
|
1315
|
-
if (!isAllowed)
|
|
1316
|
-
return false;
|
|
1317
|
-
var isExcluded = isExcludedNode(target, excluded);
|
|
1318
|
-
if (isExcluded)
|
|
1319
|
-
return false;
|
|
1320
|
-
if (!isAllowed)
|
|
1321
|
-
return false;
|
|
1322
|
-
return true;
|
|
1323
|
-
};
|
|
1324
|
-
var Context = React.createContext(contextInitialState);
|
|
1325
|
-
var TransformContext = function(_super) {
|
|
1326
|
-
__extends(TransformContext2, _super);
|
|
1327
|
-
function TransformContext2() {
|
|
949
|
+
var StateProvider = function(_super) {
|
|
950
|
+
__extends(StateProvider2, _super);
|
|
951
|
+
function StateProvider2() {
|
|
1328
952
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1329
953
|
_this.mounted = true;
|
|
1330
|
-
_this.
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
_this.
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
_this.
|
|
1338
|
-
_this.
|
|
1339
|
-
_this.isPanning = false;
|
|
954
|
+
_this.state = {
|
|
955
|
+
wrapperComponent: void 0,
|
|
956
|
+
contentComponent: void 0
|
|
957
|
+
};
|
|
958
|
+
_this.stateProvider = __assign(__assign(__assign(__assign({}, initialState), mergeProps(initialState, _this.props.dynamicValues)), _this.props.defaultValues), {
|
|
959
|
+
previousScale: _this.props.dynamicValues.scale || _this.props.defaultValues.scale || initialState.scale
|
|
960
|
+
});
|
|
961
|
+
_this.windowToWrapperScaleX = 0;
|
|
962
|
+
_this.windowToWrapperScaleY = 0;
|
|
1340
963
|
_this.startCoords = null;
|
|
1341
|
-
_this.
|
|
1342
|
-
_this.distance = null;
|
|
1343
|
-
_this.lastDistance = null;
|
|
964
|
+
_this.isDown = false;
|
|
1344
965
|
_this.pinchStartDistance = null;
|
|
966
|
+
_this.lastDistance = null;
|
|
1345
967
|
_this.pinchStartScale = null;
|
|
1346
|
-
_this.
|
|
1347
|
-
_this.
|
|
968
|
+
_this.distance = null;
|
|
969
|
+
_this.bounds = null;
|
|
1348
970
|
_this.velocityTime = null;
|
|
1349
971
|
_this.lastMousePosition = null;
|
|
1350
|
-
_this.
|
|
972
|
+
_this.velocity = null;
|
|
973
|
+
_this.offsetX = null;
|
|
974
|
+
_this.offsetY = null;
|
|
975
|
+
_this.throttle = false;
|
|
976
|
+
_this.previousWheelEvent = null;
|
|
977
|
+
_this.lastScale = null;
|
|
978
|
+
_this.animate = null;
|
|
1351
979
|
_this.animation = null;
|
|
1352
980
|
_this.maxBounds = null;
|
|
1353
|
-
_this.
|
|
1354
|
-
|
|
1355
|
-
var
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
wrapper.addEventListener("touchstart", _this.onTouchPanningStart, passive);
|
|
1359
|
-
wrapper.addEventListener("touchmove", _this.onTouchPanning, passive);
|
|
1360
|
-
wrapper.addEventListener("touchend", _this.onTouchPanningStop, passive);
|
|
1361
|
-
};
|
|
1362
|
-
_this.handleInitialize = function() {
|
|
1363
|
-
var centerOnInit = _this.setup.centerOnInit;
|
|
1364
|
-
_this.applyTransformation();
|
|
1365
|
-
_this.forceUpdate();
|
|
1366
|
-
if (centerOnInit) {
|
|
1367
|
-
setTimeout(function() {
|
|
1368
|
-
if (_this.mounted) {
|
|
1369
|
-
_this.setCenter();
|
|
1370
|
-
}
|
|
1371
|
-
}, 50);
|
|
1372
|
-
setTimeout(function() {
|
|
1373
|
-
if (_this.mounted) {
|
|
1374
|
-
_this.setCenter();
|
|
1375
|
-
}
|
|
1376
|
-
}, 100);
|
|
1377
|
-
setTimeout(function() {
|
|
1378
|
-
if (_this.mounted) {
|
|
1379
|
-
_this.setCenter();
|
|
1380
|
-
}
|
|
1381
|
-
}, 200);
|
|
1382
|
-
}
|
|
1383
|
-
};
|
|
1384
|
-
_this.onWheelZoom = function(event) {
|
|
1385
|
-
var disabled = _this.setup.disabled;
|
|
1386
|
-
if (disabled)
|
|
981
|
+
_this.handleWheel = function(event) {
|
|
982
|
+
var _a = _this.stateProvider, scale = _a.scale, _b = _a.wheel, disabled = _b.disabled, wheelEnabled = _b.wheelEnabled, touchPadEnabled = _b.touchPadEnabled;
|
|
983
|
+
var _c = _this.props, onWheelStart = _c.onWheelStart, onWheel = _c.onWheel, onWheelStop = _c.onWheelStop;
|
|
984
|
+
var _d = _this.state, wrapperComponent = _d.wrapperComponent, contentComponent = _d.contentComponent;
|
|
985
|
+
if (_this.isDown || disabled || _this.stateProvider.options.disabled || !wrapperComponent || !contentComponent)
|
|
1387
986
|
return;
|
|
1388
|
-
|
|
1389
|
-
if (!isAllowed)
|
|
987
|
+
if (!wheelEnabled && !event.ctrlKey)
|
|
1390
988
|
return;
|
|
1391
|
-
|
|
1392
|
-
if (!keysPressed)
|
|
989
|
+
if (!touchPadEnabled && event.ctrlKey)
|
|
1393
990
|
return;
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
991
|
+
if (!wheelStopEventTimer) {
|
|
992
|
+
_this.lastScale = scale;
|
|
993
|
+
handleDisableAnimation.call(_this);
|
|
994
|
+
handleCallback(onWheelStart, _this.getCallbackProps());
|
|
995
|
+
}
|
|
996
|
+
handleWheelZoom.call(_this, event);
|
|
997
|
+
handleCallback(onWheel, _this.getCallbackProps());
|
|
998
|
+
_this.applyTransformation(null, null, null);
|
|
999
|
+
_this.previousWheelEvent = event;
|
|
1000
|
+
if (handleWheelStop(_this.previousWheelEvent, event, _this.stateProvider)) {
|
|
1001
|
+
clearTimeout(wheelStopEventTimer);
|
|
1002
|
+
wheelStopEventTimer = setTimeout(function() {
|
|
1003
|
+
if (!_this.mounted)
|
|
1004
|
+
return;
|
|
1005
|
+
handleCallback(onWheelStop, _this.getCallbackProps());
|
|
1006
|
+
wheelStopEventTimer = null;
|
|
1007
|
+
}, wheelStopEventTime);
|
|
1008
|
+
}
|
|
1009
|
+
_this.animate = false;
|
|
1010
|
+
_this.lastScale = _this.stateProvider.scale;
|
|
1011
|
+
clearTimeout(wheelAnimationTimer);
|
|
1012
|
+
wheelAnimationTimer = setTimeout(function() {
|
|
1013
|
+
if (!_this.mounted)
|
|
1014
|
+
return;
|
|
1015
|
+
handlePaddingAnimation$1.call(_this, event);
|
|
1016
|
+
}, wheelAnimationTime);
|
|
1397
1017
|
};
|
|
1398
|
-
_this.
|
|
1399
|
-
var
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
return;
|
|
1406
|
-
var keysPressed = _this.isPressingKeys(_this.setup.panning.activationKeys);
|
|
1407
|
-
if (!keysPressed)
|
|
1408
|
-
return;
|
|
1409
|
-
event.preventDefault();
|
|
1410
|
-
event.stopPropagation();
|
|
1411
|
-
handleCancelAnimation(_this);
|
|
1412
|
-
handlePanningStart(_this, event);
|
|
1413
|
-
handleCallback(getContext(_this), event, onPanningStart);
|
|
1018
|
+
_this.checkPanningTarget = function(event) {
|
|
1019
|
+
var disableOnTarget = _this.stateProvider.pan.disableOnTarget;
|
|
1020
|
+
return disableOnTarget.map(function(tag) {
|
|
1021
|
+
return tag.toUpperCase();
|
|
1022
|
+
}).includes(event.target.tagName) || disableOnTarget.find(function(element) {
|
|
1023
|
+
return event.target.classList.value.includes(element);
|
|
1024
|
+
});
|
|
1414
1025
|
};
|
|
1415
|
-
_this.
|
|
1416
|
-
var disabled = _this.
|
|
1417
|
-
var
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1026
|
+
_this.checkIsPanningActive = function(event) {
|
|
1027
|
+
var disabled = _this.stateProvider.pan.disabled;
|
|
1028
|
+
var _a = _this.state, wrapperComponent = _a.wrapperComponent, contentComponent = _a.contentComponent;
|
|
1029
|
+
return !_this.isDown || disabled || _this.stateProvider.options.disabled || event.touches && (event.touches.length !== 1 || Math.abs(_this.startCoords.x - event.touches[0].clientX) < 1 || Math.abs(_this.startCoords.y - event.touches[0].clientY) < 1) || !wrapperComponent || !contentComponent;
|
|
1030
|
+
};
|
|
1031
|
+
_this.handleSetUpPanning = function(x, y) {
|
|
1032
|
+
var _a = _this.stateProvider, positionX = _a.positionX, positionY = _a.positionY;
|
|
1033
|
+
_this.isDown = true;
|
|
1034
|
+
_this.startCoords = {
|
|
1035
|
+
x: x - positionX,
|
|
1036
|
+
y: y - positionY
|
|
1037
|
+
};
|
|
1038
|
+
handleCallback(_this.props.onPanningStart, _this.getCallbackProps());
|
|
1039
|
+
};
|
|
1040
|
+
_this.handleStartPanning = function(event) {
|
|
1041
|
+
var _a = _this.stateProvider, wrapperComponent = _a.wrapperComponent, scale = _a.scale, _b = _a.options, minScale = _b.minScale, maxScale = _b.maxScale, limitToWrapper = _b.limitToWrapper, disabled = _a.pan.disabled;
|
|
1042
|
+
var target = event.target, touches = event.touches;
|
|
1043
|
+
if (disabled || _this.stateProvider.options.disabled || wrapperComponent && !wrapperComponent.contains(target) || _this.checkPanningTarget(event) || scale < minScale || scale > maxScale)
|
|
1422
1044
|
return;
|
|
1423
|
-
|
|
1424
|
-
|
|
1045
|
+
handleDisableAnimation.call(_this);
|
|
1046
|
+
_this.bounds = handleCalculateBounds.call(_this, scale, limitToWrapper);
|
|
1047
|
+
if (touches && touches.length === 1) {
|
|
1048
|
+
_this.handleSetUpPanning(touches[0].clientX, touches[0].clientY);
|
|
1049
|
+
}
|
|
1050
|
+
if (!touches) {
|
|
1051
|
+
_this.handleSetUpPanning(event.clientX, event.clientY);
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
_this.handlePanning = function(event) {
|
|
1055
|
+
if (_this.isDown)
|
|
1056
|
+
event.preventDefault();
|
|
1057
|
+
if (_this.checkIsPanningActive(event))
|
|
1425
1058
|
return;
|
|
1426
|
-
event.preventDefault();
|
|
1427
1059
|
event.stopPropagation();
|
|
1428
|
-
|
|
1429
|
-
|
|
1060
|
+
calculateVelocityStart.call(_this, event);
|
|
1061
|
+
handlePanning.call(_this, event);
|
|
1062
|
+
handleCallback(_this.props.onPanning, _this.getCallbackProps());
|
|
1430
1063
|
};
|
|
1431
|
-
_this.
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1064
|
+
_this.handleStopPanning = function() {
|
|
1065
|
+
if (_this.isDown) {
|
|
1066
|
+
_this.isDown = false;
|
|
1067
|
+
_this.animate = false;
|
|
1068
|
+
_this.animation = false;
|
|
1069
|
+
handleFireVelocity.call(_this);
|
|
1070
|
+
handleCallback(_this.props.onPanningStop, _this.getCallbackProps());
|
|
1071
|
+
var _a = _this.stateProvider, velocity = _a.pan.velocity, scale = _a.scale;
|
|
1072
|
+
if (_this.velocity && velocity && scale > 1) {
|
|
1073
|
+
animateVelocity.call(_this);
|
|
1074
|
+
} else {
|
|
1075
|
+
handlePanningAnimation.call(_this);
|
|
1076
|
+
}
|
|
1436
1077
|
}
|
|
1437
1078
|
};
|
|
1438
|
-
_this.
|
|
1439
|
-
var
|
|
1440
|
-
var _a = _this.props, onPinchingStart = _a.onPinchingStart, onZoomStart = _a.onZoomStart;
|
|
1441
|
-
if (disabled)
|
|
1442
|
-
return;
|
|
1443
|
-
var isAllowed = isPinchStartAllowed(_this, event);
|
|
1444
|
-
if (!isAllowed)
|
|
1445
|
-
return;
|
|
1446
|
-
handlePinchStart(_this, event);
|
|
1447
|
-
handleCancelAnimation(_this);
|
|
1448
|
-
handleCallback(getContext(_this), event, onPinchingStart);
|
|
1449
|
-
handleCallback(getContext(_this), event, onZoomStart);
|
|
1450
|
-
};
|
|
1451
|
-
_this.onPinch = function(event) {
|
|
1452
|
-
var disabled = _this.setup.disabled;
|
|
1453
|
-
var _a = _this.props, onPinching = _a.onPinching, onZoom = _a.onZoom;
|
|
1454
|
-
if (disabled)
|
|
1455
|
-
return;
|
|
1456
|
-
var isAllowed = isPinchAllowed(_this);
|
|
1457
|
-
if (!isAllowed)
|
|
1458
|
-
return;
|
|
1079
|
+
_this.handlePinchStart = function(event) {
|
|
1080
|
+
var scale = _this.stateProvider.scale;
|
|
1459
1081
|
event.preventDefault();
|
|
1460
1082
|
event.stopPropagation();
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1083
|
+
handleDisableAnimation.call(_this);
|
|
1084
|
+
var distance = getDistance(event.touches[0], event.touches[1]);
|
|
1085
|
+
_this.pinchStartDistance = distance;
|
|
1086
|
+
_this.lastDistance = distance;
|
|
1087
|
+
_this.pinchStartScale = scale;
|
|
1088
|
+
_this.isDown = false;
|
|
1089
|
+
handleCallback(_this.props.onPinchingStart, _this.getCallbackProps());
|
|
1464
1090
|
};
|
|
1465
|
-
_this.
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1091
|
+
_this.handlePinch = function(event) {
|
|
1092
|
+
_this.isDown = false;
|
|
1093
|
+
handleZoomPinch.call(_this, event);
|
|
1094
|
+
handleCallback(_this.props.onPinching, _this.getCallbackProps());
|
|
1095
|
+
};
|
|
1096
|
+
_this.handlePinchStop = function() {
|
|
1097
|
+
if (typeof _this.pinchStartScale === "number") {
|
|
1098
|
+
_this.isDown = false;
|
|
1099
|
+
_this.velocity = null;
|
|
1100
|
+
_this.lastDistance = null;
|
|
1101
|
+
_this.pinchStartScale = null;
|
|
1102
|
+
_this.pinchStartDistance = null;
|
|
1103
|
+
handlePaddingAnimation$1.call(_this);
|
|
1104
|
+
handleCallback(_this.props.onPinchingStop, _this.getCallbackProps());
|
|
1471
1105
|
}
|
|
1472
1106
|
};
|
|
1473
|
-
_this.
|
|
1474
|
-
var
|
|
1475
|
-
var
|
|
1476
|
-
if (disabled)
|
|
1107
|
+
_this.handleTouchStart = function(event) {
|
|
1108
|
+
var _a = _this.stateProvider, wrapperComponent = _a.wrapperComponent, contentComponent = _a.contentComponent, scale = _a.scale, _b = _a.options, disabled = _b.disabled, minScale = _b.minScale;
|
|
1109
|
+
var touches = event.touches;
|
|
1110
|
+
if (disabled || !wrapperComponent || !contentComponent || scale < minScale)
|
|
1477
1111
|
return;
|
|
1478
|
-
|
|
1479
|
-
if (
|
|
1112
|
+
handleDisableAnimation.call(_this);
|
|
1113
|
+
if (touches && touches.length === 1)
|
|
1114
|
+
return _this.handleStartPanning(event);
|
|
1115
|
+
if (touches && touches.length === 2)
|
|
1116
|
+
return _this.handlePinchStart(event);
|
|
1117
|
+
};
|
|
1118
|
+
_this.handleTouch = function(event) {
|
|
1119
|
+
var _a = _this.stateProvider, pan = _a.pan, pinch = _a.pinch, options = _a.options;
|
|
1120
|
+
if (options.disabled)
|
|
1480
1121
|
return;
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
_this.lastTouch = +new Date();
|
|
1486
|
-
handleCancelAnimation(_this);
|
|
1487
|
-
var touches = event.touches;
|
|
1488
|
-
var isPanningAction = touches.length === 1;
|
|
1489
|
-
var isPinchAction = touches.length === 2;
|
|
1490
|
-
if (isPanningAction) {
|
|
1491
|
-
handleCancelAnimation(_this);
|
|
1492
|
-
handlePanningStart(_this, event);
|
|
1493
|
-
handleCallback(getContext(_this), event, onPanningStart);
|
|
1494
|
-
}
|
|
1495
|
-
if (isPinchAction) {
|
|
1496
|
-
_this.onPinchStart(event);
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1122
|
+
if (!pan.disabled && event.touches.length === 1)
|
|
1123
|
+
return _this.handlePanning(event);
|
|
1124
|
+
if (!pinch.disabled && event.touches.length === 2)
|
|
1125
|
+
return _this.handlePinch(event);
|
|
1499
1126
|
};
|
|
1500
|
-
_this.
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
if (_this.isPanning && event.touches.length === 1) {
|
|
1504
|
-
if (disabled)
|
|
1505
|
-
return;
|
|
1506
|
-
var isAllowed = isPanningAllowed(_this);
|
|
1507
|
-
if (!isAllowed)
|
|
1508
|
-
return;
|
|
1509
|
-
event.preventDefault();
|
|
1510
|
-
event.stopPropagation();
|
|
1511
|
-
var touch = event.touches[0];
|
|
1512
|
-
handlePanning(_this, touch.clientX, touch.clientY);
|
|
1513
|
-
handleCallback(getContext(_this), event, onPanning);
|
|
1514
|
-
} else if (event.touches.length > 1) {
|
|
1515
|
-
_this.onPinch(event);
|
|
1516
|
-
}
|
|
1127
|
+
_this.handleTouchStop = function() {
|
|
1128
|
+
_this.handleStopPanning();
|
|
1129
|
+
_this.handlePinchStop();
|
|
1517
1130
|
};
|
|
1518
|
-
_this.
|
|
1519
|
-
_this.
|
|
1520
|
-
_this.
|
|
1131
|
+
_this.zoomIn = function(event) {
|
|
1132
|
+
var _a = _this.stateProvider, _b = _a.zoomIn, disabled = _b.disabled, step = _b.step, options = _a.options;
|
|
1133
|
+
var _c = _this.state, wrapperComponent = _c.wrapperComponent, contentComponent = _c.contentComponent;
|
|
1134
|
+
if (!event)
|
|
1135
|
+
throw Error("Zoom in function requires event prop");
|
|
1136
|
+
if (disabled || options.disabled || !wrapperComponent || !contentComponent)
|
|
1137
|
+
return;
|
|
1138
|
+
handleZoomControls.call(_this, 1, step);
|
|
1521
1139
|
};
|
|
1522
|
-
_this.
|
|
1523
|
-
var
|
|
1524
|
-
|
|
1140
|
+
_this.zoomOut = function(event) {
|
|
1141
|
+
var _a = _this.stateProvider, _b = _a.zoomOut, disabled = _b.disabled, step = _b.step, options = _a.options;
|
|
1142
|
+
var _c = _this.state, wrapperComponent = _c.wrapperComponent, contentComponent = _c.contentComponent;
|
|
1143
|
+
if (!event)
|
|
1144
|
+
throw Error("Zoom out function requires event prop");
|
|
1145
|
+
if (disabled || options.disabled || !wrapperComponent || !contentComponent)
|
|
1525
1146
|
return;
|
|
1526
|
-
|
|
1527
|
-
|
|
1147
|
+
handleZoomControls.call(_this, -1, step);
|
|
1148
|
+
};
|
|
1149
|
+
_this.handleDbClick = function(event) {
|
|
1150
|
+
var _a = _this.stateProvider, options = _a.options, _b = _a.doubleClick, disabled = _b.disabled, step = _b.step;
|
|
1151
|
+
var _c = _this.state, wrapperComponent = _c.wrapperComponent, contentComponent = _c.contentComponent;
|
|
1152
|
+
if (!event)
|
|
1153
|
+
throw Error("Double click function requires event prop");
|
|
1154
|
+
if (disabled || options.disabled || !wrapperComponent || !contentComponent)
|
|
1528
1155
|
return;
|
|
1529
|
-
handleDoubleClick(_this, event);
|
|
1156
|
+
handleDoubleClick.call(_this, event, 1, step);
|
|
1530
1157
|
};
|
|
1531
|
-
_this.
|
|
1532
|
-
if (
|
|
1533
|
-
|
|
1158
|
+
_this.setScale = function(newScale, speed, type) {
|
|
1159
|
+
if (speed === void 0) {
|
|
1160
|
+
speed = 200;
|
|
1161
|
+
}
|
|
1162
|
+
if (type === void 0) {
|
|
1163
|
+
type = "easeOut";
|
|
1534
1164
|
}
|
|
1165
|
+
var _a = _this.stateProvider, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale, disabled = _a.options.disabled;
|
|
1166
|
+
var _b = _this.state, wrapperComponent = _b.wrapperComponent, contentComponent = _b.contentComponent;
|
|
1167
|
+
if (disabled || !wrapperComponent || !contentComponent)
|
|
1168
|
+
return;
|
|
1169
|
+
var targetState = {
|
|
1170
|
+
positionX,
|
|
1171
|
+
positionY,
|
|
1172
|
+
scale: isNaN(newScale) ? scale : newScale
|
|
1173
|
+
};
|
|
1174
|
+
animateComponent.call(_this, {
|
|
1175
|
+
targetState,
|
|
1176
|
+
speed,
|
|
1177
|
+
type
|
|
1178
|
+
});
|
|
1535
1179
|
};
|
|
1536
|
-
_this.
|
|
1537
|
-
|
|
1180
|
+
_this.setPositionX = function(newPosX, speed, type) {
|
|
1181
|
+
if (speed === void 0) {
|
|
1182
|
+
speed = 200;
|
|
1183
|
+
}
|
|
1184
|
+
if (type === void 0) {
|
|
1185
|
+
type = "easeOut";
|
|
1186
|
+
}
|
|
1187
|
+
var _a = _this.stateProvider, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale, _b = _a.options, disabled = _b.disabled, transformEnabled = _b.transformEnabled;
|
|
1188
|
+
var _c = _this.state, wrapperComponent = _c.wrapperComponent, contentComponent = _c.contentComponent;
|
|
1189
|
+
if (disabled || !transformEnabled || !wrapperComponent || !contentComponent)
|
|
1190
|
+
return;
|
|
1191
|
+
var targetState = {
|
|
1192
|
+
positionX: isNaN(newPosX) ? positionX : newPosX,
|
|
1193
|
+
positionY,
|
|
1194
|
+
scale
|
|
1195
|
+
};
|
|
1196
|
+
animateComponent.call(_this, {
|
|
1197
|
+
targetState,
|
|
1198
|
+
speed,
|
|
1199
|
+
type
|
|
1200
|
+
});
|
|
1538
1201
|
};
|
|
1539
|
-
_this.
|
|
1540
|
-
|
|
1202
|
+
_this.setPositionY = function(newPosY, speed, type) {
|
|
1203
|
+
if (speed === void 0) {
|
|
1204
|
+
speed = 200;
|
|
1205
|
+
}
|
|
1206
|
+
if (type === void 0) {
|
|
1207
|
+
type = "easeOut";
|
|
1208
|
+
}
|
|
1209
|
+
var _a = _this.stateProvider, positionX = _a.positionX, scale = _a.scale, positionY = _a.positionY, _b = _a.options, disabled = _b.disabled, transformEnabled = _b.transformEnabled;
|
|
1210
|
+
var _c = _this.state, wrapperComponent = _c.wrapperComponent, contentComponent = _c.contentComponent;
|
|
1211
|
+
if (disabled || !transformEnabled || !wrapperComponent || !contentComponent)
|
|
1212
|
+
return;
|
|
1213
|
+
var targetState = {
|
|
1214
|
+
positionX,
|
|
1215
|
+
positionY: isNaN(newPosY) ? positionY : newPosY,
|
|
1216
|
+
scale
|
|
1217
|
+
};
|
|
1218
|
+
animateComponent.call(_this, {
|
|
1219
|
+
targetState,
|
|
1220
|
+
speed,
|
|
1221
|
+
type
|
|
1222
|
+
});
|
|
1541
1223
|
};
|
|
1542
|
-
_this.
|
|
1543
|
-
if (
|
|
1544
|
-
|
|
1224
|
+
_this.setTransform = function(newPosX, newPosY, newScale, speed, type) {
|
|
1225
|
+
if (speed === void 0) {
|
|
1226
|
+
speed = 200;
|
|
1545
1227
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
}
|
|
1228
|
+
if (type === void 0) {
|
|
1229
|
+
type = "easeOut";
|
|
1230
|
+
}
|
|
1231
|
+
var _a = _this.stateProvider, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale, _b = _a.options, disabled = _b.disabled, transformEnabled = _b.transformEnabled;
|
|
1232
|
+
var _c = _this.state, wrapperComponent = _c.wrapperComponent, contentComponent = _c.contentComponent;
|
|
1233
|
+
if (disabled || !transformEnabled || !wrapperComponent || !contentComponent)
|
|
1234
|
+
return;
|
|
1235
|
+
var targetState = {
|
|
1236
|
+
positionX: isNaN(newPosX) ? positionX : newPosX,
|
|
1237
|
+
positionY: isNaN(newPosY) ? positionY : newPosY,
|
|
1238
|
+
scale: isNaN(newScale) ? scale : newScale
|
|
1239
|
+
};
|
|
1240
|
+
animateComponent.call(_this, {
|
|
1241
|
+
targetState,
|
|
1242
|
+
speed,
|
|
1243
|
+
type
|
|
1244
|
+
});
|
|
1549
1245
|
};
|
|
1550
|
-
_this.
|
|
1551
|
-
_this.
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
_this.handleInitialize();
|
|
1556
|
-
_this.handleRef();
|
|
1557
|
-
_this.isInitialized = true;
|
|
1558
|
-
handleCallback(getContext(_this), void 0, _this.props.onInit);
|
|
1246
|
+
_this.resetTransform = function() {
|
|
1247
|
+
var _a = _this.stateProvider.options, disabled = _a.disabled, transformEnabled = _a.transformEnabled;
|
|
1248
|
+
if (disabled || !transformEnabled)
|
|
1249
|
+
return;
|
|
1250
|
+
resetTransformations.call(_this);
|
|
1559
1251
|
};
|
|
1560
|
-
_this.
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
_this.applyTransformation();
|
|
1569
|
-
} else {
|
|
1570
|
-
console.error("Detected NaN set state values");
|
|
1571
|
-
}
|
|
1252
|
+
_this.setDefaultState = function() {
|
|
1253
|
+
_this.animation = null;
|
|
1254
|
+
_this.stateProvider = __assign(__assign(__assign({}, _this.stateProvider), {
|
|
1255
|
+
scale: initialState.scale,
|
|
1256
|
+
positionX: initialState.positionX,
|
|
1257
|
+
positionY: initialState.positionY
|
|
1258
|
+
}), _this.props.defaultValues);
|
|
1259
|
+
_this.forceUpdate();
|
|
1572
1260
|
};
|
|
1573
|
-
_this.
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
}
|
|
1261
|
+
_this.setWrapperComponent = function(wrapperComponent) {
|
|
1262
|
+
_this.setState({
|
|
1263
|
+
wrapperComponent
|
|
1264
|
+
});
|
|
1578
1265
|
};
|
|
1579
|
-
_this.
|
|
1580
|
-
|
|
1266
|
+
_this.setContentComponent = function(contentComponent) {
|
|
1267
|
+
_this.setState({
|
|
1268
|
+
contentComponent
|
|
1269
|
+
}, function() {
|
|
1270
|
+
var _a = _this.stateProvider, wrapperComponent = _a.wrapperComponent, _b = _a.options, centerContent = _b.centerContent, limitToBounds = _b.limitToBounds, limitToWrapper = _b.limitToWrapper, scale = _a.scale;
|
|
1271
|
+
var _c = _this.props.defaultValues, positionX = _c.positionX, positionY = _c.positionY;
|
|
1272
|
+
if (limitToBounds && !limitToWrapper || centerContent && !positionX && !positionY) {
|
|
1273
|
+
var transform = "translate(25%, 25%) scale(" + scale + ")";
|
|
1274
|
+
contentComponent.style.transform = transform;
|
|
1275
|
+
contentComponent.style.WebkitTransform = transform;
|
|
1276
|
+
_this.forceUpdate();
|
|
1277
|
+
var startTime_1 = new Date().getTime();
|
|
1278
|
+
var maxTimeWait_1 = 2e3;
|
|
1279
|
+
var interval_1 = setInterval(function() {
|
|
1280
|
+
if (wrapperComponent.offsetWidth) {
|
|
1281
|
+
var bounds = handleCalculateBounds.call(_this, scale, false);
|
|
1282
|
+
_this.stateProvider.positionX = bounds.minPositionX;
|
|
1283
|
+
_this.stateProvider.positionY = bounds.minPositionY;
|
|
1284
|
+
_this.applyTransformation(null, null, null);
|
|
1285
|
+
clearInterval(interval_1);
|
|
1286
|
+
interval_1 = null;
|
|
1287
|
+
} else if (new Date().getTime() - startTime_1 > maxTimeWait_1) {
|
|
1288
|
+
clearInterval(interval_1);
|
|
1289
|
+
interval_1 = null;
|
|
1290
|
+
}
|
|
1291
|
+
}, 20);
|
|
1292
|
+
} else {
|
|
1293
|
+
_this.applyTransformation(null, null, null);
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
};
|
|
1297
|
+
_this.applyTransformation = function(newScale, posX, posY) {
|
|
1298
|
+
if (!_this.mounted)
|
|
1581
1299
|
return;
|
|
1582
|
-
var
|
|
1583
|
-
var
|
|
1584
|
-
_this.
|
|
1585
|
-
|
|
1300
|
+
var contentComponent = _this.state.contentComponent;
|
|
1301
|
+
var onZoomChange = _this.props.onZoomChange;
|
|
1302
|
+
var _a = _this.stateProvider, previousScale = _a.previousScale, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
1303
|
+
if (!contentComponent)
|
|
1304
|
+
return console.error("There is no content component");
|
|
1305
|
+
var transform = "translate(" + (posX || positionX) + "px, " + (posY || positionY) + "px) scale(" + (newScale || scale) + ")";
|
|
1306
|
+
contentComponent.style.transform = transform;
|
|
1307
|
+
contentComponent.style.WebkitTransform = transform;
|
|
1308
|
+
_this.forceUpdate();
|
|
1309
|
+
if (onZoomChange && previousScale !== scale) {
|
|
1310
|
+
handleCallback(onZoomChange, _this.getCallbackProps());
|
|
1311
|
+
}
|
|
1586
1312
|
};
|
|
1587
|
-
_this.
|
|
1588
|
-
_this.
|
|
1313
|
+
_this.getCallbackProps = function() {
|
|
1314
|
+
return getValidPropsFromObject(_this.stateProvider);
|
|
1589
1315
|
};
|
|
1590
1316
|
return _this;
|
|
1591
1317
|
}
|
|
1592
|
-
|
|
1593
|
-
var
|
|
1594
|
-
window.addEventListener("mousedown", this.
|
|
1595
|
-
window.addEventListener("mousemove", this.
|
|
1596
|
-
window.addEventListener("mouseup", this.
|
|
1597
|
-
document.addEventListener("mouseleave", this.clearPanning, passive);
|
|
1598
|
-
window.addEventListener("keyup", this.setKeyUnPressed, passive);
|
|
1599
|
-
window.addEventListener("keydown", this.setKeyPressed, passive);
|
|
1600
|
-
this.handleRef();
|
|
1318
|
+
StateProvider2.prototype.componentDidMount = function() {
|
|
1319
|
+
var passiveOption = makePassiveEventOption(false);
|
|
1320
|
+
window.addEventListener("mousedown", this.handleStartPanning, passiveOption);
|
|
1321
|
+
window.addEventListener("mousemove", this.handlePanning, passiveOption);
|
|
1322
|
+
window.addEventListener("mouseup", this.handleStopPanning, passiveOption);
|
|
1601
1323
|
};
|
|
1602
|
-
|
|
1603
|
-
var
|
|
1604
|
-
window.removeEventListener("mousedown", this.
|
|
1605
|
-
window.removeEventListener("mousemove", this.
|
|
1606
|
-
window.removeEventListener("mouseup", this.
|
|
1607
|
-
|
|
1608
|
-
window.removeEventListener("keydown", this.setKeyPressed, passive);
|
|
1609
|
-
handleCancelAnimation(this);
|
|
1324
|
+
StateProvider2.prototype.componentWillUnmount = function() {
|
|
1325
|
+
var passiveOption = makePassiveEventOption(false);
|
|
1326
|
+
window.removeEventListener("mousedown", this.handleStartPanning, passiveOption);
|
|
1327
|
+
window.removeEventListener("mousemove", this.handlePanning, passiveOption);
|
|
1328
|
+
window.removeEventListener("mouseup", this.handleStopPanning, passiveOption);
|
|
1329
|
+
handleDisableAnimation.call(this);
|
|
1610
1330
|
};
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1331
|
+
StateProvider2.prototype.componentDidUpdate = function(oldProps, oldState) {
|
|
1332
|
+
var _a = this.state, wrapperComponent = _a.wrapperComponent, contentComponent = _a.contentComponent;
|
|
1333
|
+
var dynamicValues = this.props.dynamicValues;
|
|
1334
|
+
if (!oldState.contentComponent && contentComponent) {
|
|
1335
|
+
this.stateProvider.contentComponent = contentComponent;
|
|
1336
|
+
}
|
|
1337
|
+
if (!oldState.wrapperComponent && wrapperComponent && wrapperComponent !== void 0) {
|
|
1338
|
+
this.stateProvider.wrapperComponent = wrapperComponent;
|
|
1339
|
+
this.windowToWrapperScaleX = getWindowScaleX(wrapperComponent);
|
|
1340
|
+
this.windowToWrapperScaleY = getWindowScaleY(wrapperComponent);
|
|
1341
|
+
var passiveOption = makePassiveEventOption(false);
|
|
1342
|
+
wrapperComponent.addEventListener("wheel", this.handleWheel, passiveOption);
|
|
1343
|
+
wrapperComponent.addEventListener("dblclick", this.handleDbClick, passiveOption);
|
|
1344
|
+
wrapperComponent.addEventListener("touchstart", this.handleTouchStart, passiveOption);
|
|
1345
|
+
wrapperComponent.addEventListener("touchmove", this.handleTouch, passiveOption);
|
|
1346
|
+
wrapperComponent.addEventListener("touchend", this.handleTouchStop, passiveOption);
|
|
1347
|
+
}
|
|
1348
|
+
if (wrapperComponent && contentComponent || oldProps.dynamicValues !== dynamicValues) {
|
|
1349
|
+
this.maxBounds = handleCalculateBounds.call(this, this.stateProvider.scale, this.stateProvider.options.limitToWrapper);
|
|
1350
|
+
}
|
|
1351
|
+
if (oldProps.dynamicValues && oldProps.dynamicValues !== dynamicValues) {
|
|
1352
|
+
this.animation = null;
|
|
1353
|
+
this.stateProvider = __assign(__assign({}, this.stateProvider), mergeProps(this.stateProvider, dynamicValues));
|
|
1354
|
+
this.applyTransformation(null, null, null);
|
|
1615
1355
|
}
|
|
1616
1356
|
};
|
|
1617
|
-
|
|
1618
|
-
var
|
|
1357
|
+
StateProvider2.prototype.render = function() {
|
|
1358
|
+
var _a = this.state, wrapperComponent = _a.wrapperComponent, contentComponent = _a.contentComponent;
|
|
1359
|
+
var value = {
|
|
1360
|
+
loaded: Boolean(wrapperComponent && contentComponent),
|
|
1361
|
+
state: this.getCallbackProps(),
|
|
1362
|
+
dispatch: {
|
|
1363
|
+
setScale: this.setScale,
|
|
1364
|
+
setPositionX: this.setPositionX,
|
|
1365
|
+
setPositionY: this.setPositionY,
|
|
1366
|
+
zoomIn: this.zoomIn,
|
|
1367
|
+
zoomOut: this.zoomOut,
|
|
1368
|
+
setTransform: this.setTransform,
|
|
1369
|
+
resetTransform: this.resetTransform,
|
|
1370
|
+
setDefaultState: this.setDefaultState
|
|
1371
|
+
},
|
|
1372
|
+
nodes: {
|
|
1373
|
+
setWrapperComponent: this.setWrapperComponent,
|
|
1374
|
+
setContentComponent: this.setContentComponent
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1619
1377
|
var children = this.props.children;
|
|
1620
|
-
var content = typeof children === "function" ? children(value) : children;
|
|
1378
|
+
var content = typeof children === "function" ? children(__assign(__assign({}, value.state), value.dispatch)) : children;
|
|
1621
1379
|
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
1622
|
-
value
|
|
1623
|
-
setComponents: this.setComponents,
|
|
1624
|
-
contextInstance: this
|
|
1625
|
-
}),
|
|
1380
|
+
value,
|
|
1626
1381
|
children: content
|
|
1627
1382
|
});
|
|
1628
1383
|
};
|
|
1629
|
-
return
|
|
1384
|
+
return StateProvider2;
|
|
1630
1385
|
}(Component);
|
|
1631
|
-
var TransformWrapper =
|
|
1632
|
-
var _a =
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1386
|
+
var TransformWrapper = function(_a) {
|
|
1387
|
+
var children = _a.children, defaultPositionX = _a.defaultPositionX, defaultPositionY = _a.defaultPositionY, defaultScale = _a.defaultScale, onWheelStart = _a.onWheelStart, onWheel = _a.onWheel, onWheelStop = _a.onWheelStop, onPanningStart = _a.onPanningStart, onPanning = _a.onPanning, onPanningStop = _a.onPanningStop, onPinchingStart = _a.onPinchingStart, onPinching = _a.onPinching, onPinchingStop = _a.onPinchingStop, onZoomChange = _a.onZoomChange, rest = __rest(_a, ["children", "defaultPositionX", "defaultPositionY", "defaultScale", "onWheelStart", "onWheel", "onWheelStop", "onPanningStart", "onPanning", "onPanningStop", "onPinchingStart", "onPinching", "onPinchingStop", "onZoomChange"]);
|
|
1388
|
+
var props = __assign({}, rest);
|
|
1389
|
+
if (props.options && props.options.limitToWrapper) {
|
|
1390
|
+
props.options.limitToBounds = true;
|
|
1391
|
+
}
|
|
1392
|
+
return /* @__PURE__ */ jsx(StateProvider, {
|
|
1393
|
+
defaultValues: deleteUndefinedProps({
|
|
1394
|
+
positionX: defaultPositionX,
|
|
1395
|
+
positionY: defaultPositionY,
|
|
1396
|
+
scale: defaultScale
|
|
1397
|
+
}),
|
|
1398
|
+
dynamicValues: deleteUndefinedProps(getValidPropsFromObject(props)),
|
|
1399
|
+
onWheelStart,
|
|
1400
|
+
onWheel,
|
|
1401
|
+
onWheelStop,
|
|
1402
|
+
onPanningStart,
|
|
1403
|
+
onPanning,
|
|
1404
|
+
onPanningStop,
|
|
1405
|
+
onPinchingStart,
|
|
1406
|
+
onPinching,
|
|
1407
|
+
onPinchingStop,
|
|
1408
|
+
onZoomChange,
|
|
1409
|
+
children
|
|
1410
|
+
});
|
|
1411
|
+
};
|
|
1412
|
+
function styleInject(css2, ref) {
|
|
1641
1413
|
if (ref === void 0)
|
|
1642
1414
|
ref = {};
|
|
1643
1415
|
var insertAt = ref.insertAt;
|
|
1644
|
-
if (!
|
|
1416
|
+
if (!css2 || typeof document === "undefined") {
|
|
1645
1417
|
return;
|
|
1646
1418
|
}
|
|
1647
1419
|
var head = document.head || document.getElementsByTagName("head")[0];
|
|
@@ -1657,41 +1429,51 @@ function styleInject(css, ref) {
|
|
|
1657
1429
|
head.appendChild(style);
|
|
1658
1430
|
}
|
|
1659
1431
|
if (style.styleSheet) {
|
|
1660
|
-
style.styleSheet.cssText =
|
|
1432
|
+
style.styleSheet.cssText = css2;
|
|
1661
1433
|
} else {
|
|
1662
|
-
style.appendChild(document.createTextNode(
|
|
1434
|
+
style.appendChild(document.createTextNode(css2));
|
|
1663
1435
|
}
|
|
1664
1436
|
}
|
|
1665
|
-
var
|
|
1437
|
+
var css = ".TransformComponent-module_container__3NwNd {\n position: relative;\n width: fit-content;\n height: fit-content;\n overflow: hidden;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -khtml-user-select: none; /* Konqueror HTML */\n -moz-user-select: none; /* Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none;\n margin: 0;\n padding: 0;\n}\n.TransformComponent-module_content__TZU5O {\n display: flex;\n flex-wrap: wrap;\n width: fit-content;\n height: fit-content;\n margin: 0;\n padding: 0;\n transform-origin: 0% 0%;\n}\n.TransformComponent-module_content__TZU5O img {\n pointer-events: none;\n}\n";
|
|
1666
1438
|
var styles$1 = {
|
|
1667
|
-
"
|
|
1668
|
-
"content": "
|
|
1669
|
-
};
|
|
1670
|
-
styleInject(css_248z);
|
|
1671
|
-
var TransformComponent = function(_a) {
|
|
1672
|
-
var children = _a.children, _b = _a.wrapperClass, wrapperClass = _b === void 0 ? "" : _b, _c = _a.contentClass, contentClass = _c === void 0 ? "" : _c, wrapperStyle = _a.wrapperStyle, contentStyle = _a.contentStyle;
|
|
1673
|
-
var setComponents = useContext(Context).setComponents;
|
|
1674
|
-
var wrapperRef = useRef(null);
|
|
1675
|
-
var contentRef = useRef(null);
|
|
1676
|
-
useEffect(function() {
|
|
1677
|
-
var wrapper = wrapperRef.current;
|
|
1678
|
-
var content = contentRef.current;
|
|
1679
|
-
if (wrapper !== null && content !== null && setComponents) {
|
|
1680
|
-
setComponents(wrapper, content);
|
|
1681
|
-
}
|
|
1682
|
-
}, []);
|
|
1683
|
-
return /* @__PURE__ */ jsx("div", {
|
|
1684
|
-
ref: wrapperRef,
|
|
1685
|
-
className: "react-transform-wrapper " + styles$1.wrapper + " " + wrapperClass,
|
|
1686
|
-
style: wrapperStyle,
|
|
1687
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
1688
|
-
ref: contentRef,
|
|
1689
|
-
className: "react-transform-component " + styles$1.content + " " + contentClass,
|
|
1690
|
-
style: contentStyle,
|
|
1691
|
-
children
|
|
1692
|
-
})
|
|
1693
|
-
});
|
|
1439
|
+
"container": "TransformComponent-module_container__3NwNd",
|
|
1440
|
+
"content": "TransformComponent-module_content__TZU5O"
|
|
1694
1441
|
};
|
|
1442
|
+
styleInject(css);
|
|
1443
|
+
var TransformComponent = function(_super) {
|
|
1444
|
+
__extends(TransformComponent2, _super);
|
|
1445
|
+
function TransformComponent2() {
|
|
1446
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1447
|
+
_this.wrapperRef = React.createRef();
|
|
1448
|
+
_this.contentRef = React.createRef();
|
|
1449
|
+
return _this;
|
|
1450
|
+
}
|
|
1451
|
+
TransformComponent2.prototype.componentDidMount = function() {
|
|
1452
|
+
var nodes = this.context.nodes;
|
|
1453
|
+
nodes.setWrapperComponent(this.wrapperRef.current);
|
|
1454
|
+
nodes.setContentComponent(this.contentRef.current);
|
|
1455
|
+
};
|
|
1456
|
+
TransformComponent2.prototype.render = function() {
|
|
1457
|
+
var children = this.props.children;
|
|
1458
|
+
var _a = this.context.state, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale, _b = _a.options, wrapperClass = _b.wrapperClass, contentClass = _b.contentClass;
|
|
1459
|
+
var style = {
|
|
1460
|
+
WebkitTransform: "translate(" + positionX + "px, " + positionY + "px) scale(" + scale + ")",
|
|
1461
|
+
transform: "translate(" + positionX + "px, " + positionY + "px) scale(" + scale + ")"
|
|
1462
|
+
};
|
|
1463
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1464
|
+
ref: this.wrapperRef,
|
|
1465
|
+
className: "react-transform-component " + styles$1.container + " " + wrapperClass,
|
|
1466
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1467
|
+
ref: this.contentRef,
|
|
1468
|
+
className: "react-transform-element " + styles$1.content + " " + contentClass,
|
|
1469
|
+
style,
|
|
1470
|
+
children
|
|
1471
|
+
})
|
|
1472
|
+
});
|
|
1473
|
+
};
|
|
1474
|
+
return TransformComponent2;
|
|
1475
|
+
}(React.Component);
|
|
1476
|
+
TransformComponent.contextType = Context;
|
|
1695
1477
|
const extraStyle = `
|
|
1696
1478
|
.lds-dual-ring {
|
|
1697
1479
|
display: inline-block;
|
|
@@ -1925,7 +1707,7 @@ function ImgGallery(props) {
|
|
|
1925
1707
|
style: __spreadProps(__spreadValues({}, styles.Grid), {
|
|
1926
1708
|
gridTemplateColumns: `repeat(${((_a = props.options) == null ? void 0 : _a.picsPerRow) ? props.options.picsPerRow : "3"}, 1fr)`
|
|
1927
1709
|
}),
|
|
1928
|
-
children: props.imgList.map((element,
|
|
1710
|
+
children: props.imgList.map((element, index) => {
|
|
1929
1711
|
var _a2;
|
|
1930
1712
|
return /* @__PURE__ */ jsx("div", {
|
|
1931
1713
|
className: "reactPic-imgDiv",
|
|
@@ -1954,7 +1736,7 @@ function ImgGallery(props) {
|
|
|
1954
1736
|
minWidth: "100%",
|
|
1955
1737
|
minHeight: "100%"
|
|
1956
1738
|
},
|
|
1957
|
-
onClick: () => props.onOpen(
|
|
1739
|
+
onClick: () => props.onOpen(index)
|
|
1958
1740
|
})
|
|
1959
1741
|
})
|
|
1960
1742
|
}, element.thumbnailSrc ? element.thumbnailSrc : element.fullSrc);
|
|
@@ -1969,8 +1751,8 @@ const defaultOptions = {
|
|
|
1969
1751
|
};
|
|
1970
1752
|
function PicGallery(props) {
|
|
1971
1753
|
var _a;
|
|
1972
|
-
const [open, setOpen] =
|
|
1973
|
-
const [modalImgIndex, setModalImgIndex] =
|
|
1754
|
+
const [open, setOpen] = useState(false);
|
|
1755
|
+
const [modalImgIndex, setModalImgIndex] = useState(0);
|
|
1974
1756
|
const options = __spreadValues(__spreadValues({}, defaultOptions), props.options);
|
|
1975
1757
|
useEffect(() => {
|
|
1976
1758
|
if (typeof props.setExtLightboxChildren == "function") {
|
|
@@ -2009,5 +1791,4 @@ function PicGallery(props) {
|
|
|
2009
1791
|
})]
|
|
2010
1792
|
});
|
|
2011
1793
|
}
|
|
2012
|
-
|
|
2013
|
-
export { index as default };
|
|
1794
|
+
export { PicGallery as default };
|