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.cjs.js CHANGED
@@ -8,7 +8,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
8
8
 
9
9
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
10
10
 
11
- /*! *****************************************************************************
11
+ /******************************************************************************
12
12
  Copyright (c) Microsoft Corporation.
13
13
 
14
14
  Permission to use, copy, modify, and/or distribute this software for any
@@ -22,22 +22,6 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
22
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
23
  PERFORMANCE OF THIS SOFTWARE.
24
24
  ***************************************************************************** */
25
- /* global Reflect, Promise */
26
-
27
- var extendStatics = function(d, b) {
28
- extendStatics = Object.setPrototypeOf ||
29
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
30
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
31
- return extendStatics(d, b);
32
- };
33
-
34
- function __extends(d, b) {
35
- if (typeof b !== "function" && b !== null)
36
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
37
- extendStatics(d, b);
38
- function __() { this.constructor = d; }
39
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
40
- }
41
25
 
42
26
  var __assign = function() {
43
27
  __assign = Object.assign || function __assign(t) {
@@ -57,7 +41,7 @@ function __spreadArray(to, from, pack) {
57
41
  ar[i] = from[i];
58
42
  }
59
43
  }
60
- return to.concat(ar || from);
44
+ return to.concat(ar || Array.prototype.slice.call(from));
61
45
  }
62
46
 
63
47
  /**
@@ -82,6 +66,8 @@ var handleCallback = function (context, event, callback) {
82
66
  }
83
67
  };
84
68
 
69
+ /* eslint-disable no-plusplus */
70
+ /* eslint-disable no-param-reassign */
85
71
  /**
86
72
  * Functions should return denominator of the target value, which is the next animation step.
87
73
  * t is a value from 0 to 1, reflecting the percentage of animation status.
@@ -158,6 +144,7 @@ var animations = {
158
144
  easeInOutQuint: easeInOutQuint,
159
145
  };
160
146
 
147
+ /* eslint-disable no-param-reassign */
161
148
  var handleCancelAnimationFrame = function (animation) {
162
149
  if (typeof animation === "number") {
163
150
  cancelAnimationFrame(animation);
@@ -199,6 +186,15 @@ function handleSetupAnimation(contextInstance, animationName, animationTime, cal
199
186
  };
200
187
  requestAnimationFrame(contextInstance.animation);
201
188
  }
189
+ function isValidTargetState(targetState) {
190
+ var scale = targetState.scale, positionX = targetState.positionX, positionY = targetState.positionY;
191
+ if (Number.isNaN(scale) ||
192
+ Number.isNaN(positionX) ||
193
+ Number.isNaN(positionY)) {
194
+ return false;
195
+ }
196
+ return true;
197
+ }
202
198
  function animate(contextInstance, targetState, animationTime, animationName) {
203
199
  var isValid = isValidTargetState(targetState);
204
200
  if (!contextInstance.mounted || !isValid)
@@ -221,14 +217,8 @@ function animate(contextInstance, targetState, animationTime, animationName) {
221
217
  });
222
218
  }
223
219
  }
224
- function isValidTargetState(targetState) {
225
- var scale = targetState.scale, positionX = targetState.positionX, positionY = targetState.positionY;
226
- if (isNaN(scale) || isNaN(positionX) || isNaN(positionY)) {
227
- return false;
228
- }
229
- return true;
230
- }
231
220
 
221
+ /* eslint-disable no-param-reassign */
232
222
  function getComponentsSizes(wrapperComponent, contentComponent, newScale) {
233
223
  var wrapperWidth = wrapperComponent.offsetWidth;
234
224
  var wrapperHeight = wrapperComponent.offsetHeight;
@@ -270,6 +260,22 @@ var calculateBounds = function (contextInstance, newScale) {
270
260
  var bounds = getBounds(wrapperWidth, newContentWidth, newDiffWidth, wrapperHeight, newContentHeight, newDiffHeight, Boolean(centerZoomedOut));
271
261
  return bounds;
272
262
  };
263
+ /**
264
+ * Keeps value between given bounds, used for limiting view to given boundaries
265
+ * 1# eg. boundLimiter(2, 0, 3, true) => 2
266
+ * 2# eg. boundLimiter(4, 0, 3, true) => 3
267
+ * 3# eg. boundLimiter(-2, 0, 3, true) => 0
268
+ * 4# eg. boundLimiter(10, 0, 3, false) => 10
269
+ */
270
+ var boundLimiter = function (value, minBound, maxBound, isActive) {
271
+ if (!isActive)
272
+ return roundNumber(value, 2);
273
+ if (value < minBound)
274
+ return roundNumber(minBound, 2);
275
+ if (value > maxBound)
276
+ return roundNumber(maxBound, 2);
277
+ return roundNumber(value, 2);
278
+ };
273
279
  var handleCalculateBounds = function (contextInstance, newScale) {
274
280
  var bounds = calculateBounds(contextInstance, newScale);
275
281
  // Save bounds
@@ -288,22 +294,6 @@ function getMouseBoundedPosition(positionX, positionY, bounds, limitToBounds, pa
288
294
  var y = boundLimiter(positionY, minPositionY - paddingY, maxPositionY + paddingY, limitToBounds);
289
295
  return { x: x, y: y };
290
296
  }
291
- /**
292
- * Keeps value between given bounds, used for limiting view to given boundaries
293
- * 1# eg. boundLimiter(2, 0, 3, true) => 2
294
- * 2# eg. boundLimiter(4, 0, 3, true) => 3
295
- * 3# eg. boundLimiter(-2, 0, 3, true) => 0
296
- * 4# eg. boundLimiter(10, 0, 3, false) => 10
297
- */
298
- var boundLimiter = function (value, minBound, maxBound, isActive) {
299
- if (!isActive)
300
- return roundNumber(value, 2);
301
- if (value < minBound)
302
- return roundNumber(minBound, 2);
303
- if (value > maxBound)
304
- return roundNumber(maxBound, 2);
305
- return roundNumber(value, 2);
306
- };
307
297
 
308
298
  function handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds) {
309
299
  var _a = contextInstance.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
@@ -322,9 +312,9 @@ function handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale,
322
312
  function checkZoomBounds(zoom, minScale, maxScale, zoomPadding, enablePadding) {
323
313
  var scalePadding = enablePadding ? zoomPadding : 0;
324
314
  var minScaleWithPadding = minScale - scalePadding;
325
- if (!isNaN(maxScale) && zoom >= maxScale)
315
+ if (!Number.isNaN(maxScale) && zoom >= maxScale)
326
316
  return maxScale;
327
- if (!isNaN(minScale) && zoom <= minScaleWithPadding)
317
+ if (!Number.isNaN(minScale) && zoom <= minScaleWithPadding)
328
318
  return minScaleWithPadding;
329
319
  return zoom;
330
320
  }
@@ -566,6 +556,18 @@ function handlePanningStart(contextInstance, event) {
566
556
  handlePanningSetup(contextInstance, event);
567
557
  }
568
558
  }
559
+ function handleAlignToBounds(contextInstance) {
560
+ var scale = contextInstance.transformState.scale;
561
+ var _a = contextInstance.setup, minScale = _a.minScale, alignmentAnimation = _a.alignmentAnimation;
562
+ var disabled = alignmentAnimation.disabled, sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, animationTime = alignmentAnimation.animationTime, animationType = alignmentAnimation.animationType;
563
+ var isDisabled = disabled || scale < minScale || (!sizeX && !sizeY);
564
+ if (isDisabled)
565
+ return;
566
+ var targetState = handlePanToBounds(contextInstance);
567
+ if (targetState) {
568
+ animate(contextInstance, targetState, animationTime, animationType);
569
+ }
570
+ }
569
571
  function handlePanning(contextInstance, clientX, clientY) {
570
572
  var startCoords = contextInstance.startCoords, setup = contextInstance.setup;
571
573
  var _a = setup.alignmentAnimation, sizeX = _a.sizeX, sizeY = _a.sizeY;
@@ -600,19 +602,14 @@ function handlePanningEnd(contextInstance) {
600
602
  }
601
603
  }
602
604
  }
603
- function handleAlignToBounds(contextInstance) {
604
- var scale = contextInstance.transformState.scale;
605
- var _a = contextInstance.setup, minScale = _a.minScale, alignmentAnimation = _a.alignmentAnimation;
606
- var disabled = alignmentAnimation.disabled, sizeX = alignmentAnimation.sizeX, sizeY = alignmentAnimation.sizeY, animationTime = alignmentAnimation.animationTime, animationType = alignmentAnimation.animationType;
607
- var isDisabled = disabled || scale < minScale || (!sizeX && !sizeY);
608
- if (isDisabled)
609
- return;
610
- var targetState = handlePanToBounds(contextInstance);
611
- if (targetState) {
612
- animate(contextInstance, targetState, animationTime, animationType);
613
- }
614
- }
615
605
 
606
+ function handleZoomToPoint(contextInstance, scale, mouseX, mouseY) {
607
+ var _a = contextInstance.setup, minScale = _a.minScale, maxScale = _a.maxScale, limitToBounds = _a.limitToBounds;
608
+ var newScale = checkZoomBounds(roundNumber(scale, 2), minScale, maxScale, 0, false);
609
+ var bounds = handleCalculateBounds(contextInstance, newScale);
610
+ var _b = handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds), x = _b.x, y = _b.y;
611
+ return { scale: newScale, positionX: x, positionY: y };
612
+ }
616
613
  function handleAlignToScaleBounds(contextInstance, mousePositionX, mousePositionY) {
617
614
  var scale = contextInstance.transformState.scale;
618
615
  var wrapperComponent = contextInstance.wrapperComponent;
@@ -632,13 +629,6 @@ function handleAlignToScaleBounds(contextInstance, mousePositionX, mousePosition
632
629
  animate(contextInstance, targetState, animationTime, animationType);
633
630
  }
634
631
  }
635
- function handleZoomToPoint(contextInstance, scale, mouseX, mouseY) {
636
- var _a = contextInstance.setup, minScale = _a.minScale, maxScale = _a.maxScale, limitToBounds = _a.limitToBounds;
637
- var newScale = checkZoomBounds(roundNumber(scale, 2), minScale, maxScale, 0, false);
638
- var bounds = handleCalculateBounds(contextInstance, newScale);
639
- var _b = handleCalculateZoomPositions(contextInstance, mouseX, mouseY, newScale, bounds, limitToBounds), x = _b.x, y = _b.y;
640
- return { scale: newScale, positionX: x, positionY: y };
641
- }
642
632
 
643
633
  var initialState = {
644
634
  previousScale: 1,
@@ -733,7 +723,7 @@ var createSetup = function (props) {
733
723
  newSetup[key] = __assign(__assign({}, initialSetup[key]), props[key]);
734
724
  }
735
725
  else if (isArray) {
736
- newSetup[key] = __spreadArray(__spreadArray([], initialSetup[key]), props[key]);
726
+ newSetup[key] = __spreadArray(__spreadArray([], initialSetup[key], true), props[key], true);
737
727
  }
738
728
  else {
739
729
  newSetup[key] = props[key];
@@ -792,6 +782,20 @@ function resetTransformations(contextInstance, animationTime, animationType) {
792
782
  }
793
783
  animate(contextInstance, newState, animationTime, animationType);
794
784
  }
785
+ function getOffset(element) {
786
+ var el = element;
787
+ var offsetLeft = 0;
788
+ var offsetTop = 0;
789
+ while (el) {
790
+ offsetLeft += el.offsetLeft;
791
+ offsetTop += el.offsetTop;
792
+ el = el.offsetParent;
793
+ }
794
+ return {
795
+ x: offsetLeft - window.scrollX,
796
+ y: offsetTop - window.scrollY,
797
+ };
798
+ }
795
799
  function calculateZoomToNode(contextInstance, node, customZoom) {
796
800
  var wrapperComponent = contextInstance.wrapperComponent;
797
801
  var _a = contextInstance.setup, limitToBounds = _a.limitToBounds, minScale = _a.minScale, maxScale = _a.maxScale;
@@ -814,88 +818,85 @@ function calculateZoomToNode(contextInstance, node, customZoom) {
814
818
  var _b = getMouseBoundedPosition(newPositionX, newPositionY, bounds, limitToBounds, 0, 0, wrapperComponent), x = _b.x, y = _b.y;
815
819
  return { positionX: x, positionY: y, scale: newScale };
816
820
  }
817
- function getOffset(element) {
818
- var el = element;
819
- var offsetLeft = 0;
820
- var offsetTop = 0;
821
- while (el) {
822
- offsetLeft += el.offsetLeft;
823
- offsetTop += el.offsetTop;
824
- el = el.offsetParent;
825
- }
826
- return {
827
- x: offsetLeft - window.scrollX,
828
- y: offsetTop - window.scrollY,
829
- };
830
- }
831
821
  function isValidZoomNode(node) {
832
822
  if (!node) {
833
823
  console.error("Zoom node not found");
834
824
  return false;
835
825
  }
836
- else if ((node === null || node === void 0 ? void 0 : node.offsetWidth) === undefined ||
837
- (node === null || node === void 0 ? void 0 : node.offsetHeight) === undefined) {
826
+ if ((node === null || node === void 0 ? void 0 : node.offsetWidth) === undefined || (node === null || node === void 0 ? void 0 : node.offsetHeight) === undefined) {
838
827
  console.error("Zoom node is not valid - it must contain offsetWidth and offsetHeight");
839
828
  return false;
840
829
  }
841
830
  return true;
842
831
  }
843
832
 
844
- var zoomIn = function (contextInstance) { return function (step, animationTime, animationType) {
845
- if (step === void 0) { step = 0.5; }
846
- if (animationTime === void 0) { animationTime = 300; }
847
- if (animationType === void 0) { animationType = "easeOut"; }
848
- handleZoomToViewCenter(contextInstance, 1, step, animationTime, animationType);
849
- }; };
850
- var zoomOut = function (contextInstance) { return function (step, animationTime, animationType) {
851
- if (step === void 0) { step = 0.5; }
852
- if (animationTime === void 0) { animationTime = 300; }
853
- if (animationType === void 0) { animationType = "easeOut"; }
854
- handleZoomToViewCenter(contextInstance, -1, step, animationTime, animationType);
855
- }; };
856
- var setTransform = function (contextInstance) { return function (newPositionX, newPositionY, newScale, animationTime, animationType) {
857
- if (animationTime === void 0) { animationTime = 300; }
858
- if (animationType === void 0) { animationType = "easeOut"; }
859
- var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
860
- var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
861
- var disabled = contextInstance.setup.disabled;
862
- if (disabled || !wrapperComponent || !contentComponent)
863
- return;
864
- var targetState = {
865
- positionX: isNaN(newPositionX) ? positionX : newPositionX,
866
- positionY: isNaN(newPositionY) ? positionY : newPositionY,
867
- scale: isNaN(newScale) ? scale : newScale,
833
+ var zoomIn = 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);
868
839
  };
869
- animate(contextInstance, targetState, animationTime, animationType);
870
- }; };
871
- var resetTransform = function (contextInstance) { return function (animationTime, animationType) {
872
- if (animationTime === void 0) { animationTime = 200; }
873
- if (animationType === void 0) { animationType = "easeOut"; }
874
- resetTransformations(contextInstance, animationTime, animationType);
875
- }; };
876
- var centerView = function (contextInstance) { return function (scale, animationTime, animationType) {
877
- if (animationTime === void 0) { animationTime = 200; }
878
- if (animationType === void 0) { animationType = "easeOut"; }
879
- var transformState = contextInstance.transformState, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
880
- if (wrapperComponent && contentComponent) {
881
- var targetState = getCenterPosition(scale || transformState.scale, wrapperComponent, contentComponent);
882
- animate(contextInstance, targetState, animationTime, animationType);
883
- }
884
- }; };
885
- var zoomToElement = function (contextInstance) { return function (node, scale, animationTime, animationType) {
886
- if (animationTime === void 0) { animationTime = 600; }
887
- if (animationType === void 0) { animationType = "easeOut"; }
888
- handleCancelAnimation(contextInstance);
889
- var wrapperComponent = contextInstance.wrapperComponent;
890
- var target = typeof node === "string" ? document.getElementById(node) : node;
891
- if (wrapperComponent &&
892
- isValidZoomNode(target) &&
893
- target &&
894
- wrapperComponent.contains(target)) {
895
- var targetState = calculateZoomToNode(contextInstance, target, scale);
840
+ };
841
+ var zoomOut = function (contextInstance) {
842
+ 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
+ };
849
+ var setTransform = function (contextInstance) {
850
+ return function (newPositionX, newPositionY, newScale, animationTime, animationType) {
851
+ if (animationTime === void 0) { animationTime = 300; }
852
+ if (animationType === void 0) { animationType = "easeOut"; }
853
+ var _a = contextInstance.transformState, positionX = _a.positionX, positionY = _a.positionY, scale = _a.scale;
854
+ var wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
855
+ var disabled = contextInstance.setup.disabled;
856
+ if (disabled || !wrapperComponent || !contentComponent)
857
+ return;
858
+ var targetState = {
859
+ positionX: Number.isNaN(newPositionX) ? positionX : newPositionX,
860
+ positionY: Number.isNaN(newPositionY) ? positionY : newPositionY,
861
+ scale: Number.isNaN(newScale) ? scale : newScale,
862
+ };
896
863
  animate(contextInstance, targetState, animationTime, animationType);
897
- }
898
- }; };
864
+ };
865
+ };
866
+ var resetTransform = function (contextInstance) {
867
+ return function (animationTime, animationType) {
868
+ if (animationTime === void 0) { animationTime = 200; }
869
+ if (animationType === void 0) { animationType = "easeOut"; }
870
+ resetTransformations(contextInstance, animationTime, animationType);
871
+ };
872
+ };
873
+ var centerView = function (contextInstance) {
874
+ return function (scale, animationTime, animationType) {
875
+ if (animationTime === void 0) { animationTime = 200; }
876
+ if (animationType === void 0) { animationType = "easeOut"; }
877
+ var transformState = contextInstance.transformState, wrapperComponent = contextInstance.wrapperComponent, contentComponent = contextInstance.contentComponent;
878
+ if (wrapperComponent && contentComponent) {
879
+ var targetState = getCenterPosition(scale || transformState.scale, wrapperComponent, contentComponent);
880
+ animate(contextInstance, targetState, animationTime, animationType);
881
+ }
882
+ };
883
+ };
884
+ var zoomToElement = function (contextInstance) {
885
+ return function (node, scale, animationTime, animationType) {
886
+ if (animationTime === void 0) { animationTime = 600; }
887
+ if (animationType === void 0) { animationType = "easeOut"; }
888
+ handleCancelAnimation(contextInstance);
889
+ var wrapperComponent = contextInstance.wrapperComponent;
890
+ var target = typeof node === "string" ? document.getElementById(node) : node;
891
+ if (wrapperComponent &&
892
+ isValidZoomNode(target) &&
893
+ target &&
894
+ wrapperComponent.contains(target)) {
895
+ var targetState = calculateZoomToNode(contextInstance, target, scale);
896
+ animate(contextInstance, targetState, animationTime, animationType);
897
+ }
898
+ };
899
+ };
899
900
 
900
901
  var getContext = function (contextInstance) {
901
902
  return {
@@ -951,7 +952,15 @@ var cancelTimeout = function (timeout) {
951
952
  };
952
953
 
953
954
  var getTransformStyles = function (x, y, scale) {
954
- return "matrix(" + scale + ", 0,0, " + scale + ", " + x + ", " + y + ")";
955
+ // The shorthand for matrix does not work for Safari hence the need to explicitly use matrix3d
956
+ // Refer to https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix
957
+ var a = scale;
958
+ var b = 0;
959
+ var c = 0;
960
+ var d = scale;
961
+ var tx = x;
962
+ var ty = y;
963
+ return "matrix3d(".concat(a, ", ").concat(b, ", 0, 0, ").concat(c, ", ").concat(d, ", 0, 0, 0, 0, 1, 0, ").concat(tx, ", ").concat(ty, ", 0, 1)");
955
964
  };
956
965
  var getCenterPosition = function (scale, wrapperComponent, contentComponent) {
957
966
  var contentWidth = contentComponent.offsetWidth * scale;
@@ -982,8 +991,14 @@ var isWheelAllowed = function (contextInstance, event) {
982
991
  return false;
983
992
  return true;
984
993
  };
994
+ var getDeltaY = function (event) {
995
+ if (event) {
996
+ return event.deltaY < 0 ? 1 : -1;
997
+ }
998
+ return 0;
999
+ };
985
1000
  function getDelta(event, customDelta) {
986
- var deltaY = event ? (event.deltaY < 0 ? 1 : -1) : 0;
1001
+ var deltaY = getDeltaY(event);
987
1002
  var delta = checkIsNumber(customDelta, deltaY);
988
1003
  return delta;
989
1004
  }
@@ -1001,7 +1016,7 @@ function getMousePosition(event, contentComponent, scale) {
1001
1016
  mouseX = (touch.clientX - contentRect.left) / scale;
1002
1017
  mouseY = (touch.clientY - contentRect.top) / scale;
1003
1018
  }
1004
- if (isNaN(mouseX) || isNaN(mouseY))
1019
+ if (Number.isNaN(mouseX) || Number.isNaN(mouseY))
1005
1020
  console.error("No mouse or touch offset found");
1006
1021
  return {
1007
1022
  x: mouseX,
@@ -1075,8 +1090,8 @@ var calculateTouchMidPoint = function (event, scale, contentComponent) {
1075
1090
  };
1076
1091
  };
1077
1092
  var getTouchDistance = function (event) {
1078
- return Math.sqrt(Math.pow(event.touches[0].pageX - event.touches[1].pageX, 2) +
1079
- Math.pow(event.touches[0].pageY - event.touches[1].pageY, 2));
1093
+ return Math.sqrt(Math.pow((event.touches[0].pageX - event.touches[1].pageX), 2) +
1094
+ Math.pow((event.touches[0].pageY - event.touches[1].pageY), 2));
1080
1095
  };
1081
1096
  var calculatePinchZoom = function (contextInstance, currentDistance) {
1082
1097
  var pinchStartScale = contextInstance.pinchStartScale, pinchStartDistance = contextInstance.pinchStartDistance, setup = contextInstance.setup;
@@ -1172,7 +1187,7 @@ var handlePinchZoom = function (contextInstance, event) {
1172
1187
  return;
1173
1188
  var midPoint = calculateTouchMidPoint(event, scale, contentComponent);
1174
1189
  // if touches goes off of the wrapper element
1175
- if (!isFinite(midPoint.x) || !isFinite(midPoint.y))
1190
+ if (!Number.isFinite(midPoint.x) || !Number.isFinite(midPoint.y))
1176
1191
  return;
1177
1192
  var currentDistance = getTouchDistance(event);
1178
1193
  var newScale = calculatePinchZoom(contextInstance, currentDistance);
@@ -1232,45 +1247,52 @@ var isDoubleClickAllowed = function (contextInstance, event) {
1232
1247
  return true;
1233
1248
  };
1234
1249
 
1235
- var Context = React__default['default'].createContext(contextInitialState);
1236
- var TransformContext = /** @class */ (function (_super) {
1237
- __extends(TransformContext, _super);
1238
- function TransformContext() {
1239
- var _this = _super !== null && _super.apply(this, arguments) || this;
1240
- _this.mounted = true;
1241
- _this.transformState = createState(_this.props);
1242
- _this.setup = createSetup(_this.props);
1250
+ var ZoomPanPinch = /** @class */ (function () {
1251
+ function ZoomPanPinch(props) {
1252
+ var _this = this;
1253
+ this.props = props;
1254
+ this.mounted = true;
1243
1255
  // Components
1244
- _this.wrapperComponent = null;
1245
- _this.contentComponent = null;
1256
+ this.wrapperComponent = null;
1257
+ this.contentComponent = null;
1246
1258
  // Initialization
1247
- _this.isInitialized = false;
1248
- _this.bounds = null;
1259
+ this.isInitialized = false;
1260
+ this.bounds = null;
1249
1261
  // wheel helpers
1250
- _this.previousWheelEvent = null;
1251
- _this.wheelStopEventTimer = null;
1252
- _this.wheelAnimationTimer = null;
1262
+ this.previousWheelEvent = null;
1263
+ this.wheelStopEventTimer = null;
1264
+ this.wheelAnimationTimer = null;
1253
1265
  // panning helpers
1254
- _this.isPanning = false;
1255
- _this.startCoords = null;
1256
- _this.lastTouch = null;
1266
+ this.isPanning = false;
1267
+ this.startCoords = null;
1268
+ this.lastTouch = null;
1257
1269
  // pinch helpers
1258
- _this.distance = null;
1259
- _this.lastDistance = null;
1260
- _this.pinchStartDistance = null;
1261
- _this.pinchStartScale = null;
1262
- _this.pinchMidpoint = null;
1270
+ this.distance = null;
1271
+ this.lastDistance = null;
1272
+ this.pinchStartDistance = null;
1273
+ this.pinchStartScale = null;
1274
+ this.pinchMidpoint = null;
1263
1275
  // velocity helpers
1264
- _this.velocity = null;
1265
- _this.velocityTime = null;
1266
- _this.lastMousePosition = null;
1276
+ this.velocity = null;
1277
+ this.velocityTime = null;
1278
+ this.lastMousePosition = null;
1267
1279
  // animations helpers
1268
- _this.animate = false;
1269
- _this.animation = null;
1270
- _this.maxBounds = null;
1280
+ this.animate = false;
1281
+ this.animation = null;
1282
+ this.maxBounds = null;
1271
1283
  // key press
1272
- _this.pressedKeys = {};
1273
- _this.initializeWindowEvents = function () {
1284
+ this.pressedKeys = {};
1285
+ this.mount = function () {
1286
+ _this.initializeWindowEvents();
1287
+ };
1288
+ this.unmount = function () {
1289
+ _this.cleanupWindowEvents();
1290
+ };
1291
+ this.update = function (newProps) {
1292
+ handleCalculateBounds(_this, _this.transformState.scale);
1293
+ _this.setup = createSetup(newProps);
1294
+ };
1295
+ this.initializeWindowEvents = function () {
1274
1296
  var _a;
1275
1297
  var passive = makePassiveEventOption();
1276
1298
  var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
@@ -1282,10 +1304,9 @@ var TransformContext = /** @class */ (function (_super) {
1282
1304
  currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.addEventListener("mouseleave", _this.clearPanning, passive);
1283
1305
  currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("keyup", _this.setKeyUnPressed, passive);
1284
1306
  currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("keydown", _this.setKeyPressed, passive);
1285
- _this.handleRef();
1286
1307
  };
1287
- _this.cleanupWindowEvents = function () {
1288
- var _a;
1308
+ this.cleanupWindowEvents = function () {
1309
+ var _a, _b;
1289
1310
  var passive = makePassiveEventOption();
1290
1311
  var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
1291
1312
  var currentWindow = currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.defaultView;
@@ -1297,8 +1318,9 @@ var TransformContext = /** @class */ (function (_super) {
1297
1318
  currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.removeEventListener("keydown", _this.setKeyPressed, passive);
1298
1319
  document.removeEventListener("mouseleave", _this.clearPanning, passive);
1299
1320
  handleCancelAnimation(_this);
1321
+ (_b = _this.observer) === null || _b === void 0 ? void 0 : _b.disconnect();
1300
1322
  };
1301
- _this.handleInitializeWrapperEvents = function (wrapper) {
1323
+ this.handleInitializeWrapperEvents = function (wrapper) {
1302
1324
  // Zooming events on wrapper
1303
1325
  var passive = makePassiveEventOption();
1304
1326
  wrapper.addEventListener("wheel", _this.onWheelZoom, passive);
@@ -1307,34 +1329,24 @@ var TransformContext = /** @class */ (function (_super) {
1307
1329
  wrapper.addEventListener("touchmove", _this.onTouchPanning, passive);
1308
1330
  wrapper.addEventListener("touchend", _this.onTouchPanningStop, passive);
1309
1331
  };
1310
- _this.handleInitialize = function () {
1332
+ this.handleInitialize = function (contentComponent) {
1311
1333
  var centerOnInit = _this.setup.centerOnInit;
1312
1334
  _this.applyTransformation();
1313
- _this.forceUpdate();
1314
1335
  if (centerOnInit) {
1315
- // this has to be redone once the right solution is found
1316
- // problem is - we need to execute it after mounted component specify it's height / width, images are fetched async so it's tricky
1317
- setTimeout(function () {
1318
- if (_this.mounted) {
1319
- _this.setCenter();
1320
- }
1321
- }, 50);
1322
- setTimeout(function () {
1323
- if (_this.mounted) {
1324
- _this.setCenter();
1325
- }
1326
- }, 100);
1327
- setTimeout(function () {
1328
- if (_this.mounted) {
1329
- _this.setCenter();
1330
- }
1331
- }, 200);
1336
+ _this.setCenter();
1337
+ _this.observer = new ResizeObserver(function () {
1338
+ var _a;
1339
+ _this.setCenter();
1340
+ (_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
1341
+ });
1342
+ // Start observing the target node for configured mutations
1343
+ _this.observer.observe(contentComponent);
1332
1344
  }
1333
1345
  };
1334
- //////////
1346
+ /// ///////
1335
1347
  // Zoom
1336
- //////////
1337
- _this.onWheelZoom = function (event) {
1348
+ /// ///////
1349
+ this.onWheelZoom = function (event) {
1338
1350
  var disabled = _this.setup.disabled;
1339
1351
  if (disabled)
1340
1352
  return;
@@ -1348,10 +1360,10 @@ var TransformContext = /** @class */ (function (_super) {
1348
1360
  handleWheelZoom(_this, event);
1349
1361
  handleWheelStop(_this, event);
1350
1362
  };
1351
- //////////
1363
+ /// ///////
1352
1364
  // Pan
1353
- //////////
1354
- _this.onPanningStart = function (event) {
1365
+ /// ///////
1366
+ this.onPanningStart = function (event) {
1355
1367
  var disabled = _this.setup.disabled;
1356
1368
  var onPanningStart = _this.props.onPanningStart;
1357
1369
  if (disabled)
@@ -1368,7 +1380,7 @@ var TransformContext = /** @class */ (function (_super) {
1368
1380
  handlePanningStart(_this, event);
1369
1381
  handleCallback(getContext(_this), event, onPanningStart);
1370
1382
  };
1371
- _this.onPanning = function (event) {
1383
+ this.onPanning = function (event) {
1372
1384
  var disabled = _this.setup.disabled;
1373
1385
  var onPanning = _this.props.onPanning;
1374
1386
  if (disabled)
@@ -1384,17 +1396,17 @@ var TransformContext = /** @class */ (function (_super) {
1384
1396
  handlePanning(_this, event.clientX, event.clientY);
1385
1397
  handleCallback(getContext(_this), event, onPanning);
1386
1398
  };
1387
- _this.onPanningStop = function (event) {
1399
+ this.onPanningStop = function (event) {
1388
1400
  var onPanningStop = _this.props.onPanningStop;
1389
1401
  if (_this.isPanning) {
1390
1402
  handlePanningEnd(_this);
1391
1403
  handleCallback(getContext(_this), event, onPanningStop);
1392
1404
  }
1393
1405
  };
1394
- //////////
1406
+ /// ///////
1395
1407
  // Pinch
1396
- //////////
1397
- _this.onPinchStart = function (event) {
1408
+ /// ///////
1409
+ this.onPinchStart = function (event) {
1398
1410
  var disabled = _this.setup.disabled;
1399
1411
  var _a = _this.props, onPinchingStart = _a.onPinchingStart, onZoomStart = _a.onZoomStart;
1400
1412
  if (disabled)
@@ -1407,7 +1419,7 @@ var TransformContext = /** @class */ (function (_super) {
1407
1419
  handleCallback(getContext(_this), event, onPinchingStart);
1408
1420
  handleCallback(getContext(_this), event, onZoomStart);
1409
1421
  };
1410
- _this.onPinch = function (event) {
1422
+ this.onPinch = function (event) {
1411
1423
  var disabled = _this.setup.disabled;
1412
1424
  var _a = _this.props, onPinching = _a.onPinching, onZoom = _a.onZoom;
1413
1425
  if (disabled)
@@ -1421,7 +1433,7 @@ var TransformContext = /** @class */ (function (_super) {
1421
1433
  handleCallback(getContext(_this), event, onPinching);
1422
1434
  handleCallback(getContext(_this), event, onZoom);
1423
1435
  };
1424
- _this.onPinchStop = function (event) {
1436
+ this.onPinchStop = function (event) {
1425
1437
  var _a = _this.props, onPinchingStop = _a.onPinchingStop, onZoomStop = _a.onZoomStop;
1426
1438
  if (_this.pinchStartScale) {
1427
1439
  handlePinchStop(_this);
@@ -1429,10 +1441,10 @@ var TransformContext = /** @class */ (function (_super) {
1429
1441
  handleCallback(getContext(_this), event, onZoomStop);
1430
1442
  }
1431
1443
  };
1432
- //////////
1444
+ /// ///////
1433
1445
  // Touch
1434
- //////////
1435
- _this.onTouchPanningStart = function (event) {
1446
+ /// ///////
1447
+ this.onTouchPanningStart = function (event) {
1436
1448
  var disabled = _this.setup.disabled;
1437
1449
  var onPanningStart = _this.props.onPanningStart;
1438
1450
  if (disabled)
@@ -1460,7 +1472,7 @@ var TransformContext = /** @class */ (function (_super) {
1460
1472
  }
1461
1473
  }
1462
1474
  };
1463
- _this.onTouchPanning = function (event) {
1475
+ this.onTouchPanning = function (event) {
1464
1476
  var disabled = _this.setup.disabled;
1465
1477
  var onPanning = _this.props.onPanning;
1466
1478
  if (_this.isPanning && event.touches.length === 1) {
@@ -1479,14 +1491,14 @@ var TransformContext = /** @class */ (function (_super) {
1479
1491
  _this.onPinch(event);
1480
1492
  }
1481
1493
  };
1482
- _this.onTouchPanningStop = function (event) {
1494
+ this.onTouchPanningStop = function (event) {
1483
1495
  _this.onPanningStop(event);
1484
1496
  _this.onPinchStop(event);
1485
1497
  };
1486
- //////////
1498
+ /// ///////
1487
1499
  // Double Click
1488
- //////////
1489
- _this.onDoubleClick = function (event) {
1500
+ /// ///////
1501
+ this.onDoubleClick = function (event) {
1490
1502
  var disabled = _this.setup.disabled;
1491
1503
  if (disabled)
1492
1504
  return;
@@ -1495,41 +1507,31 @@ var TransformContext = /** @class */ (function (_super) {
1495
1507
  return;
1496
1508
  handleDoubleClick(_this, event);
1497
1509
  };
1498
- //////////
1510
+ /// ///////
1499
1511
  // Helpers
1500
- //////////
1501
- _this.clearPanning = function (event) {
1512
+ /// ///////
1513
+ this.clearPanning = function (event) {
1502
1514
  if (_this.isPanning) {
1503
1515
  _this.onPanningStop(event);
1504
1516
  }
1505
1517
  };
1506
- _this.setKeyPressed = function (e) {
1518
+ this.setKeyPressed = function (e) {
1507
1519
  _this.pressedKeys[e.key] = true;
1508
1520
  };
1509
- _this.setKeyUnPressed = function (e) {
1521
+ this.setKeyUnPressed = function (e) {
1510
1522
  _this.pressedKeys[e.key] = false;
1511
1523
  };
1512
- _this.isPressingKeys = function (keys) {
1524
+ this.isPressingKeys = function (keys) {
1513
1525
  if (!keys.length) {
1514
1526
  return true;
1515
1527
  }
1516
1528
  return Boolean(keys.find(function (key) { return _this.pressedKeys[key]; }));
1517
1529
  };
1518
- _this.setComponents = function (wrapperComponent, contentComponent) {
1519
- _this.cleanupWindowEvents();
1520
- _this.wrapperComponent = wrapperComponent;
1521
- _this.contentComponent = contentComponent;
1522
- handleCalculateBounds(_this, _this.transformState.scale);
1523
- _this.handleInitializeWrapperEvents(wrapperComponent);
1524
- _this.initializeWindowEvents();
1525
- _this.handleInitialize();
1526
- _this.handleRef();
1527
- _this.isInitialized = true;
1528
- handleCallback(getContext(_this), undefined, _this.props.onInit);
1529
- };
1530
- _this.setTransformState = function (scale, positionX, positionY) {
1530
+ this.setTransformState = function (scale, positionX, positionY) {
1531
1531
  var onTransformed = _this.props.onTransformed;
1532
- if (!isNaN(scale) && !isNaN(positionX) && !isNaN(positionY)) {
1532
+ if (!Number.isNaN(scale) &&
1533
+ !Number.isNaN(positionX) &&
1534
+ !Number.isNaN(positionY)) {
1533
1535
  if (scale !== _this.transformState.scale) {
1534
1536
  _this.transformState.previousScale = _this.transformState.scale;
1535
1537
  _this.transformState.scale = scale;
@@ -1543,50 +1545,58 @@ var TransformContext = /** @class */ (function (_super) {
1543
1545
  console.error("Detected NaN set state values");
1544
1546
  }
1545
1547
  };
1546
- _this.setCenter = function () {
1548
+ this.setCenter = function () {
1547
1549
  if (_this.wrapperComponent && _this.contentComponent) {
1548
1550
  var targetState = getCenterPosition(_this.transformState.scale, _this.wrapperComponent, _this.contentComponent);
1549
1551
  _this.setTransformState(targetState.scale, targetState.positionX, targetState.positionY);
1550
1552
  }
1551
1553
  };
1552
- _this.applyTransformation = function () {
1554
+ this.applyTransformation = function () {
1553
1555
  if (!_this.mounted || !_this.contentComponent)
1554
1556
  return;
1555
1557
  var _a = _this.transformState, scale = _a.scale, positionX = _a.positionX, positionY = _a.positionY;
1556
1558
  var transform = getTransformStyles(positionX, positionY, scale);
1557
1559
  _this.contentComponent.style.transform = transform;
1558
- _this.handleRef();
1559
1560
  };
1560
- _this.handleRef = function () {
1561
- _this.props.setRef(getContext(_this));
1561
+ this.getContext = function () {
1562
+ return getContext(_this);
1562
1563
  };
1563
- return _this;
1564
+ /**
1565
+ * Initialization
1566
+ */
1567
+ this.init = function (wrapperComponent, contentComponent) {
1568
+ _this.cleanupWindowEvents();
1569
+ _this.wrapperComponent = wrapperComponent;
1570
+ _this.contentComponent = contentComponent;
1571
+ handleCalculateBounds(_this, _this.transformState.scale);
1572
+ _this.handleInitializeWrapperEvents(wrapperComponent);
1573
+ _this.handleInitialize(contentComponent);
1574
+ _this.initializeWindowEvents();
1575
+ _this.isInitialized = true;
1576
+ handleCallback(getContext(_this), undefined, _this.props.onInit);
1577
+ };
1578
+ this.setup = createSetup(this.props);
1579
+ this.transformState = createState(this.props);
1564
1580
  }
1565
- TransformContext.prototype.componentDidMount = function () {
1566
- this.initializeWindowEvents();
1567
- };
1568
- TransformContext.prototype.componentWillUnmount = function () {
1569
- this.cleanupWindowEvents();
1570
- };
1571
- TransformContext.prototype.componentDidUpdate = function (oldProps) {
1572
- if (oldProps !== this.props) {
1573
- handleCalculateBounds(this, this.transformState.scale);
1574
- this.setup = createSetup(this.props);
1575
- }
1576
- };
1577
- TransformContext.prototype.render = function () {
1578
- var value = getContext(this);
1579
- var children = this.props.children;
1580
- var content = typeof children === "function" ? children(value) : children;
1581
- return (React__default['default'].createElement(Context.Provider, { value: __assign(__assign({}, this.transformState), { setComponents: this.setComponents, contextInstance: this }) }, content));
1582
- };
1583
- return TransformContext;
1584
- }(React.Component));
1581
+ return ZoomPanPinch;
1582
+ }());
1585
1583
 
1586
- var TransformWrapper = React__default['default'].forwardRef(function (props, ref) {
1587
- var _a = React.useState(null), innerRef = _a[0], setRef = _a[1];
1588
- React.useImperativeHandle(ref, function () { return innerRef; }, [innerRef]);
1589
- return React__default['default'].createElement(TransformContext, __assign({}, props, { setRef: setRef }));
1584
+ var Context = React__default["default"].createContext(contextInitialState);
1585
+ var TransformWrapper = React__default["default"].forwardRef(function (props, ref) {
1586
+ var children = props.children;
1587
+ var instance = React.useRef(new ZoomPanPinch(props)).current;
1588
+ var content = React.useMemo(function () {
1589
+ if (typeof children === "function") {
1590
+ return children(getContext(instance));
1591
+ }
1592
+ return children;
1593
+ }, [children, instance]);
1594
+ var value = React.useMemo(function () {
1595
+ return __assign(__assign({}, instance.transformState), { setComponents: instance.init, contextInstance: instance });
1596
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1597
+ }, [JSON.stringify(instance.transformState)]);
1598
+ React.useImperativeHandle(ref, function () { return getContext(instance); }, [instance]);
1599
+ return React__default["default"].createElement(Context.Provider, { value: value }, content);
1590
1600
  });
1591
1601
 
1592
1602
  function styleInject(css, ref) {
@@ -1616,10 +1626,11 @@ function styleInject(css, ref) {
1616
1626
  }
1617
1627
  }
1618
1628
 
1619
- 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";
1620
- var styles = {"wrapper":"transform-component-module_wrapper__1_Fgj","content":"transform-component-module_content__2jYgh"};
1629
+ 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";
1630
+ var styles = {"wrapper":"transform-component-module_wrapper__7HFJe","content":"transform-component-module_content__uCDPE"};
1621
1631
  styleInject(css_248z);
1622
1632
 
1633
+ /* eslint-disable react/require-default-props */
1623
1634
  var TransformComponent = function (_a) {
1624
1635
  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;
1625
1636
  var setComponents = React.useContext(Context).setComponents;
@@ -1632,8 +1643,8 @@ var TransformComponent = function (_a) {
1632
1643
  setComponents(wrapper, content);
1633
1644
  }
1634
1645
  }, []);
1635
- return (React__default['default'].createElement("div", { ref: wrapperRef, className: "react-transform-wrapper " + styles.wrapper + " " + wrapperClass, style: wrapperStyle },
1636
- React__default['default'].createElement("div", { ref: contentRef, className: "react-transform-component " + styles.content + " " + contentClass, style: contentStyle }, children)));
1646
+ return (React__default["default"].createElement("div", { ref: wrapperRef, className: "react-transform-wrapper ".concat(styles.wrapper, " ").concat(wrapperClass), style: wrapperStyle },
1647
+ React__default["default"].createElement("div", { ref: contentRef, className: "react-transform-component ".concat(styles.content, " ").concat(contentClass), style: contentStyle }, children)));
1637
1648
  };
1638
1649
 
1639
1650
  var useTransformContext = function () {