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