react-zoom-pan-pinch 3.7.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +785 -310
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +117 -23
- package/dist/index.esm.js +781 -302
- package/dist/index.esm.js.map +1 -1
- package/package.json +74 -62
- package/src/components/index.ts +5 -0
- package/src/components/keep-scale/keep-scale.tsx +28 -0
- package/src/components/mini-map/mini-map.tsx +292 -0
- package/src/components/mini-map/use-resize.hook.ts +74 -0
- package/src/components/transform-component/transform-component.module.css +43 -0
- package/src/components/transform-component/transform-component.tsx +96 -0
- package/src/components/transform-wrapper/transform-wrapper.tsx +39 -0
- package/src/components/virtualize/virtualize.tsx +133 -0
- package/src/components/virtualize/virtualize.utils.ts +104 -0
- package/src/constants/state.constants.ts +99 -0
- package/src/core/animations/animations.constants.ts +78 -0
- package/src/core/animations/animations.utils.ts +115 -0
- package/src/core/bounds/bounds.types.ts +8 -0
- package/src/core/bounds/bounds.utils.ts +226 -0
- package/src/core/double-click/double-click.logic.ts +127 -0
- package/src/core/handlers/handlers.logic.ts +122 -0
- package/src/core/handlers/handlers.utils.ts +243 -0
- package/src/core/instance.core.ts +704 -0
- package/src/core/pan/panning.logic.ts +122 -0
- package/src/core/pan/panning.utils.ts +216 -0
- package/src/core/pan/velocity.logic.ts +187 -0
- package/src/core/pan/velocity.utils.ts +83 -0
- package/src/core/pinch/pinch.logic.ts +139 -0
- package/src/core/pinch/pinch.utils.ts +95 -0
- package/src/core/wheel/wheel.logic.ts +161 -0
- package/src/core/wheel/wheel.utils.ts +157 -0
- package/src/core/zoom/zoom.logic.ts +71 -0
- package/src/core/zoom/zoom.utils.ts +62 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/use-controls.tsx +9 -0
- package/src/hooks/use-transform-component.tsx +30 -0
- package/src/hooks/use-transform-context.tsx +13 -0
- package/src/hooks/use-transform-effect.tsx +22 -0
- package/src/hooks/use-transform-init.tsx +28 -0
- package/src/hooks/use-zoom-pan-pinch.tsx +48 -0
- package/src/index.ts +6 -0
- package/src/models/calculations.model.ts +34 -0
- package/src/models/context.model.ts +218 -0
- package/src/models/helpers.model.ts +15 -0
- package/src/models/index.ts +3 -0
- package/src/react-app-env.d.ts +1 -0
- package/src/styles.css +8 -0
- package/src/typings.d.ts +21 -0
- package/src/utils/calculations.utils.ts +16 -0
- package/src/utils/callback.utils.ts +11 -0
- package/src/utils/context.utils.ts +49 -0
- package/src/utils/event.utils.ts +38 -0
- package/src/utils/helpers.utils.ts +22 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/ref.utils.ts +32 -0
- package/src/utils/state.utils.ts +77 -0
- package/src/utils/styles.utils.ts +49 -0
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useRef, useImperativeHandle, useEffect, useContext, useLayoutEffect, useState, useCallback, useMemo } from 'react';
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Rounds number to given decimal
|
|
@@ -111,7 +112,7 @@ var handleCancelAnimation = function (contextInstance) {
|
|
|
111
112
|
return;
|
|
112
113
|
handleCancelAnimationFrame(contextInstance.animation);
|
|
113
114
|
// Clear animation state
|
|
114
|
-
contextInstance.
|
|
115
|
+
contextInstance.isAnimating = false;
|
|
115
116
|
contextInstance.animation = null;
|
|
116
117
|
contextInstance.velocity = null;
|
|
117
118
|
};
|
|
@@ -155,21 +156,27 @@ function animate(contextInstance, targetState, animationTime, animationName) {
|
|
|
155
156
|
var isValid = isValidTargetState(targetState);
|
|
156
157
|
if (!contextInstance.mounted || !isValid)
|
|
157
158
|
return;
|
|
158
|
-
var
|
|
159
|
-
var _a = contextInstance.
|
|
159
|
+
var setState = contextInstance.setState;
|
|
160
|
+
var _a = contextInstance.state, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
160
161
|
var scaleDiff = targetState.scale - scale;
|
|
161
162
|
var positionXDiff = targetState.positionX - positionX;
|
|
162
163
|
var positionYDiff = targetState.positionY - positionY;
|
|
163
164
|
if (animationTime === 0) {
|
|
164
|
-
|
|
165
|
+
setState(targetState.scale, targetState.positionX, targetState.positionY);
|
|
165
166
|
}
|
|
166
167
|
else {
|
|
167
168
|
// animation start timestamp
|
|
168
169
|
handleSetupAnimation(contextInstance, animationName, animationTime, function (step) {
|
|
170
|
+
if (step !== 1) {
|
|
171
|
+
contextInstance.isAnimating = true;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
contextInstance.isAnimating = false;
|
|
175
|
+
}
|
|
169
176
|
var newScale = scale + scaleDiff * step;
|
|
170
177
|
var newPositionX = positionX + positionXDiff * step;
|
|
171
178
|
var newPositionY = positionY + positionYDiff * step;
|
|
172
|
-
|
|
179
|
+
setState(newScale, newPositionX, newPositionY);
|
|
173
180
|
});
|
|
174
181
|
}
|
|
175
182
|
}
|
|
@@ -195,25 +202,54 @@ function getComponentsSizes(wrapperComponent, contentComponent, newScale) {
|
|
|
195
202
|
}
|
|
196
203
|
var getBounds = function (wrapperWidth, newContentWidth, diffWidth, wrapperHeight, newContentHeight, diffHeight, centerZoomedOut) {
|
|
197
204
|
var scaleWidthFactor = wrapperWidth > newContentWidth
|
|
198
|
-
? diffWidth * (centerZoomedOut ?
|
|
205
|
+
? diffWidth * (centerZoomedOut ? 0.5 : 1)
|
|
199
206
|
: 0;
|
|
200
207
|
var scaleHeightFactor = wrapperHeight > newContentHeight
|
|
201
|
-
? diffHeight * (centerZoomedOut ?
|
|
208
|
+
? diffHeight * (centerZoomedOut ? 0.5 : 1)
|
|
202
209
|
: 0;
|
|
203
210
|
var minPositionX = wrapperWidth - newContentWidth - scaleWidthFactor;
|
|
204
211
|
var maxPositionX = scaleWidthFactor;
|
|
205
212
|
var minPositionY = wrapperHeight - newContentHeight - scaleHeightFactor;
|
|
206
213
|
var maxPositionY = scaleHeightFactor;
|
|
207
|
-
return {
|
|
214
|
+
return {
|
|
215
|
+
minPositionX: minPositionX,
|
|
216
|
+
maxPositionX: maxPositionX,
|
|
217
|
+
minPositionY: minPositionY,
|
|
218
|
+
maxPositionY: maxPositionY,
|
|
219
|
+
scaleWidthFactor: scaleWidthFactor,
|
|
220
|
+
scaleHeightFactor: scaleHeightFactor,
|
|
221
|
+
};
|
|
208
222
|
};
|
|
209
223
|
var calculateBounds = function (contextInstance, newScale) {
|
|
210
224
|
var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
211
|
-
var
|
|
225
|
+
var _a = contextInstance.setup, centerZoomedOut = _a.centerZoomedOut, disablePadding = _a.disablePadding;
|
|
212
226
|
if (!wrapperComponent || !contentComponent) {
|
|
213
227
|
throw new Error("Components are not mounted");
|
|
214
228
|
}
|
|
215
|
-
var
|
|
229
|
+
var _b = getComponentsSizes(wrapperComponent, contentComponent, newScale), wrapperWidth = _b.wrapperWidth, wrapperHeight = _b.wrapperHeight, newContentWidth = _b.newContentWidth, newContentHeight = _b.newContentHeight, newDiffWidth = _b.newDiffWidth, newDiffHeight = _b.newDiffHeight;
|
|
216
230
|
var bounds = getBounds(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, Boolean(centerZoomedOut));
|
|
231
|
+
var contentFitsCompletely = wrapperWidth >= newContentWidth && wrapperHeight >= newContentHeight;
|
|
232
|
+
if (disablePadding && contentFitsCompletely && !centerZoomedOut) {
|
|
233
|
+
bounds.minPositionX = 0;
|
|
234
|
+
bounds.maxPositionX = 0;
|
|
235
|
+
bounds.minPositionY = 0;
|
|
236
|
+
bounds.maxPositionY = 0;
|
|
237
|
+
}
|
|
238
|
+
var _c = contextInstance.setup, propMinX = _c.minPositionX, propMaxX = _c.maxPositionX, propMinY = _c.minPositionY, propMaxY = _c.maxPositionY;
|
|
239
|
+
// Explicit position props define content-space boundaries at scale=1.
|
|
240
|
+
// Scale them so the same content region stays reachable at every zoom level.
|
|
241
|
+
if (propMinX != null) {
|
|
242
|
+
bounds.minPositionX = wrapperWidth * (1 - newScale) + propMinX * newScale;
|
|
243
|
+
}
|
|
244
|
+
if (propMaxX != null) {
|
|
245
|
+
bounds.maxPositionX = propMaxX * newScale;
|
|
246
|
+
}
|
|
247
|
+
if (propMinY != null) {
|
|
248
|
+
bounds.minPositionY = wrapperHeight * (1 - newScale) + propMinY * newScale;
|
|
249
|
+
}
|
|
250
|
+
if (propMaxY != null) {
|
|
251
|
+
bounds.maxPositionY = propMaxY * newScale;
|
|
252
|
+
}
|
|
217
253
|
return bounds;
|
|
218
254
|
};
|
|
219
255
|
/**
|
|
@@ -252,7 +288,7 @@ function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, pa
|
|
|
252
288
|
}
|
|
253
289
|
|
|
254
290
|
function handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds) {
|
|
255
|
-
var _a = contextInstance.
|
|
291
|
+
var _a = contextInstance.state, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
256
292
|
var scaleDifference = newScale - scale;
|
|
257
293
|
if (typeof mouseX !== "number" || typeof mouseY !== "number") {
|
|
258
294
|
console.error("Mouse X and Y position were not provided!");
|
|
@@ -265,14 +301,16 @@ function handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale,
|
|
|
265
301
|
var newPositions = getMouseBoundedPosition(calculatedPositionX, calculatedPositionY, bounds, limitToBounds, 0, 0, null);
|
|
266
302
|
return newPositions;
|
|
267
303
|
}
|
|
304
|
+
var MIN_SAFE_SCALE = 1e-7;
|
|
268
305
|
function checkZoomBounds(zoom, minScale, maxScale, zoomPadding, enablePadding) {
|
|
269
306
|
var scalePadding = enablePadding ? zoomPadding : 0;
|
|
270
|
-
var minScaleWithPadding = minScale - scalePadding;
|
|
271
|
-
|
|
272
|
-
|
|
307
|
+
var minScaleWithPadding = Math.max(minScale - scalePadding, MIN_SAFE_SCALE);
|
|
308
|
+
var maxScaleWithPadding = maxScale + scalePadding;
|
|
309
|
+
if (!Number.isNaN(maxScale) && zoom >= maxScaleWithPadding)
|
|
310
|
+
return maxScaleWithPadding;
|
|
273
311
|
if (!Number.isNaN(minScale) && zoom <= minScaleWithPadding)
|
|
274
312
|
return minScaleWithPadding;
|
|
275
|
-
return zoom;
|
|
313
|
+
return Math.max(zoom, MIN_SAFE_SCALE);
|
|
276
314
|
}
|
|
277
315
|
|
|
278
316
|
var isPanningStartAllowed = function (contextInstance, event) {
|
|
@@ -294,6 +332,11 @@ var isPanningStartAllowed = function (contextInstance, event) {
|
|
|
294
332
|
var isExcluded = isExcludedNode(target, excluded);
|
|
295
333
|
if (isExcluded)
|
|
296
334
|
return false;
|
|
335
|
+
if (target.getAttribute("draggable") === "true" ||
|
|
336
|
+
target.getAttribute("contenteditable") === "true" ||
|
|
337
|
+
target.isContentEditable) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
297
340
|
return true;
|
|
298
341
|
};
|
|
299
342
|
var isPanningAllowed = function (contextInstance) {
|
|
@@ -305,7 +348,7 @@ var isPanningAllowed = function (contextInstance) {
|
|
|
305
348
|
return true;
|
|
306
349
|
};
|
|
307
350
|
var handlePanningSetup = function (contextInstance, event) {
|
|
308
|
-
var _a = contextInstance.
|
|
351
|
+
var _a = contextInstance.state, positionX = _a.positionX, positionY = _a.positionY;
|
|
309
352
|
contextInstance.isPanning = true;
|
|
310
353
|
// Panning with mouse
|
|
311
354
|
var x = event.clientX;
|
|
@@ -314,7 +357,7 @@ var handlePanningSetup = function (contextInstance, event) {
|
|
|
314
357
|
};
|
|
315
358
|
var handleTouchPanningSetup = function (contextInstance, event) {
|
|
316
359
|
var touches = event.touches;
|
|
317
|
-
var _a = contextInstance.
|
|
360
|
+
var _a = contextInstance.state, positionX = _a.positionX, positionY = _a.positionY;
|
|
318
361
|
contextInstance.isPanning = true;
|
|
319
362
|
// Panning with touch
|
|
320
363
|
var oneFingerTouch = touches.length === 1;
|
|
@@ -325,7 +368,7 @@ var handleTouchPanningSetup = function (contextInstance, event) {
|
|
|
325
368
|
}
|
|
326
369
|
};
|
|
327
370
|
function handlePanToBounds(contextInstance) {
|
|
328
|
-
var _a = contextInstance.
|
|
371
|
+
var _a = contextInstance.state, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
|
|
329
372
|
var _b = contextInstance.setup, disabled = _b.disabled, limitToBounds = _b.limitToBounds, centerZoomedOut = _b.centerZoomedOut;
|
|
330
373
|
var wrapperComponent = contextInstance.wrapperComponent;
|
|
331
374
|
if (disabled || !wrapperComponent || !contextInstance.bounds)
|
|
@@ -349,20 +392,20 @@ function handlePanToBounds(contextInstance) {
|
|
|
349
392
|
function handleNewPosition(contextInstance, newPositionX, newPositionY, paddingValueX, paddingValueY) {
|
|
350
393
|
var limitToBounds = contextInstance.setup.limitToBounds;
|
|
351
394
|
var wrapperComponent = contextInstance.wrapperComponent, bounds = contextInstance.bounds;
|
|
352
|
-
var _a = contextInstance.
|
|
395
|
+
var _a = contextInstance.state, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
353
396
|
if (wrapperComponent === null ||
|
|
354
397
|
bounds === null ||
|
|
355
398
|
(newPositionX === positionX && newPositionY === positionY)) {
|
|
356
399
|
return;
|
|
357
400
|
}
|
|
358
401
|
var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, paddingValueX, paddingValueY, wrapperComponent), x = _b.x, y = _b.y;
|
|
359
|
-
contextInstance.
|
|
402
|
+
contextInstance.setState(scale, x, y);
|
|
360
403
|
}
|
|
361
404
|
var getPanningClientPosition = function (contextInstance, clientX, clientY) {
|
|
362
|
-
var startCoords = contextInstance.startCoords,
|
|
405
|
+
var startCoords = contextInstance.startCoords, state = contextInstance.state;
|
|
363
406
|
var panning = contextInstance.setup.panning;
|
|
364
407
|
var lockAxisX = panning.lockAxisX, lockAxisY = panning.lockAxisY;
|
|
365
|
-
var positionX =
|
|
408
|
+
var positionX = state.positionX, positionY = state.positionY;
|
|
366
409
|
if (!startCoords) {
|
|
367
410
|
return { x: positionX, y: positionY };
|
|
368
411
|
}
|
|
@@ -372,32 +415,43 @@ var getPanningClientPosition = function (contextInstance, clientX, clientY) {
|
|
|
372
415
|
var newPositionY = lockAxisY ? positionY : mouseY;
|
|
373
416
|
return { x: newPositionX, y: newPositionY };
|
|
374
417
|
};
|
|
375
|
-
var getPaddingValue = function (contextInstance, size) {
|
|
376
|
-
var setup = contextInstance.setup,
|
|
377
|
-
var
|
|
378
|
-
var
|
|
379
|
-
if (size > 0 && scale >= minScale && !disablePadding) {
|
|
418
|
+
var getPaddingValue = function (contextInstance, size, explicitScale) {
|
|
419
|
+
var setup = contextInstance.setup, state = contextInstance.state;
|
|
420
|
+
var minScale = setup.minScale, disablePadding = setup.disablePadding, centerZoomedOut = setup.centerZoomedOut;
|
|
421
|
+
var scale = explicitScale !== null && explicitScale !== void 0 ? explicitScale : state.scale;
|
|
422
|
+
if (size > 0 && scale >= minScale && !disablePadding && !centerZoomedOut) {
|
|
380
423
|
return size;
|
|
381
424
|
}
|
|
382
425
|
return 0;
|
|
383
426
|
};
|
|
384
427
|
|
|
428
|
+
var DeviceType;
|
|
429
|
+
(function (DeviceType) {
|
|
430
|
+
DeviceType["TRACK_PAD"] = "track_pad";
|
|
431
|
+
DeviceType["MOUSE"] = "mouse";
|
|
432
|
+
DeviceType["TOUCH"] = "touch";
|
|
433
|
+
})(DeviceType || (DeviceType = {}));
|
|
434
|
+
|
|
385
435
|
var isVelocityCalculationAllowed = function (contextInstance) {
|
|
386
|
-
var mounted = contextInstance.mounted;
|
|
387
|
-
var _a = contextInstance.setup, disabled = _a.disabled, velocityAnimation = _a.velocityAnimation;
|
|
388
|
-
var scale = contextInstance.
|
|
436
|
+
var mounted = contextInstance.mounted, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
437
|
+
var _a = contextInstance.setup, disabled = _a.disabled, velocityAnimation = _a.velocityAnimation, limitToBounds = _a.limitToBounds;
|
|
438
|
+
var scale = contextInstance.state.scale;
|
|
389
439
|
var disabledVelocity = velocityAnimation.disabled;
|
|
390
|
-
|
|
391
|
-
if (!isAllowed)
|
|
440
|
+
if (disabledVelocity || disabled || !mounted)
|
|
392
441
|
return false;
|
|
393
|
-
|
|
442
|
+
if (!wrapperComponent || !contentComponent)
|
|
443
|
+
return false;
|
|
444
|
+
if (!limitToBounds)
|
|
445
|
+
return true;
|
|
446
|
+
var contentOverflows = wrapperComponent.offsetWidth < contentComponent.offsetWidth * scale ||
|
|
447
|
+
wrapperComponent.offsetHeight < contentComponent.offsetHeight * scale;
|
|
448
|
+
return contentOverflows;
|
|
394
449
|
};
|
|
395
450
|
var isVelocityAllowed = function (contextInstance) {
|
|
396
451
|
var mounted = contextInstance.mounted, velocity = contextInstance.velocity, bounds = contextInstance.bounds;
|
|
397
452
|
var _a = contextInstance.setup, disabled = _a.disabled, velocityAnimation = _a.velocityAnimation;
|
|
398
|
-
var scale = contextInstance.transformState.scale;
|
|
399
453
|
var disabledVelocity = velocityAnimation.disabled;
|
|
400
|
-
var isAllowed = !disabledVelocity
|
|
454
|
+
var isAllowed = !disabledVelocity && !disabled && mounted;
|
|
401
455
|
if (!isAllowed)
|
|
402
456
|
return false;
|
|
403
457
|
if (!velocity || !bounds)
|
|
@@ -406,11 +460,8 @@ var isVelocityAllowed = function (contextInstance) {
|
|
|
406
460
|
};
|
|
407
461
|
function getVelocityMoveTime(contextInstance, velocity) {
|
|
408
462
|
var velocityAnimation = contextInstance.setup.velocityAnimation;
|
|
409
|
-
var
|
|
410
|
-
|
|
411
|
-
return animationTime * velocity * sensitivity;
|
|
412
|
-
}
|
|
413
|
-
return animationTime;
|
|
463
|
+
var animationTime = velocityAnimation.animationTime, maxAnimationTime = velocityAnimation.maxAnimationTime, inertia = velocityAnimation.inertia;
|
|
464
|
+
return Math.min(animationTime * Math.max(1, Math.abs(velocity / inertia)), maxAnimationTime);
|
|
414
465
|
}
|
|
415
466
|
function getVelocityPosition(newPosition, startPosition, currentPosition, isLocked, limitToBounds, minPosition, maxPosition, minTarget, maxTarget, step) {
|
|
416
467
|
if (limitToBounds) {
|
|
@@ -436,31 +487,53 @@ function getVelocityPosition(newPosition, startPosition, currentPosition, isLock
|
|
|
436
487
|
return boundLimiter(newPosition, minPosition, maxPosition, limitToBounds);
|
|
437
488
|
}
|
|
438
489
|
|
|
439
|
-
|
|
490
|
+
/* eslint-disable no-param-reassign */
|
|
491
|
+
function getSizeMultiplier(wrapperComponent) {
|
|
440
492
|
var defaultMultiplier = 1;
|
|
441
|
-
|
|
442
|
-
|
|
493
|
+
var value = wrapperComponent.offsetWidth / window.innerWidth;
|
|
494
|
+
if (Number.isNaN(value)) {
|
|
495
|
+
return defaultMultiplier;
|
|
443
496
|
}
|
|
444
|
-
return defaultMultiplier;
|
|
497
|
+
return Math.min(defaultMultiplier, value);
|
|
445
498
|
}
|
|
446
|
-
function
|
|
499
|
+
var getMinMaxVelocity = function (velocity, maxStrength, sensitivity) {
|
|
500
|
+
var defaultMultiplier = 0;
|
|
501
|
+
var value = velocity * sensitivity;
|
|
502
|
+
if (Number.isNaN(value)) {
|
|
503
|
+
return defaultMultiplier;
|
|
504
|
+
}
|
|
505
|
+
if (velocity < 0) {
|
|
506
|
+
return Math.max(value, -maxStrength);
|
|
507
|
+
}
|
|
508
|
+
return Math.min(value, maxStrength);
|
|
509
|
+
};
|
|
510
|
+
function handleCalculateVelocity(contextInstance, position, device) {
|
|
511
|
+
var _a, _b;
|
|
447
512
|
var isAllowed = isVelocityCalculationAllowed(contextInstance);
|
|
448
513
|
if (!isAllowed) {
|
|
449
514
|
return;
|
|
450
515
|
}
|
|
451
516
|
var lastMousePosition = contextInstance.lastMousePosition, velocityTime = contextInstance.velocityTime, setup = contextInstance.setup;
|
|
452
517
|
var wrapperComponent = contextInstance.wrapperComponent;
|
|
453
|
-
var
|
|
518
|
+
var _c = setup.velocityAnimation, maxStrengthMouse = _c.maxStrengthMouse, maxStrengthTouch = _c.maxStrengthTouch, sensitivityTouch = _c.sensitivityTouch, sensitivityMouse = _c.sensitivityMouse;
|
|
454
519
|
var now = Date.now();
|
|
455
520
|
if (lastMousePosition && velocityTime && wrapperComponent) {
|
|
456
|
-
var sizeMultiplier = getSizeMultiplier(wrapperComponent
|
|
521
|
+
var sizeMultiplier = getSizeMultiplier(wrapperComponent);
|
|
522
|
+
var sensitivity = (_a = {},
|
|
523
|
+
_a[DeviceType.TOUCH] = sensitivityTouch,
|
|
524
|
+
_a[DeviceType.MOUSE] = sensitivityMouse,
|
|
525
|
+
_a)[device];
|
|
526
|
+
var maxStrength = (_b = {},
|
|
527
|
+
_b[DeviceType.TOUCH] = maxStrengthTouch,
|
|
528
|
+
_b[DeviceType.MOUSE] = maxStrengthMouse,
|
|
529
|
+
_b)[device];
|
|
457
530
|
var distanceX = position.x - lastMousePosition.x;
|
|
458
531
|
var distanceY = position.y - lastMousePosition.y;
|
|
459
|
-
var velocityX = distanceX / sizeMultiplier;
|
|
460
|
-
var velocityY = distanceY / sizeMultiplier;
|
|
532
|
+
var velocityX = getMinMaxVelocity(distanceX / sizeMultiplier, maxStrength, sensitivity);
|
|
533
|
+
var velocityY = getMinMaxVelocity(distanceY / sizeMultiplier, maxStrength, sensitivity);
|
|
461
534
|
var interval = now - velocityTime;
|
|
462
535
|
var speed = distanceX * distanceX + distanceY * distanceY;
|
|
463
|
-
var velocity = Math.sqrt(speed) / interval;
|
|
536
|
+
var velocity = getMinMaxVelocity(Math.sqrt(speed) / interval, maxStrength, sensitivity);
|
|
464
537
|
contextInstance.velocity = { velocityX: velocityX, velocityY: velocityY, total: velocity };
|
|
465
538
|
}
|
|
466
539
|
contextInstance.lastMousePosition = position;
|
|
@@ -474,11 +547,11 @@ function handleVelocityPanning(contextInstance) {
|
|
|
474
547
|
}
|
|
475
548
|
var velocityX = velocity.velocityX, velocityY = velocity.velocityY, total = velocity.total;
|
|
476
549
|
var maxPositionX = bounds.maxPositionX, minPositionX = bounds.minPositionX, maxPositionY = bounds.maxPositionY, minPositionY = bounds.minPositionY;
|
|
477
|
-
var limitToBounds = setup.limitToBounds,
|
|
550
|
+
var limitToBounds = setup.limitToBounds, autoAlignment = setup.autoAlignment;
|
|
478
551
|
var zoomAnimation = setup.zoomAnimation, panning = setup.panning;
|
|
479
552
|
var lockAxisY = panning.lockAxisY, lockAxisX = panning.lockAxisX;
|
|
480
553
|
var animationType = zoomAnimation.animationType;
|
|
481
|
-
var sizeX =
|
|
554
|
+
var sizeX = autoAlignment.sizeX, sizeY = autoAlignment.sizeY, velocityAlignmentTime = autoAlignment.velocityAlignmentTime;
|
|
482
555
|
var alignAnimationTime = velocityAlignmentTime;
|
|
483
556
|
var moveAnimationTime = getVelocityMoveTime(contextInstance, total);
|
|
484
557
|
var finalAnimationTime = Math.max(moveAnimationTime, alignAnimationTime);
|
|
@@ -490,13 +563,13 @@ function handleVelocityPanning(contextInstance) {
|
|
|
490
563
|
var minTargetX = minPositionX - paddingX;
|
|
491
564
|
var maxTargetY = maxPositionY + paddingY;
|
|
492
565
|
var minTargetY = minPositionY - paddingY;
|
|
493
|
-
var startState = contextInstance.
|
|
566
|
+
var startState = contextInstance.state;
|
|
494
567
|
var startTime = new Date().getTime();
|
|
495
568
|
handleSetupAnimation(contextInstance, animationType, finalAnimationTime, function (step) {
|
|
496
|
-
var _a = contextInstance.
|
|
569
|
+
var _a = contextInstance.state, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
497
570
|
var frameTime = new Date().getTime() - startTime;
|
|
498
571
|
var animationProgress = frameTime / alignAnimationTime;
|
|
499
|
-
var alignAnimation = animations[
|
|
572
|
+
var alignAnimation = animations[autoAlignment.animationType];
|
|
500
573
|
var alignStep = 1 - alignAnimation(Math.min(1, animationProgress));
|
|
501
574
|
var customStep = 1 - step;
|
|
502
575
|
var newPositionX = positionX + velocityX * customStep;
|
|
@@ -504,13 +577,18 @@ function handleVelocityPanning(contextInstance) {
|
|
|
504
577
|
var currentPositionX = getVelocityPosition(newPositionX, startState.positionX, positionX, lockAxisX, limitToBounds, minPositionX, maxPositionX, minTargetX, maxTargetX, alignStep);
|
|
505
578
|
var currentPositionY = getVelocityPosition(newPositionY, startState.positionY, positionY, lockAxisY, limitToBounds, minPositionY, maxPositionY, minTargetY, maxTargetY, alignStep);
|
|
506
579
|
if (positionX !== newPositionX || positionY !== newPositionY) {
|
|
507
|
-
contextInstance.
|
|
580
|
+
contextInstance.setState(scale, currentPositionX, currentPositionY);
|
|
581
|
+
var onPanning = contextInstance.props.onPanning;
|
|
582
|
+
if (onPanning) {
|
|
583
|
+
onPanning(getContext(contextInstance), {});
|
|
584
|
+
}
|
|
508
585
|
}
|
|
509
586
|
});
|
|
510
587
|
}
|
|
511
588
|
|
|
512
589
|
function handlePanningStart(contextInstance, event) {
|
|
513
|
-
var
|
|
590
|
+
var _a = contextInstance.state, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
591
|
+
contextInstance.panStartPosition = { x: positionX, y: positionY };
|
|
514
592
|
handleCancelAnimation(contextInstance);
|
|
515
593
|
handleCalculateBounds(contextInstance, scale);
|
|
516
594
|
if (window.TouchEvent !== undefined && event instanceof TouchEvent) {
|
|
@@ -521,9 +599,9 @@ function handlePanningStart(contextInstance, event) {
|
|
|
521
599
|
}
|
|
522
600
|
}
|
|
523
601
|
function handleAlignToBounds(contextInstance, customAnimationTime) {
|
|
524
|
-
var scale = contextInstance.
|
|
525
|
-
var _a = contextInstance.setup, minScale = _a.minScale,
|
|
526
|
-
var disabled =
|
|
602
|
+
var scale = contextInstance.state.scale;
|
|
603
|
+
var _a = contextInstance.setup, minScale = _a.minScale, autoAlignment = _a.autoAlignment;
|
|
604
|
+
var disabled = autoAlignment.disabled, sizeX = autoAlignment.sizeX, sizeY = autoAlignment.sizeY, animationTime = autoAlignment.animationTime, animationType = autoAlignment.animationType;
|
|
527
605
|
var isDisabled = disabled || scale < minScale || (!sizeX && !sizeY);
|
|
528
606
|
if (isDisabled)
|
|
529
607
|
return;
|
|
@@ -532,32 +610,43 @@ function handleAlignToBounds(contextInstance, customAnimationTime) {
|
|
|
532
610
|
animate(contextInstance, targetState, customAnimationTime !== null && customAnimationTime !== void 0 ? customAnimationTime : animationTime, animationType);
|
|
533
611
|
}
|
|
534
612
|
}
|
|
535
|
-
function handlePanning(contextInstance, clientX, clientY) {
|
|
613
|
+
function handlePanning(contextInstance, clientX, clientY, device) {
|
|
536
614
|
var startCoords = contextInstance.startCoords, setup = contextInstance.setup;
|
|
537
|
-
var _a = setup.
|
|
615
|
+
var _a = setup.autoAlignment, sizeX = _a.sizeX, sizeY = _a.sizeY;
|
|
538
616
|
if (!startCoords)
|
|
539
617
|
return;
|
|
540
618
|
var _b = getPanningClientPosition(contextInstance, clientX, clientY), x = _b.x, y = _b.y;
|
|
541
619
|
var paddingValueX = getPaddingValue(contextInstance, sizeX);
|
|
542
620
|
var paddingValueY = getPaddingValue(contextInstance, sizeY);
|
|
543
|
-
handleCalculateVelocity(contextInstance, { x: x, y: y });
|
|
621
|
+
handleCalculateVelocity(contextInstance, { x: x, y: y }, device);
|
|
544
622
|
handleNewPosition(contextInstance, x, y, paddingValueX, paddingValueY);
|
|
545
623
|
}
|
|
546
|
-
function handlePanningEnd(contextInstance) {
|
|
624
|
+
function handlePanningEnd(contextInstance, velocityDisabled) {
|
|
547
625
|
if (contextInstance.isPanning) {
|
|
548
|
-
var velocityDisabled = contextInstance.setup.panning.velocityDisabled;
|
|
549
626
|
var velocity = contextInstance.velocity, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
550
627
|
contextInstance.isPanning = false;
|
|
551
|
-
contextInstance.
|
|
628
|
+
var _a = contextInstance.state, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
|
|
629
|
+
var start = contextInstance.panStartPosition;
|
|
630
|
+
contextInstance.panStartPosition = null;
|
|
631
|
+
if (start) {
|
|
632
|
+
var dx = positionX - start.x;
|
|
633
|
+
var dy = positionY - start.y;
|
|
634
|
+
if (dx * dx + dy * dy <= 25)
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
contextInstance.isAnimating = false;
|
|
552
638
|
contextInstance.animation = null;
|
|
553
|
-
var
|
|
554
|
-
var
|
|
555
|
-
var
|
|
556
|
-
var
|
|
557
|
-
var
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
var shouldAnimate = !velocityDisabled &&
|
|
639
|
+
var wrapperWidth = (wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.offsetWidth) || 0;
|
|
640
|
+
var wrapperHeight = (wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.offsetHeight) || 0;
|
|
641
|
+
var contentWidth = ((contentComponent === null || contentComponent === void 0 ? void 0 : contentComponent.offsetWidth) || 0) * scale;
|
|
642
|
+
var contentHeight = ((contentComponent === null || contentComponent === void 0 ? void 0 : contentComponent.offsetHeight) || 0) * scale;
|
|
643
|
+
var isContentOverflowing = !contextInstance.setup.limitToBounds ||
|
|
644
|
+
wrapperWidth < contentWidth ||
|
|
645
|
+
wrapperHeight < contentHeight;
|
|
646
|
+
var shouldAnimate = !velocityDisabled &&
|
|
647
|
+
velocity &&
|
|
648
|
+
velocity.total > 0.1 &&
|
|
649
|
+
isContentOverflowing;
|
|
561
650
|
if (shouldAnimate) {
|
|
562
651
|
handleVelocityPanning(contextInstance);
|
|
563
652
|
}
|
|
@@ -575,20 +664,21 @@ function handleZoomToPoint(contextInstance, scale, mouseX, mouseY) {
|
|
|
575
664
|
return { scale: newScale, positionX: x, positionY: y };
|
|
576
665
|
}
|
|
577
666
|
function handleAlignToScaleBounds(contextInstance, mousePositionX, mousePositionY) {
|
|
578
|
-
var scale = contextInstance.
|
|
667
|
+
var scale = contextInstance.state.scale;
|
|
579
668
|
var wrapperComponent = contextInstance.wrapperComponent;
|
|
580
|
-
var _a = contextInstance.setup, minScale = _a.minScale, limitToBounds = _a.limitToBounds, zoomAnimation = _a.zoomAnimation;
|
|
669
|
+
var _a = contextInstance.setup, minScale = _a.minScale, maxScale = _a.maxScale, limitToBounds = _a.limitToBounds, zoomAnimation = _a.zoomAnimation;
|
|
581
670
|
var disabled = zoomAnimation.disabled, animationTime = zoomAnimation.animationTime, animationType = zoomAnimation.animationType;
|
|
582
|
-
var
|
|
671
|
+
var isWithinBounds = scale >= minScale && scale <= maxScale;
|
|
672
|
+
var isDisabled = disabled || isWithinBounds;
|
|
583
673
|
if (scale >= 1 || limitToBounds) {
|
|
584
|
-
// fire fit to bounds animation
|
|
585
674
|
handleAlignToBounds(contextInstance);
|
|
586
675
|
}
|
|
587
676
|
if (isDisabled || !wrapperComponent || !contextInstance.mounted)
|
|
588
677
|
return;
|
|
589
678
|
var mouseX = mousePositionX || wrapperComponent.offsetWidth / 2;
|
|
590
679
|
var mouseY = mousePositionY || wrapperComponent.offsetHeight / 2;
|
|
591
|
-
var
|
|
680
|
+
var targetScale = scale < minScale ? minScale : maxScale;
|
|
681
|
+
var targetState = handleZoomToPoint(contextInstance, targetScale, mouseX, mouseY);
|
|
592
682
|
if (targetState) {
|
|
593
683
|
animate(contextInstance, targetState, animationTime, animationType);
|
|
594
684
|
}
|
|
@@ -608,6 +698,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
608
698
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
609
699
|
PERFORMANCE OF THIS SOFTWARE.
|
|
610
700
|
***************************************************************************** */
|
|
701
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
702
|
+
|
|
611
703
|
|
|
612
704
|
var __assign = function() {
|
|
613
705
|
__assign = Object.assign || function __assign(t) {
|
|
@@ -666,15 +758,23 @@ var initialSetup = {
|
|
|
666
758
|
centerOnInit: false,
|
|
667
759
|
disablePadding: false,
|
|
668
760
|
smooth: true,
|
|
761
|
+
detached: false,
|
|
669
762
|
wheel: {
|
|
670
|
-
step: 0.
|
|
763
|
+
step: 0.015,
|
|
671
764
|
disabled: false,
|
|
672
|
-
smoothStep: 0.001,
|
|
673
765
|
wheelDisabled: false,
|
|
674
766
|
touchPadDisabled: false,
|
|
675
767
|
activationKeys: [],
|
|
676
768
|
excluded: [],
|
|
677
769
|
},
|
|
770
|
+
trackPadPanning: {
|
|
771
|
+
disabled: true,
|
|
772
|
+
velocityDisabled: false,
|
|
773
|
+
lockAxisX: false,
|
|
774
|
+
lockAxisY: false,
|
|
775
|
+
activationKeys: [],
|
|
776
|
+
excluded: [],
|
|
777
|
+
},
|
|
678
778
|
panning: {
|
|
679
779
|
disabled: false,
|
|
680
780
|
velocityDisabled: false,
|
|
@@ -683,13 +783,13 @@ var initialSetup = {
|
|
|
683
783
|
allowLeftClickPan: true,
|
|
684
784
|
allowMiddleClickPan: true,
|
|
685
785
|
allowRightClickPan: true,
|
|
686
|
-
wheelPanning: false,
|
|
687
786
|
activationKeys: [],
|
|
688
787
|
excluded: [],
|
|
689
788
|
},
|
|
690
789
|
pinch: {
|
|
691
790
|
step: 5,
|
|
692
791
|
disabled: false,
|
|
792
|
+
allowPanning: true,
|
|
693
793
|
excluded: [],
|
|
694
794
|
},
|
|
695
795
|
doubleClick: {
|
|
@@ -706,7 +806,7 @@ var initialSetup = {
|
|
|
706
806
|
animationTime: 200,
|
|
707
807
|
animationType: "easeOut",
|
|
708
808
|
},
|
|
709
|
-
|
|
809
|
+
autoAlignment: {
|
|
710
810
|
disabled: false,
|
|
711
811
|
sizeX: 100,
|
|
712
812
|
sizeY: 100,
|
|
@@ -716,10 +816,14 @@ var initialSetup = {
|
|
|
716
816
|
},
|
|
717
817
|
velocityAnimation: {
|
|
718
818
|
disabled: false,
|
|
719
|
-
|
|
720
|
-
|
|
819
|
+
sensitivityMouse: 1,
|
|
820
|
+
sensitivityTouch: 1.2,
|
|
821
|
+
maxStrengthMouse: 20,
|
|
822
|
+
maxStrengthTouch: 40,
|
|
823
|
+
inertia: 1,
|
|
824
|
+
animationTime: 300,
|
|
825
|
+
maxAnimationTime: 800,
|
|
721
826
|
animationType: "easeOut",
|
|
722
|
-
equalToMove: true,
|
|
723
827
|
},
|
|
724
828
|
};
|
|
725
829
|
var baseClasses = {
|
|
@@ -728,39 +832,49 @@ var baseClasses = {
|
|
|
728
832
|
};
|
|
729
833
|
|
|
730
834
|
var createState = function (props) {
|
|
731
|
-
var _a, _b, _c, _d;
|
|
835
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
836
|
+
var minScale = Math.max((_a = props.minScale) !== null && _a !== void 0 ? _a : initialSetup.minScale, 1e-7);
|
|
837
|
+
var maxScale = (_b = props.maxScale) !== null && _b !== void 0 ? _b : initialSetup.maxScale;
|
|
838
|
+
var rawScale = (_c = props.initialScale) !== null && _c !== void 0 ? _c : initialState.scale;
|
|
839
|
+
var scale = Math.min(Math.max(rawScale, minScale), maxScale);
|
|
840
|
+
var positionX = boundLimiter((_d = props.initialPositionX) !== null && _d !== void 0 ? _d : initialState.positionX, (_e = props.minPositionX) !== null && _e !== void 0 ? _e : -Infinity, (_f = props.maxPositionX) !== null && _f !== void 0 ? _f : Infinity, props.minPositionX != null || props.maxPositionX != null);
|
|
841
|
+
var positionY = boundLimiter((_g = props.initialPositionY) !== null && _g !== void 0 ? _g : initialState.positionY, (_h = props.minPositionY) !== null && _h !== void 0 ? _h : -Infinity, (_j = props.maxPositionY) !== null && _j !== void 0 ? _j : Infinity, props.minPositionY != null || props.maxPositionY != null);
|
|
732
842
|
return {
|
|
733
|
-
previousScale:
|
|
734
|
-
scale:
|
|
735
|
-
positionX:
|
|
736
|
-
positionY:
|
|
843
|
+
previousScale: scale,
|
|
844
|
+
scale: scale,
|
|
845
|
+
positionX: positionX,
|
|
846
|
+
positionY: positionY,
|
|
737
847
|
};
|
|
738
848
|
};
|
|
739
849
|
var createSetup = function (props) {
|
|
740
850
|
var newSetup = __assign({}, initialSetup);
|
|
741
851
|
Object.keys(props).forEach(function (key) {
|
|
742
|
-
var
|
|
743
|
-
var
|
|
852
|
+
var k = key;
|
|
853
|
+
var validValue = typeof props[k] !== "undefined";
|
|
854
|
+
var validParameter = typeof initialSetup[k] !== "undefined";
|
|
744
855
|
if (validParameter && validValue) {
|
|
745
|
-
var dataType = Object.prototype.toString.call(initialSetup[
|
|
856
|
+
var dataType = Object.prototype.toString.call(initialSetup[k]);
|
|
746
857
|
var isObject = dataType === "[object Object]";
|
|
747
858
|
var isArray = dataType === "[object Array]";
|
|
748
859
|
if (isObject) {
|
|
749
|
-
newSetup[
|
|
860
|
+
newSetup[k] = __assign(__assign({}, initialSetup[k]), props[k]);
|
|
750
861
|
}
|
|
751
862
|
else if (isArray) {
|
|
752
|
-
newSetup[
|
|
863
|
+
newSetup[k] = __spreadArray(__spreadArray([], initialSetup[k], true), props[k], true);
|
|
753
864
|
}
|
|
754
865
|
else {
|
|
755
|
-
newSetup[
|
|
866
|
+
newSetup[k] = props[k];
|
|
756
867
|
}
|
|
757
868
|
}
|
|
758
869
|
});
|
|
870
|
+
if (newSetup.minScale <= 0) {
|
|
871
|
+
newSetup.minScale = 1e-7;
|
|
872
|
+
}
|
|
759
873
|
return newSetup;
|
|
760
874
|
};
|
|
761
875
|
|
|
762
876
|
var handleCalculateButtonZoom = function (contextInstance, delta, step) {
|
|
763
|
-
var scale = contextInstance.
|
|
877
|
+
var scale = contextInstance.state.scale;
|
|
764
878
|
var wrapperComponent = contextInstance.wrapperComponent, setup = contextInstance.setup;
|
|
765
879
|
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation, smooth = setup.smooth;
|
|
766
880
|
var size = zoomAnimation.size;
|
|
@@ -774,10 +888,13 @@ var handleCalculateButtonZoom = function (contextInstance, delta, step) {
|
|
|
774
888
|
return newScale;
|
|
775
889
|
};
|
|
776
890
|
function handleZoomToViewCenter(contextInstance, delta, step, animationTime, animationType) {
|
|
891
|
+
var _a, _b;
|
|
777
892
|
var wrapperComponent = contextInstance.wrapperComponent;
|
|
778
|
-
var
|
|
893
|
+
var _c = contextInstance.state, scale = _c.scale, positionX = _c.positionX, positionY = _c.positionY;
|
|
894
|
+
var zoomAnimation = contextInstance.setup.zoomAnimation;
|
|
779
895
|
if (!wrapperComponent)
|
|
780
896
|
return console.error("No WrapperComponent found");
|
|
897
|
+
var effectiveAnimationTime = zoomAnimation.disabled ? 0 : animationTime;
|
|
781
898
|
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
782
899
|
var wrapperHeight = wrapperComponent.offsetHeight;
|
|
783
900
|
var mouseX = (wrapperWidth / 2 - positionX) / scale;
|
|
@@ -787,17 +904,38 @@ function handleZoomToViewCenter(contextInstance, delta, step, animationTime, ani
|
|
|
787
904
|
if (!targetState) {
|
|
788
905
|
return console.error("Error during zoom event. New transformation state was not calculated.");
|
|
789
906
|
}
|
|
790
|
-
|
|
907
|
+
var _d = contextInstance.props, onZoomStart = _d.onZoomStart, onZoom = _d.onZoom, onZoomStop = _d.onZoomStop;
|
|
908
|
+
var event = new MouseEvent("mousemove", { bubbles: true });
|
|
909
|
+
var ctx = getContext(contextInstance);
|
|
910
|
+
handleCallback(ctx, event, onZoomStart);
|
|
911
|
+
handleCallback(ctx, event, onZoom);
|
|
912
|
+
animate(contextInstance, targetState, effectiveAnimationTime, animationType);
|
|
913
|
+
var win = (_b = (_a = wrapperComponent.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) !== null && _b !== void 0 ? _b : (typeof window !== "undefined" ? window : null);
|
|
914
|
+
if (win) {
|
|
915
|
+
win.setTimeout(function () {
|
|
916
|
+
if (!contextInstance.mounted)
|
|
917
|
+
return;
|
|
918
|
+
handleCallback(getContext(contextInstance), event, onZoomStop);
|
|
919
|
+
}, effectiveAnimationTime);
|
|
920
|
+
}
|
|
791
921
|
}
|
|
792
922
|
function resetTransformations(contextInstance, animationTime, animationType, onResetTransformation) {
|
|
793
|
-
var
|
|
794
|
-
var
|
|
923
|
+
var _a, _b;
|
|
924
|
+
var setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
925
|
+
var limitToBounds = setup.limitToBounds, centerOnInit = setup.centerOnInit;
|
|
795
926
|
var initialTransformation = createState(contextInstance.props);
|
|
796
|
-
var
|
|
927
|
+
var _c = contextInstance.state, scale = _c.scale, positionX = _c.positionX, positionY = _c.positionY;
|
|
797
928
|
if (!wrapperComponent)
|
|
798
929
|
return;
|
|
930
|
+
var targetPositionX = initialTransformation.positionX;
|
|
931
|
+
var targetPositionY = initialTransformation.positionY;
|
|
932
|
+
if (centerOnInit && contentComponent) {
|
|
933
|
+
var centered = getCenterPosition(initialTransformation.scale, wrapperComponent, contentComponent);
|
|
934
|
+
targetPositionX = centered.positionX;
|
|
935
|
+
targetPositionY = centered.positionY;
|
|
936
|
+
}
|
|
799
937
|
var newBounds = calculateBounds(contextInstance, initialTransformation.scale);
|
|
800
|
-
var boundedPositions = getMouseBoundedPosition(
|
|
938
|
+
var boundedPositions = getMouseBoundedPosition(targetPositionX, targetPositionY, newBounds, limitToBounds, 0, 0, wrapperComponent);
|
|
801
939
|
var newState = {
|
|
802
940
|
scale: initialTransformation.scale,
|
|
803
941
|
positionX: boundedPositions.x,
|
|
@@ -809,7 +947,20 @@ function resetTransformations(contextInstance, animationTime, animationType, onR
|
|
|
809
947
|
return;
|
|
810
948
|
}
|
|
811
949
|
onResetTransformation === null || onResetTransformation === void 0 ? void 0 : onResetTransformation();
|
|
950
|
+
var _d = contextInstance.props, onZoomStart = _d.onZoomStart, onZoom = _d.onZoom, onZoomStop = _d.onZoomStop;
|
|
951
|
+
var event = new MouseEvent("mousemove", { bubbles: true });
|
|
952
|
+
var ctx = getContext(contextInstance);
|
|
953
|
+
handleCallback(ctx, event, onZoomStart);
|
|
954
|
+
handleCallback(ctx, event, onZoom);
|
|
812
955
|
animate(contextInstance, newState, animationTime, animationType);
|
|
956
|
+
var win = (_b = (_a = wrapperComponent.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) !== null && _b !== void 0 ? _b : (typeof window !== "undefined" ? window : null);
|
|
957
|
+
if (win) {
|
|
958
|
+
win.setTimeout(function () {
|
|
959
|
+
if (!contextInstance.mounted)
|
|
960
|
+
return;
|
|
961
|
+
handleCallback(getContext(contextInstance), event, onZoomStop);
|
|
962
|
+
}, animationTime);
|
|
963
|
+
}
|
|
813
964
|
}
|
|
814
965
|
function getOffset(element, wrapper, content, state) {
|
|
815
966
|
var offset = element.getBoundingClientRect();
|
|
@@ -822,25 +973,27 @@ function getOffset(element, wrapper, content, state) {
|
|
|
822
973
|
y: (offset.y - contentOffset.y + yOff) / state.scale,
|
|
823
974
|
};
|
|
824
975
|
}
|
|
825
|
-
function calculateZoomToNode(contextInstance, node, customZoom) {
|
|
826
|
-
|
|
976
|
+
function calculateZoomToNode(contextInstance, node, customZoom, customOffsetX, customOffsetY) {
|
|
977
|
+
if (customOffsetX === void 0) { customOffsetX = 0; }
|
|
978
|
+
if (customOffsetY === void 0) { customOffsetY = 0; }
|
|
979
|
+
var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent, state = contextInstance.state;
|
|
827
980
|
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, minScale = _a.minScale, maxScale = _a.maxScale;
|
|
828
981
|
if (!wrapperComponent || !contentComponent)
|
|
829
|
-
return
|
|
982
|
+
return state;
|
|
830
983
|
var wrapperRect = wrapperComponent.getBoundingClientRect();
|
|
831
984
|
var nodeRect = node.getBoundingClientRect();
|
|
832
|
-
var nodeOffset = getOffset(node, wrapperComponent, contentComponent,
|
|
985
|
+
var nodeOffset = getOffset(node, wrapperComponent, contentComponent, state);
|
|
833
986
|
var nodeLeft = nodeOffset.x;
|
|
834
987
|
var nodeTop = nodeOffset.y;
|
|
835
|
-
var nodeWidth = nodeRect.width /
|
|
836
|
-
var nodeHeight = nodeRect.height /
|
|
988
|
+
var nodeWidth = nodeRect.width / state.scale;
|
|
989
|
+
var nodeHeight = nodeRect.height / state.scale;
|
|
837
990
|
var scaleX = wrapperComponent.offsetWidth / nodeWidth;
|
|
838
991
|
var scaleY = wrapperComponent.offsetHeight / nodeHeight;
|
|
839
992
|
var newScale = checkZoomBounds(customZoom || Math.min(scaleX, scaleY), minScale, maxScale, 0, false);
|
|
840
993
|
var offsetX = (wrapperRect.width - nodeWidth * newScale) / 2;
|
|
841
994
|
var offsetY = (wrapperRect.height - nodeHeight * newScale) / 2;
|
|
842
|
-
var newPositionX = (wrapperRect.left - nodeLeft) * newScale + offsetX;
|
|
843
|
-
var newPositionY = (wrapperRect.top - nodeTop) * newScale + offsetY;
|
|
995
|
+
var newPositionX = (wrapperRect.left - nodeLeft) * newScale + offsetX + customOffsetX;
|
|
996
|
+
var newPositionY = (wrapperRect.top - nodeTop) * newScale + offsetY + customOffsetY;
|
|
844
997
|
var bounds = calculateBounds(contextInstance, newScale);
|
|
845
998
|
var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, 0, 0, wrapperComponent), x = _b.x, y = _b.y;
|
|
846
999
|
return { positionX: x, positionY: y, scale: newScale };
|
|
@@ -866,7 +1019,7 @@ var setTransform = function (contextInstance) {
|
|
|
866
1019
|
return function (newPositionX, newPositionY, newScale, animationTime, animationType) {
|
|
867
1020
|
if (animationTime === void 0) { animationTime = 300; }
|
|
868
1021
|
if (animationType === void 0) { animationType = "easeOut"; }
|
|
869
|
-
var _a = contextInstance.
|
|
1022
|
+
var _a = contextInstance.state, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
|
|
870
1023
|
var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
871
1024
|
var disabled = contextInstance.setup.disabled;
|
|
872
1025
|
if (disabled || !wrapperComponent || !contentComponent)
|
|
@@ -890,22 +1043,24 @@ var centerView = function (contextInstance) {
|
|
|
890
1043
|
return function (scale, animationTime, animationType) {
|
|
891
1044
|
if (animationTime === void 0) { animationTime = 200; }
|
|
892
1045
|
if (animationType === void 0) { animationType = "easeOut"; }
|
|
893
|
-
var
|
|
1046
|
+
var state = contextInstance.state, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
894
1047
|
if (wrapperComponent && contentComponent) {
|
|
895
|
-
var targetState = getCenterPosition(scale ||
|
|
1048
|
+
var targetState = getCenterPosition(scale || state.scale, wrapperComponent, contentComponent);
|
|
896
1049
|
animate(contextInstance, targetState, animationTime, animationType);
|
|
897
1050
|
}
|
|
898
1051
|
};
|
|
899
1052
|
};
|
|
900
1053
|
var zoomToElement = function (contextInstance) {
|
|
901
|
-
return function (node, scale, animationTime, animationType) {
|
|
1054
|
+
return function (node, scale, animationTime, animationType, offsetX, offsetY) {
|
|
902
1055
|
if (animationTime === void 0) { animationTime = 600; }
|
|
903
1056
|
if (animationType === void 0) { animationType = "easeOut"; }
|
|
1057
|
+
if (offsetX === void 0) { offsetX = 0; }
|
|
1058
|
+
if (offsetY === void 0) { offsetY = 0; }
|
|
904
1059
|
handleCancelAnimation(contextInstance);
|
|
905
1060
|
var wrapperComponent = contextInstance.wrapperComponent;
|
|
906
1061
|
var target = typeof node === "string" ? document.getElementById(node) : node;
|
|
907
1062
|
if (wrapperComponent && target && wrapperComponent.contains(target)) {
|
|
908
|
-
var targetState = calculateZoomToNode(contextInstance, target, scale);
|
|
1063
|
+
var targetState = calculateZoomToNode(contextInstance, target, scale, offsetX, offsetY);
|
|
909
1064
|
animate(contextInstance, targetState, animationTime, animationType);
|
|
910
1065
|
}
|
|
911
1066
|
};
|
|
@@ -914,6 +1069,7 @@ var zoomToElement = function (contextInstance) {
|
|
|
914
1069
|
var getControls = function (contextInstance) {
|
|
915
1070
|
return {
|
|
916
1071
|
instance: contextInstance,
|
|
1072
|
+
state: contextInstance.state,
|
|
917
1073
|
zoomIn: zoomIn(contextInstance),
|
|
918
1074
|
zoomOut: zoomOut(contextInstance),
|
|
919
1075
|
setTransform: setTransform(contextInstance),
|
|
@@ -925,7 +1081,7 @@ var getControls = function (contextInstance) {
|
|
|
925
1081
|
var getState = function (contextInstance) {
|
|
926
1082
|
return {
|
|
927
1083
|
instance: contextInstance,
|
|
928
|
-
state: contextInstance.
|
|
1084
|
+
state: contextInstance.state,
|
|
929
1085
|
};
|
|
930
1086
|
};
|
|
931
1087
|
var getContext = function (contextInstance) {
|
|
@@ -969,9 +1125,14 @@ var cancelTimeout = function (timeout) {
|
|
|
969
1125
|
}
|
|
970
1126
|
};
|
|
971
1127
|
|
|
1128
|
+
/** Drop binary float noise on scale (e.g. 1.5000000000000002) without clipping real zoom values. */
|
|
1129
|
+
var roundScaleForTransform = function (scale) {
|
|
1130
|
+
return Number.parseFloat(scale.toFixed(8));
|
|
1131
|
+
};
|
|
972
1132
|
var getTransformStyles = function (x, y, scale) {
|
|
973
1133
|
// Standard translate prevents blurry svg on the safari
|
|
974
|
-
|
|
1134
|
+
var s = roundScaleForTransform(scale);
|
|
1135
|
+
return "translate(".concat(x, "px, ").concat(y, "px) scale(").concat(s, ")");
|
|
975
1136
|
};
|
|
976
1137
|
var getMatrixTransformStyles = function (x, y, scale) {
|
|
977
1138
|
// The shorthand for matrix does not work for Safari hence the need to explicitly use matrix3d
|
|
@@ -996,6 +1157,16 @@ var getCenterPosition = function (scale, wrapperComponent, contentComponent) {
|
|
|
996
1157
|
};
|
|
997
1158
|
};
|
|
998
1159
|
|
|
1160
|
+
function assignRef(ref, value) {
|
|
1161
|
+
if (ref == null)
|
|
1162
|
+
return;
|
|
1163
|
+
if (typeof ref === "function") {
|
|
1164
|
+
ref(value);
|
|
1165
|
+
}
|
|
1166
|
+
else {
|
|
1167
|
+
ref.current = value;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
999
1170
|
function mergeRefs(refs) {
|
|
1000
1171
|
return function (value) {
|
|
1001
1172
|
refs.forEach(function (ref) {
|
|
@@ -1024,6 +1195,31 @@ var isWheelAllowed = function (contextInstance, event) {
|
|
|
1024
1195
|
var isExcluded = isExcludedNode(target, excluded);
|
|
1025
1196
|
if (isExcluded)
|
|
1026
1197
|
return false;
|
|
1198
|
+
var keysPressed = contextInstance.isPressingKeys(contextInstance.setup.wheel.activationKeys);
|
|
1199
|
+
if (!keysPressed)
|
|
1200
|
+
return false;
|
|
1201
|
+
return true;
|
|
1202
|
+
};
|
|
1203
|
+
var isWheelPanningAllowed = function (contextInstance, event) {
|
|
1204
|
+
var _a = contextInstance.setup, disabled = _a.disabled, trackPadPanning = _a.trackPadPanning;
|
|
1205
|
+
var activationKeys = trackPadPanning.activationKeys, excluded = trackPadPanning.excluded;
|
|
1206
|
+
if (!contextInstance.wrapperComponent || !contextInstance.contentComponent) {
|
|
1207
|
+
return false;
|
|
1208
|
+
}
|
|
1209
|
+
if (disabled || trackPadPanning.disabled || event.ctrlKey) {
|
|
1210
|
+
return false;
|
|
1211
|
+
}
|
|
1212
|
+
var isAllowed = isWheelAllowed(contextInstance, event);
|
|
1213
|
+
// Cannot execute at the same time as wheel zoom
|
|
1214
|
+
if (isAllowed)
|
|
1215
|
+
return false;
|
|
1216
|
+
var target = event.target;
|
|
1217
|
+
var isExcluded = isExcludedNode(target, excluded);
|
|
1218
|
+
if (isExcluded)
|
|
1219
|
+
return false;
|
|
1220
|
+
var keysPressed = contextInstance.isPressingKeys(activationKeys);
|
|
1221
|
+
if (!keysPressed)
|
|
1222
|
+
return false;
|
|
1027
1223
|
return true;
|
|
1028
1224
|
};
|
|
1029
1225
|
var getDeltaY = function (event) {
|
|
@@ -1059,7 +1255,7 @@ function getMousePosition(event, contentComponent, scale) {
|
|
|
1059
1255
|
};
|
|
1060
1256
|
}
|
|
1061
1257
|
var handleCalculateWheelZoom = function (contextInstance, delta, step, disable, getTarget) {
|
|
1062
|
-
var scale = contextInstance.
|
|
1258
|
+
var scale = contextInstance.state.scale;
|
|
1063
1259
|
var wrapperComponent = contextInstance.wrapperComponent, setup = contextInstance.setup;
|
|
1064
1260
|
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation, disablePadding = setup.disablePadding;
|
|
1065
1261
|
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
@@ -1070,12 +1266,12 @@ var handleCalculateWheelZoom = function (contextInstance, delta, step, disable,
|
|
|
1070
1266
|
if (getTarget)
|
|
1071
1267
|
return targetScale;
|
|
1072
1268
|
var paddingEnabled = disable ? false : !disabled;
|
|
1073
|
-
var newScale = checkZoomBounds(
|
|
1269
|
+
var newScale = checkZoomBounds(targetScale, minScale, maxScale, size, paddingEnabled && !disablePadding);
|
|
1074
1270
|
return newScale;
|
|
1075
1271
|
};
|
|
1076
1272
|
var handleWheelZoomStop = function (contextInstance, event) {
|
|
1077
1273
|
var previousWheelEvent = contextInstance.previousWheelEvent;
|
|
1078
|
-
var scale = contextInstance.
|
|
1274
|
+
var scale = contextInstance.state.scale;
|
|
1079
1275
|
var _a = contextInstance.setup, maxScale = _a.maxScale, minScale = _a.minScale;
|
|
1080
1276
|
if (!previousWheelEvent)
|
|
1081
1277
|
return false;
|
|
@@ -1107,7 +1303,7 @@ var isPinchStartAllowed = function (contextInstance, event) {
|
|
|
1107
1303
|
var isPinchAllowed = function (contextInstance) {
|
|
1108
1304
|
var disabled = contextInstance.setup.pinch.disabled;
|
|
1109
1305
|
var isInitialized = contextInstance.isInitialized, pinchStartDistance = contextInstance.pinchStartDistance;
|
|
1110
|
-
var isAllowed = isInitialized && !disabled && pinchStartDistance;
|
|
1306
|
+
var isAllowed = isInitialized && !disabled && pinchStartDistance !== null;
|
|
1111
1307
|
if (!isAllowed)
|
|
1112
1308
|
return false;
|
|
1113
1309
|
return true;
|
|
@@ -1115,10 +1311,10 @@ var isPinchAllowed = function (contextInstance) {
|
|
|
1115
1311
|
var calculateTouchMidPoint = function (event, scale, contentComponent) {
|
|
1116
1312
|
var contentRect = contentComponent.getBoundingClientRect();
|
|
1117
1313
|
var touches = event.touches;
|
|
1118
|
-
var firstPointX =
|
|
1119
|
-
var firstPointY =
|
|
1120
|
-
var secondPointX =
|
|
1121
|
-
var secondPointY =
|
|
1314
|
+
var firstPointX = touches[0].clientX - contentRect.left;
|
|
1315
|
+
var firstPointY = touches[0].clientY - contentRect.top;
|
|
1316
|
+
var secondPointX = touches[1].clientX - contentRect.left;
|
|
1317
|
+
var secondPointY = touches[1].clientY - contentRect.top;
|
|
1122
1318
|
return {
|
|
1123
1319
|
x: (firstPointX + secondPointX) / 2 / scale,
|
|
1124
1320
|
y: (firstPointY + secondPointY) / 2 / scale,
|
|
@@ -1128,19 +1324,24 @@ var getTouchDistance = function (event) {
|
|
|
1128
1324
|
return Math.sqrt(Math.pow((event.touches[0].pageX - event.touches[1].pageX), 2) +
|
|
1129
1325
|
Math.pow((event.touches[0].pageY - event.touches[1].pageY), 2));
|
|
1130
1326
|
};
|
|
1327
|
+
var DEFAULT_PINCH_STEP = 5;
|
|
1131
1328
|
var calculatePinchZoom = function (contextInstance, currentDistance) {
|
|
1132
1329
|
var pinchStartScale = contextInstance.pinchStartScale, pinchStartDistance = contextInstance.pinchStartDistance, setup = contextInstance.setup;
|
|
1133
|
-
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation, disablePadding = setup.disablePadding;
|
|
1330
|
+
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation, disablePadding = setup.disablePadding, pinch = setup.pinch;
|
|
1134
1331
|
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
1135
|
-
|
|
1332
|
+
var step = pinch.step;
|
|
1333
|
+
if (!pinchStartScale || pinchStartDistance === null) {
|
|
1136
1334
|
throw new Error("Pinch touches distance was not provided");
|
|
1137
1335
|
}
|
|
1138
1336
|
if (currentDistance < 0) {
|
|
1139
|
-
return contextInstance.
|
|
1337
|
+
return contextInstance.state.scale;
|
|
1140
1338
|
}
|
|
1141
1339
|
var touchProportion = currentDistance / pinchStartDistance;
|
|
1142
|
-
var
|
|
1143
|
-
|
|
1340
|
+
var rawScale = touchProportion * pinchStartScale;
|
|
1341
|
+
var scaleDelta = (rawScale - pinchStartScale) * (step / DEFAULT_PINCH_STEP);
|
|
1342
|
+
var computed = pinchStartScale + scaleDelta;
|
|
1343
|
+
var scale = computed === Infinity ? 0 : roundNumber(computed, 10);
|
|
1344
|
+
return checkZoomBounds(scale, minScale, maxScale, size, !disabled && !disablePadding);
|
|
1144
1345
|
};
|
|
1145
1346
|
|
|
1146
1347
|
var wheelStopEventTime = 160;
|
|
@@ -1155,18 +1356,18 @@ var handleWheelStart = function (contextInstance, event) {
|
|
|
1155
1356
|
};
|
|
1156
1357
|
var handleWheelZoom = function (contextInstance, event) {
|
|
1157
1358
|
var _a = contextInstance.props, onWheel = _a.onWheel, onZoom = _a.onZoom;
|
|
1158
|
-
var contentComponent = contextInstance.contentComponent, setup = contextInstance.setup,
|
|
1159
|
-
var scale =
|
|
1359
|
+
var contentComponent = contextInstance.contentComponent, setup = contextInstance.setup, state = contextInstance.state;
|
|
1360
|
+
var scale = state.scale;
|
|
1160
1361
|
var limitToBounds = setup.limitToBounds, centerZoomedOut = setup.centerZoomedOut, zoomAnimation = setup.zoomAnimation, wheel = setup.wheel, disablePadding = setup.disablePadding, smooth = setup.smooth;
|
|
1161
1362
|
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
1162
|
-
var step = wheel.step
|
|
1363
|
+
var step = wheel.step;
|
|
1163
1364
|
if (!contentComponent) {
|
|
1164
1365
|
throw new Error("Component not mounted");
|
|
1165
1366
|
}
|
|
1166
1367
|
event.preventDefault();
|
|
1167
1368
|
event.stopPropagation();
|
|
1168
1369
|
var delta = getDelta(event, null);
|
|
1169
|
-
var zoomStep = smooth ?
|
|
1370
|
+
var zoomStep = smooth ? step * Math.abs(event.deltaY) : step;
|
|
1170
1371
|
var newScale = handleCalculateWheelZoom(contextInstance, delta, zoomStep, !event.ctrlKey);
|
|
1171
1372
|
// if scale not change
|
|
1172
1373
|
if (scale === newScale)
|
|
@@ -1177,7 +1378,7 @@ var handleWheelZoom = function (contextInstance, event) {
|
|
|
1177
1378
|
var isLimitedToBounds = limitToBounds && isPaddingDisabled;
|
|
1178
1379
|
var _b = handleCalculateZoomPositions(contextInstance, mousePosition.x, mousePosition.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
|
|
1179
1380
|
contextInstance.previousWheelEvent = event;
|
|
1180
|
-
contextInstance.
|
|
1381
|
+
contextInstance.setState(newScale, x, y);
|
|
1181
1382
|
handleCallback(getContext(contextInstance), event, onWheel);
|
|
1182
1383
|
handleCallback(getContext(contextInstance), event, onZoom);
|
|
1183
1384
|
};
|
|
@@ -1204,6 +1405,37 @@ var handleWheelStop = function (contextInstance, event) {
|
|
|
1204
1405
|
}, wheelStopEventTime);
|
|
1205
1406
|
}
|
|
1206
1407
|
};
|
|
1408
|
+
var handleWheelPanningStart = function (contextInstance, event) {
|
|
1409
|
+
var _a = contextInstance.props, onWheelStart = _a.onWheelStart, onPanningStart = _a.onPanningStart;
|
|
1410
|
+
if (!contextInstance.wheelStopEventTimer) {
|
|
1411
|
+
handleCancelAnimation(contextInstance);
|
|
1412
|
+
handleCallback(getContext(contextInstance), event, onWheelStart);
|
|
1413
|
+
handleCallback(getContext(contextInstance), event, onPanningStart);
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
var handleWheelPanningStop = function (contextInstance, event) {
|
|
1417
|
+
var _a = contextInstance.props, onWheelStop = _a.onWheelStop, onPanningStop = _a.onPanningStop;
|
|
1418
|
+
// fire animation
|
|
1419
|
+
cancelTimeout(contextInstance.wheelAnimationTimer);
|
|
1420
|
+
contextInstance.wheelAnimationTimer = setTimeout(function () {
|
|
1421
|
+
if (!contextInstance.mounted)
|
|
1422
|
+
return;
|
|
1423
|
+
handleAlignToScaleBounds(contextInstance, event.x, event.y);
|
|
1424
|
+
contextInstance.wheelAnimationTimer = null;
|
|
1425
|
+
}, wheelAnimationTime);
|
|
1426
|
+
// Wheel stop event
|
|
1427
|
+
var hasStoppedZooming = handleWheelZoomStop(contextInstance, event);
|
|
1428
|
+
if (hasStoppedZooming) {
|
|
1429
|
+
cancelTimeout(contextInstance.wheelStopEventTimer);
|
|
1430
|
+
contextInstance.wheelStopEventTimer = setTimeout(function () {
|
|
1431
|
+
if (!contextInstance.mounted)
|
|
1432
|
+
return;
|
|
1433
|
+
contextInstance.wheelStopEventTimer = null;
|
|
1434
|
+
handleCallback(getContext(contextInstance), event, onWheelStop);
|
|
1435
|
+
handleCallback(getContext(contextInstance), event, onPanningStop);
|
|
1436
|
+
}, wheelStopEventTime);
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1207
1439
|
|
|
1208
1440
|
var getTouchCenter = function (event) {
|
|
1209
1441
|
var totalX = 0;
|
|
@@ -1222,18 +1454,18 @@ var handlePinchStart = function (contextInstance, event) {
|
|
|
1222
1454
|
var distance = getTouchDistance(event);
|
|
1223
1455
|
contextInstance.pinchStartDistance = distance;
|
|
1224
1456
|
contextInstance.lastDistance = distance;
|
|
1225
|
-
contextInstance.pinchStartScale = contextInstance.
|
|
1457
|
+
contextInstance.pinchStartScale = contextInstance.state.scale;
|
|
1226
1458
|
contextInstance.isPanning = false;
|
|
1227
|
-
|
|
1228
|
-
contextInstance.
|
|
1229
|
-
contextInstance.pinchLastCenterY = center.y;
|
|
1459
|
+
contextInstance.isPinching = true;
|
|
1460
|
+
contextInstance.pinchPreviousCenter = getTouchCenter(event);
|
|
1230
1461
|
handleCancelAnimation(contextInstance);
|
|
1231
1462
|
};
|
|
1232
1463
|
var handlePinchZoom = function (contextInstance, event) {
|
|
1233
|
-
var contentComponent = contextInstance.contentComponent, pinchStartDistance = contextInstance.pinchStartDistance, wrapperComponent = contextInstance.wrapperComponent;
|
|
1234
|
-
var scale = contextInstance.
|
|
1235
|
-
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, centerZoomedOut = _a.centerZoomedOut, zoomAnimation = _a.zoomAnimation,
|
|
1464
|
+
var contentComponent = contextInstance.contentComponent, pinchStartDistance = contextInstance.pinchStartDistance, wrapperComponent = contextInstance.wrapperComponent, pinchPreviousCenter = contextInstance.pinchPreviousCenter;
|
|
1465
|
+
var scale = contextInstance.state.scale;
|
|
1466
|
+
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, centerZoomedOut = _a.centerZoomedOut, zoomAnimation = _a.zoomAnimation, autoAlignment = _a.autoAlignment, pinch = _a.pinch, panning = _a.panning;
|
|
1236
1467
|
var disabled = zoomAnimation.disabled, size = zoomAnimation.size;
|
|
1468
|
+
var allowPanning = pinch.allowPanning;
|
|
1237
1469
|
// if one finger starts from outside of wrapper
|
|
1238
1470
|
if (pinchStartDistance === null || !contentComponent)
|
|
1239
1471
|
return;
|
|
@@ -1245,25 +1477,30 @@ var handlePinchZoom = function (contextInstance, event) {
|
|
|
1245
1477
|
var newScale = calculatePinchZoom(contextInstance, currentDistance);
|
|
1246
1478
|
var center = getTouchCenter(event);
|
|
1247
1479
|
// pan should be scale invariant.
|
|
1248
|
-
var
|
|
1249
|
-
var
|
|
1480
|
+
var scaleDiff = scale / newScale;
|
|
1481
|
+
var panX = (center.x - ((pinchPreviousCenter === null || pinchPreviousCenter === void 0 ? void 0 : pinchPreviousCenter.x) || 0)) * scaleDiff;
|
|
1482
|
+
var panY = (center.y - ((pinchPreviousCenter === null || pinchPreviousCenter === void 0 ? void 0 : pinchPreviousCenter.y) || 0)) * scaleDiff;
|
|
1250
1483
|
if (newScale === scale && panX === 0 && panY === 0)
|
|
1251
1484
|
return;
|
|
1252
|
-
contextInstance.
|
|
1253
|
-
contextInstance.pinchLastCenterY = center.y;
|
|
1485
|
+
contextInstance.pinchPreviousCenter = center;
|
|
1254
1486
|
var bounds = handleCalculateBounds(contextInstance, newScale);
|
|
1255
1487
|
var isPaddingDisabled = disabled || size === 0 || centerZoomedOut;
|
|
1256
1488
|
var isLimitedToBounds = limitToBounds && isPaddingDisabled;
|
|
1257
1489
|
var _b = handleCalculateZoomPositions(contextInstance, midPoint.x, midPoint.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
|
|
1258
1490
|
contextInstance.pinchMidpoint = midPoint;
|
|
1259
1491
|
contextInstance.lastDistance = currentDistance;
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1492
|
+
if (panning.disabled || !allowPanning) {
|
|
1493
|
+
contextInstance.setState(newScale, x, y);
|
|
1494
|
+
}
|
|
1495
|
+
else {
|
|
1496
|
+
var sizeX = autoAlignment.sizeX, sizeY = autoAlignment.sizeY;
|
|
1497
|
+
var paddingValueX = getPaddingValue(contextInstance, sizeX, newScale);
|
|
1498
|
+
var paddingValueY = getPaddingValue(contextInstance, sizeY, newScale);
|
|
1499
|
+
var newPositionX = x + panX;
|
|
1500
|
+
var newPositionY = y + panY;
|
|
1501
|
+
var _c = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, paddingValueX, paddingValueY, wrapperComponent), finalX = _c.x, finalY = _c.y;
|
|
1502
|
+
contextInstance.setState(newScale, finalX, finalY);
|
|
1503
|
+
}
|
|
1267
1504
|
};
|
|
1268
1505
|
var handlePinchStop = function (contextInstance) {
|
|
1269
1506
|
var pinchMidpoint = contextInstance.pinchMidpoint;
|
|
@@ -1272,6 +1509,7 @@ var handlePinchStop = function (contextInstance) {
|
|
|
1272
1509
|
contextInstance.pinchMidpoint = null;
|
|
1273
1510
|
contextInstance.pinchStartScale = null;
|
|
1274
1511
|
contextInstance.pinchStartDistance = null;
|
|
1512
|
+
contextInstance.isPinching = false;
|
|
1275
1513
|
handleAlignToScaleBounds(contextInstance, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.x, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.y);
|
|
1276
1514
|
};
|
|
1277
1515
|
|
|
@@ -1300,8 +1538,8 @@ function getDoubleClickScale(mode, scale) {
|
|
|
1300
1538
|
return mode === "zoomOut" ? -1 : 1;
|
|
1301
1539
|
}
|
|
1302
1540
|
function handleDoubleClick(contextInstance, event) {
|
|
1303
|
-
var setup = contextInstance.setup, doubleClickStopEventTimer = contextInstance.doubleClickStopEventTimer,
|
|
1304
|
-
var scale =
|
|
1541
|
+
var setup = contextInstance.setup, doubleClickStopEventTimer = contextInstance.doubleClickStopEventTimer, state = contextInstance.state, contentComponent = contextInstance.contentComponent;
|
|
1542
|
+
var scale = state.scale;
|
|
1305
1543
|
var _a = contextInstance.props, onZoomStart = _a.onZoomStart, onZoom = _a.onZoom;
|
|
1306
1544
|
var _b = setup.doubleClick, disabled = _b.disabled, mode = _b.mode, step = _b.step, animationTime = _b.animationTime, animationType = _b.animationType;
|
|
1307
1545
|
if (disabled)
|
|
@@ -1313,7 +1551,7 @@ function handleDoubleClick(contextInstance, event) {
|
|
|
1313
1551
|
}
|
|
1314
1552
|
if (!contentComponent)
|
|
1315
1553
|
return console.error("No ContentComponent found");
|
|
1316
|
-
var delta = getDoubleClickScale(mode, contextInstance.
|
|
1554
|
+
var delta = getDoubleClickScale(mode, contextInstance.state.scale);
|
|
1317
1555
|
var newScale = handleCalculateButtonZoom(contextInstance, delta, step);
|
|
1318
1556
|
// stop execution when scale didn't change
|
|
1319
1557
|
if (scale === newScale)
|
|
@@ -1346,10 +1584,9 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1346
1584
|
function ZoomPanPinch(props) {
|
|
1347
1585
|
var _this = this;
|
|
1348
1586
|
this.mounted = true;
|
|
1349
|
-
this.pinchLastCenterX = null;
|
|
1350
|
-
this.pinchLastCenterY = null;
|
|
1351
1587
|
this.onChangeCallbacks = new Set();
|
|
1352
1588
|
this.onInitCallbacks = new Set();
|
|
1589
|
+
this.onTransformCallbacks = new Set();
|
|
1353
1590
|
// Components
|
|
1354
1591
|
this.wrapperComponent = null;
|
|
1355
1592
|
this.contentComponent = null;
|
|
@@ -1364,13 +1601,16 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1364
1601
|
this.isPanning = false;
|
|
1365
1602
|
this.isWheelPanning = false;
|
|
1366
1603
|
this.startCoords = null;
|
|
1604
|
+
this.panStartPosition = null;
|
|
1367
1605
|
this.lastTouch = null;
|
|
1368
1606
|
// pinch helpers
|
|
1607
|
+
this.isPinching = false;
|
|
1369
1608
|
this.distance = null;
|
|
1370
1609
|
this.lastDistance = null;
|
|
1371
1610
|
this.pinchStartDistance = null;
|
|
1372
1611
|
this.pinchStartScale = null;
|
|
1373
1612
|
this.pinchMidpoint = null;
|
|
1613
|
+
this.pinchPreviousCenter = null;
|
|
1374
1614
|
// double click helpers
|
|
1375
1615
|
this.doubleClickStopEventTimer = null;
|
|
1376
1616
|
// velocity helpers
|
|
@@ -1378,9 +1618,8 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1378
1618
|
this.velocityTime = null;
|
|
1379
1619
|
this.lastMousePosition = null;
|
|
1380
1620
|
// animations helpers
|
|
1381
|
-
this.
|
|
1621
|
+
this.isAnimating = false;
|
|
1382
1622
|
this.animation = null;
|
|
1383
|
-
this.maxBounds = null;
|
|
1384
1623
|
// key press
|
|
1385
1624
|
this.pressedKeys = {};
|
|
1386
1625
|
this.mount = function () {
|
|
@@ -1391,15 +1630,19 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1391
1630
|
};
|
|
1392
1631
|
this.update = function (newProps) {
|
|
1393
1632
|
_this.props = newProps;
|
|
1394
|
-
|
|
1633
|
+
if (_this.wrapperComponent && _this.contentComponent) {
|
|
1634
|
+
handleCalculateBounds(_this, _this.state.scale);
|
|
1635
|
+
}
|
|
1395
1636
|
_this.setup = createSetup(newProps);
|
|
1396
1637
|
};
|
|
1397
1638
|
this.initializeWindowEvents = function () {
|
|
1398
|
-
var _a, _b;
|
|
1639
|
+
var _a, _b, _c, _d;
|
|
1399
1640
|
var passive = makePassiveEventOption();
|
|
1400
1641
|
var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
|
|
1401
1642
|
var currentWindow = currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.defaultView;
|
|
1402
1643
|
(_b = _this.wrapperComponent) === null || _b === void 0 ? void 0 : _b.addEventListener("wheel", _this.onWheelPanning, passive);
|
|
1644
|
+
(_c = _this.wrapperComponent) === null || _c === void 0 ? void 0 : _c.addEventListener("keyup", _this.setKeyUnPressed, passive);
|
|
1645
|
+
(_d = _this.wrapperComponent) === null || _d === void 0 ? void 0 : _d.addEventListener("keydown", _this.setKeyPressed, passive);
|
|
1403
1646
|
// Panning on window to allow panning when mouse is out of component wrapper
|
|
1404
1647
|
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("mousedown", _this.onPanningStart, passive);
|
|
1405
1648
|
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("mousemove", _this.onPanning, passive);
|
|
@@ -1407,9 +1650,10 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1407
1650
|
currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.addEventListener("mouseleave", _this.clearPanning, passive);
|
|
1408
1651
|
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("keyup", _this.setKeyUnPressed, passive);
|
|
1409
1652
|
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("keydown", _this.setKeyPressed, passive);
|
|
1653
|
+
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("blur", _this.handleWindowBlur);
|
|
1410
1654
|
};
|
|
1411
1655
|
this.cleanupWindowEvents = function () {
|
|
1412
|
-
var _a, _b;
|
|
1656
|
+
var _a, _b, _c, _d, _e;
|
|
1413
1657
|
var passive = makePassiveEventOption();
|
|
1414
1658
|
var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
|
|
1415
1659
|
var currentWindow = currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.defaultView;
|
|
@@ -1419,9 +1663,13 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1419
1663
|
currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.removeEventListener("mouseleave", _this.clearPanning, passive);
|
|
1420
1664
|
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("keyup", _this.setKeyUnPressed, passive);
|
|
1421
1665
|
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("keydown", _this.setKeyPressed, passive);
|
|
1666
|
+
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("blur", _this.handleWindowBlur);
|
|
1422
1667
|
document.removeEventListener("mouseleave", _this.clearPanning, passive);
|
|
1668
|
+
(_b = _this.wrapperComponent) === null || _b === void 0 ? void 0 : _b.removeEventListener("wheel", _this.onWheelPanning, passive);
|
|
1669
|
+
(_c = _this.wrapperComponent) === null || _c === void 0 ? void 0 : _c.removeEventListener("keyup", _this.setKeyUnPressed, passive);
|
|
1670
|
+
(_d = _this.wrapperComponent) === null || _d === void 0 ? void 0 : _d.removeEventListener("keydown", _this.setKeyPressed, passive);
|
|
1423
1671
|
handleCancelAnimation(_this);
|
|
1424
|
-
(
|
|
1672
|
+
(_e = _this.observer) === null || _e === void 0 ? void 0 : _e.disconnect();
|
|
1425
1673
|
};
|
|
1426
1674
|
this.handleInitializeWrapperEvents = function (wrapper) {
|
|
1427
1675
|
// Zooming events on wrapper
|
|
@@ -1432,43 +1680,33 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1432
1680
|
wrapper.addEventListener("touchmove", _this.onTouchPanning, passive);
|
|
1433
1681
|
wrapper.addEventListener("touchend", _this.onTouchPanningStop, passive);
|
|
1434
1682
|
};
|
|
1435
|
-
this.handleInitialize = function (
|
|
1436
|
-
var isCentered = false;
|
|
1683
|
+
this.handleInitialize = function (contentComponent) {
|
|
1437
1684
|
var centerOnInit = _this.setup.centerOnInit;
|
|
1438
|
-
var hasTarget = function (entries, target) {
|
|
1439
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
1440
|
-
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
|
1441
|
-
var entry = entries_1[_i];
|
|
1442
|
-
if (entry.target === target) {
|
|
1443
|
-
return true;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
return false;
|
|
1447
|
-
};
|
|
1448
1685
|
_this.applyTransformation();
|
|
1449
|
-
_this.onInitCallbacks.forEach(function (callback) {
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1686
|
+
_this.onInitCallbacks.forEach(function (callback) { return callback(getContext(_this)); });
|
|
1687
|
+
if (centerOnInit) {
|
|
1688
|
+
_this.setCenter();
|
|
1689
|
+
_this.observer = new ResizeObserver(function () {
|
|
1690
|
+
var _a;
|
|
1691
|
+
var currentWidth = contentComponent.offsetWidth;
|
|
1692
|
+
var currentHeight = contentComponent.offsetHeight;
|
|
1693
|
+
if (currentWidth > 0 || currentHeight > 0) {
|
|
1694
|
+
_this.onInitCallbacks.forEach(function (callback) {
|
|
1695
|
+
return callback(getContext(_this));
|
|
1696
|
+
});
|
|
1697
|
+
_this.setCenter();
|
|
1698
|
+
(_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
1461
1699
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1700
|
+
});
|
|
1701
|
+
// TODO: CHANGE to first interaction?
|
|
1702
|
+
// if nothing about the contentComponent has changed after 5 seconds, disconnect the observer
|
|
1703
|
+
setTimeout(function () {
|
|
1704
|
+
var _a;
|
|
1705
|
+
(_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
1706
|
+
}, 5000);
|
|
1707
|
+
// Start observing the target node for configured mutations
|
|
1708
|
+
_this.observer.observe(contentComponent);
|
|
1709
|
+
}
|
|
1472
1710
|
};
|
|
1473
1711
|
/// ///////
|
|
1474
1712
|
// Zoom
|
|
@@ -1477,49 +1715,51 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1477
1715
|
var disabled = _this.setup.disabled;
|
|
1478
1716
|
if (disabled)
|
|
1479
1717
|
return;
|
|
1718
|
+
_this.syncModifierKeys(event);
|
|
1480
1719
|
var isAllowed = isWheelAllowed(_this, event);
|
|
1481
1720
|
if (!isAllowed)
|
|
1482
1721
|
return;
|
|
1483
|
-
var keysPressed = _this.isPressingKeys(_this.setup.wheel.activationKeys);
|
|
1484
|
-
if (!keysPressed)
|
|
1485
|
-
return;
|
|
1486
1722
|
handleWheelStart(_this, event);
|
|
1487
1723
|
handleWheelZoom(_this, event);
|
|
1488
1724
|
handleWheelStop(_this, event);
|
|
1489
1725
|
};
|
|
1490
1726
|
/// ///////
|
|
1491
|
-
//
|
|
1727
|
+
// Track Pad Panning
|
|
1492
1728
|
/// ///////
|
|
1493
1729
|
this.onWheelPanning = function (event) {
|
|
1494
|
-
var
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
!panning.wheelPanning ||
|
|
1501
|
-
event.ctrlKey) {
|
|
1730
|
+
var onPanning = _this.props.onPanning;
|
|
1731
|
+
var trackPadPanning = _this.setup.trackPadPanning;
|
|
1732
|
+
var lockAxisX = trackPadPanning.lockAxisX, lockAxisY = trackPadPanning.lockAxisY;
|
|
1733
|
+
_this.syncModifierKeys(event);
|
|
1734
|
+
var isAllowed = isWheelPanningAllowed(_this, event);
|
|
1735
|
+
if (!isAllowed)
|
|
1502
1736
|
return;
|
|
1503
|
-
}
|
|
1504
1737
|
event.preventDefault();
|
|
1505
1738
|
event.stopPropagation();
|
|
1506
|
-
var
|
|
1739
|
+
var _a = _this.state, positionX = _a.positionX, positionY = _a.positionY;
|
|
1507
1740
|
var mouseX = positionX - event.deltaX;
|
|
1508
1741
|
var mouseY = positionY - event.deltaY;
|
|
1509
|
-
var newPositionX =
|
|
1510
|
-
var newPositionY =
|
|
1511
|
-
var
|
|
1742
|
+
var newPositionX = lockAxisX ? positionX : mouseX;
|
|
1743
|
+
var newPositionY = lockAxisY ? positionY : mouseY;
|
|
1744
|
+
var _b = _this.setup.autoAlignment, sizeX = _b.sizeX, sizeY = _b.sizeY;
|
|
1512
1745
|
var paddingValueX = getPaddingValue(_this, sizeX);
|
|
1513
1746
|
var paddingValueY = getPaddingValue(_this, sizeY);
|
|
1514
1747
|
if (newPositionX === positionX && newPositionY === positionY)
|
|
1515
1748
|
return;
|
|
1749
|
+
handleWheelPanningStart(_this, event);
|
|
1516
1750
|
handleNewPosition(_this, newPositionX, newPositionY, paddingValueX, paddingValueY);
|
|
1751
|
+
handleCallback(getContext(_this), event, onPanning);
|
|
1752
|
+
handleWheelPanningStop(_this, event);
|
|
1517
1753
|
};
|
|
1754
|
+
/// ///////
|
|
1755
|
+
// Pan
|
|
1756
|
+
/// ///////
|
|
1518
1757
|
this.onPanningStart = function (event) {
|
|
1519
1758
|
var disabled = _this.setup.disabled;
|
|
1520
1759
|
var onPanningStart = _this.props.onPanningStart;
|
|
1521
1760
|
if (disabled)
|
|
1522
1761
|
return;
|
|
1762
|
+
_this.syncModifierKeys(event);
|
|
1523
1763
|
var isAllowed = isPanningStartAllowed(_this, event);
|
|
1524
1764
|
if (!isAllowed)
|
|
1525
1765
|
return;
|
|
@@ -1543,6 +1783,13 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1543
1783
|
var onPanning = _this.props.onPanning;
|
|
1544
1784
|
if (disabled)
|
|
1545
1785
|
return;
|
|
1786
|
+
_this.syncModifierKeys(event);
|
|
1787
|
+
// Detect missed mouseup — e.g. when the mouse was released outside an
|
|
1788
|
+
// iframe boundary where the host frame swallows the mouseup event.
|
|
1789
|
+
if (_this.isPanning && event.buttons === 0) {
|
|
1790
|
+
_this.clearPanning(event);
|
|
1791
|
+
return;
|
|
1792
|
+
}
|
|
1546
1793
|
var isAllowed = isPanningAllowed(_this);
|
|
1547
1794
|
if (!isAllowed)
|
|
1548
1795
|
return;
|
|
@@ -1551,13 +1798,14 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1551
1798
|
return;
|
|
1552
1799
|
event.preventDefault();
|
|
1553
1800
|
event.stopPropagation();
|
|
1554
|
-
handlePanning(_this, event.clientX, event.clientY);
|
|
1801
|
+
handlePanning(_this, event.clientX, event.clientY, DeviceType.MOUSE);
|
|
1555
1802
|
handleCallback(getContext(_this), event, onPanning);
|
|
1556
1803
|
};
|
|
1557
1804
|
this.onPanningStop = function (event) {
|
|
1805
|
+
var velocityDisabled = _this.setup.panning.velocityDisabled;
|
|
1558
1806
|
var onPanningStop = _this.props.onPanningStop;
|
|
1559
1807
|
if (_this.isPanning) {
|
|
1560
|
-
handlePanningEnd(_this);
|
|
1808
|
+
handlePanningEnd(_this, velocityDisabled);
|
|
1561
1809
|
handleCallback(getContext(_this), event, onPanningStop);
|
|
1562
1810
|
}
|
|
1563
1811
|
};
|
|
@@ -1566,7 +1814,7 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1566
1814
|
/// ///////
|
|
1567
1815
|
this.onPinchStart = function (event) {
|
|
1568
1816
|
var disabled = _this.setup.disabled;
|
|
1569
|
-
var
|
|
1817
|
+
var onPinchStart = _this.props.onPinchStart;
|
|
1570
1818
|
if (disabled)
|
|
1571
1819
|
return;
|
|
1572
1820
|
var isAllowed = isPinchStartAllowed(_this, event);
|
|
@@ -1574,12 +1822,11 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1574
1822
|
return;
|
|
1575
1823
|
handlePinchStart(_this, event);
|
|
1576
1824
|
handleCancelAnimation(_this);
|
|
1577
|
-
handleCallback(getContext(_this), event,
|
|
1578
|
-
handleCallback(getContext(_this), event, onZoomStart);
|
|
1825
|
+
handleCallback(getContext(_this), event, onPinchStart);
|
|
1579
1826
|
};
|
|
1580
1827
|
this.onPinch = function (event) {
|
|
1581
1828
|
var disabled = _this.setup.disabled;
|
|
1582
|
-
var
|
|
1829
|
+
var onPinch = _this.props.onPinch;
|
|
1583
1830
|
if (disabled)
|
|
1584
1831
|
return;
|
|
1585
1832
|
var isAllowed = isPinchAllowed(_this);
|
|
@@ -1588,38 +1835,38 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1588
1835
|
event.preventDefault();
|
|
1589
1836
|
event.stopPropagation();
|
|
1590
1837
|
handlePinchZoom(_this, event);
|
|
1591
|
-
handleCallback(getContext(_this), event,
|
|
1592
|
-
handleCallback(getContext(_this), event, onZoom);
|
|
1838
|
+
handleCallback(getContext(_this), event, onPinch);
|
|
1593
1839
|
};
|
|
1594
1840
|
this.onPinchStop = function (event) {
|
|
1595
|
-
var
|
|
1841
|
+
var onPinchStop = _this.props.onPinchStop;
|
|
1596
1842
|
if (_this.pinchStartScale) {
|
|
1597
1843
|
handlePinchStop(_this);
|
|
1598
|
-
handleCallback(getContext(_this), event,
|
|
1599
|
-
handleCallback(getContext(_this), event, onZoomStop);
|
|
1844
|
+
handleCallback(getContext(_this), event, onPinchStop);
|
|
1600
1845
|
}
|
|
1601
1846
|
};
|
|
1602
1847
|
/// ///////
|
|
1603
1848
|
// Touch
|
|
1604
1849
|
/// ///////
|
|
1605
1850
|
this.onTouchPanningStart = function (event) {
|
|
1606
|
-
var
|
|
1851
|
+
var _a = _this.setup, disabled = _a.disabled, doubleClick = _a.doubleClick;
|
|
1607
1852
|
var onPanningStart = _this.props.onPanningStart;
|
|
1608
1853
|
if (disabled)
|
|
1609
1854
|
return;
|
|
1610
|
-
var
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
if (!isDoubleTap) {
|
|
1855
|
+
var isDoubleTapAllowed = !(doubleClick === null || doubleClick === void 0 ? void 0 : doubleClick.disabled);
|
|
1856
|
+
var isDoubleTap = _this.lastTouch && +new Date() - _this.lastTouch < 200;
|
|
1857
|
+
if (isDoubleTapAllowed && isDoubleTap && event.touches.length === 1) {
|
|
1858
|
+
_this.onDoubleClick(event);
|
|
1859
|
+
}
|
|
1860
|
+
else {
|
|
1617
1861
|
_this.lastTouch = +new Date();
|
|
1618
1862
|
handleCancelAnimation(_this);
|
|
1619
1863
|
var touches = event.touches;
|
|
1620
1864
|
var isPanningAction = touches.length === 1;
|
|
1621
1865
|
var isPinchAction = touches.length === 2;
|
|
1866
|
+
var isAllowed = isPanningStartAllowed(_this, event);
|
|
1622
1867
|
if (isPanningAction) {
|
|
1868
|
+
if (!isAllowed)
|
|
1869
|
+
return;
|
|
1623
1870
|
handleCancelAnimation(_this);
|
|
1624
1871
|
handlePanningStart(_this, event);
|
|
1625
1872
|
handleCallback(getContext(_this), event, onPanningStart);
|
|
@@ -1638,10 +1885,12 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1638
1885
|
var isAllowed = isPanningAllowed(_this);
|
|
1639
1886
|
if (!isAllowed)
|
|
1640
1887
|
return;
|
|
1641
|
-
event.
|
|
1888
|
+
if (event.cancelable) {
|
|
1889
|
+
event.preventDefault();
|
|
1890
|
+
}
|
|
1642
1891
|
event.stopPropagation();
|
|
1643
1892
|
var touch = event.touches[0];
|
|
1644
|
-
handlePanning(_this, touch.clientX, touch.clientY);
|
|
1893
|
+
handlePanning(_this, touch.clientX, touch.clientY, DeviceType.TOUCH);
|
|
1645
1894
|
handleCallback(getContext(_this), event, onPanning);
|
|
1646
1895
|
}
|
|
1647
1896
|
else if (event.touches.length > 1) {
|
|
@@ -1672,6 +1921,44 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1672
1921
|
_this.onPanningStop(event);
|
|
1673
1922
|
}
|
|
1674
1923
|
};
|
|
1924
|
+
// When the window loses focus (e.g. user clicks outside an iframe),
|
|
1925
|
+
// keyup and mouseup events are swallowed by the parent frame. Clear all
|
|
1926
|
+
// tracked state to prevent stale activation keys or ghost panning.
|
|
1927
|
+
this.handleWindowBlur = function () {
|
|
1928
|
+
_this.pressedKeys = {};
|
|
1929
|
+
if (_this.isPanning) {
|
|
1930
|
+
_this.isPanning = false;
|
|
1931
|
+
_this.startCoords = null;
|
|
1932
|
+
}
|
|
1933
|
+
};
|
|
1934
|
+
// Iframe focus problem (e.g. Storybook):
|
|
1935
|
+
//
|
|
1936
|
+
// When the library runs inside an iframe, keyboard events (keydown/keyup)
|
|
1937
|
+
// only reach the iframe's window when it has focus. If the user navigates
|
|
1938
|
+
// via the host UI (e.g. Storybook sidebar) the iframe never receives
|
|
1939
|
+
// focus, so keydown never fires and activationKeys like Cmd/Ctrl are
|
|
1940
|
+
// invisible to pressedKeys.
|
|
1941
|
+
//
|
|
1942
|
+
// Mouse and wheel events, however, DO reach the iframe regardless of
|
|
1943
|
+
// focus — and they carry modifier flags (ctrlKey, metaKey, shiftKey,
|
|
1944
|
+
// altKey) that always reflect the real physical key state at event time.
|
|
1945
|
+
//
|
|
1946
|
+
// We sync those flags into pressedKeys on every interaction event so
|
|
1947
|
+
// that activationKeys checks work without requiring iframe focus.
|
|
1948
|
+
// Both pressed (true) AND released (false) states must be written;
|
|
1949
|
+
// writing only `true` would leave stale keys after release because
|
|
1950
|
+
// keyup never fires in an unfocused iframe.
|
|
1951
|
+
this.syncModifierKeys = function (event) {
|
|
1952
|
+
var ctrlKey = event.ctrlKey, metaKey = event.metaKey, shiftKey = event.shiftKey, altKey = event.altKey;
|
|
1953
|
+
if (typeof ctrlKey === "boolean")
|
|
1954
|
+
_this.pressedKeys.Control = ctrlKey;
|
|
1955
|
+
if (typeof metaKey === "boolean")
|
|
1956
|
+
_this.pressedKeys.Meta = metaKey;
|
|
1957
|
+
if (typeof shiftKey === "boolean")
|
|
1958
|
+
_this.pressedKeys.Shift = shiftKey;
|
|
1959
|
+
if (typeof altKey === "boolean")
|
|
1960
|
+
_this.pressedKeys.Alt = altKey;
|
|
1961
|
+
};
|
|
1675
1962
|
this.setKeyPressed = function (e) {
|
|
1676
1963
|
_this.pressedKeys[e.key] = true;
|
|
1677
1964
|
};
|
|
@@ -1679,35 +1966,26 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1679
1966
|
_this.pressedKeys[e.key] = false;
|
|
1680
1967
|
};
|
|
1681
1968
|
this.isPressingKeys = function (keys) {
|
|
1969
|
+
if (typeof keys === "function") {
|
|
1970
|
+
return keys(Object.entries(_this.pressedKeys)
|
|
1971
|
+
.filter(function (_a) {
|
|
1972
|
+
var pressed = _a[1];
|
|
1973
|
+
return pressed;
|
|
1974
|
+
})
|
|
1975
|
+
.map(function (_a) {
|
|
1976
|
+
var key = _a[0];
|
|
1977
|
+
return key;
|
|
1978
|
+
}));
|
|
1979
|
+
}
|
|
1682
1980
|
if (!keys.length) {
|
|
1683
1981
|
return true;
|
|
1684
1982
|
}
|
|
1685
|
-
return Boolean(keys.
|
|
1686
|
-
};
|
|
1687
|
-
this.setTransformState = function (scale, positionX, positionY) {
|
|
1688
|
-
var onTransformed = _this.props.onTransformed;
|
|
1689
|
-
if (!Number.isNaN(scale) &&
|
|
1690
|
-
!Number.isNaN(positionX) &&
|
|
1691
|
-
!Number.isNaN(positionY)) {
|
|
1692
|
-
if (scale !== _this.transformState.scale) {
|
|
1693
|
-
_this.transformState.previousScale = _this.transformState.scale;
|
|
1694
|
-
_this.transformState.scale = scale;
|
|
1695
|
-
}
|
|
1696
|
-
_this.transformState.positionX = positionX;
|
|
1697
|
-
_this.transformState.positionY = positionY;
|
|
1698
|
-
_this.applyTransformation();
|
|
1699
|
-
var ctx_1 = getContext(_this);
|
|
1700
|
-
_this.onChangeCallbacks.forEach(function (callback) { return callback(ctx_1); });
|
|
1701
|
-
handleCallback(ctx_1, { scale: scale, positionX: positionX, positionY: positionY }, onTransformed);
|
|
1702
|
-
}
|
|
1703
|
-
else {
|
|
1704
|
-
console.error("Detected NaN set state values");
|
|
1705
|
-
}
|
|
1983
|
+
return Boolean(keys.every(function (key) { return _this.pressedKeys[key]; }));
|
|
1706
1984
|
};
|
|
1707
1985
|
this.setCenter = function () {
|
|
1708
1986
|
if (_this.wrapperComponent && _this.contentComponent) {
|
|
1709
|
-
var targetState = getCenterPosition(_this.
|
|
1710
|
-
_this.
|
|
1987
|
+
var targetState = getCenterPosition(_this.state.scale, _this.wrapperComponent, _this.contentComponent);
|
|
1988
|
+
_this.setState(targetState.scale, targetState.positionX, targetState.positionY);
|
|
1711
1989
|
}
|
|
1712
1990
|
};
|
|
1713
1991
|
this.handleTransformStyles = function (x, y, scale) {
|
|
@@ -1716,19 +1994,60 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1716
1994
|
}
|
|
1717
1995
|
return getTransformStyles(x, y, scale);
|
|
1718
1996
|
};
|
|
1997
|
+
this.getContext = function () {
|
|
1998
|
+
return getContext(_this);
|
|
1999
|
+
};
|
|
1719
2000
|
this.applyTransformation = function () {
|
|
1720
2001
|
if (!_this.mounted || !_this.contentComponent)
|
|
1721
2002
|
return;
|
|
1722
|
-
var _a = _this.
|
|
2003
|
+
var _a = _this.state, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
1723
2004
|
var transform = _this.handleTransformStyles(positionX, positionY, scale);
|
|
1724
|
-
|
|
2005
|
+
// Detached mode do not apply transformation directly to content component
|
|
2006
|
+
if (!_this.props.detached) {
|
|
2007
|
+
_this.contentComponent.style.transform = transform;
|
|
2008
|
+
}
|
|
2009
|
+
_this.onTransformCallbacks.forEach(function (callback) {
|
|
2010
|
+
return callback({
|
|
2011
|
+
scale: scale,
|
|
2012
|
+
positionX: positionX,
|
|
2013
|
+
positionY: positionY,
|
|
2014
|
+
previousScale: _this.state.previousScale,
|
|
2015
|
+
ref: getContext(_this),
|
|
2016
|
+
});
|
|
2017
|
+
});
|
|
1725
2018
|
};
|
|
1726
|
-
this.
|
|
1727
|
-
|
|
2019
|
+
this.setState = function (scale, positionX, positionY) {
|
|
2020
|
+
var onTransform = _this.props.onTransform;
|
|
2021
|
+
if (!Number.isNaN(scale) &&
|
|
2022
|
+
!Number.isNaN(positionX) &&
|
|
2023
|
+
!Number.isNaN(positionY)) {
|
|
2024
|
+
var safeScale = Math.max(scale, 1e-7);
|
|
2025
|
+
if (safeScale !== _this.state.scale) {
|
|
2026
|
+
_this.state.previousScale = _this.state.scale;
|
|
2027
|
+
_this.state.scale = safeScale;
|
|
2028
|
+
}
|
|
2029
|
+
_this.state.positionX = positionX;
|
|
2030
|
+
_this.state.positionY = positionY;
|
|
2031
|
+
_this.applyTransformation();
|
|
2032
|
+
var ctx_1 = getContext(_this);
|
|
2033
|
+
_this.onChangeCallbacks.forEach(function (callback) { return callback(ctx_1); });
|
|
2034
|
+
handleCallback(ctx_1, { scale: _this.state.scale, positionX: positionX, positionY: positionY }, onTransform);
|
|
2035
|
+
}
|
|
2036
|
+
else {
|
|
2037
|
+
console.error("Detected NaN set state values");
|
|
2038
|
+
}
|
|
1728
2039
|
};
|
|
1729
2040
|
/**
|
|
1730
2041
|
* Hooks
|
|
1731
2042
|
*/
|
|
2043
|
+
this.onTransform = function (callback) {
|
|
2044
|
+
if (!_this.onTransformCallbacks.has(callback)) {
|
|
2045
|
+
_this.onTransformCallbacks.add(callback);
|
|
2046
|
+
}
|
|
2047
|
+
return function () {
|
|
2048
|
+
_this.onTransformCallbacks.delete(callback);
|
|
2049
|
+
};
|
|
2050
|
+
};
|
|
1732
2051
|
this.onChange = function (callback) {
|
|
1733
2052
|
if (!_this.onChangeCallbacks.has(callback)) {
|
|
1734
2053
|
_this.onChangeCallbacks.add(callback);
|
|
@@ -1752,17 +2071,18 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1752
2071
|
_this.cleanupWindowEvents();
|
|
1753
2072
|
_this.wrapperComponent = wrapperComponent;
|
|
1754
2073
|
_this.contentComponent = contentComponent;
|
|
1755
|
-
handleCalculateBounds(_this, _this.
|
|
2074
|
+
handleCalculateBounds(_this, _this.state.scale);
|
|
1756
2075
|
_this.handleInitializeWrapperEvents(wrapperComponent);
|
|
1757
|
-
_this.handleInitialize(
|
|
2076
|
+
_this.handleInitialize(contentComponent);
|
|
1758
2077
|
_this.initializeWindowEvents();
|
|
1759
2078
|
_this.isInitialized = true;
|
|
1760
2079
|
var ctx = getContext(_this);
|
|
1761
2080
|
handleCallback(ctx, undefined, _this.props.onInit);
|
|
2081
|
+
assignRef(_this.props.ref, ctx);
|
|
1762
2082
|
};
|
|
1763
2083
|
this.props = props;
|
|
1764
2084
|
this.setup = createSetup(this.props);
|
|
1765
|
-
this.
|
|
2085
|
+
this.state = createState(this.props);
|
|
1766
2086
|
}
|
|
1767
2087
|
return ZoomPanPinch;
|
|
1768
2088
|
}());
|
|
@@ -1781,7 +2101,7 @@ var TransformWrapper = React.forwardRef(function (props, ref) {
|
|
|
1781
2101
|
useEffect(function () {
|
|
1782
2102
|
instance.update(props);
|
|
1783
2103
|
}, [instance, props]);
|
|
1784
|
-
return
|
|
2104
|
+
return jsx(Context.Provider, __assign({ value: instance }, { children: content }));
|
|
1785
2105
|
});
|
|
1786
2106
|
|
|
1787
2107
|
var KeepScale = React.forwardRef(function (props, ref) {
|
|
@@ -1792,11 +2112,11 @@ var KeepScale = React.forwardRef(function (props, ref) {
|
|
|
1792
2112
|
if (localRef.current) {
|
|
1793
2113
|
var positionX = 0;
|
|
1794
2114
|
var positionY = 0;
|
|
1795
|
-
localRef.current.style.transform = instance.handleTransformStyles(positionX, positionY, 1 / ctx.instance.
|
|
2115
|
+
localRef.current.style.transform = instance.handleTransformStyles(positionX, positionY, 1 / ctx.instance.state.scale);
|
|
1796
2116
|
}
|
|
1797
2117
|
});
|
|
1798
2118
|
}, [instance]);
|
|
1799
|
-
return
|
|
2119
|
+
return jsx("div", __assign({}, props, { ref: mergeRefs([localRef, ref]) }));
|
|
1800
2120
|
});
|
|
1801
2121
|
|
|
1802
2122
|
var initialElementRect = {
|
|
@@ -1853,11 +2173,13 @@ var previewStyles = {
|
|
|
1853
2173
|
border: "3px solid red",
|
|
1854
2174
|
transformOrigin: "0% 0%",
|
|
1855
2175
|
boxShadow: "rgba(0,0,0,0.2) 0 0 0 10000000px",
|
|
2176
|
+
pointerEvents: "none",
|
|
1856
2177
|
};
|
|
1857
2178
|
var MiniMap = function (_a) {
|
|
1858
|
-
var _b = _a.width, width = _b === void 0 ? 200 : _b, _c = _a.height, height = _c === void 0 ? 200 : _c, _d = _a.borderColor, borderColor = _d === void 0 ? "red" : _d, children = _a.children, rest = __rest(_a, ["width", "height", "borderColor", "children"]);
|
|
1859
|
-
var
|
|
2179
|
+
var _b = _a.width, width = _b === void 0 ? 200 : _b, _c = _a.height, height = _c === void 0 ? 200 : _c, _d = _a.borderColor, borderColor = _d === void 0 ? "red" : _d, previewStyle = _a.previewStyle, wrapperClassName = _a.wrapperClassName, previewClassName = _a.previewClassName, children = _a.children, _e = _a.panning, panning = _e === void 0 ? true : _e, rest = __rest(_a, ["width", "height", "borderColor", "previewStyle", "wrapperClassName", "previewClassName", "children", "panning"]);
|
|
2180
|
+
var _f = useState(false), initialized = _f[0], setInitialized = _f[1];
|
|
1860
2181
|
var instance = useTransformContext();
|
|
2182
|
+
var _g = useState(false), isDown = _g[0], setIsDown = _g[1];
|
|
1861
2183
|
var miniMapInstance = useRef(null);
|
|
1862
2184
|
var mainRef = useRef(null);
|
|
1863
2185
|
var wrapperRef = useRef(null);
|
|
@@ -1879,15 +2201,15 @@ var MiniMap = function (_a) {
|
|
|
1879
2201
|
if (instance.contentComponent) {
|
|
1880
2202
|
var rect = instance.contentComponent.getBoundingClientRect();
|
|
1881
2203
|
return {
|
|
1882
|
-
width: rect.width / instance.
|
|
1883
|
-
height: rect.height / instance.
|
|
2204
|
+
width: rect.width / instance.state.scale,
|
|
2205
|
+
height: rect.height / instance.state.scale,
|
|
1884
2206
|
};
|
|
1885
2207
|
}
|
|
1886
2208
|
return {
|
|
1887
2209
|
width: 0,
|
|
1888
2210
|
height: 0,
|
|
1889
2211
|
};
|
|
1890
|
-
}, [instance.contentComponent, instance.
|
|
2212
|
+
}, [instance.contentComponent, instance.state.scale]);
|
|
1891
2213
|
var computeMiniMapScale = useCallback(function () {
|
|
1892
2214
|
var contentSize = getContentSize();
|
|
1893
2215
|
var scaleX = width / contentSize.width;
|
|
@@ -1912,13 +2234,16 @@ var MiniMap = function (_a) {
|
|
|
1912
2234
|
position: "absolute",
|
|
1913
2235
|
boxSizing: "border-box",
|
|
1914
2236
|
zIndex: 1,
|
|
1915
|
-
overflow: "hidden",
|
|
2237
|
+
// overflow: "hidden",
|
|
1916
2238
|
};
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
2239
|
+
if (wrapperRef.current) {
|
|
2240
|
+
var el = wrapperRef.current.style;
|
|
2241
|
+
el.transform = style.transform;
|
|
2242
|
+
el.transformOrigin = style.transformOrigin;
|
|
2243
|
+
el.position = style.position;
|
|
2244
|
+
el.boxSizing = style.boxSizing;
|
|
2245
|
+
el.zIndex = String(style.zIndex);
|
|
2246
|
+
}
|
|
1922
2247
|
};
|
|
1923
2248
|
var transformMiniMap = function () {
|
|
1924
2249
|
computeMiniMapStyle();
|
|
@@ -1935,8 +2260,8 @@ var MiniMap = function (_a) {
|
|
|
1935
2260
|
if (previewRef.current) {
|
|
1936
2261
|
var size = getViewportSize();
|
|
1937
2262
|
var scale = computeMiniMapScale();
|
|
1938
|
-
var previewScale = scale * (1 / instance.
|
|
1939
|
-
var transform = instance.handleTransformStyles(-instance.
|
|
2263
|
+
var previewScale = scale * (1 / instance.state.scale);
|
|
2264
|
+
var transform = instance.handleTransformStyles(-instance.state.positionX * previewScale, -instance.state.positionY * previewScale, 1);
|
|
1940
2265
|
previewRef.current.style.transform = transform;
|
|
1941
2266
|
previewRef.current.style.width = "".concat(size.width * previewScale, "px");
|
|
1942
2267
|
previewRef.current.style.height = "".concat(size.height * previewScale, "px");
|
|
@@ -1957,25 +2282,66 @@ var MiniMap = function (_a) {
|
|
|
1957
2282
|
return instance.onChange(function (zpp) {
|
|
1958
2283
|
var scale = computeMiniMapScale();
|
|
1959
2284
|
if (miniMapInstance.current) {
|
|
1960
|
-
miniMapInstance.current.instance.
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
zpp.instance.transformState.positionY * scale;
|
|
2285
|
+
miniMapInstance.current.instance.state.scale = zpp.instance.state.scale;
|
|
2286
|
+
miniMapInstance.current.instance.state.positionX =
|
|
2287
|
+
zpp.instance.state.positionX * scale;
|
|
2288
|
+
miniMapInstance.current.instance.state.positionY =
|
|
2289
|
+
zpp.instance.state.positionY * scale;
|
|
1966
2290
|
}
|
|
1967
2291
|
});
|
|
1968
2292
|
}, [computeMiniMapScale, instance, miniMapInstance]);
|
|
2293
|
+
useEffect(function () {
|
|
2294
|
+
var move = function (e) {
|
|
2295
|
+
var _a, _b;
|
|
2296
|
+
if (panning &&
|
|
2297
|
+
isDown &&
|
|
2298
|
+
instance.contentComponent &&
|
|
2299
|
+
previewRef.current &&
|
|
2300
|
+
mainRef.current) {
|
|
2301
|
+
var scale = computeMiniMapScale();
|
|
2302
|
+
var previewRect = previewRef.current.getBoundingClientRect();
|
|
2303
|
+
var mainRect = mainRef.current.getBoundingClientRect();
|
|
2304
|
+
var relativeX = (e.clientX - mainRect.left) / scale;
|
|
2305
|
+
var relativeY = (e.clientY - mainRect.top) / scale;
|
|
2306
|
+
var x = relativeX - previewRect.width / 2;
|
|
2307
|
+
var y = relativeY - previewRect.height / 2;
|
|
2308
|
+
var instanceWidth = (((_a = instance.wrapperComponent) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0) * instance.state.scale;
|
|
2309
|
+
var instanceHeight = (((_b = instance.wrapperComponent) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0) * instance.state.scale;
|
|
2310
|
+
var limitWidth = instanceWidth - previewRect.width * 2 * instance.state.scale;
|
|
2311
|
+
var limitHeight = instanceHeight - previewRect.height * 2 * instance.state.scale;
|
|
2312
|
+
var boundedX = boundLimiter(x * instance.state.scale, 0, limitWidth, true);
|
|
2313
|
+
var boundedY = boundLimiter(y * instance.state.scale, 0, limitHeight, true);
|
|
2314
|
+
instance.setState(instance.state.scale, -boundedX, -boundedY);
|
|
2315
|
+
}
|
|
2316
|
+
};
|
|
2317
|
+
var setDown = function (e) {
|
|
2318
|
+
var _a;
|
|
2319
|
+
if (((_a = mainRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target)) ||
|
|
2320
|
+
e.target === mainRef.current) {
|
|
2321
|
+
move(e);
|
|
2322
|
+
setIsDown(true);
|
|
2323
|
+
}
|
|
2324
|
+
};
|
|
2325
|
+
var setUp = function () {
|
|
2326
|
+
setIsDown(false);
|
|
2327
|
+
};
|
|
2328
|
+
document.addEventListener("mousedown", setDown);
|
|
2329
|
+
document.addEventListener("mouseup", setUp);
|
|
2330
|
+
document.addEventListener("mousemove", move);
|
|
2331
|
+
return function () {
|
|
2332
|
+
document.removeEventListener("mousemove", move);
|
|
2333
|
+
document.removeEventListener("mouseup", setUp);
|
|
2334
|
+
};
|
|
2335
|
+
});
|
|
1969
2336
|
var wrapperStyle = useMemo(function () {
|
|
1970
2337
|
return {
|
|
1971
2338
|
position: "relative",
|
|
1972
2339
|
zIndex: 2,
|
|
1973
|
-
overflow: "hidden",
|
|
2340
|
+
// overflow: "hidden",
|
|
2341
|
+
userSelect: "none",
|
|
1974
2342
|
};
|
|
1975
2343
|
}, []);
|
|
1976
|
-
return (
|
|
1977
|
-
React.createElement("div", __assign({}, rest, { ref: wrapperRef, className: "rzpp-wrapper" }), children),
|
|
1978
|
-
React.createElement("div", { className: "rzpp-preview", ref: previewRef, style: __assign(__assign({}, previewStyles), { borderColor: borderColor }) })));
|
|
2344
|
+
return (jsxs("div", __assign({}, rest, { ref: mainRef, style: wrapperStyle, className: "rzpp-mini-map ".concat(rest.className || "").trim() }, { children: [jsx("div", __assign({ style: { pointerEvents: "none" }, ref: wrapperRef, className: "rzpp-minimap-wrapper ".concat(wrapperClassName || "").trim() }, { children: children })), jsx("div", { className: "rzpp-minimap-preview ".concat(previewClassName || "").trim(), ref: previewRef, style: __assign(__assign(__assign({}, previewStyles), { borderColor: borderColor }), previewStyle) })] })));
|
|
1979
2345
|
};
|
|
1980
2346
|
|
|
1981
2347
|
function styleInject(css, ref) {
|
|
@@ -2005,30 +2371,142 @@ function styleInject(css, ref) {
|
|
|
2005
2371
|
}
|
|
2006
2372
|
}
|
|
2007
2373
|
|
|
2008
|
-
var css_248z = ".transform-component-module_wrapper__SPB86 {\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 transform: translate3d(0, 0, 0);\n}\n.transform-component-module_content__FBWxo {\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__FBWxo img {\n pointer-events: none;\n}\n";
|
|
2009
|
-
var styles = {"wrapper":"transform-component-module_wrapper__SPB86","content":"transform-component-module_content__FBWxo"};
|
|
2374
|
+
var css_248z = ".transform-component-module_wrapper__SPB86 {\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 transform: translate3d(0, 0, 0);\n}\n.transform-component-module_content__FBWxo {\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__FBWxo img {\n pointer-events: none;\n}\n.transform-component-module_infiniteGrid__Z-aP3 {\n position: absolute;\n inset: 0;\n pointer-events: none;\n background-image: radial-gradient(\n circle,\n rgba(0, 0, 0, 0.12) 1px,\n transparent 1px\n );\n background-size: 20px 20px;\n background-position: 0 0;\n}\n";
|
|
2375
|
+
var styles = {"wrapper":"transform-component-module_wrapper__SPB86","content":"transform-component-module_content__FBWxo","infiniteGrid":"transform-component-module_infiniteGrid__Z-aP3"};
|
|
2010
2376
|
styleInject(css_248z);
|
|
2011
2377
|
|
|
2012
2378
|
var TransformComponent = function (_a) {
|
|
2013
|
-
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, _d = _a.wrapperProps, wrapperProps = _d === void 0 ? {} : _d, _e = _a.contentProps, contentProps = _e === void 0 ? {} : _e;
|
|
2014
|
-
var
|
|
2379
|
+
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, _d = _a.wrapperProps, wrapperProps = _d === void 0 ? {} : _d, _e = _a.contentProps, contentProps = _e === void 0 ? {} : _e, _f = _a.infinite, infinite = _f === void 0 ? false : _f;
|
|
2380
|
+
var instance = useContext(Context);
|
|
2381
|
+
var init = instance.init, cleanupWindowEvents = instance.cleanupWindowEvents;
|
|
2015
2382
|
var wrapperRef = useRef(null);
|
|
2016
2383
|
var contentRef = useRef(null);
|
|
2384
|
+
var gridRef = useRef(null);
|
|
2017
2385
|
useEffect(function () {
|
|
2018
2386
|
var wrapper = wrapperRef.current;
|
|
2019
2387
|
var content = contentRef.current;
|
|
2020
2388
|
if (wrapper !== null && content !== null && init) {
|
|
2021
2389
|
init === null || init === void 0 ? void 0 : init(wrapper, content);
|
|
2022
2390
|
}
|
|
2023
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2024
2391
|
return function () {
|
|
2025
2392
|
cleanupWindowEvents === null || cleanupWindowEvents === void 0 ? void 0 : cleanupWindowEvents();
|
|
2026
2393
|
};
|
|
2394
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2027
2395
|
}, []);
|
|
2028
|
-
|
|
2029
|
-
|
|
2396
|
+
useEffect(function () {
|
|
2397
|
+
if (!infinite)
|
|
2398
|
+
return;
|
|
2399
|
+
var grid = gridRef.current;
|
|
2400
|
+
if (!grid)
|
|
2401
|
+
return;
|
|
2402
|
+
var sync = function () {
|
|
2403
|
+
var _a = instance.state, positionX = _a.positionX, positionY = _a.positionY;
|
|
2404
|
+
grid.style.backgroundPosition = "".concat(positionX, "px ").concat(positionY, "px");
|
|
2405
|
+
};
|
|
2406
|
+
sync();
|
|
2407
|
+
return instance.onChange(sync);
|
|
2408
|
+
}, [infinite, instance]);
|
|
2409
|
+
return (jsxs("div", __assign({}, wrapperProps, { ref: wrapperRef, className: "".concat(baseClasses.wrapperClass, " ").concat(styles.wrapper, " ").concat(wrapperClass), style: wrapperStyle }, { children: [infinite && (jsx("div", { ref: gridRef, className: styles.infiniteGrid, "aria-hidden": true })), jsx("div", __assign({}, contentProps, { ref: contentRef, className: "".concat(baseClasses.contentClass, " ").concat(styles.content, " ").concat(contentClass), style: __assign(__assign({}, contentStyle), { transform: getTransformStyles(instance.state.positionX, instance.state.positionY, instance.state.scale) }) }, { children: children }))] })));
|
|
2030
2410
|
};
|
|
2031
2411
|
|
|
2412
|
+
/**
|
|
2413
|
+
* Compute the overlap area between two axis-aligned rectangles.
|
|
2414
|
+
* Returns 0 when the rectangles do not intersect.
|
|
2415
|
+
*/
|
|
2416
|
+
function getOverlapArea(a, b) {
|
|
2417
|
+
var overlapX = Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x));
|
|
2418
|
+
var overlapY = Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));
|
|
2419
|
+
return overlapX * overlapY;
|
|
2420
|
+
}
|
|
2421
|
+
/**
|
|
2422
|
+
* Determine whether an element's content-space bounding box is visible
|
|
2423
|
+
* in the current viewport, accounting for transform, margin, and threshold.
|
|
2424
|
+
*/
|
|
2425
|
+
function isElementVisible(opts) {
|
|
2426
|
+
var elementX = opts.elementX, elementY = opts.elementY, elementWidth = opts.elementWidth, elementHeight = opts.elementHeight, scale = opts.scale, positionX = opts.positionX, positionY = opts.positionY, viewportWidth = opts.viewportWidth, viewportHeight = opts.viewportHeight, _a = opts.margin, margin = _a === void 0 ? 0 : _a, _b = opts.threshold, threshold = _b === void 0 ? 0 : _b;
|
|
2427
|
+
var viewport = {
|
|
2428
|
+
x: -margin,
|
|
2429
|
+
y: -margin,
|
|
2430
|
+
width: viewportWidth + 2 * margin,
|
|
2431
|
+
height: viewportHeight + 2 * margin,
|
|
2432
|
+
};
|
|
2433
|
+
var element = {
|
|
2434
|
+
x: elementX * scale + positionX,
|
|
2435
|
+
y: elementY * scale + positionY,
|
|
2436
|
+
width: elementWidth * scale,
|
|
2437
|
+
height: elementHeight * scale,
|
|
2438
|
+
};
|
|
2439
|
+
if (threshold <= 0) {
|
|
2440
|
+
var intersectsX = element.x < viewport.x + viewport.width &&
|
|
2441
|
+
element.x + element.width > viewport.x;
|
|
2442
|
+
var intersectsY = element.y < viewport.y + viewport.height &&
|
|
2443
|
+
element.y + element.height > viewport.y;
|
|
2444
|
+
return intersectsX && intersectsY;
|
|
2445
|
+
}
|
|
2446
|
+
var elementArea = element.width * element.height;
|
|
2447
|
+
if (elementArea <= 0)
|
|
2448
|
+
return false;
|
|
2449
|
+
var overlap = getOverlapArea(viewport, element);
|
|
2450
|
+
return overlap / elementArea >= threshold;
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
var Virtualize = React.forwardRef(function (_a, ref) {
|
|
2454
|
+
var x = _a.x, y = _a.y, width = _a.width, height = _a.height, _b = _a.margin, margin = _b === void 0 ? 0 : _b, _c = _a.threshold, threshold = _c === void 0 ? 0 : _c, _d = _a.placeholder, placeholder = _d === void 0 ? null : _d, onShow = _a.onShow, onHide = _a.onHide, children = _a.children, className = _a.className, style = _a.style;
|
|
2455
|
+
var instance = useContext(Context);
|
|
2456
|
+
var _e = useState(false), visible = _e[0], setVisible = _e[1];
|
|
2457
|
+
var visibleRef = useRef(false);
|
|
2458
|
+
var onShowRef = useRef(onShow);
|
|
2459
|
+
var onHideRef = useRef(onHide);
|
|
2460
|
+
onShowRef.current = onShow;
|
|
2461
|
+
onHideRef.current = onHide;
|
|
2462
|
+
useEffect(function () {
|
|
2463
|
+
var check = function () {
|
|
2464
|
+
var _a, _b;
|
|
2465
|
+
var wrapper = instance.wrapperComponent;
|
|
2466
|
+
if (!wrapper)
|
|
2467
|
+
return;
|
|
2468
|
+
var nowVisible = isElementVisible({
|
|
2469
|
+
elementX: x,
|
|
2470
|
+
elementY: y,
|
|
2471
|
+
elementWidth: width,
|
|
2472
|
+
elementHeight: height,
|
|
2473
|
+
scale: instance.state.scale,
|
|
2474
|
+
positionX: instance.state.positionX,
|
|
2475
|
+
positionY: instance.state.positionY,
|
|
2476
|
+
viewportWidth: wrapper.offsetWidth,
|
|
2477
|
+
viewportHeight: wrapper.offsetHeight,
|
|
2478
|
+
margin: margin,
|
|
2479
|
+
threshold: threshold,
|
|
2480
|
+
});
|
|
2481
|
+
if (nowVisible !== visibleRef.current) {
|
|
2482
|
+
visibleRef.current = nowVisible;
|
|
2483
|
+
setVisible(nowVisible);
|
|
2484
|
+
if (nowVisible) {
|
|
2485
|
+
(_a = onShowRef.current) === null || _a === void 0 ? void 0 : _a.call(onShowRef);
|
|
2486
|
+
}
|
|
2487
|
+
else {
|
|
2488
|
+
(_b = onHideRef.current) === null || _b === void 0 ? void 0 : _b.call(onHideRef);
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
};
|
|
2492
|
+
check();
|
|
2493
|
+
var unsubChange = instance.onChange(check);
|
|
2494
|
+
var unsubInit;
|
|
2495
|
+
if (!instance.wrapperComponent) {
|
|
2496
|
+
unsubInit = instance.onInit(function () { return check(); });
|
|
2497
|
+
}
|
|
2498
|
+
return function () {
|
|
2499
|
+
unsubChange();
|
|
2500
|
+
unsubInit === null || unsubInit === void 0 ? void 0 : unsubInit();
|
|
2501
|
+
};
|
|
2502
|
+
}, [instance, x, y, width, height, margin, threshold]);
|
|
2503
|
+
if (!visible) {
|
|
2504
|
+
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
2505
|
+
return placeholder ? jsx(Fragment, { children: placeholder }) : null;
|
|
2506
|
+
}
|
|
2507
|
+
return (jsx("div", __assign({ ref: ref, className: className, style: style }, { children: children })));
|
|
2508
|
+
});
|
|
2509
|
+
|
|
2032
2510
|
var useTransformContext = function () {
|
|
2033
2511
|
var libraryContext = useContext(Context);
|
|
2034
2512
|
if (!libraryContext) {
|
|
@@ -2059,6 +2537,7 @@ var useTransformInit = function (callback) {
|
|
|
2059
2537
|
unmount === null || unmount === void 0 ? void 0 : unmount();
|
|
2060
2538
|
unmountCallback === null || unmountCallback === void 0 ? void 0 : unmountCallback();
|
|
2061
2539
|
};
|
|
2540
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2062
2541
|
}, []);
|
|
2063
2542
|
};
|
|
2064
2543
|
|
|
@@ -2094,5 +2573,5 @@ function useTransformComponent(callback) {
|
|
|
2094
2573
|
return transformRender;
|
|
2095
2574
|
}
|
|
2096
2575
|
|
|
2097
|
-
export { Context, KeepScale, MiniMap, TransformComponent, TransformWrapper, getCenterPosition, getMatrixTransformStyles, getTransformStyles, useControls, useTransformComponent, useTransformContext, useTransformEffect, useTransformInit };
|
|
2576
|
+
export { Context, DeviceType, KeepScale, MiniMap, TransformComponent, TransformWrapper, Virtualize, getCenterPosition, getMatrixTransformStyles, getTransformStyles, roundScaleForTransform, useControls, useTransformComponent, useTransformContext, useTransformEffect, useTransformInit };
|
|
2098
2577
|
//# sourceMappingURL=index.esm.js.map
|