react-pic-gallery 1.5.6 → 1.5.10
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/README.md +15 -7
- package/dist/react-pic-gallery.es.js +1412 -1183
- package/dist/react-pic-gallery.umd.js +11 -7
- package/package.json +49 -41
|
@@ -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, { Component,
|
|
20
|
+
import React, { useState, useImperativeHandle, Component, useContext, useRef, useEffect, useCallback } from "react";
|
|
21
21
|
var jsxRuntime = { exports: {} };
|
|
22
22
|
var reactJsxRuntime_production_min = {};
|
|
23
23
|
/*
|
|
@@ -130,12 +130,14 @@ 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 (Object.prototype.hasOwnProperty.call(b2, 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");
|
|
139
141
|
extendStatics(d, b);
|
|
140
142
|
function __() {
|
|
141
143
|
this.constructor = d;
|
|
@@ -154,183 +156,28 @@ var __assign = function() {
|
|
|
154
156
|
};
|
|
155
157
|
return __assign.apply(this, arguments);
|
|
156
158
|
};
|
|
157
|
-
function
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
t[p2[i]] = s[p2[i]];
|
|
159
|
+
function __spreadArray(to, from, pack) {
|
|
160
|
+
if (pack || arguments.length === 2)
|
|
161
|
+
for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
162
|
+
if (ar || !(i in from)) {
|
|
163
|
+
if (!ar)
|
|
164
|
+
ar = Array.prototype.slice.call(from, 0, i);
|
|
165
|
+
ar[i] = from[i];
|
|
166
|
+
}
|
|
166
167
|
}
|
|
167
|
-
return
|
|
168
|
+
return to.concat(ar || from);
|
|
168
169
|
}
|
|
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
|
-
};
|
|
254
170
|
var roundNumber = function(num, decimal) {
|
|
255
171
|
return Number(num.toFixed(decimal));
|
|
256
172
|
};
|
|
257
173
|
var checkIsNumber = function(num, defaultValue) {
|
|
258
174
|
return typeof num === "number" ? num : defaultValue;
|
|
259
175
|
};
|
|
260
|
-
var
|
|
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) {
|
|
176
|
+
var handleCallback = function(context, event, callback) {
|
|
294
177
|
if (callback && typeof callback === "function") {
|
|
295
|
-
callback(
|
|
178
|
+
callback(context, event);
|
|
296
179
|
}
|
|
297
180
|
};
|
|
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
|
-
}
|
|
334
181
|
var easeOut = function(t) {
|
|
335
182
|
return -Math.cos(t * Math.PI) / 2 + 0.5;
|
|
336
183
|
};
|
|
@@ -373,7 +220,7 @@ var easeOutQuint = function(t) {
|
|
|
373
220
|
var easeInOutQuint = function(t) {
|
|
374
221
|
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
|
|
375
222
|
};
|
|
376
|
-
var
|
|
223
|
+
var animations = {
|
|
377
224
|
easeOut,
|
|
378
225
|
linear,
|
|
379
226
|
easeInQuad,
|
|
@@ -389,98 +236,69 @@ var availableAnimations = {
|
|
|
389
236
|
easeOutQuint,
|
|
390
237
|
easeInOutQuint
|
|
391
238
|
};
|
|
392
|
-
function
|
|
393
|
-
if (
|
|
394
|
-
|
|
395
|
-
if (this.animation) {
|
|
396
|
-
cancelAnimationFrame(this.animation);
|
|
239
|
+
var handleCancelAnimationFrame = function(animation) {
|
|
240
|
+
if (typeof animation === "number") {
|
|
241
|
+
cancelAnimationFrame(animation);
|
|
397
242
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
243
|
+
};
|
|
244
|
+
var handleCancelAnimation = function(contextInstance) {
|
|
245
|
+
if (!contextInstance.mounted)
|
|
246
|
+
return;
|
|
247
|
+
handleCancelAnimationFrame(contextInstance.animation);
|
|
248
|
+
contextInstance.animate = false;
|
|
249
|
+
contextInstance.animation = null;
|
|
250
|
+
contextInstance.velocity = null;
|
|
251
|
+
};
|
|
252
|
+
function handleSetupAnimation(contextInstance, animationName, animationTime, callback) {
|
|
253
|
+
if (!contextInstance.mounted)
|
|
405
254
|
return;
|
|
406
255
|
var startTime = new Date().getTime();
|
|
407
256
|
var lastStep = 1;
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
if (!
|
|
411
|
-
return;
|
|
257
|
+
handleCancelAnimation(contextInstance);
|
|
258
|
+
contextInstance.animation = function() {
|
|
259
|
+
if (!contextInstance.mounted) {
|
|
260
|
+
return handleCancelAnimationFrame(contextInstance.animation);
|
|
261
|
+
}
|
|
412
262
|
var frameTime = new Date().getTime() - startTime;
|
|
413
263
|
var animationProgress = frameTime / animationTime;
|
|
414
|
-
var animationType =
|
|
264
|
+
var animationType = animations[animationName];
|
|
415
265
|
var step = animationType(animationProgress);
|
|
416
266
|
if (frameTime >= animationTime) {
|
|
417
267
|
callback(lastStep);
|
|
418
|
-
|
|
419
|
-
} else {
|
|
268
|
+
contextInstance.animation = null;
|
|
269
|
+
} else if (contextInstance.animation) {
|
|
420
270
|
callback(step);
|
|
421
|
-
requestAnimationFrame(
|
|
271
|
+
requestAnimationFrame(contextInstance.animation);
|
|
422
272
|
}
|
|
423
273
|
};
|
|
424
|
-
requestAnimationFrame(
|
|
274
|
+
requestAnimationFrame(contextInstance.animation);
|
|
425
275
|
}
|
|
426
|
-
function
|
|
427
|
-
var
|
|
428
|
-
|
|
429
|
-
|
|
276
|
+
function animate(contextInstance, targetState, animationTime, animationName) {
|
|
277
|
+
var isValid = isValidTargetState(targetState);
|
|
278
|
+
if (!contextInstance.mounted || !isValid)
|
|
279
|
+
return;
|
|
280
|
+
var setTransformState = contextInstance.setTransformState;
|
|
281
|
+
var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
430
282
|
var scaleDiff = targetState.scale - scale;
|
|
431
283
|
var positionXDiff = targetState.positionX - positionX;
|
|
432
284
|
var positionYDiff = targetState.positionY - positionY;
|
|
433
|
-
if (
|
|
434
|
-
|
|
435
|
-
this.stateProvider.scale = targetState.scale;
|
|
436
|
-
this.stateProvider.positionX = targetState.positionX;
|
|
437
|
-
this.stateProvider.positionY = targetState.positionY;
|
|
438
|
-
this.applyTransformation();
|
|
285
|
+
if (animationTime === 0) {
|
|
286
|
+
setTransformState(targetState.scale, targetState.positionX, targetState.positionY);
|
|
439
287
|
} else {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
_this.applyTransformation();
|
|
288
|
+
handleSetupAnimation(contextInstance, animationName, animationTime, function(step) {
|
|
289
|
+
var newScale = scale + scaleDiff * step;
|
|
290
|
+
var newPositionX = positionX + positionXDiff * step;
|
|
291
|
+
var newPositionY = positionY + positionYDiff * step;
|
|
292
|
+
setTransformState(newScale, newPositionX, newPositionY);
|
|
446
293
|
});
|
|
447
294
|
}
|
|
448
295
|
}
|
|
449
|
-
function
|
|
450
|
-
var
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
-
};
|
|
296
|
+
function isValidTargetState(targetState) {
|
|
297
|
+
var scale = targetState.scale, positionX = targetState.positionX, positionY = targetState.positionY;
|
|
298
|
+
if (isNaN(scale) || isNaN(positionX) || isNaN(positionY)) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
484
302
|
}
|
|
485
303
|
function getComponentsSizes(wrapperComponent, contentComponent, newScale) {
|
|
486
304
|
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
@@ -500,920 +318,1330 @@ function getComponentsSizes(wrapperComponent, contentComponent, newScale) {
|
|
|
500
318
|
newDiffHeight
|
|
501
319
|
};
|
|
502
320
|
}
|
|
503
|
-
function
|
|
504
|
-
var
|
|
321
|
+
var getBounds = function(wrapperWidth, newContentWidth, diffWidth, wrapperHeight, newContentHeight, diffHeight, centerZoomedOut) {
|
|
322
|
+
var scaleWidthFactor = wrapperWidth > newContentWidth ? diffWidth * (centerZoomedOut ? 1 : 0.5) : 0;
|
|
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;
|
|
505
376
|
var scaleDifference = newScale - scale;
|
|
506
|
-
if (typeof mouseX !== "number" || typeof mouseY !== "number")
|
|
507
|
-
|
|
508
|
-
if (!transformEnabled)
|
|
377
|
+
if (typeof mouseX !== "number" || typeof mouseY !== "number") {
|
|
378
|
+
console.error("Mouse X and Y position were not provided!");
|
|
509
379
|
return {
|
|
510
|
-
|
|
511
|
-
|
|
380
|
+
x: positionX,
|
|
381
|
+
y: positionY
|
|
512
382
|
};
|
|
383
|
+
}
|
|
513
384
|
var calculatedPositionX = positionX - mouseX * scaleDifference;
|
|
514
385
|
var calculatedPositionY = positionY - mouseY * scaleDifference;
|
|
515
|
-
var newPositions =
|
|
386
|
+
var newPositions = getMouseBoundedPosition(calculatedPositionX, calculatedPositionY, bounds, limitToBounds, 0, 0, null);
|
|
516
387
|
return newPositions;
|
|
517
388
|
}
|
|
518
|
-
function
|
|
389
|
+
function checkZoomBounds(zoom, minScale, maxScale, zoomPadding, enablePadding) {
|
|
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) {
|
|
519
430
|
var touches = event.touches;
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
clientY: event.clientY
|
|
431
|
+
var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY;
|
|
432
|
+
contextInstance.isPanning = true;
|
|
433
|
+
var oneFingerTouch = touches.length === 1;
|
|
434
|
+
if (oneFingerTouch) {
|
|
435
|
+
var x = touches[0].clientX;
|
|
436
|
+
var y = touches[0].clientY;
|
|
437
|
+
contextInstance.startCoords = {
|
|
438
|
+
x: x - positionX,
|
|
439
|
+
y: y - positionY
|
|
530
440
|
};
|
|
531
441
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
var
|
|
536
|
-
|
|
537
|
-
|
|
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)
|
|
557
|
-
return;
|
|
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)
|
|
442
|
+
};
|
|
443
|
+
function handlePanToBounds(contextInstance) {
|
|
444
|
+
var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
|
|
445
|
+
var _b = contextInstance.setup, disabled = _b.disabled, limitToBounds = _b.limitToBounds, centerZoomedOut = _b.centerZoomedOut;
|
|
446
|
+
var wrapperComponent = contextInstance.wrapperComponent;
|
|
447
|
+
if (disabled || !wrapperComponent || !contextInstance.bounds)
|
|
569
448
|
return;
|
|
570
|
-
var _c =
|
|
449
|
+
var _c = contextInstance.bounds, maxPositionX = _c.maxPositionX, minPositionX = _c.minPositionX, maxPositionY = _c.maxPositionY, minPositionY = _c.minPositionY;
|
|
571
450
|
var xChanged = positionX > maxPositionX || positionX < minPositionX;
|
|
572
451
|
var yChanged = positionY > maxPositionY || positionY < minPositionY;
|
|
573
|
-
var
|
|
574
|
-
var
|
|
575
|
-
var mousePosX =
|
|
576
|
-
var mousePosY = mouseY;
|
|
577
|
-
var _d = handleCalculatePositions.call(this, mousePosX, mousePosY, scale, this.bounds, limitToBounds || limitToWrapper), x = _d.x, y = _d.y;
|
|
452
|
+
var mousePosX = positionX > maxPositionX ? wrapperComponent.offsetWidth : contextInstance.setup.minPositionX || 0;
|
|
453
|
+
var mousePosY = positionY > maxPositionY ? wrapperComponent.offsetHeight : contextInstance.setup.minPositionY || 0;
|
|
454
|
+
var _d = handleCalculateZoomPositions(contextInstance, mousePosX, mousePosY, scale, contextInstance.bounds, limitToBounds || centerZoomedOut), x = _d.x, y = _d.y;
|
|
578
455
|
return {
|
|
579
456
|
scale,
|
|
580
457
|
positionX: xChanged ? x : positionX,
|
|
581
458
|
positionY: yChanged ? y : positionY
|
|
582
459
|
};
|
|
583
460
|
}
|
|
584
|
-
function
|
|
585
|
-
var
|
|
586
|
-
|
|
461
|
+
function handleNewPosition(contextInstance, newPositionX, newPositionY, paddingValueX, paddingValueY) {
|
|
462
|
+
var limitToBounds = contextInstance.setup.limitToBounds;
|
|
463
|
+
var wrapperComponent = contextInstance.wrapperComponent, bounds = contextInstance.bounds;
|
|
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) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, paddingValueX, paddingValueY, wrapperComponent), x = _b.x, y = _b.y;
|
|
472
|
+
contextInstance.setTransformState(scale, x, y);
|
|
473
|
+
}
|
|
474
|
+
var getPanningClientPosition = function(contextInstance, clientX, clientY) {
|
|
475
|
+
var startCoords = contextInstance.startCoords, transformState = contextInstance.transformState;
|
|
476
|
+
var panning = contextInstance.setup.panning;
|
|
477
|
+
var lockAxisX = panning.lockAxisX, lockAxisY = panning.lockAxisY;
|
|
478
|
+
var positionX = transformState.positionX, positionY = transformState.positionY;
|
|
479
|
+
if (!startCoords) {
|
|
480
|
+
return {
|
|
481
|
+
x: positionX,
|
|
482
|
+
y: positionY
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
var mouseX = clientX - startCoords.x;
|
|
486
|
+
var mouseY = clientY - startCoords.y;
|
|
487
|
+
var newPositionX = lockAxisX ? positionX : mouseX;
|
|
488
|
+
var newPositionY = lockAxisY ? positionY : mouseY;
|
|
489
|
+
return {
|
|
490
|
+
x: newPositionX,
|
|
491
|
+
y: newPositionY
|
|
492
|
+
};
|
|
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
|
+
}
|
|
533
|
+
function getVelocityPosition(newPosition, startPosition, currentPosition, isLocked, limitToBounds, minPosition, maxPosition, minTarget, maxTarget, step) {
|
|
534
|
+
if (limitToBounds) {
|
|
535
|
+
if (startPosition > maxPosition && currentPosition > maxPosition) {
|
|
536
|
+
var calculatedPosition = maxPosition + (newPosition - maxPosition) * step;
|
|
537
|
+
if (calculatedPosition > maxTarget)
|
|
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
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (isLocked)
|
|
553
|
+
return startPosition;
|
|
554
|
+
return boundLimiter(newPosition, minPosition, maxPosition, limitToBounds);
|
|
555
|
+
}
|
|
556
|
+
function getSizeMultiplier(wrapperComponent, equalToMove) {
|
|
557
|
+
var defaultMultiplier = 1;
|
|
558
|
+
if (equalToMove) {
|
|
559
|
+
return Math.min(defaultMultiplier, wrapperComponent.offsetWidth / window.innerWidth);
|
|
560
|
+
}
|
|
561
|
+
return defaultMultiplier;
|
|
562
|
+
}
|
|
563
|
+
function handleCalculateVelocity(contextInstance, position) {
|
|
564
|
+
var isAllowed = isVelocityCalculationAllowed(contextInstance);
|
|
565
|
+
if (!isAllowed) {
|
|
587
566
|
return;
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
567
|
+
}
|
|
568
|
+
var lastMousePosition = contextInstance.lastMousePosition, velocityTime = contextInstance.velocityTime, setup = contextInstance.setup;
|
|
569
|
+
var wrapperComponent = contextInstance.wrapperComponent;
|
|
570
|
+
var equalToMove = setup.velocityAnimation.equalToMove;
|
|
571
|
+
var now = Date.now();
|
|
572
|
+
if (lastMousePosition && velocityTime && wrapperComponent) {
|
|
573
|
+
var sizeMultiplier = getSizeMultiplier(wrapperComponent, equalToMove);
|
|
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;
|
|
591
589
|
}
|
|
592
|
-
function
|
|
593
|
-
var
|
|
594
|
-
var
|
|
595
|
-
if (
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
590
|
+
function handleVelocityPanning(contextInstance) {
|
|
591
|
+
var velocity = contextInstance.velocity, bounds = contextInstance.bounds, setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent;
|
|
592
|
+
var isAllowed = isVelocityAllowed(contextInstance);
|
|
593
|
+
if (!isAllowed || !velocity || !bounds || !wrapperComponent) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
var velocityX = velocity.velocityX, velocityY = velocity.velocityY, total = velocity.total;
|
|
597
|
+
var maxPositionX = bounds.maxPositionX, minPositionX = bounds.minPositionX, maxPositionY = bounds.maxPositionY, minPositionY = bounds.minPositionY;
|
|
598
|
+
var limitToBounds = setup.limitToBounds, alignmentAnimation = setup.alignmentAnimation;
|
|
599
|
+
var zoomAnimation = setup.zoomAnimation, panning = setup.panning;
|
|
600
|
+
var lockAxisY = panning.lockAxisY, lockAxisX = panning.lockAxisX;
|
|
601
|
+
var animationType = zoomAnimation.animationType;
|
|
602
|
+
var sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, velocityAlignmentTime = alignmentAnimation.velocityAlignmentTime;
|
|
603
|
+
var alignAnimationTime = velocityAlignmentTime;
|
|
604
|
+
var moveAnimationTime = getVelocityMoveTime(contextInstance, total);
|
|
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
|
+
}
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
function handlePanningStart(contextInstance, event) {
|
|
633
|
+
var scale = contextInstance.transformState.scale;
|
|
634
|
+
handleCancelAnimation(contextInstance);
|
|
635
|
+
handleCalculateBounds(contextInstance, scale);
|
|
636
|
+
if (event.touches) {
|
|
637
|
+
handleTouchPanningSetup(contextInstance, event);
|
|
599
638
|
} else {
|
|
600
|
-
|
|
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);
|
|
639
|
+
handlePanningSetup(contextInstance, event);
|
|
604
640
|
}
|
|
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;
|
|
610
641
|
}
|
|
611
|
-
function
|
|
612
|
-
var
|
|
613
|
-
var
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
642
|
+
function handlePanning(contextInstance, clientX, clientY) {
|
|
643
|
+
var startCoords = contextInstance.startCoords, setup = contextInstance.setup;
|
|
644
|
+
var _a = setup.alignmentAnimation, sizeX = _a.sizeX, sizeY = _a.sizeY;
|
|
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);
|
|
617
655
|
}
|
|
618
|
-
function
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
656
|
+
function handlePanningEnd(contextInstance) {
|
|
657
|
+
if (contextInstance.isPanning) {
|
|
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
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function handleAlignToBounds(contextInstance) {
|
|
679
|
+
var scale = contextInstance.transformState.scale;
|
|
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)
|
|
625
684
|
return;
|
|
626
|
-
var
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
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();
|
|
685
|
+
var targetState = handlePanToBounds(contextInstance);
|
|
686
|
+
if (targetState) {
|
|
687
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
688
|
+
}
|
|
636
689
|
}
|
|
637
|
-
function
|
|
638
|
-
var
|
|
639
|
-
|
|
690
|
+
function handleAlignToScaleBounds(contextInstance, mousePositionX, mousePositionY) {
|
|
691
|
+
var scale = contextInstance.transformState.scale;
|
|
692
|
+
var wrapperComponent = contextInstance.wrapperComponent;
|
|
693
|
+
var _a = contextInstance.setup, minScale = _a.minScale, limitToBounds = _a.limitToBounds, zoomAnimation = _a.zoomAnimation;
|
|
694
|
+
var disabled = zoomAnimation.disabled, animationTime = zoomAnimation.animationTime, animationType = zoomAnimation.animationType;
|
|
695
|
+
var isDisabled = disabled || scale >= minScale;
|
|
696
|
+
if (scale >= 1 || limitToBounds) {
|
|
697
|
+
handleAlignToBounds(contextInstance);
|
|
698
|
+
}
|
|
699
|
+
if (isDisabled || !wrapperComponent || !contextInstance.mounted)
|
|
640
700
|
return;
|
|
641
|
-
var
|
|
642
|
-
var
|
|
643
|
-
var
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
var mousePosition = wheelMousePosition(event, contentComponent, scale);
|
|
647
|
-
mousePosX = mousePosition.mouseX;
|
|
648
|
-
mousePosY = mousePosition.mouseY;
|
|
701
|
+
var mouseX = mousePositionX || wrapperComponent.offsetWidth / 2;
|
|
702
|
+
var mouseY = mousePositionY || wrapperComponent.offsetHeight / 2;
|
|
703
|
+
var targetState = handleZoomToPoint(contextInstance, minScale, mouseX, mouseY);
|
|
704
|
+
if (targetState) {
|
|
705
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
649
706
|
}
|
|
650
|
-
|
|
707
|
+
}
|
|
708
|
+
function handleZoomToPoint(contextInstance, scale, mouseX, mouseY) {
|
|
709
|
+
var _a = contextInstance.setup, minScale = _a.minScale, maxScale = _a.maxScale, limitToBounds = _a.limitToBounds;
|
|
710
|
+
var newScale = checkZoomBounds(roundNumber(scale, 2), minScale, maxScale, 0, false);
|
|
711
|
+
var bounds = handleCalculateBounds(contextInstance, newScale);
|
|
712
|
+
var _b = handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds), x = _b.x, y = _b.y;
|
|
651
713
|
return {
|
|
652
714
|
scale: newScale,
|
|
653
715
|
positionX: x,
|
|
654
716
|
positionY: y
|
|
655
717
|
};
|
|
656
718
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
719
|
+
var initialState = {
|
|
720
|
+
previousScale: 1,
|
|
721
|
+
scale: 1,
|
|
722
|
+
positionX: 0,
|
|
723
|
+
positionY: 0
|
|
724
|
+
};
|
|
725
|
+
var contextInitialState = __assign(__assign({}, initialState), {
|
|
726
|
+
setComponents: function() {
|
|
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
|
|
662
791
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
var
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
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
|
+
}
|
|
672
819
|
});
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
var
|
|
678
|
-
|
|
679
|
-
|
|
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");
|
|
680
829
|
}
|
|
681
|
-
var
|
|
682
|
-
var newScale =
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
var
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
targetState,
|
|
691
|
-
speed: time,
|
|
692
|
-
type: animationType
|
|
693
|
-
});
|
|
694
|
-
}
|
|
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;
|
|
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");
|
|
697
839
|
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
698
840
|
var wrapperHeight = wrapperComponent.offsetHeight;
|
|
699
841
|
var mouseX = (wrapperWidth / 2 - positionX) / scale;
|
|
700
842
|
var mouseY = (wrapperHeight / 2 - positionY) / scale;
|
|
701
|
-
var newScale =
|
|
702
|
-
var
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
if (targetState.scale === scale)
|
|
708
|
-
return;
|
|
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
|
-
});
|
|
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.");
|
|
847
|
+
}
|
|
848
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
716
849
|
}
|
|
717
|
-
function resetTransformations(
|
|
718
|
-
var
|
|
719
|
-
var
|
|
720
|
-
|
|
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)
|
|
721
856
|
return;
|
|
722
|
-
|
|
857
|
+
var newBounds = calculateBounds(contextInstance, initialTransformation.scale);
|
|
858
|
+
var boundedPositions = getMouseBoundedPosition(initialTransformation.positionX, initialTransformation.positionY, newBounds, limitToBounds, 0, 0, wrapperComponent);
|
|
859
|
+
var newState = {
|
|
860
|
+
scale: initialTransformation.scale,
|
|
861
|
+
positionX: boundedPositions.x,
|
|
862
|
+
positionY: boundedPositions.y
|
|
863
|
+
};
|
|
864
|
+
if (scale === initialTransformation.scale && positionX === initialTransformation.positionX && positionY === initialTransformation.positionY) {
|
|
723
865
|
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;
|
|
732
866
|
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
867
|
+
animate(contextInstance, newState, animationTime, animationType);
|
|
868
|
+
}
|
|
869
|
+
function calculateZoomToNode(contextInstance, node, customZoom) {
|
|
870
|
+
var wrapperComponent = contextInstance.wrapperComponent;
|
|
871
|
+
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, minScale = _a.minScale, maxScale = _a.maxScale;
|
|
872
|
+
if (!wrapperComponent)
|
|
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
|
|
737
893
|
};
|
|
738
|
-
animateComponent.call(this, {
|
|
739
|
-
targetState,
|
|
740
|
-
speed,
|
|
741
|
-
type: reset.animationType
|
|
742
|
-
});
|
|
743
894
|
}
|
|
744
|
-
function
|
|
745
|
-
|
|
895
|
+
function getOffset(element) {
|
|
896
|
+
var el = element;
|
|
897
|
+
var offsetLeft = 0;
|
|
898
|
+
var offsetTop = 0;
|
|
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
|
+
};
|
|
746
908
|
}
|
|
747
|
-
function
|
|
748
|
-
|
|
749
|
-
|
|
909
|
+
function isValidZoomNode(node) {
|
|
910
|
+
if (!node) {
|
|
911
|
+
console.error("Zoom node not found");
|
|
912
|
+
return false;
|
|
913
|
+
} else if ((node === null || node === void 0 ? void 0 : node.offsetWidth) === void 0 || (node === null || node === void 0 ? void 0 : node.offsetHeight) === void 0) {
|
|
914
|
+
console.error("Zoom node is not valid - it must contain offsetWidth and offsetHeight");
|
|
915
|
+
return false;
|
|
916
|
+
}
|
|
917
|
+
return true;
|
|
750
918
|
}
|
|
751
|
-
function
|
|
752
|
-
return
|
|
919
|
+
var zoomIn = function(contextInstance) {
|
|
920
|
+
return function(step, animationTime, animationType) {
|
|
921
|
+
if (step === void 0) {
|
|
922
|
+
step = 0.5;
|
|
923
|
+
}
|
|
924
|
+
if (animationTime === void 0) {
|
|
925
|
+
animationTime = 300;
|
|
926
|
+
}
|
|
927
|
+
if (animationType === void 0) {
|
|
928
|
+
animationType = "easeOut";
|
|
929
|
+
}
|
|
930
|
+
handleZoomToViewCenter(contextInstance, 1, step, animationTime, animationType);
|
|
931
|
+
};
|
|
932
|
+
};
|
|
933
|
+
var zoomOut = function(contextInstance) {
|
|
934
|
+
return function(step, animationTime, animationType) {
|
|
935
|
+
if (step === void 0) {
|
|
936
|
+
step = 0.5;
|
|
937
|
+
}
|
|
938
|
+
if (animationTime === void 0) {
|
|
939
|
+
animationTime = 300;
|
|
940
|
+
}
|
|
941
|
+
if (animationType === void 0) {
|
|
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";
|
|
954
|
+
}
|
|
955
|
+
var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
|
|
956
|
+
var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
957
|
+
var disabled = contextInstance.setup.disabled;
|
|
958
|
+
if (disabled || !wrapperComponent || !contentComponent)
|
|
959
|
+
return;
|
|
960
|
+
var targetState = {
|
|
961
|
+
positionX: isNaN(newPositionX) ? positionX : newPositionX,
|
|
962
|
+
positionY: isNaN(newPositionY) ? positionY : newPositionY,
|
|
963
|
+
scale: isNaN(newScale) ? scale : newScale
|
|
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
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
return options;
|
|
1033
|
+
} catch (err) {
|
|
1034
|
+
passiveSupported = false;
|
|
1035
|
+
return passiveSupported;
|
|
1036
|
+
}
|
|
753
1037
|
}
|
|
754
|
-
function
|
|
755
|
-
|
|
1038
|
+
var isExcludedNode = function(node, excluded) {
|
|
1039
|
+
var targetTagName = node.tagName.toUpperCase();
|
|
1040
|
+
var isExcludedTag = excluded.find(function(tag) {
|
|
1041
|
+
return tag.toUpperCase() === targetTagName;
|
|
1042
|
+
});
|
|
1043
|
+
if (isExcludedTag)
|
|
1044
|
+
return true;
|
|
1045
|
+
var isExcludedClassName = excluded.find(function(className) {
|
|
1046
|
+
return node.classList.contains(className);
|
|
1047
|
+
});
|
|
1048
|
+
if (isExcludedClassName)
|
|
1049
|
+
return true;
|
|
1050
|
+
return false;
|
|
1051
|
+
};
|
|
1052
|
+
var cancelTimeout = function(timeout) {
|
|
1053
|
+
if (timeout) {
|
|
1054
|
+
clearTimeout(timeout);
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
var getTransformStyles = function(x, y, scale) {
|
|
1058
|
+
return "translate3d(" + x + "px, " + y + "px, 0) scale(" + scale + ")";
|
|
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;
|
|
756
1091
|
}
|
|
757
|
-
function
|
|
758
|
-
var
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if (
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
1092
|
+
function getMousePosition(event, contentComponent, scale) {
|
|
1093
|
+
var contentRect = contentComponent.getBoundingClientRect();
|
|
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
|
+
};
|
|
766
1110
|
}
|
|
767
|
-
function
|
|
1111
|
+
var handleCalculateWheelZoom = function(contextInstance, delta, step, disablePadding, getTarget) {
|
|
1112
|
+
var scale = contextInstance.transformState.scale;
|
|
1113
|
+
var wrapperComponent = contextInstance.wrapperComponent, setup = contextInstance.setup;
|
|
1114
|
+
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation;
|
|
1115
|
+
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
1116
|
+
if (!wrapperComponent) {
|
|
1117
|
+
throw new Error("Wrapper is not mounted");
|
|
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) {
|
|
768
1165
|
var contentRect = contentComponent.getBoundingClientRect();
|
|
769
1166
|
var touches = event.touches;
|
|
770
|
-
var firstPointX =
|
|
771
|
-
var firstPointY =
|
|
772
|
-
var secondPointX =
|
|
773
|
-
var secondPointY =
|
|
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);
|
|
774
1171
|
return {
|
|
775
|
-
|
|
776
|
-
|
|
1172
|
+
x: (firstPointX + secondPointX) / 2 / scale,
|
|
1173
|
+
y: (firstPointY + secondPointY) / 2 / scale
|
|
777
1174
|
};
|
|
778
|
-
}
|
|
779
|
-
function
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
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");
|
|
787
1185
|
}
|
|
788
|
-
if (
|
|
789
|
-
return;
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
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);
|
|
1192
|
+
};
|
|
1193
|
+
var wheelStopEventTime = 160;
|
|
1194
|
+
var wheelAnimationTime = 100;
|
|
1195
|
+
var handleWheelStart = function(contextInstance, event) {
|
|
1196
|
+
var _a = contextInstance.props, onWheelStart = _a.onWheelStart, onZoomStart = _a.onZoomStart;
|
|
1197
|
+
if (!contextInstance.wheelStopEventTimer) {
|
|
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)
|
|
796
1218
|
return;
|
|
797
|
-
var bounds = handleCalculateBounds
|
|
798
|
-
var
|
|
799
|
-
var
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
}
|
|
807
|
-
var
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
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);
|
|
812
1248
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
var
|
|
827
|
-
|
|
828
|
-
if (!this.mounted)
|
|
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)
|
|
829
1264
|
return;
|
|
830
|
-
|
|
831
|
-
|
|
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);
|
|
1265
|
+
var midPoint = calculateTouchMidPoint(event, scale, contentComponent);
|
|
1266
|
+
if (!isFinite(midPoint.x) || !isFinite(midPoint.y))
|
|
837
1267
|
return;
|
|
838
|
-
|
|
839
|
-
var
|
|
840
|
-
|
|
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();
|
|
864
|
-
}
|
|
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)
|
|
1268
|
+
var currentDistance = getTouchDistance(event);
|
|
1269
|
+
var newScale = calculatePinchZoom(contextInstance, currentDistance);
|
|
1270
|
+
if (newScale === scale)
|
|
871
1271
|
return;
|
|
872
|
-
|
|
873
|
-
var
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
velocity: velocity_1
|
|
896
|
-
};
|
|
897
|
-
if (this.throttle)
|
|
898
|
-
clearTimeout(this.throttle);
|
|
899
|
-
this.throttle = setTimeout(function() {
|
|
900
|
-
if (_this.mounted)
|
|
901
|
-
_this.throttle = false;
|
|
902
|
-
}, throttleTime);
|
|
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);
|
|
903
1295
|
}
|
|
904
|
-
var
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
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
|
-
}
|
|
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.");
|
|
926
1306
|
}
|
|
927
|
-
|
|
928
|
-
return startPosition;
|
|
929
|
-
var offsetPosition = offset + target * step;
|
|
930
|
-
return boundLimiter(offsetPosition, minBound, maxBound, limitToBounds);
|
|
931
|
-
}
|
|
932
|
-
function makePassiveEventOption(passive) {
|
|
933
|
-
return passive;
|
|
1307
|
+
animate(contextInstance, targetState, animationTime, animationType);
|
|
934
1308
|
}
|
|
935
|
-
var
|
|
936
|
-
var
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
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;
|
|
943
1323
|
};
|
|
944
|
-
var Context = React.createContext(
|
|
945
|
-
var
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
var wheelAnimationTime = 100;
|
|
949
|
-
var StateProvider = function(_super) {
|
|
950
|
-
__extends(StateProvider2, _super);
|
|
951
|
-
function StateProvider2() {
|
|
1324
|
+
var Context = React.createContext(contextInitialState);
|
|
1325
|
+
var TransformContext = function(_super) {
|
|
1326
|
+
__extends(TransformContext2, _super);
|
|
1327
|
+
function TransformContext2() {
|
|
952
1328
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
953
1329
|
_this.mounted = true;
|
|
954
|
-
_this.
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
_this.
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
_this.
|
|
962
|
-
_this.
|
|
1330
|
+
_this.transformState = createState(_this.props);
|
|
1331
|
+
_this.setup = createSetup(_this.props);
|
|
1332
|
+
_this.wrapperComponent = null;
|
|
1333
|
+
_this.contentComponent = null;
|
|
1334
|
+
_this.isInitialized = false;
|
|
1335
|
+
_this.bounds = null;
|
|
1336
|
+
_this.previousWheelEvent = null;
|
|
1337
|
+
_this.wheelStopEventTimer = null;
|
|
1338
|
+
_this.wheelAnimationTimer = null;
|
|
1339
|
+
_this.isPanning = false;
|
|
963
1340
|
_this.startCoords = null;
|
|
964
|
-
_this.
|
|
965
|
-
_this.
|
|
1341
|
+
_this.lastTouch = null;
|
|
1342
|
+
_this.distance = null;
|
|
966
1343
|
_this.lastDistance = null;
|
|
1344
|
+
_this.pinchStartDistance = null;
|
|
967
1345
|
_this.pinchStartScale = null;
|
|
968
|
-
_this.
|
|
969
|
-
_this.
|
|
1346
|
+
_this.pinchMidpoint = null;
|
|
1347
|
+
_this.velocity = null;
|
|
970
1348
|
_this.velocityTime = null;
|
|
971
1349
|
_this.lastMousePosition = null;
|
|
972
|
-
_this.
|
|
973
|
-
_this.offsetX = null;
|
|
974
|
-
_this.offsetY = null;
|
|
975
|
-
_this.throttle = false;
|
|
976
|
-
_this.previousWheelEvent = null;
|
|
977
|
-
_this.lastScale = null;
|
|
978
|
-
_this.animate = null;
|
|
1350
|
+
_this.animate = false;
|
|
979
1351
|
_this.animation = null;
|
|
980
1352
|
_this.maxBounds = null;
|
|
981
|
-
_this.
|
|
982
|
-
|
|
983
|
-
var
|
|
984
|
-
|
|
985
|
-
|
|
1353
|
+
_this.pressedKeys = {};
|
|
1354
|
+
_this.handleInitializeWrapperEvents = function(wrapper) {
|
|
1355
|
+
var passive = makePassiveEventOption();
|
|
1356
|
+
wrapper.addEventListener("wheel", _this.onWheelZoom, passive);
|
|
1357
|
+
wrapper.addEventListener("dblclick", _this.onDoubleClick, passive);
|
|
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)
|
|
986
1387
|
return;
|
|
987
|
-
|
|
1388
|
+
var isAllowed = isWheelAllowed(_this, event);
|
|
1389
|
+
if (!isAllowed)
|
|
988
1390
|
return;
|
|
989
|
-
|
|
1391
|
+
var keysPressed = _this.isPressingKeys(_this.setup.wheel.activationKeys);
|
|
1392
|
+
if (!keysPressed)
|
|
990
1393
|
return;
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
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);
|
|
1017
|
-
};
|
|
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
|
-
});
|
|
1394
|
+
handleWheelStart(_this, event);
|
|
1395
|
+
handleWheelZoom(_this, event);
|
|
1396
|
+
handleWheelStop(_this, event);
|
|
1025
1397
|
};
|
|
1026
|
-
_this.
|
|
1027
|
-
var disabled = _this.
|
|
1028
|
-
var
|
|
1029
|
-
|
|
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)
|
|
1398
|
+
_this.onPanningStart = function(event) {
|
|
1399
|
+
var disabled = _this.setup.disabled;
|
|
1400
|
+
var onPanningStart = _this.props.onPanningStart;
|
|
1401
|
+
if (disabled)
|
|
1044
1402
|
return;
|
|
1045
|
-
|
|
1046
|
-
|
|
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))
|
|
1403
|
+
var isAllowed = isPanningStartAllowed(_this, event);
|
|
1404
|
+
if (!isAllowed)
|
|
1058
1405
|
return;
|
|
1406
|
+
var keysPressed = _this.isPressingKeys(_this.setup.panning.activationKeys);
|
|
1407
|
+
if (!keysPressed)
|
|
1408
|
+
return;
|
|
1409
|
+
event.preventDefault();
|
|
1059
1410
|
event.stopPropagation();
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
handleCallback(_this
|
|
1411
|
+
handleCancelAnimation(_this);
|
|
1412
|
+
handlePanningStart(_this, event);
|
|
1413
|
+
handleCallback(getContext(_this), event, onPanningStart);
|
|
1063
1414
|
};
|
|
1064
|
-
_this.
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
handlePanningAnimation.call(_this);
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
};
|
|
1079
|
-
_this.handlePinchStart = function(event) {
|
|
1080
|
-
var scale = _this.stateProvider.scale;
|
|
1415
|
+
_this.onPanning = function(event) {
|
|
1416
|
+
var disabled = _this.setup.disabled;
|
|
1417
|
+
var onPanning = _this.props.onPanning;
|
|
1418
|
+
if (disabled)
|
|
1419
|
+
return;
|
|
1420
|
+
var isAllowed = isPanningAllowed(_this);
|
|
1421
|
+
if (!isAllowed)
|
|
1422
|
+
return;
|
|
1423
|
+
var keysPressed = _this.isPressingKeys(_this.setup.panning.activationKeys);
|
|
1424
|
+
if (!keysPressed)
|
|
1425
|
+
return;
|
|
1081
1426
|
event.preventDefault();
|
|
1082
1427
|
event.stopPropagation();
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
_this.pinchStartDistance = distance;
|
|
1086
|
-
_this.lastDistance = distance;
|
|
1087
|
-
_this.pinchStartScale = scale;
|
|
1088
|
-
_this.isDown = false;
|
|
1089
|
-
handleCallback(_this.props.onPinchingStart, _this.getCallbackProps());
|
|
1428
|
+
handlePanning(_this, event.clientX, event.clientY);
|
|
1429
|
+
handleCallback(getContext(_this), event, onPanning);
|
|
1090
1430
|
};
|
|
1091
|
-
_this.
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
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());
|
|
1431
|
+
_this.onPanningStop = function(event) {
|
|
1432
|
+
var onPanningStop = _this.props.onPanningStop;
|
|
1433
|
+
if (_this.isPanning) {
|
|
1434
|
+
handlePanningEnd(_this);
|
|
1435
|
+
handleCallback(getContext(_this), event, onPanningStop);
|
|
1105
1436
|
}
|
|
1106
1437
|
};
|
|
1107
|
-
_this.
|
|
1108
|
-
var
|
|
1109
|
-
var
|
|
1110
|
-
if (disabled
|
|
1111
|
-
return;
|
|
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)
|
|
1438
|
+
_this.onPinchStart = function(event) {
|
|
1439
|
+
var disabled = _this.setup.disabled;
|
|
1440
|
+
var _a = _this.props, onPinchingStart = _a.onPinchingStart, onZoomStart = _a.onZoomStart;
|
|
1441
|
+
if (disabled)
|
|
1121
1442
|
return;
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
if (!pinch.disabled && event.touches.length === 2)
|
|
1125
|
-
return _this.handlePinch(event);
|
|
1126
|
-
};
|
|
1127
|
-
_this.handleTouchStop = function() {
|
|
1128
|
-
_this.handleStopPanning();
|
|
1129
|
-
_this.handlePinchStop();
|
|
1130
|
-
};
|
|
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)
|
|
1443
|
+
var isAllowed = isPinchStartAllowed(_this, event);
|
|
1444
|
+
if (!isAllowed)
|
|
1137
1445
|
return;
|
|
1138
|
-
|
|
1446
|
+
handlePinchStart(_this, event);
|
|
1447
|
+
handleCancelAnimation(_this);
|
|
1448
|
+
handleCallback(getContext(_this), event, onPinchingStart);
|
|
1449
|
+
handleCallback(getContext(_this), event, onZoomStart);
|
|
1139
1450
|
};
|
|
1140
|
-
_this.
|
|
1141
|
-
var
|
|
1142
|
-
var
|
|
1143
|
-
if (
|
|
1144
|
-
throw Error("Zoom out function requires event prop");
|
|
1145
|
-
if (disabled || options.disabled || !wrapperComponent || !contentComponent)
|
|
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)
|
|
1146
1455
|
return;
|
|
1147
|
-
|
|
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)
|
|
1456
|
+
var isAllowed = isPinchAllowed(_this);
|
|
1457
|
+
if (!isAllowed)
|
|
1155
1458
|
return;
|
|
1156
|
-
|
|
1459
|
+
event.preventDefault();
|
|
1460
|
+
event.stopPropagation();
|
|
1461
|
+
handlePinchZoom(_this, event);
|
|
1462
|
+
handleCallback(getContext(_this), event, onPinching);
|
|
1463
|
+
handleCallback(getContext(_this), event, onZoom);
|
|
1157
1464
|
};
|
|
1158
|
-
_this.
|
|
1159
|
-
|
|
1160
|
-
|
|
1465
|
+
_this.onPinchStop = function(event) {
|
|
1466
|
+
var _a = _this.props, onPinchingStop = _a.onPinchingStop, onZoomStop = _a.onZoomStop;
|
|
1467
|
+
if (_this.pinchStartScale) {
|
|
1468
|
+
handlePinchStop(_this);
|
|
1469
|
+
handleCallback(getContext(_this), event, onPinchingStop);
|
|
1470
|
+
handleCallback(getContext(_this), event, onZoomStop);
|
|
1161
1471
|
}
|
|
1162
|
-
if (type === void 0) {
|
|
1163
|
-
type = "easeOut";
|
|
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
|
-
});
|
|
1179
1472
|
};
|
|
1180
|
-
_this.
|
|
1181
|
-
|
|
1182
|
-
|
|
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)
|
|
1473
|
+
_this.onTouchPanningStart = function(event) {
|
|
1474
|
+
var disabled = _this.setup.disabled;
|
|
1475
|
+
var onPanningStart = _this.props.onPanningStart;
|
|
1476
|
+
if (disabled)
|
|
1190
1477
|
return;
|
|
1191
|
-
var
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1478
|
+
var isAllowed = isPanningStartAllowed(_this, event);
|
|
1479
|
+
if (!isAllowed)
|
|
1480
|
+
return;
|
|
1481
|
+
var isDoubleTap = _this.lastTouch && +new Date() - _this.lastTouch < 200;
|
|
1482
|
+
if (isDoubleTap && event.touches.length === 1) {
|
|
1483
|
+
_this.onDoubleClick(event);
|
|
1484
|
+
} else {
|
|
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
|
+
}
|
|
1205
1498
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1499
|
+
};
|
|
1500
|
+
_this.onTouchPanning = function(event) {
|
|
1501
|
+
var disabled = _this.setup.disabled;
|
|
1502
|
+
var onPanning = _this.props.onPanning;
|
|
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);
|
|
1208
1516
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1517
|
+
};
|
|
1518
|
+
_this.onTouchPanningStop = function(event) {
|
|
1519
|
+
_this.onPanningStop(event);
|
|
1520
|
+
_this.onPinchStop(event);
|
|
1521
|
+
};
|
|
1522
|
+
_this.onDoubleClick = function(event) {
|
|
1523
|
+
var disabled = _this.setup.disabled;
|
|
1524
|
+
if (disabled)
|
|
1212
1525
|
return;
|
|
1213
|
-
var
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
};
|
|
1218
|
-
animateComponent.call(_this, {
|
|
1219
|
-
targetState,
|
|
1220
|
-
speed,
|
|
1221
|
-
type
|
|
1222
|
-
});
|
|
1526
|
+
var isAllowed = isDoubleClickAllowed(_this, event);
|
|
1527
|
+
if (!isAllowed)
|
|
1528
|
+
return;
|
|
1529
|
+
handleDoubleClick(_this, event);
|
|
1223
1530
|
};
|
|
1224
|
-
_this.
|
|
1225
|
-
if (
|
|
1226
|
-
|
|
1227
|
-
}
|
|
1228
|
-
if (type === void 0) {
|
|
1229
|
-
type = "easeOut";
|
|
1531
|
+
_this.clearPanning = function(event) {
|
|
1532
|
+
if (_this.isPanning) {
|
|
1533
|
+
_this.onPanningStop(event);
|
|
1230
1534
|
}
|
|
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
|
-
});
|
|
1245
1535
|
};
|
|
1246
|
-
_this.
|
|
1247
|
-
|
|
1248
|
-
if (disabled || !transformEnabled)
|
|
1249
|
-
return;
|
|
1250
|
-
resetTransformations.call(_this);
|
|
1536
|
+
_this.setKeyPressed = function(e) {
|
|
1537
|
+
_this.pressedKeys[e.key] = true;
|
|
1251
1538
|
};
|
|
1252
|
-
_this.
|
|
1253
|
-
_this.
|
|
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();
|
|
1539
|
+
_this.setKeyUnPressed = function(e) {
|
|
1540
|
+
_this.pressedKeys[e.key] = false;
|
|
1260
1541
|
};
|
|
1261
|
-
_this.
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
}
|
|
1542
|
+
_this.isPressingKeys = function(keys) {
|
|
1543
|
+
if (!keys.length) {
|
|
1544
|
+
return true;
|
|
1545
|
+
}
|
|
1546
|
+
return Boolean(keys.find(function(key) {
|
|
1547
|
+
return _this.pressedKeys[key];
|
|
1548
|
+
}));
|
|
1265
1549
|
};
|
|
1266
|
-
_this.
|
|
1267
|
-
_this.
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
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);
|
|
1550
|
+
_this.setComponents = function(wrapperComponent, contentComponent) {
|
|
1551
|
+
_this.wrapperComponent = wrapperComponent;
|
|
1552
|
+
_this.contentComponent = contentComponent;
|
|
1553
|
+
handleCalculateBounds(_this, _this.transformState.scale);
|
|
1554
|
+
_this.handleInitializeWrapperEvents(wrapperComponent);
|
|
1555
|
+
_this.handleInitialize();
|
|
1556
|
+
_this.handleRef();
|
|
1557
|
+
_this.isInitialized = true;
|
|
1558
|
+
handleCallback(getContext(_this), void 0, _this.props.onInit);
|
|
1559
|
+
};
|
|
1560
|
+
_this.setTransformState = function(scale, positionX, positionY) {
|
|
1561
|
+
if (!isNaN(scale) && !isNaN(positionX) && !isNaN(positionY)) {
|
|
1562
|
+
if (scale !== _this.transformState.scale) {
|
|
1563
|
+
_this.transformState.previousScale = _this.transformState.scale;
|
|
1564
|
+
_this.transformState.scale = scale;
|
|
1294
1565
|
}
|
|
1295
|
-
|
|
1566
|
+
_this.transformState.positionX = positionX;
|
|
1567
|
+
_this.transformState.positionY = positionY;
|
|
1568
|
+
_this.applyTransformation();
|
|
1569
|
+
} else {
|
|
1570
|
+
console.error("Detected NaN set state values");
|
|
1571
|
+
}
|
|
1296
1572
|
};
|
|
1297
|
-
_this.
|
|
1298
|
-
if (
|
|
1299
|
-
|
|
1300
|
-
|
|
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());
|
|
1573
|
+
_this.setCenter = function() {
|
|
1574
|
+
if (_this.wrapperComponent && _this.contentComponent) {
|
|
1575
|
+
var targetState = getCenterPosition(_this.transformState.scale, _this.wrapperComponent, _this.contentComponent);
|
|
1576
|
+
_this.setTransformState(targetState.scale, targetState.positionX, targetState.positionY);
|
|
1311
1577
|
}
|
|
1312
1578
|
};
|
|
1313
|
-
_this.
|
|
1314
|
-
|
|
1579
|
+
_this.applyTransformation = function() {
|
|
1580
|
+
if (!_this.mounted || !_this.contentComponent)
|
|
1581
|
+
return;
|
|
1582
|
+
var _a = _this.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
1583
|
+
var transform = getTransformStyles(positionX, positionY, scale);
|
|
1584
|
+
_this.contentComponent.style.transform = transform;
|
|
1585
|
+
_this.handleRef();
|
|
1586
|
+
};
|
|
1587
|
+
_this.handleRef = function() {
|
|
1588
|
+
_this.props.setRef(getContext(_this));
|
|
1315
1589
|
};
|
|
1316
1590
|
return _this;
|
|
1317
1591
|
}
|
|
1318
|
-
|
|
1319
|
-
var
|
|
1320
|
-
window.addEventListener("mousedown", this.
|
|
1321
|
-
window.addEventListener("mousemove", this.
|
|
1322
|
-
window.addEventListener("mouseup", this.
|
|
1592
|
+
TransformContext2.prototype.componentDidMount = function() {
|
|
1593
|
+
var passive = makePassiveEventOption();
|
|
1594
|
+
window.addEventListener("mousedown", this.onPanningStart, passive);
|
|
1595
|
+
window.addEventListener("mousemove", this.onPanning, passive);
|
|
1596
|
+
window.addEventListener("mouseup", this.onPanningStop, passive);
|
|
1597
|
+
document.addEventListener("mouseleave", this.clearPanning, passive);
|
|
1598
|
+
window.addEventListener("keyup", this.setKeyUnPressed, passive);
|
|
1599
|
+
window.addEventListener("keydown", this.setKeyPressed, passive);
|
|
1600
|
+
this.handleRef();
|
|
1323
1601
|
};
|
|
1324
|
-
|
|
1325
|
-
var
|
|
1326
|
-
window.removeEventListener("mousedown", this.
|
|
1327
|
-
window.removeEventListener("mousemove", this.
|
|
1328
|
-
window.removeEventListener("mouseup", this.
|
|
1329
|
-
|
|
1602
|
+
TransformContext2.prototype.componentWillUnmount = function() {
|
|
1603
|
+
var passive = makePassiveEventOption();
|
|
1604
|
+
window.removeEventListener("mousedown", this.onPanningStart, passive);
|
|
1605
|
+
window.removeEventListener("mousemove", this.onPanning, passive);
|
|
1606
|
+
window.removeEventListener("mouseup", this.onPanningStop, passive);
|
|
1607
|
+
window.removeEventListener("keyup", this.setKeyUnPressed, passive);
|
|
1608
|
+
window.removeEventListener("keydown", this.setKeyPressed, passive);
|
|
1609
|
+
handleCancelAnimation(this);
|
|
1330
1610
|
};
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
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);
|
|
1611
|
+
TransformContext2.prototype.componentDidUpdate = function(oldProps) {
|
|
1612
|
+
if (oldProps !== this.props) {
|
|
1613
|
+
handleCalculateBounds(this, this.transformState.scale);
|
|
1614
|
+
this.setup = createSetup(this.props);
|
|
1355
1615
|
}
|
|
1356
1616
|
};
|
|
1357
|
-
|
|
1358
|
-
var
|
|
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
|
-
};
|
|
1617
|
+
TransformContext2.prototype.render = function() {
|
|
1618
|
+
var value = getContext(this);
|
|
1377
1619
|
var children = this.props.children;
|
|
1378
|
-
var content = typeof children === "function" ? children(
|
|
1620
|
+
var content = typeof children === "function" ? children(value) : children;
|
|
1379
1621
|
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
1380
|
-
value,
|
|
1622
|
+
value: __assign(__assign({}, this.transformState), {
|
|
1623
|
+
setComponents: this.setComponents,
|
|
1624
|
+
contextInstance: this
|
|
1625
|
+
}),
|
|
1381
1626
|
children: content
|
|
1382
1627
|
});
|
|
1383
1628
|
};
|
|
1384
|
-
return
|
|
1629
|
+
return TransformContext2;
|
|
1385
1630
|
}(Component);
|
|
1386
|
-
var TransformWrapper = function(
|
|
1387
|
-
var
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
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) {
|
|
1631
|
+
var TransformWrapper = React.forwardRef(function(props, ref) {
|
|
1632
|
+
var _a = useState(null), innerRef = _a[0], setRef = _a[1];
|
|
1633
|
+
useImperativeHandle(ref, function() {
|
|
1634
|
+
return innerRef;
|
|
1635
|
+
}, [innerRef]);
|
|
1636
|
+
return /* @__PURE__ */ jsx(TransformContext, __spreadValues({}, __assign({}, props, {
|
|
1637
|
+
setRef
|
|
1638
|
+
})));
|
|
1639
|
+
});
|
|
1640
|
+
function styleInject(css, ref) {
|
|
1413
1641
|
if (ref === void 0)
|
|
1414
1642
|
ref = {};
|
|
1415
1643
|
var insertAt = ref.insertAt;
|
|
1416
|
-
if (!
|
|
1644
|
+
if (!css || typeof document === "undefined") {
|
|
1417
1645
|
return;
|
|
1418
1646
|
}
|
|
1419
1647
|
var head = document.head || document.getElementsByTagName("head")[0];
|
|
@@ -1429,91 +1657,41 @@ function styleInject(css2, ref) {
|
|
|
1429
1657
|
head.appendChild(style);
|
|
1430
1658
|
}
|
|
1431
1659
|
if (style.styleSheet) {
|
|
1432
|
-
style.styleSheet.cssText =
|
|
1660
|
+
style.styleSheet.cssText = css;
|
|
1433
1661
|
} else {
|
|
1434
|
-
style.appendChild(document.createTextNode(
|
|
1662
|
+
style.appendChild(document.createTextNode(css));
|
|
1435
1663
|
}
|
|
1436
1664
|
}
|
|
1437
|
-
var
|
|
1665
|
+
var css_248z = ".transform-component-module_wrapper__1_Fgj {\n position: relative;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-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.transform-component-module_content__2jYgh {\n display: flex;\n flex-wrap: wrap;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n margin: 0;\n padding: 0;\n transform-origin: 0% 0%;\n}\n.transform-component-module_content__2jYgh img {\n pointer-events: none;\n}\n";
|
|
1438
1666
|
var styles$1 = {
|
|
1439
|
-
"
|
|
1440
|
-
"content": "
|
|
1667
|
+
"wrapper": "transform-component-module_wrapper__1_Fgj",
|
|
1668
|
+
"content": "transform-component-module_content__2jYgh"
|
|
1441
1669
|
};
|
|
1442
|
-
styleInject(
|
|
1443
|
-
var TransformComponent = function(
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
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;
|
|
1477
|
-
const extraStyle = `
|
|
1478
|
-
.lds-dual-ring {
|
|
1479
|
-
display: inline-block;
|
|
1480
|
-
width: 40px;
|
|
1481
|
-
height: 40px;
|
|
1482
|
-
}
|
|
1483
|
-
.lds-dual-ring:after {
|
|
1484
|
-
content: " ";
|
|
1485
|
-
display: block;
|
|
1486
|
-
width: 32px;
|
|
1487
|
-
height: 32px;
|
|
1488
|
-
margin: 8px;
|
|
1489
|
-
border-radius: 50%;
|
|
1490
|
-
border: 3px solid rgba(185, 185, 185, 0.466);
|
|
1491
|
-
border-color: rgba(185, 185, 185, 0.466) transparent rgba(185, 185, 185, 0.466) transparent;
|
|
1492
|
-
animation: lds-dual-ring 1.2s linear infinite;
|
|
1493
|
-
}
|
|
1494
|
-
@keyframes lds-dual-ring {
|
|
1495
|
-
0% {
|
|
1496
|
-
transform: rotate(0deg);
|
|
1497
|
-
}
|
|
1498
|
-
100% {
|
|
1499
|
-
transform: rotate(360deg);
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
`;
|
|
1503
|
-
function CircularLoading() {
|
|
1504
|
-
const styleTag = document.querySelector("#react-pic-style");
|
|
1505
|
-
if (!styleTag) {
|
|
1506
|
-
const sheet = document.createElement("style");
|
|
1507
|
-
sheet.id = "react-pic-style";
|
|
1508
|
-
sheet.innerHTML = extraStyle;
|
|
1509
|
-
document.body.appendChild(sheet);
|
|
1510
|
-
} else {
|
|
1511
|
-
styleTag.innerHTML = styleTag.innerHTML + extraStyle;
|
|
1512
|
-
}
|
|
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
|
+
}, []);
|
|
1513
1683
|
return /* @__PURE__ */ jsx("div", {
|
|
1514
|
-
|
|
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
|
+
})
|
|
1515
1693
|
});
|
|
1516
|
-
}
|
|
1694
|
+
};
|
|
1517
1695
|
let styles = {};
|
|
1518
1696
|
styles.lightbox = {
|
|
1519
1697
|
position: "fixed",
|
|
@@ -1571,20 +1749,106 @@ styles.Grid = {
|
|
|
1571
1749
|
width: "100%",
|
|
1572
1750
|
height: "auto"
|
|
1573
1751
|
};
|
|
1574
|
-
const
|
|
1575
|
-
|
|
1752
|
+
const extraStyle = `
|
|
1753
|
+
.lds-dual-ring {
|
|
1754
|
+
display: inline-block;
|
|
1755
|
+
width: 40px;
|
|
1756
|
+
height: 40px;
|
|
1757
|
+
}
|
|
1758
|
+
.lds-dual-ring:after {
|
|
1759
|
+
content: " ";
|
|
1760
|
+
display: block;
|
|
1761
|
+
width: 32px;
|
|
1762
|
+
height: 32px;
|
|
1763
|
+
margin: 8px;
|
|
1764
|
+
border-radius: 50%;
|
|
1765
|
+
border: 3px solid rgba(185, 185, 185, 0.466);
|
|
1766
|
+
border-color: rgba(185, 185, 185, 0.466) transparent rgba(185, 185, 185, 0.466) transparent;
|
|
1767
|
+
animation: lds-dual-ring 1.2s linear infinite;
|
|
1768
|
+
}
|
|
1769
|
+
@keyframes lds-dual-ring {
|
|
1770
|
+
0% {
|
|
1771
|
+
transform: rotate(0deg);
|
|
1772
|
+
}
|
|
1773
|
+
100% {
|
|
1774
|
+
transform: rotate(360deg);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
`;
|
|
1778
|
+
function CircularLoading() {
|
|
1779
|
+
useEffect(() => {
|
|
1780
|
+
const styleTag = document.querySelector("#react-pic-style");
|
|
1781
|
+
if (!styleTag) {
|
|
1782
|
+
const sheet = document.createElement("style");
|
|
1783
|
+
sheet.id = "react-pic-style";
|
|
1784
|
+
sheet.innerHTML = extraStyle;
|
|
1785
|
+
document.body.appendChild(sheet);
|
|
1786
|
+
} else {
|
|
1787
|
+
styleTag.innerHTML = styleTag.innerHTML + extraStyle;
|
|
1788
|
+
}
|
|
1789
|
+
return () => {
|
|
1790
|
+
var _a;
|
|
1791
|
+
(_a = document.querySelector("#react-pic-style")) == null ? void 0 : _a.remove();
|
|
1792
|
+
};
|
|
1793
|
+
}, []);
|
|
1794
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1795
|
+
className: "lds-dual-ring"
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
const ImgLazyLoading = (props) => {
|
|
1799
|
+
var _a;
|
|
1576
1800
|
const [imgSrcUrl, setImgSrcUrl] = React.useState("");
|
|
1577
1801
|
const Loading = ((_a = props.options) == null ? void 0 : _a.customLoadComponent) !== void 0 ? props.options.customLoadComponent : CircularLoading;
|
|
1802
|
+
const [loadingState, setLoadingState] = useState(true);
|
|
1578
1803
|
React.useEffect(() => {
|
|
1579
|
-
|
|
1580
|
-
const
|
|
1581
|
-
if (imgSrc) {
|
|
1582
|
-
fetch(imgSrc).then((response) => response.blob()).then((blob) => {
|
|
1804
|
+
setLoadingState(true);
|
|
1805
|
+
const ac = new AbortController();
|
|
1806
|
+
if (props.imgSrc) {
|
|
1807
|
+
fetch(props.imgSrc).then((response) => response.blob()).then((blob) => {
|
|
1583
1808
|
setImgSrcUrl(URL.createObjectURL(blob));
|
|
1809
|
+
setLoadingState(false);
|
|
1584
1810
|
});
|
|
1585
1811
|
}
|
|
1812
|
+
return () => {
|
|
1813
|
+
ac.abort();
|
|
1814
|
+
};
|
|
1815
|
+
}, [props.imgSrc]);
|
|
1816
|
+
if (loadingState) {
|
|
1817
|
+
return /* @__PURE__ */ jsx("div", {
|
|
1818
|
+
style: {
|
|
1819
|
+
height: "100%",
|
|
1820
|
+
width: "100%",
|
|
1821
|
+
display: "flex",
|
|
1822
|
+
alignItems: "center",
|
|
1823
|
+
alignContent: "center",
|
|
1824
|
+
justifyContent: "center",
|
|
1825
|
+
background: !props.lightboxMode ? "rgba(0, 0, 0, 0.157)" : "",
|
|
1826
|
+
border: !props.lightboxMode ? "1px solid rgba(0, 0, 0,0.3)" : ""
|
|
1827
|
+
},
|
|
1828
|
+
children: /* @__PURE__ */ jsx(Loading, {})
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
return /* @__PURE__ */ jsx("img", {
|
|
1832
|
+
src: imgSrcUrl,
|
|
1833
|
+
alt: "",
|
|
1834
|
+
id: props.id,
|
|
1835
|
+
style: __spreadValues({}, props.style),
|
|
1836
|
+
onClick: props.onClick
|
|
1837
|
+
});
|
|
1838
|
+
};
|
|
1839
|
+
const ImgLightbox = (props) => {
|
|
1840
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1841
|
+
const [imgSrcUrl, setImgSrcUrl] = useState("");
|
|
1842
|
+
const [modalImgIndex, setModalImgIndex] = useState(props.currentImgIndex);
|
|
1843
|
+
useCallback(() => setModalImgIndex(modalImgIndex + 1), [modalImgIndex]);
|
|
1844
|
+
useCallback(() => setModalImgIndex(modalImgIndex - 1), [modalImgIndex]);
|
|
1845
|
+
React.useEffect(() => {
|
|
1846
|
+
var _a2, _b2;
|
|
1847
|
+
const imgSrc = ((_a2 = props.imgList[modalImgIndex]) == null ? void 0 : _a2.fullSrc) ? props.imgList[modalImgIndex].fullSrc : ((_b2 = props.imgList[modalImgIndex]) == null ? void 0 : _b2.thumbnailSrc) ? props.imgList[modalImgIndex].thumbnailSrc : null;
|
|
1848
|
+
if (imgSrc)
|
|
1849
|
+
setImgSrcUrl(imgSrc);
|
|
1586
1850
|
document.body.style.overflow = "hidden";
|
|
1587
|
-
}, [
|
|
1851
|
+
}, [modalImgIndex]);
|
|
1588
1852
|
return /* @__PURE__ */ jsxs("div", {
|
|
1589
1853
|
className: "reactPic-lightbox",
|
|
1590
1854
|
style: styles.lightbox,
|
|
@@ -1598,22 +1862,19 @@ const ImgLightbox = (props) => {
|
|
|
1598
1862
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1599
1863
|
style: styles.topCustomContent,
|
|
1600
1864
|
className: "reactPic-topCustomContent",
|
|
1601
|
-
children: (
|
|
1865
|
+
children: (_a = props.topCustomContent) == null ? void 0 : _a.call(props, {
|
|
1602
1866
|
closeLightbox: props.onClose,
|
|
1603
|
-
imgObject: props.
|
|
1867
|
+
imgObject: props.imgList[modalImgIndex]
|
|
1604
1868
|
})
|
|
1605
|
-
}),
|
|
1606
|
-
style: {
|
|
1607
|
-
display: "block",
|
|
1608
|
-
margin: "auto"
|
|
1609
|
-
},
|
|
1610
|
-
children: /* @__PURE__ */ jsx(Loading, {})
|
|
1611
|
-
}) : /* @__PURE__ */ jsxs("div", {
|
|
1869
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1612
1870
|
children: [/* @__PURE__ */ jsx(TransformWrapper, {
|
|
1613
1871
|
children: /* @__PURE__ */ jsx(TransformComponent, {
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1872
|
+
wrapperStyle: {
|
|
1873
|
+
overflow: "visible"
|
|
1874
|
+
},
|
|
1875
|
+
children: /* @__PURE__ */ jsx(ImgLazyLoading, {
|
|
1876
|
+
lightboxMode: true,
|
|
1877
|
+
imgSrc: imgSrcUrl,
|
|
1617
1878
|
id: "lightboxImg",
|
|
1618
1879
|
style: {
|
|
1619
1880
|
maxWidth: "80vw",
|
|
@@ -1623,85 +1884,48 @@ const ImgLightbox = (props) => {
|
|
|
1623
1884
|
}
|
|
1624
1885
|
})
|
|
1625
1886
|
})
|
|
1626
|
-
}), props.
|
|
1887
|
+
}), modalImgIndex - 1 >= 0 && !((_b = props.options) == null ? void 0 : _b.hidePagination) && /* @__PURE__ */ jsx("div", {
|
|
1627
1888
|
className: "react-lightbox-prevBtn",
|
|
1628
1889
|
style: {
|
|
1629
1890
|
position: "absolute",
|
|
1630
1891
|
left: 20,
|
|
1631
|
-
|
|
1892
|
+
height: 50,
|
|
1893
|
+
top: "calc(50% - 50px)",
|
|
1632
1894
|
fontSize: 50,
|
|
1633
1895
|
cursor: "pointer",
|
|
1634
1896
|
color: "white",
|
|
1635
1897
|
display: ((_c = props.options) == null ? void 0 : _c.hidePagination) ? "none" : "inherit"
|
|
1636
1898
|
},
|
|
1637
|
-
onClick:
|
|
1899
|
+
onClick: modalImgIndex - 1 >= 0 ? () => setModalImgIndex(modalImgIndex - 1) : void 0,
|
|
1638
1900
|
children: "\u2039"
|
|
1639
|
-
}), props.
|
|
1901
|
+
}), modalImgIndex + 1 < props.imgList.length && !((_d = props.options) == null ? void 0 : _d.hidePagination) && /* @__PURE__ */ jsx("div", {
|
|
1640
1902
|
className: "react-lightbox-nextBtn",
|
|
1641
1903
|
style: {
|
|
1642
1904
|
position: "absolute",
|
|
1643
1905
|
right: 20,
|
|
1644
|
-
|
|
1906
|
+
height: 50,
|
|
1907
|
+
top: "calc(50% - 50px)",
|
|
1645
1908
|
fontSize: 50,
|
|
1646
1909
|
cursor: "pointer",
|
|
1647
1910
|
color: "white",
|
|
1648
|
-
display: ((
|
|
1911
|
+
display: ((_e = props.options) == null ? void 0 : _e.hidePagination) ? "none" : "inherit"
|
|
1649
1912
|
},
|
|
1650
|
-
onClick: props.
|
|
1913
|
+
onClick: modalImgIndex + 1 < props.imgList.length ? () => setModalImgIndex(modalImgIndex + 1) : void 0,
|
|
1651
1914
|
children: "\u203A"
|
|
1652
1915
|
})]
|
|
1653
1916
|
}), /* @__PURE__ */ jsx("div", {
|
|
1654
1917
|
style: styles.bottomCustomContent,
|
|
1655
1918
|
className: "reactPic-bottomCustomContent",
|
|
1656
|
-
children: (
|
|
1919
|
+
children: (_f = props.bottomCustomContent) == null ? void 0 : _f.call(props, {
|
|
1657
1920
|
closeLightbox: props.onClose,
|
|
1658
|
-
imgObject: props.
|
|
1921
|
+
imgObject: props.imgList[modalImgIndex]
|
|
1659
1922
|
})
|
|
1660
1923
|
})]
|
|
1661
1924
|
});
|
|
1662
1925
|
};
|
|
1663
|
-
const ImgLazyLoading = (props) => {
|
|
1664
|
-
var _a;
|
|
1665
|
-
const [imgSrcUrl, setImgSrcUrl] = React.useState("");
|
|
1666
|
-
const Loading = ((_a = props.options) == null ? void 0 : _a.customLoadComponent) !== void 0 ? props.options.customLoadComponent : CircularLoading;
|
|
1667
|
-
React.useEffect(() => {
|
|
1668
|
-
const ac = new AbortController();
|
|
1669
|
-
if (props.imgSrc) {
|
|
1670
|
-
fetch(props.imgSrc).then((response) => response.blob()).then((blob) => {
|
|
1671
|
-
setImgSrcUrl(URL.createObjectURL(blob));
|
|
1672
|
-
});
|
|
1673
|
-
}
|
|
1674
|
-
return () => {
|
|
1675
|
-
ac.abort();
|
|
1676
|
-
};
|
|
1677
|
-
}, [props.imgSrc]);
|
|
1678
|
-
if (imgSrcUrl) {
|
|
1679
|
-
return /* @__PURE__ */ jsx("img", {
|
|
1680
|
-
src: imgSrcUrl,
|
|
1681
|
-
alt: "",
|
|
1682
|
-
style: __spreadValues({}, props.style),
|
|
1683
|
-
onClick: () => {
|
|
1684
|
-
props.onClick();
|
|
1685
|
-
}
|
|
1686
|
-
});
|
|
1687
|
-
} else {
|
|
1688
|
-
return /* @__PURE__ */ jsx("div", {
|
|
1689
|
-
style: {
|
|
1690
|
-
height: "100%",
|
|
1691
|
-
width: "100%",
|
|
1692
|
-
display: "flex",
|
|
1693
|
-
alignItems: "center",
|
|
1694
|
-
alignContent: "center",
|
|
1695
|
-
justifyContent: "center",
|
|
1696
|
-
background: "rgba(0, 0, 0, 0.157)",
|
|
1697
|
-
border: "1px solid rgba(0, 0, 0,0.3)"
|
|
1698
|
-
},
|
|
1699
|
-
children: /* @__PURE__ */ jsx(Loading, {})
|
|
1700
|
-
});
|
|
1701
|
-
}
|
|
1702
|
-
};
|
|
1703
1926
|
function ImgGallery(props) {
|
|
1704
1927
|
var _a;
|
|
1928
|
+
const onOpen = useCallback((index) => () => props.onOpen(index), []);
|
|
1705
1929
|
return /* @__PURE__ */ jsx("div", {
|
|
1706
1930
|
className: "reactPic-grid",
|
|
1707
1931
|
style: __spreadProps(__spreadValues({}, styles.Grid), {
|
|
@@ -1736,7 +1960,7 @@ function ImgGallery(props) {
|
|
|
1736
1960
|
minWidth: "100%",
|
|
1737
1961
|
minHeight: "100%"
|
|
1738
1962
|
},
|
|
1739
|
-
onClick:
|
|
1963
|
+
onClick: onOpen(index)
|
|
1740
1964
|
})
|
|
1741
1965
|
})
|
|
1742
1966
|
}, element.thumbnailSrc ? element.thumbnailSrc : element.fullSrc);
|
|
@@ -1758,11 +1982,13 @@ function PicGallery(props) {
|
|
|
1758
1982
|
if (typeof props.setExtLightboxChildren == "function") {
|
|
1759
1983
|
if (open) {
|
|
1760
1984
|
props.setExtLightboxChildren(/* @__PURE__ */ jsx(ImgLightbox, {
|
|
1761
|
-
|
|
1985
|
+
open,
|
|
1986
|
+
currentImgIndex: modalImgIndex,
|
|
1987
|
+
imgList: props.imgList,
|
|
1988
|
+
topCustomContent: props.topCustomContent,
|
|
1989
|
+
bottomCustomContent: props.bottomCustomContent,
|
|
1762
1990
|
options,
|
|
1763
|
-
onClose: () =>
|
|
1764
|
-
setOpen(false);
|
|
1765
|
-
}
|
|
1991
|
+
onClose: () => setOpen(false)
|
|
1766
1992
|
}));
|
|
1767
1993
|
} else {
|
|
1768
1994
|
props.setExtLightboxChildren(void 0);
|
|
@@ -1773,17 +1999,20 @@ function PicGallery(props) {
|
|
|
1773
1999
|
setModalImgIndex(count);
|
|
1774
2000
|
setOpen(true);
|
|
1775
2001
|
}, []);
|
|
2002
|
+
const onClose = useCallback(() => {
|
|
2003
|
+
setOpen(false);
|
|
2004
|
+
}, []);
|
|
1776
2005
|
return /* @__PURE__ */ jsxs("div", {
|
|
1777
2006
|
className: "reactPic-wrapper",
|
|
1778
2007
|
style: styles.Wrapper,
|
|
1779
2008
|
children: [open && !((_a = props.options) == null ? void 0 : _a.externalLightbox) ? /* @__PURE__ */ jsx(ImgLightbox, {
|
|
1780
|
-
|
|
2009
|
+
open,
|
|
2010
|
+
currentImgIndex: modalImgIndex,
|
|
2011
|
+
imgList: props.imgList,
|
|
1781
2012
|
topCustomContent: props.topCustomContent,
|
|
1782
2013
|
bottomCustomContent: props.bottomCustomContent,
|
|
1783
2014
|
options,
|
|
1784
|
-
onClose
|
|
1785
|
-
onClickPrevious: modalImgIndex - 1 >= 0 ? () => setModalImgIndex(modalImgIndex - 1) : void 0,
|
|
1786
|
-
onClickNext: modalImgIndex + 1 < props.imgList.length ? () => setModalImgIndex(modalImgIndex + 1) : void 0
|
|
2015
|
+
onClose
|
|
1787
2016
|
}) : null, /* @__PURE__ */ jsx(ImgGallery$1, {
|
|
1788
2017
|
options: props.options,
|
|
1789
2018
|
imgList: props.imgList,
|