react-zoom-pan-pinch 3.6.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +770 -277
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +116 -22
- package/dist/index.esm.js +766 -269
- package/dist/index.esm.js.map +1 -1
- package/package.json +73 -60
- 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/stories/assets/big-image.jpeg +0 -0
- package/src/stories/assets/map.jpg +0 -0
- package/src/stories/assets/medium-image.jpg +0 -0
- package/src/stories/assets/pin.svg +1 -0
- package/src/stories/assets/small-image.jpg +0 -0
- package/src/stories/assets/svg-example.svg +14 -0
- package/src/stories/docs/DocTable.tsx +59 -0
- package/src/stories/docs/HandlerCards.tsx +102 -0
- package/src/stories/docs/Introduction.stories.mdx +135 -0
- package/src/stories/docs/PropTable.tsx +116 -0
- package/src/stories/docs/docs.module.css +370 -0
- package/src/stories/docs/handlers.stories.mdx +7 -0
- package/src/stories/docs/handlers.tsx +111 -0
- package/src/stories/docs/props.stories.mdx +11 -0
- package/src/stories/docs/props.tsx +571 -0
- package/src/stories/examples/axis-lock/axis-lock.stories.mdx +35 -0
- package/src/stories/examples/axis-lock/example.tsx +114 -0
- package/src/stories/examples/bounds/bounds.data.tsx +191 -0
- package/src/stories/examples/bounds/bounds.stories.mdx +99 -0
- package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +206 -0
- package/src/stories/examples/cinema/cinema-data.tsx +578 -0
- package/src/stories/examples/cinema/cinema.stories.mdx +30 -0
- package/src/stories/examples/cinema/example.tsx +378 -0
- package/src/stories/examples/cinema/image.png +0 -0
- package/src/stories/examples/content/content.stories.mdx +172 -0
- package/src/stories/examples/content/mixed-content.data.tsx +624 -0
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +34 -0
- package/src/stories/examples/content-rerendering/example.tsx +631 -0
- package/src/stories/examples/controls/controls.stories.mdx +120 -0
- package/src/stories/examples/image/example.tsx +149 -0
- package/src/stories/examples/image/image.stories.mdx +46 -0
- package/src/stories/examples/image-annotations/example.tsx +1442 -0
- package/src/stories/examples/image-annotations/image-annotations.stories.mdx +39 -0
- package/src/stories/examples/image-responsive/example.tsx +152 -0
- package/src/stories/examples/image-responsive/image-responsive.stories.mdx +51 -0
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +107 -0
- package/src/stories/examples/initial-transform/example.tsx +233 -0
- package/src/stories/examples/initial-transform/initial-transform.stories.mdx +37 -0
- package/src/stories/examples/keep-scale/example.tsx +882 -0
- package/src/stories/examples/keep-scale/keep-scale.stories.mdx +30 -0
- package/src/stories/examples/keep-scale/map.stories.mdx +28 -0
- package/src/stories/examples/medical-viewer/chest-xray.tsx +246 -0
- package/src/stories/examples/medical-viewer/example.tsx +690 -0
- package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +49 -0
- package/src/stories/examples/mini-map/example.tsx +122 -0
- package/src/stories/examples/mini-map/mini-map.stories.mdx +26 -0
- package/src/stories/examples/miro/example.tsx +1573 -0
- package/src/stories/examples/miro/miro.stories.mdx +31 -0
- package/src/stories/examples/padding/example.tsx +147 -0
- package/src/stories/examples/padding/padding.stories.mdx +35 -0
- package/src/stories/examples/product-card/example.tsx +594 -0
- package/src/stories/examples/product-card/product-card.stories.mdx +29 -0
- package/src/stories/examples/stadium/example.tsx +1040 -0
- package/src/stories/examples/stadium/stadium-data.ts +224 -0
- package/src/stories/examples/stadium/stadium.stories.mdx +32 -0
- package/src/stories/examples/stress/example.tsx +59 -0
- package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
- package/src/stories/examples/svg-zoom-to-element/creativity.svg +143 -0
- package/src/stories/examples/svg-zoom-to-element/example.tsx +95 -0
- package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +28 -0
- package/src/stories/examples/text-selection/example.tsx +221 -0
- package/src/stories/examples/text-selection/text-selection.stories.mdx +31 -0
- package/src/stories/examples/velocity/example.tsx +908 -0
- package/src/stories/examples/velocity/velocity.stories.mdx +35 -0
- package/src/stories/examples/virtualize/example.tsx +239 -0
- package/src/stories/examples/virtualize/virtualize.stories.mdx +84 -0
- package/src/stories/examples/zoom-to-element/example.tsx +219 -0
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +31 -0
- package/src/stories/hooks/use-controls.stories.mdx +86 -0
- package/src/stories/hooks/use-transform-component.stories.mdx +108 -0
- package/src/stories/hooks/use-transform-context.stories.mdx +92 -0
- package/src/stories/hooks/use-transform-effect.stories.mdx +114 -0
- package/src/stories/hooks/use-transform-init.stories.mdx +105 -0
- package/src/stories/types/args.types.ts +192 -0
- package/src/stories/utils/args.utils.ts +35 -0
- package/src/stories/utils/bounds-overlay.tsx +168 -0
- package/src/stories/utils/code.utils.tsx +22 -0
- package/src/stories/utils/controls.utils.tsx +347 -0
- package/src/stories/utils/index.ts +5 -0
- package/src/stories/utils/styles.module.css +223 -0
- package/src/stories/utils/viewer.styles.ts +34 -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) {
|
|
@@ -520,44 +598,55 @@ function handlePanningStart(contextInstance, event) {
|
|
|
520
598
|
handlePanningSetup(contextInstance, event);
|
|
521
599
|
}
|
|
522
600
|
}
|
|
523
|
-
function handleAlignToBounds(contextInstance) {
|
|
524
|
-
var scale = contextInstance.
|
|
525
|
-
var _a = contextInstance.setup, minScale = _a.minScale,
|
|
526
|
-
var disabled =
|
|
601
|
+
function handleAlignToBounds(contextInstance, customAnimationTime) {
|
|
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;
|
|
530
608
|
var targetState = handlePanToBounds(contextInstance);
|
|
531
609
|
if (targetState) {
|
|
532
|
-
animate(contextInstance, targetState, animationTime, animationType);
|
|
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) {
|
|
@@ -640,7 +732,12 @@ function __spreadArray(to, from, pack) {
|
|
|
640
732
|
}
|
|
641
733
|
}
|
|
642
734
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
643
|
-
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
738
|
+
var e = new Error(message);
|
|
739
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
740
|
+
};
|
|
644
741
|
|
|
645
742
|
var initialState = {
|
|
646
743
|
previousScale: 1,
|
|
@@ -661,15 +758,23 @@ var initialSetup = {
|
|
|
661
758
|
centerOnInit: false,
|
|
662
759
|
disablePadding: false,
|
|
663
760
|
smooth: true,
|
|
761
|
+
detached: false,
|
|
664
762
|
wheel: {
|
|
665
|
-
step: 0.
|
|
763
|
+
step: 0.015,
|
|
666
764
|
disabled: false,
|
|
667
|
-
smoothStep: 0.001,
|
|
668
765
|
wheelDisabled: false,
|
|
669
766
|
touchPadDisabled: false,
|
|
670
767
|
activationKeys: [],
|
|
671
768
|
excluded: [],
|
|
672
769
|
},
|
|
770
|
+
trackPadPanning: {
|
|
771
|
+
disabled: true,
|
|
772
|
+
velocityDisabled: false,
|
|
773
|
+
lockAxisX: false,
|
|
774
|
+
lockAxisY: false,
|
|
775
|
+
activationKeys: [],
|
|
776
|
+
excluded: [],
|
|
777
|
+
},
|
|
673
778
|
panning: {
|
|
674
779
|
disabled: false,
|
|
675
780
|
velocityDisabled: false,
|
|
@@ -678,13 +783,13 @@ var initialSetup = {
|
|
|
678
783
|
allowLeftClickPan: true,
|
|
679
784
|
allowMiddleClickPan: true,
|
|
680
785
|
allowRightClickPan: true,
|
|
681
|
-
wheelPanning: false,
|
|
682
786
|
activationKeys: [],
|
|
683
787
|
excluded: [],
|
|
684
788
|
},
|
|
685
789
|
pinch: {
|
|
686
790
|
step: 5,
|
|
687
791
|
disabled: false,
|
|
792
|
+
allowPanning: true,
|
|
688
793
|
excluded: [],
|
|
689
794
|
},
|
|
690
795
|
doubleClick: {
|
|
@@ -701,7 +806,7 @@ var initialSetup = {
|
|
|
701
806
|
animationTime: 200,
|
|
702
807
|
animationType: "easeOut",
|
|
703
808
|
},
|
|
704
|
-
|
|
809
|
+
autoAlignment: {
|
|
705
810
|
disabled: false,
|
|
706
811
|
sizeX: 100,
|
|
707
812
|
sizeY: 100,
|
|
@@ -711,10 +816,14 @@ var initialSetup = {
|
|
|
711
816
|
},
|
|
712
817
|
velocityAnimation: {
|
|
713
818
|
disabled: false,
|
|
714
|
-
|
|
715
|
-
|
|
819
|
+
sensitivityMouse: 1,
|
|
820
|
+
sensitivityTouch: 1.2,
|
|
821
|
+
maxStrengthMouse: 20,
|
|
822
|
+
maxStrengthTouch: 40,
|
|
823
|
+
inertia: 1,
|
|
824
|
+
animationTime: 300,
|
|
825
|
+
maxAnimationTime: 800,
|
|
716
826
|
animationType: "easeOut",
|
|
717
|
-
equalToMove: true,
|
|
718
827
|
},
|
|
719
828
|
};
|
|
720
829
|
var baseClasses = {
|
|
@@ -723,39 +832,49 @@ var baseClasses = {
|
|
|
723
832
|
};
|
|
724
833
|
|
|
725
834
|
var createState = function (props) {
|
|
726
|
-
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);
|
|
727
842
|
return {
|
|
728
|
-
previousScale:
|
|
729
|
-
scale:
|
|
730
|
-
positionX:
|
|
731
|
-
positionY:
|
|
843
|
+
previousScale: scale,
|
|
844
|
+
scale: scale,
|
|
845
|
+
positionX: positionX,
|
|
846
|
+
positionY: positionY,
|
|
732
847
|
};
|
|
733
848
|
};
|
|
734
849
|
var createSetup = function (props) {
|
|
735
850
|
var newSetup = __assign({}, initialSetup);
|
|
736
851
|
Object.keys(props).forEach(function (key) {
|
|
737
|
-
var
|
|
738
|
-
var
|
|
852
|
+
var k = key;
|
|
853
|
+
var validValue = typeof props[k] !== "undefined";
|
|
854
|
+
var validParameter = typeof initialSetup[k] !== "undefined";
|
|
739
855
|
if (validParameter && validValue) {
|
|
740
|
-
var dataType = Object.prototype.toString.call(initialSetup[
|
|
856
|
+
var dataType = Object.prototype.toString.call(initialSetup[k]);
|
|
741
857
|
var isObject = dataType === "[object Object]";
|
|
742
858
|
var isArray = dataType === "[object Array]";
|
|
743
859
|
if (isObject) {
|
|
744
|
-
newSetup[
|
|
860
|
+
newSetup[k] = __assign(__assign({}, initialSetup[k]), props[k]);
|
|
745
861
|
}
|
|
746
862
|
else if (isArray) {
|
|
747
|
-
newSetup[
|
|
863
|
+
newSetup[k] = __spreadArray(__spreadArray([], initialSetup[k], true), props[k], true);
|
|
748
864
|
}
|
|
749
865
|
else {
|
|
750
|
-
newSetup[
|
|
866
|
+
newSetup[k] = props[k];
|
|
751
867
|
}
|
|
752
868
|
}
|
|
753
869
|
});
|
|
870
|
+
if (newSetup.minScale <= 0) {
|
|
871
|
+
newSetup.minScale = 1e-7;
|
|
872
|
+
}
|
|
754
873
|
return newSetup;
|
|
755
874
|
};
|
|
756
875
|
|
|
757
876
|
var handleCalculateButtonZoom = function (contextInstance, delta, step) {
|
|
758
|
-
var scale = contextInstance.
|
|
877
|
+
var scale = contextInstance.state.scale;
|
|
759
878
|
var wrapperComponent = contextInstance.wrapperComponent, setup = contextInstance.setup;
|
|
760
879
|
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation, smooth = setup.smooth;
|
|
761
880
|
var size = zoomAnimation.size;
|
|
@@ -769,10 +888,13 @@ var handleCalculateButtonZoom = function (contextInstance, delta, step) {
|
|
|
769
888
|
return newScale;
|
|
770
889
|
};
|
|
771
890
|
function handleZoomToViewCenter(contextInstance, delta, step, animationTime, animationType) {
|
|
891
|
+
var _a, _b;
|
|
772
892
|
var wrapperComponent = contextInstance.wrapperComponent;
|
|
773
|
-
var
|
|
893
|
+
var _c = contextInstance.state, scale = _c.scale, positionX = _c.positionX, positionY = _c.positionY;
|
|
894
|
+
var zoomAnimation = contextInstance.setup.zoomAnimation;
|
|
774
895
|
if (!wrapperComponent)
|
|
775
896
|
return console.error("No WrapperComponent found");
|
|
897
|
+
var effectiveAnimationTime = zoomAnimation.disabled ? 0 : animationTime;
|
|
776
898
|
var wrapperWidth = wrapperComponent.offsetWidth;
|
|
777
899
|
var wrapperHeight = wrapperComponent.offsetHeight;
|
|
778
900
|
var mouseX = (wrapperWidth / 2 - positionX) / scale;
|
|
@@ -782,17 +904,38 @@ function handleZoomToViewCenter(contextInstance, delta, step, animationTime, ani
|
|
|
782
904
|
if (!targetState) {
|
|
783
905
|
return console.error("Error during zoom event. New transformation state was not calculated.");
|
|
784
906
|
}
|
|
785
|
-
|
|
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
|
+
}
|
|
786
921
|
}
|
|
787
922
|
function resetTransformations(contextInstance, animationTime, animationType, onResetTransformation) {
|
|
788
|
-
var
|
|
789
|
-
var
|
|
923
|
+
var _a, _b;
|
|
924
|
+
var setup = contextInstance.setup, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
925
|
+
var limitToBounds = setup.limitToBounds, centerOnInit = setup.centerOnInit;
|
|
790
926
|
var initialTransformation = createState(contextInstance.props);
|
|
791
|
-
var
|
|
927
|
+
var _c = contextInstance.state, scale = _c.scale, positionX = _c.positionX, positionY = _c.positionY;
|
|
792
928
|
if (!wrapperComponent)
|
|
793
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
|
+
}
|
|
794
937
|
var newBounds = calculateBounds(contextInstance, initialTransformation.scale);
|
|
795
|
-
var boundedPositions = getMouseBoundedPosition(
|
|
938
|
+
var boundedPositions = getMouseBoundedPosition(targetPositionX, targetPositionY, newBounds, limitToBounds, 0, 0, wrapperComponent);
|
|
796
939
|
var newState = {
|
|
797
940
|
scale: initialTransformation.scale,
|
|
798
941
|
positionX: boundedPositions.x,
|
|
@@ -804,7 +947,20 @@ function resetTransformations(contextInstance, animationTime, animationType, onR
|
|
|
804
947
|
return;
|
|
805
948
|
}
|
|
806
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);
|
|
807
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
|
+
}
|
|
808
964
|
}
|
|
809
965
|
function getOffset(element, wrapper, content, state) {
|
|
810
966
|
var offset = element.getBoundingClientRect();
|
|
@@ -817,25 +973,27 @@ function getOffset(element, wrapper, content, state) {
|
|
|
817
973
|
y: (offset.y - contentOffset.y + yOff) / state.scale,
|
|
818
974
|
};
|
|
819
975
|
}
|
|
820
|
-
function calculateZoomToNode(contextInstance, node, customZoom) {
|
|
821
|
-
|
|
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;
|
|
822
980
|
var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, minScale = _a.minScale, maxScale = _a.maxScale;
|
|
823
981
|
if (!wrapperComponent || !contentComponent)
|
|
824
|
-
return
|
|
982
|
+
return state;
|
|
825
983
|
var wrapperRect = wrapperComponent.getBoundingClientRect();
|
|
826
984
|
var nodeRect = node.getBoundingClientRect();
|
|
827
|
-
var nodeOffset = getOffset(node, wrapperComponent, contentComponent,
|
|
985
|
+
var nodeOffset = getOffset(node, wrapperComponent, contentComponent, state);
|
|
828
986
|
var nodeLeft = nodeOffset.x;
|
|
829
987
|
var nodeTop = nodeOffset.y;
|
|
830
|
-
var nodeWidth = nodeRect.width /
|
|
831
|
-
var nodeHeight = nodeRect.height /
|
|
988
|
+
var nodeWidth = nodeRect.width / state.scale;
|
|
989
|
+
var nodeHeight = nodeRect.height / state.scale;
|
|
832
990
|
var scaleX = wrapperComponent.offsetWidth / nodeWidth;
|
|
833
991
|
var scaleY = wrapperComponent.offsetHeight / nodeHeight;
|
|
834
992
|
var newScale = checkZoomBounds(customZoom || Math.min(scaleX, scaleY), minScale, maxScale, 0, false);
|
|
835
993
|
var offsetX = (wrapperRect.width - nodeWidth * newScale) / 2;
|
|
836
994
|
var offsetY = (wrapperRect.height - nodeHeight * newScale) / 2;
|
|
837
|
-
var newPositionX = (wrapperRect.left - nodeLeft) * newScale + offsetX;
|
|
838
|
-
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;
|
|
839
997
|
var bounds = calculateBounds(contextInstance, newScale);
|
|
840
998
|
var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, 0, 0, wrapperComponent), x = _b.x, y = _b.y;
|
|
841
999
|
return { positionX: x, positionY: y, scale: newScale };
|
|
@@ -861,7 +1019,7 @@ var setTransform = function (contextInstance) {
|
|
|
861
1019
|
return function (newPositionX, newPositionY, newScale, animationTime, animationType) {
|
|
862
1020
|
if (animationTime === void 0) { animationTime = 300; }
|
|
863
1021
|
if (animationType === void 0) { animationType = "easeOut"; }
|
|
864
|
-
var _a = contextInstance.
|
|
1022
|
+
var _a = contextInstance.state, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
|
|
865
1023
|
var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
866
1024
|
var disabled = contextInstance.setup.disabled;
|
|
867
1025
|
if (disabled || !wrapperComponent || !contentComponent)
|
|
@@ -885,22 +1043,24 @@ var centerView = function (contextInstance) {
|
|
|
885
1043
|
return function (scale, animationTime, animationType) {
|
|
886
1044
|
if (animationTime === void 0) { animationTime = 200; }
|
|
887
1045
|
if (animationType === void 0) { animationType = "easeOut"; }
|
|
888
|
-
var
|
|
1046
|
+
var state = contextInstance.state, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
|
|
889
1047
|
if (wrapperComponent && contentComponent) {
|
|
890
|
-
var targetState = getCenterPosition(scale ||
|
|
1048
|
+
var targetState = getCenterPosition(scale || state.scale, wrapperComponent, contentComponent);
|
|
891
1049
|
animate(contextInstance, targetState, animationTime, animationType);
|
|
892
1050
|
}
|
|
893
1051
|
};
|
|
894
1052
|
};
|
|
895
1053
|
var zoomToElement = function (contextInstance) {
|
|
896
|
-
return function (node, scale, animationTime, animationType) {
|
|
1054
|
+
return function (node, scale, animationTime, animationType, offsetX, offsetY) {
|
|
897
1055
|
if (animationTime === void 0) { animationTime = 600; }
|
|
898
1056
|
if (animationType === void 0) { animationType = "easeOut"; }
|
|
1057
|
+
if (offsetX === void 0) { offsetX = 0; }
|
|
1058
|
+
if (offsetY === void 0) { offsetY = 0; }
|
|
899
1059
|
handleCancelAnimation(contextInstance);
|
|
900
1060
|
var wrapperComponent = contextInstance.wrapperComponent;
|
|
901
1061
|
var target = typeof node === "string" ? document.getElementById(node) : node;
|
|
902
1062
|
if (wrapperComponent && target && wrapperComponent.contains(target)) {
|
|
903
|
-
var targetState = calculateZoomToNode(contextInstance, target, scale);
|
|
1063
|
+
var targetState = calculateZoomToNode(contextInstance, target, scale, offsetX, offsetY);
|
|
904
1064
|
animate(contextInstance, targetState, animationTime, animationType);
|
|
905
1065
|
}
|
|
906
1066
|
};
|
|
@@ -909,6 +1069,7 @@ var zoomToElement = function (contextInstance) {
|
|
|
909
1069
|
var getControls = function (contextInstance) {
|
|
910
1070
|
return {
|
|
911
1071
|
instance: contextInstance,
|
|
1072
|
+
state: contextInstance.state,
|
|
912
1073
|
zoomIn: zoomIn(contextInstance),
|
|
913
1074
|
zoomOut: zoomOut(contextInstance),
|
|
914
1075
|
setTransform: setTransform(contextInstance),
|
|
@@ -920,7 +1081,7 @@ var getControls = function (contextInstance) {
|
|
|
920
1081
|
var getState = function (contextInstance) {
|
|
921
1082
|
return {
|
|
922
1083
|
instance: contextInstance,
|
|
923
|
-
state: contextInstance.
|
|
1084
|
+
state: contextInstance.state,
|
|
924
1085
|
};
|
|
925
1086
|
};
|
|
926
1087
|
var getContext = function (contextInstance) {
|
|
@@ -964,9 +1125,14 @@ var cancelTimeout = function (timeout) {
|
|
|
964
1125
|
}
|
|
965
1126
|
};
|
|
966
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
|
+
};
|
|
967
1132
|
var getTransformStyles = function (x, y, scale) {
|
|
968
1133
|
// Standard translate prevents blurry svg on the safari
|
|
969
|
-
|
|
1134
|
+
var s = roundScaleForTransform(scale);
|
|
1135
|
+
return "translate(".concat(x, "px, ").concat(y, "px) scale(").concat(s, ")");
|
|
970
1136
|
};
|
|
971
1137
|
var getMatrixTransformStyles = function (x, y, scale) {
|
|
972
1138
|
// The shorthand for matrix does not work for Safari hence the need to explicitly use matrix3d
|
|
@@ -991,6 +1157,16 @@ var getCenterPosition = function (scale, wrapperComponent, contentComponent) {
|
|
|
991
1157
|
};
|
|
992
1158
|
};
|
|
993
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
|
+
}
|
|
994
1170
|
function mergeRefs(refs) {
|
|
995
1171
|
return function (value) {
|
|
996
1172
|
refs.forEach(function (ref) {
|
|
@@ -1019,6 +1195,31 @@ var isWheelAllowed = function (contextInstance, event) {
|
|
|
1019
1195
|
var isExcluded = isExcludedNode(target, excluded);
|
|
1020
1196
|
if (isExcluded)
|
|
1021
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;
|
|
1022
1223
|
return true;
|
|
1023
1224
|
};
|
|
1024
1225
|
var getDeltaY = function (event) {
|
|
@@ -1054,7 +1255,7 @@ function getMousePosition(event, contentComponent, scale) {
|
|
|
1054
1255
|
};
|
|
1055
1256
|
}
|
|
1056
1257
|
var handleCalculateWheelZoom = function (contextInstance, delta, step, disable, getTarget) {
|
|
1057
|
-
var scale = contextInstance.
|
|
1258
|
+
var scale = contextInstance.state.scale;
|
|
1058
1259
|
var wrapperComponent = contextInstance.wrapperComponent, setup = contextInstance.setup;
|
|
1059
1260
|
var maxScale = setup.maxScale, minScale = setup.minScale, zoomAnimation = setup.zoomAnimation, disablePadding = setup.disablePadding;
|
|
1060
1261
|
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
@@ -1065,12 +1266,12 @@ var handleCalculateWheelZoom = function (contextInstance, delta, step, disable,
|
|
|
1065
1266
|
if (getTarget)
|
|
1066
1267
|
return targetScale;
|
|
1067
1268
|
var paddingEnabled = disable ? false : !disabled;
|
|
1068
|
-
var newScale = checkZoomBounds(
|
|
1269
|
+
var newScale = checkZoomBounds(targetScale, minScale, maxScale, size, paddingEnabled && !disablePadding);
|
|
1069
1270
|
return newScale;
|
|
1070
1271
|
};
|
|
1071
1272
|
var handleWheelZoomStop = function (contextInstance, event) {
|
|
1072
1273
|
var previousWheelEvent = contextInstance.previousWheelEvent;
|
|
1073
|
-
var scale = contextInstance.
|
|
1274
|
+
var scale = contextInstance.state.scale;
|
|
1074
1275
|
var _a = contextInstance.setup, maxScale = _a.maxScale, minScale = _a.minScale;
|
|
1075
1276
|
if (!previousWheelEvent)
|
|
1076
1277
|
return false;
|
|
@@ -1102,7 +1303,7 @@ var isPinchStartAllowed = function (contextInstance, event) {
|
|
|
1102
1303
|
var isPinchAllowed = function (contextInstance) {
|
|
1103
1304
|
var disabled = contextInstance.setup.pinch.disabled;
|
|
1104
1305
|
var isInitialized = contextInstance.isInitialized, pinchStartDistance = contextInstance.pinchStartDistance;
|
|
1105
|
-
var isAllowed = isInitialized && !disabled && pinchStartDistance;
|
|
1306
|
+
var isAllowed = isInitialized && !disabled && pinchStartDistance !== null;
|
|
1106
1307
|
if (!isAllowed)
|
|
1107
1308
|
return false;
|
|
1108
1309
|
return true;
|
|
@@ -1110,10 +1311,10 @@ var isPinchAllowed = function (contextInstance) {
|
|
|
1110
1311
|
var calculateTouchMidPoint = function (event, scale, contentComponent) {
|
|
1111
1312
|
var contentRect = contentComponent.getBoundingClientRect();
|
|
1112
1313
|
var touches = event.touches;
|
|
1113
|
-
var firstPointX =
|
|
1114
|
-
var firstPointY =
|
|
1115
|
-
var secondPointX =
|
|
1116
|
-
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;
|
|
1117
1318
|
return {
|
|
1118
1319
|
x: (firstPointX + secondPointX) / 2 / scale,
|
|
1119
1320
|
y: (firstPointY + secondPointY) / 2 / scale,
|
|
@@ -1123,19 +1324,24 @@ var getTouchDistance = function (event) {
|
|
|
1123
1324
|
return Math.sqrt(Math.pow((event.touches[0].pageX - event.touches[1].pageX), 2) +
|
|
1124
1325
|
Math.pow((event.touches[0].pageY - event.touches[1].pageY), 2));
|
|
1125
1326
|
};
|
|
1327
|
+
var DEFAULT_PINCH_STEP = 5;
|
|
1126
1328
|
var calculatePinchZoom = function (contextInstance, currentDistance) {
|
|
1127
1329
|
var pinchStartScale = contextInstance.pinchStartScale, pinchStartDistance = contextInstance.pinchStartDistance, setup = contextInstance.setup;
|
|
1128
|
-
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;
|
|
1129
1331
|
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
1130
|
-
|
|
1332
|
+
var step = pinch.step;
|
|
1333
|
+
if (!pinchStartScale || pinchStartDistance === null) {
|
|
1131
1334
|
throw new Error("Pinch touches distance was not provided");
|
|
1132
1335
|
}
|
|
1133
1336
|
if (currentDistance < 0) {
|
|
1134
|
-
return contextInstance.
|
|
1337
|
+
return contextInstance.state.scale;
|
|
1135
1338
|
}
|
|
1136
1339
|
var touchProportion = currentDistance / pinchStartDistance;
|
|
1137
|
-
var
|
|
1138
|
-
|
|
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);
|
|
1139
1345
|
};
|
|
1140
1346
|
|
|
1141
1347
|
var wheelStopEventTime = 160;
|
|
@@ -1150,18 +1356,18 @@ var handleWheelStart = function (contextInstance, event) {
|
|
|
1150
1356
|
};
|
|
1151
1357
|
var handleWheelZoom = function (contextInstance, event) {
|
|
1152
1358
|
var _a = contextInstance.props, onWheel = _a.onWheel, onZoom = _a.onZoom;
|
|
1153
|
-
var contentComponent = contextInstance.contentComponent, setup = contextInstance.setup,
|
|
1154
|
-
var scale =
|
|
1359
|
+
var contentComponent = contextInstance.contentComponent, setup = contextInstance.setup, state = contextInstance.state;
|
|
1360
|
+
var scale = state.scale;
|
|
1155
1361
|
var limitToBounds = setup.limitToBounds, centerZoomedOut = setup.centerZoomedOut, zoomAnimation = setup.zoomAnimation, wheel = setup.wheel, disablePadding = setup.disablePadding, smooth = setup.smooth;
|
|
1156
1362
|
var size = zoomAnimation.size, disabled = zoomAnimation.disabled;
|
|
1157
|
-
var step = wheel.step
|
|
1363
|
+
var step = wheel.step;
|
|
1158
1364
|
if (!contentComponent) {
|
|
1159
1365
|
throw new Error("Component not mounted");
|
|
1160
1366
|
}
|
|
1161
1367
|
event.preventDefault();
|
|
1162
1368
|
event.stopPropagation();
|
|
1163
1369
|
var delta = getDelta(event, null);
|
|
1164
|
-
var zoomStep = smooth ?
|
|
1370
|
+
var zoomStep = smooth ? step * Math.abs(event.deltaY) : step;
|
|
1165
1371
|
var newScale = handleCalculateWheelZoom(contextInstance, delta, zoomStep, !event.ctrlKey);
|
|
1166
1372
|
// if scale not change
|
|
1167
1373
|
if (scale === newScale)
|
|
@@ -1172,7 +1378,7 @@ var handleWheelZoom = function (contextInstance, event) {
|
|
|
1172
1378
|
var isLimitedToBounds = limitToBounds && isPaddingDisabled;
|
|
1173
1379
|
var _b = handleCalculateZoomPositions(contextInstance, mousePosition.x, mousePosition.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
|
|
1174
1380
|
contextInstance.previousWheelEvent = event;
|
|
1175
|
-
contextInstance.
|
|
1381
|
+
contextInstance.setState(newScale, x, y);
|
|
1176
1382
|
handleCallback(getContext(contextInstance), event, onWheel);
|
|
1177
1383
|
handleCallback(getContext(contextInstance), event, onZoom);
|
|
1178
1384
|
};
|
|
@@ -1199,6 +1405,37 @@ var handleWheelStop = function (contextInstance, event) {
|
|
|
1199
1405
|
}, wheelStopEventTime);
|
|
1200
1406
|
}
|
|
1201
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
|
+
};
|
|
1202
1439
|
|
|
1203
1440
|
var getTouchCenter = function (event) {
|
|
1204
1441
|
var totalX = 0;
|
|
@@ -1217,18 +1454,18 @@ var handlePinchStart = function (contextInstance, event) {
|
|
|
1217
1454
|
var distance = getTouchDistance(event);
|
|
1218
1455
|
contextInstance.pinchStartDistance = distance;
|
|
1219
1456
|
contextInstance.lastDistance = distance;
|
|
1220
|
-
contextInstance.pinchStartScale = contextInstance.
|
|
1457
|
+
contextInstance.pinchStartScale = contextInstance.state.scale;
|
|
1221
1458
|
contextInstance.isPanning = false;
|
|
1222
|
-
|
|
1223
|
-
contextInstance.
|
|
1224
|
-
contextInstance.pinchLastCenterY = center.y;
|
|
1459
|
+
contextInstance.isPinching = true;
|
|
1460
|
+
contextInstance.pinchPreviousCenter = getTouchCenter(event);
|
|
1225
1461
|
handleCancelAnimation(contextInstance);
|
|
1226
1462
|
};
|
|
1227
1463
|
var handlePinchZoom = function (contextInstance, event) {
|
|
1228
|
-
var contentComponent = contextInstance.contentComponent, pinchStartDistance = contextInstance.pinchStartDistance, wrapperComponent = contextInstance.wrapperComponent;
|
|
1229
|
-
var scale = contextInstance.
|
|
1230
|
-
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;
|
|
1231
1467
|
var disabled = zoomAnimation.disabled, size = zoomAnimation.size;
|
|
1468
|
+
var allowPanning = pinch.allowPanning;
|
|
1232
1469
|
// if one finger starts from outside of wrapper
|
|
1233
1470
|
if (pinchStartDistance === null || !contentComponent)
|
|
1234
1471
|
return;
|
|
@@ -1240,25 +1477,30 @@ var handlePinchZoom = function (contextInstance, event) {
|
|
|
1240
1477
|
var newScale = calculatePinchZoom(contextInstance, currentDistance);
|
|
1241
1478
|
var center = getTouchCenter(event);
|
|
1242
1479
|
// pan should be scale invariant.
|
|
1243
|
-
var
|
|
1244
|
-
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;
|
|
1245
1483
|
if (newScale === scale && panX === 0 && panY === 0)
|
|
1246
1484
|
return;
|
|
1247
|
-
contextInstance.
|
|
1248
|
-
contextInstance.pinchLastCenterY = center.y;
|
|
1485
|
+
contextInstance.pinchPreviousCenter = center;
|
|
1249
1486
|
var bounds = handleCalculateBounds(contextInstance, newScale);
|
|
1250
1487
|
var isPaddingDisabled = disabled || size === 0 || centerZoomedOut;
|
|
1251
1488
|
var isLimitedToBounds = limitToBounds && isPaddingDisabled;
|
|
1252
1489
|
var _b = handleCalculateZoomPositions(contextInstance, midPoint.x, midPoint.y, newScale, bounds, isLimitedToBounds), x = _b.x, y = _b.y;
|
|
1253
1490
|
contextInstance.pinchMidpoint = midPoint;
|
|
1254
1491
|
contextInstance.lastDistance = currentDistance;
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
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
|
+
}
|
|
1262
1504
|
};
|
|
1263
1505
|
var handlePinchStop = function (contextInstance) {
|
|
1264
1506
|
var pinchMidpoint = contextInstance.pinchMidpoint;
|
|
@@ -1267,6 +1509,7 @@ var handlePinchStop = function (contextInstance) {
|
|
|
1267
1509
|
contextInstance.pinchMidpoint = null;
|
|
1268
1510
|
contextInstance.pinchStartScale = null;
|
|
1269
1511
|
contextInstance.pinchStartDistance = null;
|
|
1512
|
+
contextInstance.isPinching = false;
|
|
1270
1513
|
handleAlignToScaleBounds(contextInstance, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.x, pinchMidpoint === null || pinchMidpoint === void 0 ? void 0 : pinchMidpoint.y);
|
|
1271
1514
|
};
|
|
1272
1515
|
|
|
@@ -1295,8 +1538,8 @@ function getDoubleClickScale(mode, scale) {
|
|
|
1295
1538
|
return mode === "zoomOut" ? -1 : 1;
|
|
1296
1539
|
}
|
|
1297
1540
|
function handleDoubleClick(contextInstance, event) {
|
|
1298
|
-
var setup = contextInstance.setup, doubleClickStopEventTimer = contextInstance.doubleClickStopEventTimer,
|
|
1299
|
-
var scale =
|
|
1541
|
+
var setup = contextInstance.setup, doubleClickStopEventTimer = contextInstance.doubleClickStopEventTimer, state = contextInstance.state, contentComponent = contextInstance.contentComponent;
|
|
1542
|
+
var scale = state.scale;
|
|
1300
1543
|
var _a = contextInstance.props, onZoomStart = _a.onZoomStart, onZoom = _a.onZoom;
|
|
1301
1544
|
var _b = setup.doubleClick, disabled = _b.disabled, mode = _b.mode, step = _b.step, animationTime = _b.animationTime, animationType = _b.animationType;
|
|
1302
1545
|
if (disabled)
|
|
@@ -1308,7 +1551,7 @@ function handleDoubleClick(contextInstance, event) {
|
|
|
1308
1551
|
}
|
|
1309
1552
|
if (!contentComponent)
|
|
1310
1553
|
return console.error("No ContentComponent found");
|
|
1311
|
-
var delta = getDoubleClickScale(mode, contextInstance.
|
|
1554
|
+
var delta = getDoubleClickScale(mode, contextInstance.state.scale);
|
|
1312
1555
|
var newScale = handleCalculateButtonZoom(contextInstance, delta, step);
|
|
1313
1556
|
// stop execution when scale didn't change
|
|
1314
1557
|
if (scale === newScale)
|
|
@@ -1341,10 +1584,9 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1341
1584
|
function ZoomPanPinch(props) {
|
|
1342
1585
|
var _this = this;
|
|
1343
1586
|
this.mounted = true;
|
|
1344
|
-
this.pinchLastCenterX = null;
|
|
1345
|
-
this.pinchLastCenterY = null;
|
|
1346
1587
|
this.onChangeCallbacks = new Set();
|
|
1347
1588
|
this.onInitCallbacks = new Set();
|
|
1589
|
+
this.onTransformCallbacks = new Set();
|
|
1348
1590
|
// Components
|
|
1349
1591
|
this.wrapperComponent = null;
|
|
1350
1592
|
this.contentComponent = null;
|
|
@@ -1359,13 +1601,16 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1359
1601
|
this.isPanning = false;
|
|
1360
1602
|
this.isWheelPanning = false;
|
|
1361
1603
|
this.startCoords = null;
|
|
1604
|
+
this.panStartPosition = null;
|
|
1362
1605
|
this.lastTouch = null;
|
|
1363
1606
|
// pinch helpers
|
|
1607
|
+
this.isPinching = false;
|
|
1364
1608
|
this.distance = null;
|
|
1365
1609
|
this.lastDistance = null;
|
|
1366
1610
|
this.pinchStartDistance = null;
|
|
1367
1611
|
this.pinchStartScale = null;
|
|
1368
1612
|
this.pinchMidpoint = null;
|
|
1613
|
+
this.pinchPreviousCenter = null;
|
|
1369
1614
|
// double click helpers
|
|
1370
1615
|
this.doubleClickStopEventTimer = null;
|
|
1371
1616
|
// velocity helpers
|
|
@@ -1373,9 +1618,8 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1373
1618
|
this.velocityTime = null;
|
|
1374
1619
|
this.lastMousePosition = null;
|
|
1375
1620
|
// animations helpers
|
|
1376
|
-
this.
|
|
1621
|
+
this.isAnimating = false;
|
|
1377
1622
|
this.animation = null;
|
|
1378
|
-
this.maxBounds = null;
|
|
1379
1623
|
// key press
|
|
1380
1624
|
this.pressedKeys = {};
|
|
1381
1625
|
this.mount = function () {
|
|
@@ -1386,15 +1630,19 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1386
1630
|
};
|
|
1387
1631
|
this.update = function (newProps) {
|
|
1388
1632
|
_this.props = newProps;
|
|
1389
|
-
|
|
1633
|
+
if (_this.wrapperComponent && _this.contentComponent) {
|
|
1634
|
+
handleCalculateBounds(_this, _this.state.scale);
|
|
1635
|
+
}
|
|
1390
1636
|
_this.setup = createSetup(newProps);
|
|
1391
1637
|
};
|
|
1392
1638
|
this.initializeWindowEvents = function () {
|
|
1393
|
-
var _a, _b;
|
|
1639
|
+
var _a, _b, _c, _d;
|
|
1394
1640
|
var passive = makePassiveEventOption();
|
|
1395
1641
|
var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
|
|
1396
1642
|
var currentWindow = currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.defaultView;
|
|
1397
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);
|
|
1398
1646
|
// Panning on window to allow panning when mouse is out of component wrapper
|
|
1399
1647
|
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("mousedown", _this.onPanningStart, passive);
|
|
1400
1648
|
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("mousemove", _this.onPanning, passive);
|
|
@@ -1402,9 +1650,10 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1402
1650
|
currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.addEventListener("mouseleave", _this.clearPanning, passive);
|
|
1403
1651
|
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("keyup", _this.setKeyUnPressed, passive);
|
|
1404
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);
|
|
1405
1654
|
};
|
|
1406
1655
|
this.cleanupWindowEvents = function () {
|
|
1407
|
-
var _a, _b;
|
|
1656
|
+
var _a, _b, _c, _d, _e;
|
|
1408
1657
|
var passive = makePassiveEventOption();
|
|
1409
1658
|
var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
|
|
1410
1659
|
var currentWindow = currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.defaultView;
|
|
@@ -1414,9 +1663,13 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1414
1663
|
currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.removeEventListener("mouseleave", _this.clearPanning, passive);
|
|
1415
1664
|
currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("keyup", _this.setKeyUnPressed, passive);
|
|
1416
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);
|
|
1417
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);
|
|
1418
1671
|
handleCancelAnimation(_this);
|
|
1419
|
-
(
|
|
1672
|
+
(_e = _this.observer) === null || _e === void 0 ? void 0 : _e.disconnect();
|
|
1420
1673
|
};
|
|
1421
1674
|
this.handleInitializeWrapperEvents = function (wrapper) {
|
|
1422
1675
|
// Zooming events on wrapper
|
|
@@ -1445,6 +1698,7 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1445
1698
|
(_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
1446
1699
|
}
|
|
1447
1700
|
});
|
|
1701
|
+
// TODO: CHANGE to first interaction?
|
|
1448
1702
|
// if nothing about the contentComponent has changed after 5 seconds, disconnect the observer
|
|
1449
1703
|
setTimeout(function () {
|
|
1450
1704
|
var _a;
|
|
@@ -1461,49 +1715,51 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1461
1715
|
var disabled = _this.setup.disabled;
|
|
1462
1716
|
if (disabled)
|
|
1463
1717
|
return;
|
|
1718
|
+
_this.syncModifierKeys(event);
|
|
1464
1719
|
var isAllowed = isWheelAllowed(_this, event);
|
|
1465
1720
|
if (!isAllowed)
|
|
1466
1721
|
return;
|
|
1467
|
-
var keysPressed = _this.isPressingKeys(_this.setup.wheel.activationKeys);
|
|
1468
|
-
if (!keysPressed)
|
|
1469
|
-
return;
|
|
1470
1722
|
handleWheelStart(_this, event);
|
|
1471
1723
|
handleWheelZoom(_this, event);
|
|
1472
1724
|
handleWheelStop(_this, event);
|
|
1473
1725
|
};
|
|
1474
1726
|
/// ///////
|
|
1475
|
-
//
|
|
1727
|
+
// Track Pad Panning
|
|
1476
1728
|
/// ///////
|
|
1477
1729
|
this.onWheelPanning = function (event) {
|
|
1478
|
-
var
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
!panning.wheelPanning ||
|
|
1485
|
-
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)
|
|
1486
1736
|
return;
|
|
1487
|
-
}
|
|
1488
1737
|
event.preventDefault();
|
|
1489
1738
|
event.stopPropagation();
|
|
1490
|
-
var
|
|
1739
|
+
var _a = _this.state, positionX = _a.positionX, positionY = _a.positionY;
|
|
1491
1740
|
var mouseX = positionX - event.deltaX;
|
|
1492
1741
|
var mouseY = positionY - event.deltaY;
|
|
1493
|
-
var newPositionX =
|
|
1494
|
-
var newPositionY =
|
|
1495
|
-
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;
|
|
1496
1745
|
var paddingValueX = getPaddingValue(_this, sizeX);
|
|
1497
1746
|
var paddingValueY = getPaddingValue(_this, sizeY);
|
|
1498
1747
|
if (newPositionX === positionX && newPositionY === positionY)
|
|
1499
1748
|
return;
|
|
1749
|
+
handleWheelPanningStart(_this, event);
|
|
1500
1750
|
handleNewPosition(_this, newPositionX, newPositionY, paddingValueX, paddingValueY);
|
|
1751
|
+
handleCallback(getContext(_this), event, onPanning);
|
|
1752
|
+
handleWheelPanningStop(_this, event);
|
|
1501
1753
|
};
|
|
1754
|
+
/// ///////
|
|
1755
|
+
// Pan
|
|
1756
|
+
/// ///////
|
|
1502
1757
|
this.onPanningStart = function (event) {
|
|
1503
1758
|
var disabled = _this.setup.disabled;
|
|
1504
1759
|
var onPanningStart = _this.props.onPanningStart;
|
|
1505
1760
|
if (disabled)
|
|
1506
1761
|
return;
|
|
1762
|
+
_this.syncModifierKeys(event);
|
|
1507
1763
|
var isAllowed = isPanningStartAllowed(_this, event);
|
|
1508
1764
|
if (!isAllowed)
|
|
1509
1765
|
return;
|
|
@@ -1527,6 +1783,13 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1527
1783
|
var onPanning = _this.props.onPanning;
|
|
1528
1784
|
if (disabled)
|
|
1529
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
|
+
}
|
|
1530
1793
|
var isAllowed = isPanningAllowed(_this);
|
|
1531
1794
|
if (!isAllowed)
|
|
1532
1795
|
return;
|
|
@@ -1535,13 +1798,14 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1535
1798
|
return;
|
|
1536
1799
|
event.preventDefault();
|
|
1537
1800
|
event.stopPropagation();
|
|
1538
|
-
handlePanning(_this, event.clientX, event.clientY);
|
|
1801
|
+
handlePanning(_this, event.clientX, event.clientY, DeviceType.MOUSE);
|
|
1539
1802
|
handleCallback(getContext(_this), event, onPanning);
|
|
1540
1803
|
};
|
|
1541
1804
|
this.onPanningStop = function (event) {
|
|
1805
|
+
var velocityDisabled = _this.setup.panning.velocityDisabled;
|
|
1542
1806
|
var onPanningStop = _this.props.onPanningStop;
|
|
1543
1807
|
if (_this.isPanning) {
|
|
1544
|
-
handlePanningEnd(_this);
|
|
1808
|
+
handlePanningEnd(_this, velocityDisabled);
|
|
1545
1809
|
handleCallback(getContext(_this), event, onPanningStop);
|
|
1546
1810
|
}
|
|
1547
1811
|
};
|
|
@@ -1550,7 +1814,7 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1550
1814
|
/// ///////
|
|
1551
1815
|
this.onPinchStart = function (event) {
|
|
1552
1816
|
var disabled = _this.setup.disabled;
|
|
1553
|
-
var
|
|
1817
|
+
var onPinchStart = _this.props.onPinchStart;
|
|
1554
1818
|
if (disabled)
|
|
1555
1819
|
return;
|
|
1556
1820
|
var isAllowed = isPinchStartAllowed(_this, event);
|
|
@@ -1558,12 +1822,11 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1558
1822
|
return;
|
|
1559
1823
|
handlePinchStart(_this, event);
|
|
1560
1824
|
handleCancelAnimation(_this);
|
|
1561
|
-
handleCallback(getContext(_this), event,
|
|
1562
|
-
handleCallback(getContext(_this), event, onZoomStart);
|
|
1825
|
+
handleCallback(getContext(_this), event, onPinchStart);
|
|
1563
1826
|
};
|
|
1564
1827
|
this.onPinch = function (event) {
|
|
1565
1828
|
var disabled = _this.setup.disabled;
|
|
1566
|
-
var
|
|
1829
|
+
var onPinch = _this.props.onPinch;
|
|
1567
1830
|
if (disabled)
|
|
1568
1831
|
return;
|
|
1569
1832
|
var isAllowed = isPinchAllowed(_this);
|
|
@@ -1572,36 +1835,38 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1572
1835
|
event.preventDefault();
|
|
1573
1836
|
event.stopPropagation();
|
|
1574
1837
|
handlePinchZoom(_this, event);
|
|
1575
|
-
handleCallback(getContext(_this), event,
|
|
1576
|
-
handleCallback(getContext(_this), event, onZoom);
|
|
1838
|
+
handleCallback(getContext(_this), event, onPinch);
|
|
1577
1839
|
};
|
|
1578
1840
|
this.onPinchStop = function (event) {
|
|
1579
|
-
var
|
|
1841
|
+
var onPinchStop = _this.props.onPinchStop;
|
|
1580
1842
|
if (_this.pinchStartScale) {
|
|
1581
1843
|
handlePinchStop(_this);
|
|
1582
|
-
handleCallback(getContext(_this), event,
|
|
1583
|
-
handleCallback(getContext(_this), event, onZoomStop);
|
|
1844
|
+
handleCallback(getContext(_this), event, onPinchStop);
|
|
1584
1845
|
}
|
|
1585
1846
|
};
|
|
1586
1847
|
/// ///////
|
|
1587
1848
|
// Touch
|
|
1588
1849
|
/// ///////
|
|
1589
1850
|
this.onTouchPanningStart = function (event) {
|
|
1590
|
-
var
|
|
1851
|
+
var _a = _this.setup, disabled = _a.disabled, doubleClick = _a.doubleClick;
|
|
1591
1852
|
var onPanningStart = _this.props.onPanningStart;
|
|
1592
1853
|
if (disabled)
|
|
1593
1854
|
return;
|
|
1594
|
-
var
|
|
1595
|
-
if (!isAllowed)
|
|
1596
|
-
return;
|
|
1855
|
+
var isDoubleTapAllowed = !(doubleClick === null || doubleClick === void 0 ? void 0 : doubleClick.disabled);
|
|
1597
1856
|
var isDoubleTap = _this.lastTouch && +new Date() - _this.lastTouch < 200;
|
|
1598
|
-
if (
|
|
1857
|
+
if (isDoubleTapAllowed && isDoubleTap && event.touches.length === 1) {
|
|
1858
|
+
_this.onDoubleClick(event);
|
|
1859
|
+
}
|
|
1860
|
+
else {
|
|
1599
1861
|
_this.lastTouch = +new Date();
|
|
1600
1862
|
handleCancelAnimation(_this);
|
|
1601
1863
|
var touches = event.touches;
|
|
1602
1864
|
var isPanningAction = touches.length === 1;
|
|
1603
1865
|
var isPinchAction = touches.length === 2;
|
|
1866
|
+
var isAllowed = isPanningStartAllowed(_this, event);
|
|
1604
1867
|
if (isPanningAction) {
|
|
1868
|
+
if (!isAllowed)
|
|
1869
|
+
return;
|
|
1605
1870
|
handleCancelAnimation(_this);
|
|
1606
1871
|
handlePanningStart(_this, event);
|
|
1607
1872
|
handleCallback(getContext(_this), event, onPanningStart);
|
|
@@ -1620,10 +1885,12 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1620
1885
|
var isAllowed = isPanningAllowed(_this);
|
|
1621
1886
|
if (!isAllowed)
|
|
1622
1887
|
return;
|
|
1623
|
-
event.
|
|
1888
|
+
if (event.cancelable) {
|
|
1889
|
+
event.preventDefault();
|
|
1890
|
+
}
|
|
1624
1891
|
event.stopPropagation();
|
|
1625
1892
|
var touch = event.touches[0];
|
|
1626
|
-
handlePanning(_this, touch.clientX, touch.clientY);
|
|
1893
|
+
handlePanning(_this, touch.clientX, touch.clientY, DeviceType.TOUCH);
|
|
1627
1894
|
handleCallback(getContext(_this), event, onPanning);
|
|
1628
1895
|
}
|
|
1629
1896
|
else if (event.touches.length > 1) {
|
|
@@ -1654,6 +1921,44 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1654
1921
|
_this.onPanningStop(event);
|
|
1655
1922
|
}
|
|
1656
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
|
+
};
|
|
1657
1962
|
this.setKeyPressed = function (e) {
|
|
1658
1963
|
_this.pressedKeys[e.key] = true;
|
|
1659
1964
|
};
|
|
@@ -1661,35 +1966,26 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1661
1966
|
_this.pressedKeys[e.key] = false;
|
|
1662
1967
|
};
|
|
1663
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
|
+
}
|
|
1664
1980
|
if (!keys.length) {
|
|
1665
1981
|
return true;
|
|
1666
1982
|
}
|
|
1667
|
-
return Boolean(keys.
|
|
1668
|
-
};
|
|
1669
|
-
this.setTransformState = function (scale, positionX, positionY) {
|
|
1670
|
-
var onTransformed = _this.props.onTransformed;
|
|
1671
|
-
if (!Number.isNaN(scale) &&
|
|
1672
|
-
!Number.isNaN(positionX) &&
|
|
1673
|
-
!Number.isNaN(positionY)) {
|
|
1674
|
-
if (scale !== _this.transformState.scale) {
|
|
1675
|
-
_this.transformState.previousScale = _this.transformState.scale;
|
|
1676
|
-
_this.transformState.scale = scale;
|
|
1677
|
-
}
|
|
1678
|
-
_this.transformState.positionX = positionX;
|
|
1679
|
-
_this.transformState.positionY = positionY;
|
|
1680
|
-
_this.applyTransformation();
|
|
1681
|
-
var ctx_1 = getContext(_this);
|
|
1682
|
-
_this.onChangeCallbacks.forEach(function (callback) { return callback(ctx_1); });
|
|
1683
|
-
handleCallback(ctx_1, { scale: scale, positionX: positionX, positionY: positionY }, onTransformed);
|
|
1684
|
-
}
|
|
1685
|
-
else {
|
|
1686
|
-
console.error("Detected NaN set state values");
|
|
1687
|
-
}
|
|
1983
|
+
return Boolean(keys.every(function (key) { return _this.pressedKeys[key]; }));
|
|
1688
1984
|
};
|
|
1689
1985
|
this.setCenter = function () {
|
|
1690
1986
|
if (_this.wrapperComponent && _this.contentComponent) {
|
|
1691
|
-
var targetState = getCenterPosition(_this.
|
|
1692
|
-
_this.
|
|
1987
|
+
var targetState = getCenterPosition(_this.state.scale, _this.wrapperComponent, _this.contentComponent);
|
|
1988
|
+
_this.setState(targetState.scale, targetState.positionX, targetState.positionY);
|
|
1693
1989
|
}
|
|
1694
1990
|
};
|
|
1695
1991
|
this.handleTransformStyles = function (x, y, scale) {
|
|
@@ -1698,19 +1994,60 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1698
1994
|
}
|
|
1699
1995
|
return getTransformStyles(x, y, scale);
|
|
1700
1996
|
};
|
|
1997
|
+
this.getContext = function () {
|
|
1998
|
+
return getContext(_this);
|
|
1999
|
+
};
|
|
1701
2000
|
this.applyTransformation = function () {
|
|
1702
2001
|
if (!_this.mounted || !_this.contentComponent)
|
|
1703
2002
|
return;
|
|
1704
|
-
var _a = _this.
|
|
2003
|
+
var _a = _this.state, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
|
|
1705
2004
|
var transform = _this.handleTransformStyles(positionX, positionY, scale);
|
|
1706
|
-
|
|
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
|
+
});
|
|
1707
2018
|
};
|
|
1708
|
-
this.
|
|
1709
|
-
|
|
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
|
+
}
|
|
1710
2039
|
};
|
|
1711
2040
|
/**
|
|
1712
2041
|
* Hooks
|
|
1713
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
|
+
};
|
|
1714
2051
|
this.onChange = function (callback) {
|
|
1715
2052
|
if (!_this.onChangeCallbacks.has(callback)) {
|
|
1716
2053
|
_this.onChangeCallbacks.add(callback);
|
|
@@ -1734,17 +2071,18 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1734
2071
|
_this.cleanupWindowEvents();
|
|
1735
2072
|
_this.wrapperComponent = wrapperComponent;
|
|
1736
2073
|
_this.contentComponent = contentComponent;
|
|
1737
|
-
handleCalculateBounds(_this, _this.
|
|
2074
|
+
handleCalculateBounds(_this, _this.state.scale);
|
|
1738
2075
|
_this.handleInitializeWrapperEvents(wrapperComponent);
|
|
1739
2076
|
_this.handleInitialize(contentComponent);
|
|
1740
2077
|
_this.initializeWindowEvents();
|
|
1741
2078
|
_this.isInitialized = true;
|
|
1742
2079
|
var ctx = getContext(_this);
|
|
1743
2080
|
handleCallback(ctx, undefined, _this.props.onInit);
|
|
2081
|
+
assignRef(_this.props.ref, ctx);
|
|
1744
2082
|
};
|
|
1745
2083
|
this.props = props;
|
|
1746
2084
|
this.setup = createSetup(this.props);
|
|
1747
|
-
this.
|
|
2085
|
+
this.state = createState(this.props);
|
|
1748
2086
|
}
|
|
1749
2087
|
return ZoomPanPinch;
|
|
1750
2088
|
}());
|
|
@@ -1763,7 +2101,7 @@ var TransformWrapper = React.forwardRef(function (props, ref) {
|
|
|
1763
2101
|
useEffect(function () {
|
|
1764
2102
|
instance.update(props);
|
|
1765
2103
|
}, [instance, props]);
|
|
1766
|
-
return
|
|
2104
|
+
return jsx(Context.Provider, __assign({ value: instance }, { children: content }));
|
|
1767
2105
|
});
|
|
1768
2106
|
|
|
1769
2107
|
var KeepScale = React.forwardRef(function (props, ref) {
|
|
@@ -1774,11 +2112,11 @@ var KeepScale = React.forwardRef(function (props, ref) {
|
|
|
1774
2112
|
if (localRef.current) {
|
|
1775
2113
|
var positionX = 0;
|
|
1776
2114
|
var positionY = 0;
|
|
1777
|
-
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);
|
|
1778
2116
|
}
|
|
1779
2117
|
});
|
|
1780
2118
|
}, [instance]);
|
|
1781
|
-
return
|
|
2119
|
+
return jsx("div", __assign({}, props, { ref: mergeRefs([localRef, ref]) }));
|
|
1782
2120
|
});
|
|
1783
2121
|
|
|
1784
2122
|
var initialElementRect = {
|
|
@@ -1835,11 +2173,13 @@ var previewStyles = {
|
|
|
1835
2173
|
border: "3px solid red",
|
|
1836
2174
|
transformOrigin: "0% 0%",
|
|
1837
2175
|
boxShadow: "rgba(0,0,0,0.2) 0 0 0 10000000px",
|
|
2176
|
+
pointerEvents: "none",
|
|
1838
2177
|
};
|
|
1839
2178
|
var MiniMap = function (_a) {
|
|
1840
|
-
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"]);
|
|
1841
|
-
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];
|
|
1842
2181
|
var instance = useTransformContext();
|
|
2182
|
+
var _g = useState(false), isDown = _g[0], setIsDown = _g[1];
|
|
1843
2183
|
var miniMapInstance = useRef(null);
|
|
1844
2184
|
var mainRef = useRef(null);
|
|
1845
2185
|
var wrapperRef = useRef(null);
|
|
@@ -1849,27 +2189,27 @@ var MiniMap = function (_a) {
|
|
|
1849
2189
|
var rect = instance.wrapperComponent.getBoundingClientRect();
|
|
1850
2190
|
return {
|
|
1851
2191
|
width: rect.width,
|
|
1852
|
-
height: rect.height
|
|
2192
|
+
height: rect.height,
|
|
1853
2193
|
};
|
|
1854
2194
|
}
|
|
1855
2195
|
return {
|
|
1856
2196
|
width: 0,
|
|
1857
|
-
height: 0
|
|
2197
|
+
height: 0,
|
|
1858
2198
|
};
|
|
1859
2199
|
}, [instance.wrapperComponent]);
|
|
1860
2200
|
var getContentSize = useCallback(function () {
|
|
1861
2201
|
if (instance.contentComponent) {
|
|
1862
2202
|
var rect = instance.contentComponent.getBoundingClientRect();
|
|
1863
2203
|
return {
|
|
1864
|
-
width: rect.width / instance.
|
|
1865
|
-
height: rect.height / instance.
|
|
2204
|
+
width: rect.width / instance.state.scale,
|
|
2205
|
+
height: rect.height / instance.state.scale,
|
|
1866
2206
|
};
|
|
1867
2207
|
}
|
|
1868
2208
|
return {
|
|
1869
2209
|
width: 0,
|
|
1870
2210
|
height: 0,
|
|
1871
2211
|
};
|
|
1872
|
-
}, [instance.contentComponent, instance.
|
|
2212
|
+
}, [instance.contentComponent, instance.state.scale]);
|
|
1873
2213
|
var computeMiniMapScale = useCallback(function () {
|
|
1874
2214
|
var contentSize = getContentSize();
|
|
1875
2215
|
var scaleX = width / contentSize.width;
|
|
@@ -1894,13 +2234,16 @@ var MiniMap = function (_a) {
|
|
|
1894
2234
|
position: "absolute",
|
|
1895
2235
|
boxSizing: "border-box",
|
|
1896
2236
|
zIndex: 1,
|
|
1897
|
-
overflow: "hidden",
|
|
2237
|
+
// overflow: "hidden",
|
|
1898
2238
|
};
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
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
|
+
}
|
|
1904
2247
|
};
|
|
1905
2248
|
var transformMiniMap = function () {
|
|
1906
2249
|
computeMiniMapStyle();
|
|
@@ -1917,8 +2260,8 @@ var MiniMap = function (_a) {
|
|
|
1917
2260
|
if (previewRef.current) {
|
|
1918
2261
|
var size = getViewportSize();
|
|
1919
2262
|
var scale = computeMiniMapScale();
|
|
1920
|
-
var previewScale = scale * (1 / instance.
|
|
1921
|
-
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);
|
|
1922
2265
|
previewRef.current.style.transform = transform;
|
|
1923
2266
|
previewRef.current.style.width = "".concat(size.width * previewScale, "px");
|
|
1924
2267
|
previewRef.current.style.height = "".concat(size.height * previewScale, "px");
|
|
@@ -1939,25 +2282,66 @@ var MiniMap = function (_a) {
|
|
|
1939
2282
|
return instance.onChange(function (zpp) {
|
|
1940
2283
|
var scale = computeMiniMapScale();
|
|
1941
2284
|
if (miniMapInstance.current) {
|
|
1942
|
-
miniMapInstance.current.instance.
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
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;
|
|
1948
2290
|
}
|
|
1949
2291
|
});
|
|
1950
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
|
+
});
|
|
1951
2336
|
var wrapperStyle = useMemo(function () {
|
|
1952
2337
|
return {
|
|
1953
2338
|
position: "relative",
|
|
1954
2339
|
zIndex: 2,
|
|
1955
|
-
overflow: "hidden",
|
|
2340
|
+
// overflow: "hidden",
|
|
2341
|
+
userSelect: "none",
|
|
1956
2342
|
};
|
|
1957
2343
|
}, []);
|
|
1958
|
-
return (
|
|
1959
|
-
React.createElement("div", __assign({}, rest, { ref: wrapperRef, className: "rzpp-wrapper" }), children),
|
|
1960
|
-
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) })] })));
|
|
1961
2345
|
};
|
|
1962
2346
|
|
|
1963
2347
|
function styleInject(css, ref) {
|
|
@@ -1987,30 +2371,142 @@ function styleInject(css, ref) {
|
|
|
1987
2371
|
}
|
|
1988
2372
|
}
|
|
1989
2373
|
|
|
1990
|
-
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}\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";
|
|
1991
|
-
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"};
|
|
1992
2376
|
styleInject(css_248z);
|
|
1993
2377
|
|
|
1994
2378
|
var TransformComponent = function (_a) {
|
|
1995
|
-
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;
|
|
1996
|
-
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;
|
|
1997
2382
|
var wrapperRef = useRef(null);
|
|
1998
2383
|
var contentRef = useRef(null);
|
|
2384
|
+
var gridRef = useRef(null);
|
|
1999
2385
|
useEffect(function () {
|
|
2000
2386
|
var wrapper = wrapperRef.current;
|
|
2001
2387
|
var content = contentRef.current;
|
|
2002
2388
|
if (wrapper !== null && content !== null && init) {
|
|
2003
2389
|
init === null || init === void 0 ? void 0 : init(wrapper, content);
|
|
2004
2390
|
}
|
|
2005
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2006
2391
|
return function () {
|
|
2007
2392
|
cleanupWindowEvents === null || cleanupWindowEvents === void 0 ? void 0 : cleanupWindowEvents();
|
|
2008
2393
|
};
|
|
2394
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2009
2395
|
}, []);
|
|
2010
|
-
|
|
2011
|
-
|
|
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 }))] })));
|
|
2012
2410
|
};
|
|
2013
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
|
+
|
|
2014
2510
|
var useTransformContext = function () {
|
|
2015
2511
|
var libraryContext = useContext(Context);
|
|
2016
2512
|
if (!libraryContext) {
|
|
@@ -2041,6 +2537,7 @@ var useTransformInit = function (callback) {
|
|
|
2041
2537
|
unmount === null || unmount === void 0 ? void 0 : unmount();
|
|
2042
2538
|
unmountCallback === null || unmountCallback === void 0 ? void 0 : unmountCallback();
|
|
2043
2539
|
};
|
|
2540
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2044
2541
|
}, []);
|
|
2045
2542
|
};
|
|
2046
2543
|
|
|
@@ -2076,5 +2573,5 @@ function useTransformComponent(callback) {
|
|
|
2076
2573
|
return transformRender;
|
|
2077
2574
|
}
|
|
2078
2575
|
|
|
2079
|
-
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 };
|
|
2080
2577
|
//# sourceMappingURL=index.esm.js.map
|