react-zoom-pan-pinch 2.2.0 → 2.3.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.
Files changed (83) hide show
  1. package/dist/components/transform-component.d.ts +10 -0
  2. package/dist/components/transform-wrapper.d.ts +8 -0
  3. package/dist/constants/state.constants.d.ts +6 -0
  4. package/dist/core/animations/animations.constants.d.ts +16 -0
  5. package/dist/core/animations/animations.utils.d.ts +4 -0
  6. package/dist/core/bounds/bounds.types.d.ts +8 -0
  7. package/dist/core/bounds/bounds.utils.d.ts +15 -0
  8. package/dist/core/double-click/double-click.logic.d.ts +3 -0
  9. package/dist/core/handlers/handlers.logic.d.ts +8 -0
  10. package/dist/core/handlers/handlers.utils.d.ts +13 -0
  11. package/dist/core/instance.core.d.ts +68 -0
  12. package/dist/core/pan/panning.logic.d.ts +5 -0
  13. package/dist/core/pan/panning.utils.d.ts +10 -0
  14. package/dist/core/pan/velocity.logic.d.ts +5 -0
  15. package/dist/core/pan/velocity.utils.d.ts +5 -0
  16. package/dist/core/pinch/pinch.logic.d.ts +4 -0
  17. package/dist/core/pinch/pinch.utils.d.ts +6 -0
  18. package/dist/core/wheel/wheel.logic.d.ts +4 -0
  19. package/dist/core/wheel/wheel.utils.d.ts +7 -0
  20. package/dist/core/zoom/zoom.logic.d.ts +3 -0
  21. package/dist/core/zoom/zoom.utils.d.ts +3 -0
  22. package/dist/hooks/use-transform-context.d.ts +3 -0
  23. package/dist/index.cjs.js +278 -267
  24. package/dist/index.cjs.js.map +1 -1
  25. package/dist/index.d.ts +63 -57
  26. package/dist/index.esm.js +278 -267
  27. package/dist/index.esm.js.map +1 -1
  28. package/dist/models/calculations.model.d.ts +25 -0
  29. package/dist/models/context.model.d.ts +117 -0
  30. package/dist/models/helpers.model.d.ts +5 -0
  31. package/dist/models/index.d.ts +3 -0
  32. package/dist/stories/docs/handlers.d.ts +12 -0
  33. package/dist/stories/docs/props.d.ts +14 -0
  34. package/dist/stories/examples/content-rerendering/example.d.ts +2 -0
  35. package/dist/stories/examples/stress/example.d.ts +2 -0
  36. package/dist/stories/examples/zoom-to-element/example.d.ts +2 -0
  37. package/dist/stories/types/args.types.d.ts +268 -0
  38. package/dist/stories/utils/args.utils.d.ts +3 -0
  39. package/dist/stories/utils/code.utils.d.ts +6 -0
  40. package/dist/stories/utils/controls.utils.d.ts +3 -0
  41. package/dist/stories/utils/index.d.ts +3 -0
  42. package/dist/utils/calculations.utils.d.ts +11 -0
  43. package/dist/utils/callback.utils.d.ts +2 -0
  44. package/dist/utils/context.utils.d.ts +2 -0
  45. package/dist/utils/event.utils.d.ts +1 -0
  46. package/dist/utils/helpers.utils.d.ts +2 -0
  47. package/dist/utils/index.d.ts +7 -0
  48. package/dist/utils/state.utils.d.ts +3 -0
  49. package/dist/utils/styles.utils.d.ts +3 -0
  50. package/package.json +30 -25
  51. package/src/.eslintrc.json +90 -0
  52. package/src/components/transform-component.tsx +2 -1
  53. package/src/components/transform-wrapper.tsx +27 -5
  54. package/src/constants/state.constants.ts +0 -2
  55. package/src/core/animations/animations.constants.ts +14 -12
  56. package/src/core/animations/animations.utils.ts +15 -11
  57. package/src/core/bounds/bounds.utils.ts +20 -20
  58. package/src/core/double-click/double-click.logic.ts +6 -12
  59. package/src/core/handlers/handlers.logic.ts +98 -89
  60. package/src/core/handlers/handlers.utils.ts +22 -24
  61. package/src/{components/transform-context.tsx → core/instance.core.ts} +85 -118
  62. package/src/core/pan/panning.logic.ts +20 -19
  63. package/src/core/pan/panning.utils.ts +4 -7
  64. package/src/core/pan/velocity.logic.ts +1 -0
  65. package/src/core/pinch/pinch.logic.ts +4 -6
  66. package/src/core/pinch/pinch.utils.ts +2 -2
  67. package/src/core/wheel/wheel.logic.ts +1 -0
  68. package/src/core/wheel/wheel.utils.ts +12 -11
  69. package/src/core/zoom/zoom.logic.ts +29 -29
  70. package/src/core/zoom/zoom.utils.ts +2 -2
  71. package/src/hooks/use-transform-context.tsx +3 -2
  72. package/src/models/context.model.ts +6 -2
  73. package/src/stories/docs/handlers.tsx +30 -30
  74. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +3 -0
  75. package/src/stories/examples/content-rerendering/example.tsx +1 -1
  76. package/src/stories/examples/stress/example.tsx +24 -0
  77. package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
  78. package/src/stories/examples/zoom-to-element/example.tsx +4 -0
  79. package/src/stories/utils/code.utils.tsx +1 -0
  80. package/src/stories/utils/controls.utils.tsx +21 -4
  81. package/src/stories/utils/styles.module.css +5 -0
  82. package/src/utils/styles.utils.ts +9 -1
  83. package/src/.eslintrc.js +0 -36
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
- import React, { Component, useState, useImperativeHandle, useContext, useRef, useEffect } from 'react';
1
+ import React, { useRef, useMemo, useImperativeHandle, useContext, useEffect } from 'react';
2
2
 
3
- /*! *****************************************************************************
3
+ /******************************************************************************
4
4
  Copyright (c) Microsoft Corporation.
5
5
 
6
6
  Permission to use, copy, modify, and/or distribute this software for any
@@ -14,22 +14,6 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
14
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  PERFORMANCE OF THIS SOFTWARE.
16
16
  ***************************************************************************** */
17
- /* global Reflect, Promise */
18
-
19
- var extendStatics = function(d, b) {
20
- extendStatics = Object.setPrototypeOf ||
21
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
22
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
23
- return extendStatics(d, b);
24
- };
25
-
26
- function __extends(d, b) {
27
- if (typeof b !== "function" && b !== null)
28
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29
- extendStatics(d, b);
30
- function __() { this.constructor = d; }
31
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
- }
33
17
 
34
18
  var __assign = function() {
35
19
  __assign = Object.assign || function __assign(t) {
@@ -49,7 +33,7 @@ function __spreadArray(to, from, pack) {
49
33
  ar[i] = from[i];
50
34
  }
51
35
  }
52
- return to.concat(ar || from);
36
+ return to.concat(ar || Array.prototype.slice.call(from));
53
37
  }
54
38
 
55
39
  /**
@@ -74,6 +58,8 @@ var handleCallback = function (context, event, callback) {
74
58
  }
75
59
  };
76
60
 
61
+ /* eslint-disable no-plusplus */
62
+ /* eslint-disable no-param-reassign */
77
63
  /**
78
64
  * Functions should return denominator of the target value, which is the next animation step.
79
65
  * t is a value from 0 to 1, reflecting the percentage of animation status.
@@ -150,6 +136,7 @@ var animations = {
150
136
  easeInOutQuint: easeInOutQuint,
151
137
  };
152
138
 
139
+ /* eslint-disable no-param-reassign */
153
140
  var handleCancelAnimationFrame = function (animation) {
154
141
  if (typeof animation === "number") {
155
142
  cancelAnimationFrame(animation);
@@ -191,6 +178,15 @@ function handleSetupAnimation(contextInstance, animationName, animationTime, cal
191
178
  };
192
179
  requestAnimationFrame(contextInstance.animation);
193
180
  }
181
+ function isValidTargetState(targetState) {
182
+ var scale = targetState.scale, positionX = targetState.positionX, positionY = targetState.positionY;
183
+ if (Number.isNaN(scale) ||
184
+ Number.isNaN(positionX) ||
185
+ Number.isNaN(positionY)) {
186
+ return false;
187
+ }
188
+ return true;
189
+ }
194
190
  function animate(contextInstance, targetState, animationTime, animationName) {
195
191
  var isValid = isValidTargetState(targetState);
196
192
  if (!contextInstance.mounted || !isValid)
@@ -213,14 +209,8 @@ function animate(contextInstance, targetState, animationTime, animationName) {
213
209
  });
214
210
  }
215
211
  }
216
- function isValidTargetState(targetState) {
217
- var scale = targetState.scale, positionX = targetState.positionX, positionY = targetState.positionY;
218
- if (isNaN(scale) || isNaN(positionX) || isNaN(positionY)) {
219
- return false;
220
- }
221
- return true;
222
- }
223
212
 
213
+ /* eslint-disable no-param-reassign */
224
214
  function getComponentsSizes(wrapperComponent, contentComponent, newScale) {
225
215
  var wrapperWidth = wrapperComponent.offsetWidth;
226
216
  var wrapperHeight = wrapperComponent.offsetHeight;
@@ -262,6 +252,22 @@ var calculateBounds = function (contextInstance, newScale) {
262
252
  var bounds = getBounds(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, Boolean(centerZoomedOut));
263
253
  return bounds;
264
254
  };
255
+ /**
256
+ * Keeps value between given bounds, used for limiting view to given boundaries
257
+ * 1# eg. boundLimiter(2, 0, 3, true) => 2
258
+ * 2# eg. boundLimiter(4, 0, 3, true) => 3
259
+ * 3# eg. boundLimiter(-2, 0, 3, true) => 0
260
+ * 4# eg. boundLimiter(10, 0, 3, false) => 10
261
+ */
262
+ var boundLimiter = function (value, minBound, maxBound, isActive) {
263
+ if (!isActive)
264
+ return roundNumber(value, 2);
265
+ if (value < minBound)
266
+ return roundNumber(minBound, 2);
267
+ if (value > maxBound)
268
+ return roundNumber(maxBound, 2);
269
+ return roundNumber(value, 2);
270
+ };
265
271
  var handleCalculateBounds = function (contextInstance, newScale) {
266
272
  var bounds = calculateBounds(contextInstance, newScale);
267
273
  // Save bounds
@@ -280,22 +286,6 @@ function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, pa
280
286
  var y = boundLimiter(positionY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
281
287
  return { x: x, y: y };
282
288
  }
283
- /**
284
- * Keeps value between given bounds, used for limiting view to given boundaries
285
- * 1# eg. boundLimiter(2, 0, 3, true) => 2
286
- * 2# eg. boundLimiter(4, 0, 3, true) => 3
287
- * 3# eg. boundLimiter(-2, 0, 3, true) => 0
288
- * 4# eg. boundLimiter(10, 0, 3, false) => 10
289
- */
290
- var boundLimiter = function (value, minBound, maxBound, isActive) {
291
- if (!isActive)
292
- return roundNumber(value, 2);
293
- if (value < minBound)
294
- return roundNumber(minBound, 2);
295
- if (value > maxBound)
296
- return roundNumber(maxBound, 2);
297
- return roundNumber(value, 2);
298
- };
299
289
 
300
290
  function handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds) {
301
291
  var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
@@ -314,9 +304,9 @@ function handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale,
314
304
  function checkZoomBounds(zoom, minScale, maxScale, zoomPadding, enablePadding) {
315
305
  var scalePadding = enablePadding ? zoomPadding : 0;
316
306
  var minScaleWithPadding = minScale - scalePadding;
317
- if (!isNaN(maxScale) && zoom >= maxScale)
307
+ if (!Number.isNaN(maxScale) && zoom >= maxScale)
318
308
  return maxScale;
319
- if (!isNaN(minScale) && zoom <= minScaleWithPadding)
309
+ if (!Number.isNaN(minScale) && zoom <= minScaleWithPadding)
320
310
  return minScaleWithPadding;
321
311
  return zoom;
322
312
  }
@@ -558,6 +548,18 @@ function handlePanningStart(contextInstance, event) {
558
548
  handlePanningSetup(contextInstance, event);
559
549
  }
560
550
  }
551
+ function handleAlignToBounds(contextInstance) {
552
+ var scale = contextInstance.transformState.scale;
553
+ var _a = contextInstance.setup, minScale = _a.minScale, alignmentAnimation = _a.alignmentAnimation;
554
+ var disabled = alignmentAnimation.disabled, sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, animationTime = alignmentAnimation.animationTime, animationType = alignmentAnimation.animationType;
555
+ var isDisabled = disabled || scale < minScale || (!sizeX && !sizeY);
556
+ if (isDisabled)
557
+ return;
558
+ var targetState = handlePanToBounds(contextInstance);
559
+ if (targetState) {
560
+ animate(contextInstance, targetState, animationTime, animationType);
561
+ }
562
+ }
561
563
  function handlePanning(contextInstance, clientX, clientY) {
562
564
  var startCoords = contextInstance.startCoords, setup = contextInstance.setup;
563
565
  var _a = setup.alignmentAnimation, sizeX = _a.sizeX, sizeY = _a.sizeY;
@@ -592,19 +594,14 @@ function handlePanningEnd(contextInstance) {
592
594
  }
593
595
  }
594
596
  }
595
- function handleAlignToBounds(contextInstance) {
596
- var scale = contextInstance.transformState.scale;
597
- var _a = contextInstance.setup, minScale = _a.minScale, alignmentAnimation = _a.alignmentAnimation;
598
- var disabled = alignmentAnimation.disabled, sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, animationTime = alignmentAnimation.animationTime, animationType = alignmentAnimation.animationType;
599
- var isDisabled = disabled || scale < minScale || (!sizeX && !sizeY);
600
- if (isDisabled)
601
- return;
602
- var targetState = handlePanToBounds(contextInstance);
603
- if (targetState) {
604
- animate(contextInstance, targetState, animationTime, animationType);
605
- }
606
- }
607
597
 
598
+ function handleZoomToPoint(contextInstance, scale, mouseX, mouseY) {
599
+ var _a = contextInstance.setup, minScale = _a.minScale, maxScale = _a.maxScale, limitToBounds = _a.limitToBounds;
600
+ var newScale = checkZoomBounds(roundNumber(scale, 2), minScale, maxScale, 0, false);
601
+ var bounds = handleCalculateBounds(contextInstance, newScale);
602
+ var _b = handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds), x = _b.x, y = _b.y;
603
+ return { scale: newScale, positionX: x, positionY: y };
604
+ }
608
605
  function handleAlignToScaleBounds(contextInstance, mousePositionX, mousePositionY) {
609
606
  var scale = contextInstance.transformState.scale;
610
607
  var wrapperComponent = contextInstance.wrapperComponent;
@@ -624,13 +621,6 @@ function handleAlignToScaleBounds(contextInstance, mousePositionX, mousePosition
624
621
  animate(contextInstance, targetState, animationTime, animationType);
625
622
  }
626
623
  }
627
- function handleZoomToPoint(contextInstance, scale, mouseX, mouseY) {
628
- var _a = contextInstance.setup, minScale = _a.minScale, maxScale = _a.maxScale, limitToBounds = _a.limitToBounds;
629
- var newScale = checkZoomBounds(roundNumber(scale, 2), minScale, maxScale, 0, false);
630
- var bounds = handleCalculateBounds(contextInstance, newScale);
631
- var _b = handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds), x = _b.x, y = _b.y;
632
- return { scale: newScale, positionX: x, positionY: y };
633
- }
634
624
 
635
625
  var initialState = {
636
626
  previousScale: 1,
@@ -725,7 +715,7 @@ var createSetup = function (props) {
725
715
  newSetup[key] = __assign(__assign({}, initialSetup[key]), props[key]);
726
716
  }
727
717
  else if (isArray) {
728
- newSetup[key] = __spreadArray(__spreadArray([], initialSetup[key]), props[key]);
718
+ newSetup[key] = __spreadArray(__spreadArray([], initialSetup[key], true), props[key], true);
729
719
  }
730
720
  else {
731
721
  newSetup[key] = props[key];
@@ -784,6 +774,20 @@ function resetTransformations(contextInstance, animationTime, animationType) {
784
774
  }
785
775
  animate(contextInstance, newState, animationTime, animationType);
786
776
  }
777
+ function getOffset(element) {
778
+ var el = element;
779
+ var offsetLeft = 0;
780
+ var offsetTop = 0;
781
+ while (el) {
782
+ offsetLeft += el.offsetLeft;
783
+ offsetTop += el.offsetTop;
784
+ el = el.offsetParent;
785
+ }
786
+ return {
787
+ x: offsetLeft - window.scrollX,
788
+ y: offsetTop - window.scrollY,
789
+ };
790
+ }
787
791
  function calculateZoomToNode(contextInstance, node, customZoom) {
788
792
  var wrapperComponent = contextInstance.wrapperComponent;
789
793
  var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, minScale = _a.minScale, maxScale = _a.maxScale;
@@ -806,88 +810,85 @@ function calculateZoomToNode(contextInstance, node, customZoom) {
806
810
  var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, 0, 0, wrapperComponent), x = _b.x, y = _b.y;
807
811
  return { positionX: x, positionY: y, scale: newScale };
808
812
  }
809
- function getOffset(element) {
810
- var el = element;
811
- var offsetLeft = 0;
812
- var offsetTop = 0;
813
- while (el) {
814
- offsetLeft += el.offsetLeft;
815
- offsetTop += el.offsetTop;
816
- el = el.offsetParent;
817
- }
818
- return {
819
- x: offsetLeft - window.scrollX,
820
- y: offsetTop - window.scrollY,
821
- };
822
- }
823
813
  function isValidZoomNode(node) {
824
814
  if (!node) {
825
815
  console.error("Zoom node not found");
826
816
  return false;
827
817
  }
828
- else if ((node === null || node === void 0 ? void 0 : node.offsetWidth) === undefined ||
829
- (node === null || node === void 0 ? void 0 : node.offsetHeight) === undefined) {
818
+ if ((node === null || node === void 0 ? void 0 : node.offsetWidth) === undefined || (node === null || node === void 0 ? void 0 : node.offsetHeight) === undefined) {
830
819
  console.error("Zoom node is not valid - it must contain offsetWidth and offsetHeight");
831
820
  return false;
832
821
  }
833
822
  return true;
834
823
  }
835
824
 
836
- var zoomIn = function (contextInstance) { return function (step, animationTime, animationType) {
837
- if (step === void 0) { step = 0.5; }
838
- if (animationTime === void 0) { animationTime = 300; }
839
- if (animationType === void 0) { animationType = "easeOut"; }
840
- handleZoomToViewCenter(contextInstance, 1, step, animationTime, animationType);
841
- }; };
842
- var zoomOut = function (contextInstance) { return function (step, animationTime, animationType) {
843
- if (step === void 0) { step = 0.5; }
844
- if (animationTime === void 0) { animationTime = 300; }
845
- if (animationType === void 0) { animationType = "easeOut"; }
846
- handleZoomToViewCenter(contextInstance, -1, step, animationTime, animationType);
847
- }; };
848
- var setTransform = function (contextInstance) { return function (newPositionX, newPositionY, newScale, animationTime, animationType) {
849
- if (animationTime === void 0) { animationTime = 300; }
850
- if (animationType === void 0) { animationType = "easeOut"; }
851
- var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
852
- var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
853
- var disabled = contextInstance.setup.disabled;
854
- if (disabled || !wrapperComponent || !contentComponent)
855
- return;
856
- var targetState = {
857
- positionX: isNaN(newPositionX) ? positionX : newPositionX,
858
- positionY: isNaN(newPositionY) ? positionY : newPositionY,
859
- scale: isNaN(newScale) ? scale : newScale,
825
+ var zoomIn = function (contextInstance) {
826
+ return function (step, animationTime, animationType) {
827
+ if (step === void 0) { step = 0.5; }
828
+ if (animationTime === void 0) { animationTime = 300; }
829
+ if (animationType === void 0) { animationType = "easeOut"; }
830
+ handleZoomToViewCenter(contextInstance, 1, step, animationTime, animationType);
860
831
  };
861
- animate(contextInstance, targetState, animationTime, animationType);
862
- }; };
863
- var resetTransform = function (contextInstance) { return function (animationTime, animationType) {
864
- if (animationTime === void 0) { animationTime = 200; }
865
- if (animationType === void 0) { animationType = "easeOut"; }
866
- resetTransformations(contextInstance, animationTime, animationType);
867
- }; };
868
- var centerView = function (contextInstance) { return function (scale, animationTime, animationType) {
869
- if (animationTime === void 0) { animationTime = 200; }
870
- if (animationType === void 0) { animationType = "easeOut"; }
871
- var transformState = contextInstance.transformState, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
872
- if (wrapperComponent && contentComponent) {
873
- var targetState = getCenterPosition(scale || transformState.scale, wrapperComponent, contentComponent);
874
- animate(contextInstance, targetState, animationTime, animationType);
875
- }
876
- }; };
877
- var zoomToElement = function (contextInstance) { return function (node, scale, animationTime, animationType) {
878
- if (animationTime === void 0) { animationTime = 600; }
879
- if (animationType === void 0) { animationType = "easeOut"; }
880
- handleCancelAnimation(contextInstance);
881
- var wrapperComponent = contextInstance.wrapperComponent;
882
- var target = typeof node === "string" ? document.getElementById(node) : node;
883
- if (wrapperComponent &&
884
- isValidZoomNode(target) &&
885
- target &&
886
- wrapperComponent.contains(target)) {
887
- var targetState = calculateZoomToNode(contextInstance, target, scale);
832
+ };
833
+ var zoomOut = function (contextInstance) {
834
+ return function (step, animationTime, animationType) {
835
+ if (step === void 0) { step = 0.5; }
836
+ if (animationTime === void 0) { animationTime = 300; }
837
+ if (animationType === void 0) { animationType = "easeOut"; }
838
+ handleZoomToViewCenter(contextInstance, -1, step, animationTime, animationType);
839
+ };
840
+ };
841
+ var setTransform = function (contextInstance) {
842
+ return function (newPositionX, newPositionY, newScale, animationTime, animationType) {
843
+ if (animationTime === void 0) { animationTime = 300; }
844
+ if (animationType === void 0) { animationType = "easeOut"; }
845
+ var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
846
+ var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
847
+ var disabled = contextInstance.setup.disabled;
848
+ if (disabled || !wrapperComponent || !contentComponent)
849
+ return;
850
+ var targetState = {
851
+ positionX: Number.isNaN(newPositionX) ? positionX : newPositionX,
852
+ positionY: Number.isNaN(newPositionY) ? positionY : newPositionY,
853
+ scale: Number.isNaN(newScale) ? scale : newScale,
854
+ };
888
855
  animate(contextInstance, targetState, animationTime, animationType);
889
- }
890
- }; };
856
+ };
857
+ };
858
+ var resetTransform = function (contextInstance) {
859
+ return function (animationTime, animationType) {
860
+ if (animationTime === void 0) { animationTime = 200; }
861
+ if (animationType === void 0) { animationType = "easeOut"; }
862
+ resetTransformations(contextInstance, animationTime, animationType);
863
+ };
864
+ };
865
+ var centerView = function (contextInstance) {
866
+ return function (scale, animationTime, animationType) {
867
+ if (animationTime === void 0) { animationTime = 200; }
868
+ if (animationType === void 0) { animationType = "easeOut"; }
869
+ var transformState = contextInstance.transformState, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
870
+ if (wrapperComponent && contentComponent) {
871
+ var targetState = getCenterPosition(scale || transformState.scale, wrapperComponent, contentComponent);
872
+ animate(contextInstance, targetState, animationTime, animationType);
873
+ }
874
+ };
875
+ };
876
+ var zoomToElement = function (contextInstance) {
877
+ return function (node, scale, animationTime, animationType) {
878
+ if (animationTime === void 0) { animationTime = 600; }
879
+ if (animationType === void 0) { animationType = "easeOut"; }
880
+ handleCancelAnimation(contextInstance);
881
+ var wrapperComponent = contextInstance.wrapperComponent;
882
+ var target = typeof node === "string" ? document.getElementById(node) : node;
883
+ if (wrapperComponent &&
884
+ isValidZoomNode(target) &&
885
+ target &&
886
+ wrapperComponent.contains(target)) {
887
+ var targetState = calculateZoomToNode(contextInstance, target, scale);
888
+ animate(contextInstance, targetState, animationTime, animationType);
889
+ }
890
+ };
891
+ };
891
892
 
892
893
  var getContext = function (contextInstance) {
893
894
  return {
@@ -943,7 +944,15 @@ var cancelTimeout = function (timeout) {
943
944
  };
944
945
 
945
946
  var getTransformStyles = function (x, y, scale) {
946
- return "matrix(" + scale + ", 0,0, " + scale + ", " + x + ", " + y + ")";
947
+ // The shorthand for matrix does not work for Safari hence the need to explicitly use matrix3d
948
+ // Refer to https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix
949
+ var a = scale;
950
+ var b = 0;
951
+ var c = 0;
952
+ var d = scale;
953
+ var tx = x;
954
+ var ty = y;
955
+ return "matrix3d(".concat(a, ", ").concat(b, ", 0, 0, ").concat(c, ", ").concat(d, ", 0, 0, 0, 0, 1, 0, ").concat(tx, ", ").concat(ty, ", 0, 1)");
947
956
  };
948
957
  var getCenterPosition = function (scale, wrapperComponent, contentComponent) {
949
958
  var contentWidth = contentComponent.offsetWidth * scale;
@@ -974,8 +983,14 @@ var isWheelAllowed = function (contextInstance, event) {
974
983
  return false;
975
984
  return true;
976
985
  };
986
+ var getDeltaY = function (event) {
987
+ if (event) {
988
+ return event.deltaY < 0 ? 1 : -1;
989
+ }
990
+ return 0;
991
+ };
977
992
  function getDelta(event, customDelta) {
978
- var deltaY = event ? (event.deltaY < 0 ? 1 : -1) : 0;
993
+ var deltaY = getDeltaY(event);
979
994
  var delta = checkIsNumber(customDelta, deltaY);
980
995
  return delta;
981
996
  }
@@ -993,7 +1008,7 @@ function getMousePosition(event, contentComponent, scale) {
993
1008
  mouseX = (touch.clientX - contentRect.left) / scale;
994
1009
  mouseY = (touch.clientY - contentRect.top) / scale;
995
1010
  }
996
- if (isNaN(mouseX) || isNaN(mouseY))
1011
+ if (Number.isNaN(mouseX) || Number.isNaN(mouseY))
997
1012
  console.error("No mouse or touch offset found");
998
1013
  return {
999
1014
  x: mouseX,
@@ -1067,8 +1082,8 @@ var calculateTouchMidPoint = function (event, scale, contentComponent) {
1067
1082
  };
1068
1083
  };
1069
1084
  var getTouchDistance = function (event) {
1070
- return Math.sqrt(Math.pow(event.touches[0].pageX - event.touches[1].pageX, 2) +
1071
- Math.pow(event.touches[0].pageY - event.touches[1].pageY, 2));
1085
+ return Math.sqrt(Math.pow((event.touches[0].pageX - event.touches[1].pageX), 2) +
1086
+ Math.pow((event.touches[0].pageY - event.touches[1].pageY), 2));
1072
1087
  };
1073
1088
  var calculatePinchZoom = function (contextInstance, currentDistance) {
1074
1089
  var pinchStartScale = contextInstance.pinchStartScale, pinchStartDistance = contextInstance.pinchStartDistance, setup = contextInstance.setup;
@@ -1164,7 +1179,7 @@ var handlePinchZoom = function (contextInstance, event) {
1164
1179
  return;
1165
1180
  var midPoint = calculateTouchMidPoint(event, scale, contentComponent);
1166
1181
  // if touches goes off of the wrapper element
1167
- if (!isFinite(midPoint.x) || !isFinite(midPoint.y))
1182
+ if (!Number.isFinite(midPoint.x) || !Number.isFinite(midPoint.y))
1168
1183
  return;
1169
1184
  var currentDistance = getTouchDistance(event);
1170
1185
  var newScale = calculatePinchZoom(contextInstance, currentDistance);
@@ -1224,45 +1239,52 @@ var isDoubleClickAllowed = function (contextInstance, event) {
1224
1239
  return true;
1225
1240
  };
1226
1241
 
1227
- var Context = React.createContext(contextInitialState);
1228
- var TransformContext = /** @class */ (function (_super) {
1229
- __extends(TransformContext, _super);
1230
- function TransformContext() {
1231
- var _this = _super !== null && _super.apply(this, arguments) || this;
1232
- _this.mounted = true;
1233
- _this.transformState = createState(_this.props);
1234
- _this.setup = createSetup(_this.props);
1242
+ var ZoomPanPinch = /** @class */ (function () {
1243
+ function ZoomPanPinch(props) {
1244
+ var _this = this;
1245
+ this.props = props;
1246
+ this.mounted = true;
1235
1247
  // Components
1236
- _this.wrapperComponent = null;
1237
- _this.contentComponent = null;
1248
+ this.wrapperComponent = null;
1249
+ this.contentComponent = null;
1238
1250
  // Initialization
1239
- _this.isInitialized = false;
1240
- _this.bounds = null;
1251
+ this.isInitialized = false;
1252
+ this.bounds = null;
1241
1253
  // wheel helpers
1242
- _this.previousWheelEvent = null;
1243
- _this.wheelStopEventTimer = null;
1244
- _this.wheelAnimationTimer = null;
1254
+ this.previousWheelEvent = null;
1255
+ this.wheelStopEventTimer = null;
1256
+ this.wheelAnimationTimer = null;
1245
1257
  // panning helpers
1246
- _this.isPanning = false;
1247
- _this.startCoords = null;
1248
- _this.lastTouch = null;
1258
+ this.isPanning = false;
1259
+ this.startCoords = null;
1260
+ this.lastTouch = null;
1249
1261
  // pinch helpers
1250
- _this.distance = null;
1251
- _this.lastDistance = null;
1252
- _this.pinchStartDistance = null;
1253
- _this.pinchStartScale = null;
1254
- _this.pinchMidpoint = null;
1262
+ this.distance = null;
1263
+ this.lastDistance = null;
1264
+ this.pinchStartDistance = null;
1265
+ this.pinchStartScale = null;
1266
+ this.pinchMidpoint = null;
1255
1267
  // velocity helpers
1256
- _this.velocity = null;
1257
- _this.velocityTime = null;
1258
- _this.lastMousePosition = null;
1268
+ this.velocity = null;
1269
+ this.velocityTime = null;
1270
+ this.lastMousePosition = null;
1259
1271
  // animations helpers
1260
- _this.animate = false;
1261
- _this.animation = null;
1262
- _this.maxBounds = null;
1272
+ this.animate = false;
1273
+ this.animation = null;
1274
+ this.maxBounds = null;
1263
1275
  // key press
1264
- _this.pressedKeys = {};
1265
- _this.initializeWindowEvents = function () {
1276
+ this.pressedKeys = {};
1277
+ this.mount = function () {
1278
+ _this.initializeWindowEvents();
1279
+ };
1280
+ this.unmount = function () {
1281
+ _this.cleanupWindowEvents();
1282
+ };
1283
+ this.update = function (newProps) {
1284
+ handleCalculateBounds(_this, _this.transformState.scale);
1285
+ _this.setup = createSetup(newProps);
1286
+ };
1287
+ this.initializeWindowEvents = function () {
1266
1288
  var _a;
1267
1289
  var passive = makePassiveEventOption();
1268
1290
  var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
@@ -1274,10 +1296,9 @@ var TransformContext = /** @class */ (function (_super) {
1274
1296
  currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.addEventListener("mouseleave", _this.clearPanning, passive);
1275
1297
  currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("keyup", _this.setKeyUnPressed, passive);
1276
1298
  currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("keydown", _this.setKeyPressed, passive);
1277
- _this.handleRef();
1278
1299
  };
1279
- _this.cleanupWindowEvents = function () {
1280
- var _a;
1300
+ this.cleanupWindowEvents = function () {
1301
+ var _a, _b;
1281
1302
  var passive = makePassiveEventOption();
1282
1303
  var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
1283
1304
  var currentWindow = currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.defaultView;
@@ -1289,8 +1310,9 @@ var TransformContext = /** @class */ (function (_super) {
1289
1310
  currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("keydown", _this.setKeyPressed, passive);
1290
1311
  document.removeEventListener("mouseleave", _this.clearPanning, passive);
1291
1312
  handleCancelAnimation(_this);
1313
+ (_b = _this.observer) === null || _b === void 0 ? void 0 : _b.disconnect();
1292
1314
  };
1293
- _this.handleInitializeWrapperEvents = function (wrapper) {
1315
+ this.handleInitializeWrapperEvents = function (wrapper) {
1294
1316
  // Zooming events on wrapper
1295
1317
  var passive = makePassiveEventOption();
1296
1318
  wrapper.addEventListener("wheel", _this.onWheelZoom, passive);
@@ -1299,34 +1321,24 @@ var TransformContext = /** @class */ (function (_super) {
1299
1321
  wrapper.addEventListener("touchmove", _this.onTouchPanning, passive);
1300
1322
  wrapper.addEventListener("touchend", _this.onTouchPanningStop, passive);
1301
1323
  };
1302
- _this.handleInitialize = function () {
1324
+ this.handleInitialize = function (contentComponent) {
1303
1325
  var centerOnInit = _this.setup.centerOnInit;
1304
1326
  _this.applyTransformation();
1305
- _this.forceUpdate();
1306
1327
  if (centerOnInit) {
1307
- // this has to be redone once the right solution is found
1308
- // problem is - we need to execute it after mounted component specify it's height / width, images are fetched async so it's tricky
1309
- setTimeout(function () {
1310
- if (_this.mounted) {
1311
- _this.setCenter();
1312
- }
1313
- }, 50);
1314
- setTimeout(function () {
1315
- if (_this.mounted) {
1316
- _this.setCenter();
1317
- }
1318
- }, 100);
1319
- setTimeout(function () {
1320
- if (_this.mounted) {
1321
- _this.setCenter();
1322
- }
1323
- }, 200);
1328
+ _this.setCenter();
1329
+ _this.observer = new ResizeObserver(function () {
1330
+ var _a;
1331
+ _this.setCenter();
1332
+ (_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
1333
+ });
1334
+ // Start observing the target node for configured mutations
1335
+ _this.observer.observe(contentComponent);
1324
1336
  }
1325
1337
  };
1326
- //////////
1338
+ /// ///////
1327
1339
  // Zoom
1328
- //////////
1329
- _this.onWheelZoom = function (event) {
1340
+ /// ///////
1341
+ this.onWheelZoom = function (event) {
1330
1342
  var disabled = _this.setup.disabled;
1331
1343
  if (disabled)
1332
1344
  return;
@@ -1340,10 +1352,10 @@ var TransformContext = /** @class */ (function (_super) {
1340
1352
  handleWheelZoom(_this, event);
1341
1353
  handleWheelStop(_this, event);
1342
1354
  };
1343
- //////////
1355
+ /// ///////
1344
1356
  // Pan
1345
- //////////
1346
- _this.onPanningStart = function (event) {
1357
+ /// ///////
1358
+ this.onPanningStart = function (event) {
1347
1359
  var disabled = _this.setup.disabled;
1348
1360
  var onPanningStart = _this.props.onPanningStart;
1349
1361
  if (disabled)
@@ -1360,7 +1372,7 @@ var TransformContext = /** @class */ (function (_super) {
1360
1372
  handlePanningStart(_this, event);
1361
1373
  handleCallback(getContext(_this), event, onPanningStart);
1362
1374
  };
1363
- _this.onPanning = function (event) {
1375
+ this.onPanning = function (event) {
1364
1376
  var disabled = _this.setup.disabled;
1365
1377
  var onPanning = _this.props.onPanning;
1366
1378
  if (disabled)
@@ -1376,17 +1388,17 @@ var TransformContext = /** @class */ (function (_super) {
1376
1388
  handlePanning(_this, event.clientX, event.clientY);
1377
1389
  handleCallback(getContext(_this), event, onPanning);
1378
1390
  };
1379
- _this.onPanningStop = function (event) {
1391
+ this.onPanningStop = function (event) {
1380
1392
  var onPanningStop = _this.props.onPanningStop;
1381
1393
  if (_this.isPanning) {
1382
1394
  handlePanningEnd(_this);
1383
1395
  handleCallback(getContext(_this), event, onPanningStop);
1384
1396
  }
1385
1397
  };
1386
- //////////
1398
+ /// ///////
1387
1399
  // Pinch
1388
- //////////
1389
- _this.onPinchStart = function (event) {
1400
+ /// ///////
1401
+ this.onPinchStart = function (event) {
1390
1402
  var disabled = _this.setup.disabled;
1391
1403
  var _a = _this.props, onPinchingStart = _a.onPinchingStart, onZoomStart = _a.onZoomStart;
1392
1404
  if (disabled)
@@ -1399,7 +1411,7 @@ var TransformContext = /** @class */ (function (_super) {
1399
1411
  handleCallback(getContext(_this), event, onPinchingStart);
1400
1412
  handleCallback(getContext(_this), event, onZoomStart);
1401
1413
  };
1402
- _this.onPinch = function (event) {
1414
+ this.onPinch = function (event) {
1403
1415
  var disabled = _this.setup.disabled;
1404
1416
  var _a = _this.props, onPinching = _a.onPinching, onZoom = _a.onZoom;
1405
1417
  if (disabled)
@@ -1413,7 +1425,7 @@ var TransformContext = /** @class */ (function (_super) {
1413
1425
  handleCallback(getContext(_this), event, onPinching);
1414
1426
  handleCallback(getContext(_this), event, onZoom);
1415
1427
  };
1416
- _this.onPinchStop = function (event) {
1428
+ this.onPinchStop = function (event) {
1417
1429
  var _a = _this.props, onPinchingStop = _a.onPinchingStop, onZoomStop = _a.onZoomStop;
1418
1430
  if (_this.pinchStartScale) {
1419
1431
  handlePinchStop(_this);
@@ -1421,10 +1433,10 @@ var TransformContext = /** @class */ (function (_super) {
1421
1433
  handleCallback(getContext(_this), event, onZoomStop);
1422
1434
  }
1423
1435
  };
1424
- //////////
1436
+ /// ///////
1425
1437
  // Touch
1426
- //////////
1427
- _this.onTouchPanningStart = function (event) {
1438
+ /// ///////
1439
+ this.onTouchPanningStart = function (event) {
1428
1440
  var disabled = _this.setup.disabled;
1429
1441
  var onPanningStart = _this.props.onPanningStart;
1430
1442
  if (disabled)
@@ -1452,7 +1464,7 @@ var TransformContext = /** @class */ (function (_super) {
1452
1464
  }
1453
1465
  }
1454
1466
  };
1455
- _this.onTouchPanning = function (event) {
1467
+ this.onTouchPanning = function (event) {
1456
1468
  var disabled = _this.setup.disabled;
1457
1469
  var onPanning = _this.props.onPanning;
1458
1470
  if (_this.isPanning && event.touches.length === 1) {
@@ -1471,14 +1483,14 @@ var TransformContext = /** @class */ (function (_super) {
1471
1483
  _this.onPinch(event);
1472
1484
  }
1473
1485
  };
1474
- _this.onTouchPanningStop = function (event) {
1486
+ this.onTouchPanningStop = function (event) {
1475
1487
  _this.onPanningStop(event);
1476
1488
  _this.onPinchStop(event);
1477
1489
  };
1478
- //////////
1490
+ /// ///////
1479
1491
  // Double Click
1480
- //////////
1481
- _this.onDoubleClick = function (event) {
1492
+ /// ///////
1493
+ this.onDoubleClick = function (event) {
1482
1494
  var disabled = _this.setup.disabled;
1483
1495
  if (disabled)
1484
1496
  return;
@@ -1487,41 +1499,31 @@ var TransformContext = /** @class */ (function (_super) {
1487
1499
  return;
1488
1500
  handleDoubleClick(_this, event);
1489
1501
  };
1490
- //////////
1502
+ /// ///////
1491
1503
  // Helpers
1492
- //////////
1493
- _this.clearPanning = function (event) {
1504
+ /// ///////
1505
+ this.clearPanning = function (event) {
1494
1506
  if (_this.isPanning) {
1495
1507
  _this.onPanningStop(event);
1496
1508
  }
1497
1509
  };
1498
- _this.setKeyPressed = function (e) {
1510
+ this.setKeyPressed = function (e) {
1499
1511
  _this.pressedKeys[e.key] = true;
1500
1512
  };
1501
- _this.setKeyUnPressed = function (e) {
1513
+ this.setKeyUnPressed = function (e) {
1502
1514
  _this.pressedKeys[e.key] = false;
1503
1515
  };
1504
- _this.isPressingKeys = function (keys) {
1516
+ this.isPressingKeys = function (keys) {
1505
1517
  if (!keys.length) {
1506
1518
  return true;
1507
1519
  }
1508
1520
  return Boolean(keys.find(function (key) { return _this.pressedKeys[key]; }));
1509
1521
  };
1510
- _this.setComponents = function (wrapperComponent, contentComponent) {
1511
- _this.cleanupWindowEvents();
1512
- _this.wrapperComponent = wrapperComponent;
1513
- _this.contentComponent = contentComponent;
1514
- handleCalculateBounds(_this, _this.transformState.scale);
1515
- _this.handleInitializeWrapperEvents(wrapperComponent);
1516
- _this.initializeWindowEvents();
1517
- _this.handleInitialize();
1518
- _this.handleRef();
1519
- _this.isInitialized = true;
1520
- handleCallback(getContext(_this), undefined, _this.props.onInit);
1521
- };
1522
- _this.setTransformState = function (scale, positionX, positionY) {
1522
+ this.setTransformState = function (scale, positionX, positionY) {
1523
1523
  var onTransformed = _this.props.onTransformed;
1524
- if (!isNaN(scale) && !isNaN(positionX) && !isNaN(positionY)) {
1524
+ if (!Number.isNaN(scale) &&
1525
+ !Number.isNaN(positionX) &&
1526
+ !Number.isNaN(positionY)) {
1525
1527
  if (scale !== _this.transformState.scale) {
1526
1528
  _this.transformState.previousScale = _this.transformState.scale;
1527
1529
  _this.transformState.scale = scale;
@@ -1535,50 +1537,58 @@ var TransformContext = /** @class */ (function (_super) {
1535
1537
  console.error("Detected NaN set state values");
1536
1538
  }
1537
1539
  };
1538
- _this.setCenter = function () {
1540
+ this.setCenter = function () {
1539
1541
  if (_this.wrapperComponent && _this.contentComponent) {
1540
1542
  var targetState = getCenterPosition(_this.transformState.scale, _this.wrapperComponent, _this.contentComponent);
1541
1543
  _this.setTransformState(targetState.scale, targetState.positionX, targetState.positionY);
1542
1544
  }
1543
1545
  };
1544
- _this.applyTransformation = function () {
1546
+ this.applyTransformation = function () {
1545
1547
  if (!_this.mounted || !_this.contentComponent)
1546
1548
  return;
1547
1549
  var _a = _this.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
1548
1550
  var transform = getTransformStyles(positionX, positionY, scale);
1549
1551
  _this.contentComponent.style.transform = transform;
1550
- _this.handleRef();
1551
1552
  };
1552
- _this.handleRef = function () {
1553
- _this.props.setRef(getContext(_this));
1553
+ this.getContext = function () {
1554
+ return getContext(_this);
1554
1555
  };
1555
- return _this;
1556
+ /**
1557
+ * Initialization
1558
+ */
1559
+ this.init = function (wrapperComponent, contentComponent) {
1560
+ _this.cleanupWindowEvents();
1561
+ _this.wrapperComponent = wrapperComponent;
1562
+ _this.contentComponent = contentComponent;
1563
+ handleCalculateBounds(_this, _this.transformState.scale);
1564
+ _this.handleInitializeWrapperEvents(wrapperComponent);
1565
+ _this.handleInitialize(contentComponent);
1566
+ _this.initializeWindowEvents();
1567
+ _this.isInitialized = true;
1568
+ handleCallback(getContext(_this), undefined, _this.props.onInit);
1569
+ };
1570
+ this.setup = createSetup(this.props);
1571
+ this.transformState = createState(this.props);
1556
1572
  }
1557
- TransformContext.prototype.componentDidMount = function () {
1558
- this.initializeWindowEvents();
1559
- };
1560
- TransformContext.prototype.componentWillUnmount = function () {
1561
- this.cleanupWindowEvents();
1562
- };
1563
- TransformContext.prototype.componentDidUpdate = function (oldProps) {
1564
- if (oldProps !== this.props) {
1565
- handleCalculateBounds(this, this.transformState.scale);
1566
- this.setup = createSetup(this.props);
1567
- }
1568
- };
1569
- TransformContext.prototype.render = function () {
1570
- var value = getContext(this);
1571
- var children = this.props.children;
1572
- var content = typeof children === "function" ? children(value) : children;
1573
- return (React.createElement(Context.Provider, { value: __assign(__assign({}, this.transformState), { setComponents: this.setComponents, contextInstance: this }) }, content));
1574
- };
1575
- return TransformContext;
1576
- }(Component));
1573
+ return ZoomPanPinch;
1574
+ }());
1577
1575
 
1576
+ var Context = React.createContext(contextInitialState);
1578
1577
  var TransformWrapper = React.forwardRef(function (props, ref) {
1579
- var _a = useState(null), innerRef = _a[0], setRef = _a[1];
1580
- useImperativeHandle(ref, function () { return innerRef; }, [innerRef]);
1581
- return React.createElement(TransformContext, __assign({}, props, { setRef: setRef }));
1578
+ var children = props.children;
1579
+ var instance = useRef(new ZoomPanPinch(props)).current;
1580
+ var content = useMemo(function () {
1581
+ if (typeof children === "function") {
1582
+ return children(getContext(instance));
1583
+ }
1584
+ return children;
1585
+ }, [children, instance]);
1586
+ var value = useMemo(function () {
1587
+ return __assign(__assign({}, instance.transformState), { setComponents: instance.init, contextInstance: instance });
1588
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1589
+ }, [JSON.stringify(instance.transformState)]);
1590
+ useImperativeHandle(ref, function () { return getContext(instance); }, [instance]);
1591
+ return React.createElement(Context.Provider, { value: value }, content);
1582
1592
  });
1583
1593
 
1584
1594
  function styleInject(css, ref) {
@@ -1608,10 +1618,11 @@ function styleInject(css, ref) {
1608
1618
  }
1609
1619
  }
1610
1620
 
1611
- var css_248z = ".transform-component-module_wrapper__1_Fgj {\n position: relative;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n overflow: hidden;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -khtml-user-select: none; /* Konqueror HTML */\n -moz-user-select: none; /* Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none;\n margin: 0;\n padding: 0;\n}\n.transform-component-module_content__2jYgh {\n display: flex;\n flex-wrap: wrap;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n margin: 0;\n padding: 0;\n transform-origin: 0% 0%;\n}\n.transform-component-module_content__2jYgh img {\n pointer-events: none;\n}\n";
1612
- var styles = {"wrapper":"transform-component-module_wrapper__1_Fgj","content":"transform-component-module_content__2jYgh"};
1621
+ var css_248z = ".transform-component-module_wrapper__7HFJe {\n position: relative;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n overflow: hidden;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -khtml-user-select: none; /* Konqueror HTML */\n -moz-user-select: none; /* Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none;\n margin: 0;\n padding: 0;\n}\n.transform-component-module_content__uCDPE {\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__uCDPE img {\n pointer-events: none;\n}\n";
1622
+ var styles = {"wrapper":"transform-component-module_wrapper__7HFJe","content":"transform-component-module_content__uCDPE"};
1613
1623
  styleInject(css_248z);
1614
1624
 
1625
+ /* eslint-disable react/require-default-props */
1615
1626
  var TransformComponent = function (_a) {
1616
1627
  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;
1617
1628
  var setComponents = useContext(Context).setComponents;
@@ -1624,8 +1635,8 @@ var TransformComponent = function (_a) {
1624
1635
  setComponents(wrapper, content);
1625
1636
  }
1626
1637
  }, []);
1627
- return (React.createElement("div", { ref: wrapperRef, className: "react-transform-wrapper " + styles.wrapper + " " + wrapperClass, style: wrapperStyle },
1628
- React.createElement("div", { ref: contentRef, className: "react-transform-component " + styles.content + " " + contentClass, style: contentStyle }, children)));
1638
+ return (React.createElement("div", { ref: wrapperRef, className: "react-transform-wrapper ".concat(styles.wrapper, " ").concat(wrapperClass), style: wrapperStyle },
1639
+ React.createElement("div", { ref: contentRef, className: "react-transform-component ".concat(styles.content, " ").concat(contentClass), style: contentStyle }, children)));
1629
1640
  };
1630
1641
 
1631
1642
  var useTransformContext = function () {