react-zoom-pan-pinch 3.3.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/dist/index.cjs.js +46 -3
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.d.ts +4 -1
  4. package/dist/index.esm.js +46 -3
  5. package/dist/index.esm.js.map +1 -1
  6. package/package.json +4 -1
  7. package/.eslintignore +0 -6
  8. package/.github/CODEOWNERS +0 -36
  9. package/.github/FUNDING.yml +0 -13
  10. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  11. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  12. package/.github/workflows/docs.yml +0 -34
  13. package/.github/workflows/release.yml +0 -46
  14. package/.github/workflows/tests.yml +0 -42
  15. package/.prettierrc +0 -10
  16. package/.releaserc.json +0 -63
  17. package/.storybook/main.js +0 -23
  18. package/.storybook/preview-head.html +0 -5
  19. package/.storybook/preview.js +0 -11
  20. package/.storybook/theme-overrides.css +0 -49
  21. package/CHANGELOG.md +0 -26
  22. package/Code_of_Conduct.md +0 -61
  23. package/Contributing.md +0 -236
  24. package/__tests__/features/props.spec.tsx +0 -11
  25. package/__tests__/features/rendering.spec.tsx +0 -36
  26. package/__tests__/shared/render.shared.tsx +0 -41
  27. package/__tests__/utils/controls.utils.tsx +0 -25
  28. package/__tests__/utils/example.tsx +0 -81
  29. package/commitlint.config.js +0 -1
  30. package/dist/__tests__/features/props.spec.d.ts +0 -1
  31. package/dist/__tests__/features/rendering.spec.d.ts +0 -1
  32. package/dist/__tests__/shared/render.shared.d.ts +0 -11
  33. package/dist/__tests__/utils/controls.utils.d.ts +0 -3
  34. package/dist/__tests__/utils/example.d.ts +0 -6
  35. package/dist/src/components/index.d.ts +0 -4
  36. package/dist/src/components/keep-scale/keep-scale.d.ts +0 -2
  37. package/dist/src/components/mini-map/mini-map.d.ts +0 -8
  38. package/dist/src/components/mini-map/use-resize.hook.d.ts +0 -8
  39. package/dist/src/components/transform-component/transform-component.d.ts +0 -12
  40. package/dist/src/components/transform-wrapper/transform-wrapper.d.ts +0 -5
  41. package/dist/src/constants/state.constants.d.ts +0 -3
  42. package/dist/src/core/animations/animations.constants.d.ts +0 -16
  43. package/dist/src/core/animations/animations.utils.d.ts +0 -4
  44. package/dist/src/core/bounds/bounds.types.d.ts +0 -8
  45. package/dist/src/core/bounds/bounds.utils.d.ts +0 -17
  46. package/dist/src/core/double-click/double-click.logic.d.ts +0 -5
  47. package/dist/src/core/handlers/handlers.logic.d.ts +0 -8
  48. package/dist/src/core/handlers/handlers.utils.d.ts +0 -14
  49. package/dist/src/core/instance.core.d.ts +0 -77
  50. package/dist/src/core/pan/panning.logic.d.ts +0 -5
  51. package/dist/src/core/pan/panning.utils.d.ts +0 -10
  52. package/dist/src/core/pan/velocity.logic.d.ts +0 -5
  53. package/dist/src/core/pan/velocity.utils.d.ts +0 -5
  54. package/dist/src/core/pinch/pinch.logic.d.ts +0 -4
  55. package/dist/src/core/pinch/pinch.utils.d.ts +0 -6
  56. package/dist/src/core/wheel/wheel.logic.d.ts +0 -4
  57. package/dist/src/core/wheel/wheel.utils.d.ts +0 -7
  58. package/dist/src/core/zoom/zoom.logic.d.ts +0 -3
  59. package/dist/src/core/zoom/zoom.utils.d.ts +0 -3
  60. package/dist/src/hooks/index.d.ts +0 -4
  61. package/dist/src/hooks/use-controls.d.ts +0 -2
  62. package/dist/src/hooks/use-transform-context.d.ts +0 -1
  63. package/dist/src/hooks/use-transform-effect.d.ts +0 -2
  64. package/dist/src/hooks/use-transform-init.d.ts +0 -2
  65. package/dist/src/index.d.ts +0 -5
  66. package/dist/src/models/calculations.model.d.ts +0 -25
  67. package/dist/src/models/context.model.d.ts +0 -127
  68. package/dist/src/models/helpers.model.d.ts +0 -5
  69. package/dist/src/models/index.d.ts +0 -3
  70. package/dist/src/stories/docs/handlers.d.ts +0 -12
  71. package/dist/src/stories/docs/props.d.ts +0 -14
  72. package/dist/src/stories/examples/content-rerendering/example.d.ts +0 -2
  73. package/dist/src/stories/examples/image-responsive/example.d.ts +0 -2
  74. package/dist/src/stories/examples/keep-scale/example.d.ts +0 -2
  75. package/dist/src/stories/examples/mini-map/example.d.ts +0 -1
  76. package/dist/src/stories/examples/stress/example.d.ts +0 -2
  77. package/dist/src/stories/examples/svg-zoom-to-element/example.d.ts +0 -2
  78. package/dist/src/stories/examples/zoom-to-element/example.d.ts +0 -2
  79. package/dist/src/stories/types/args.types.d.ts +0 -280
  80. package/dist/src/stories/utils/args.utils.d.ts +0 -3
  81. package/dist/src/stories/utils/code.utils.d.ts +0 -6
  82. package/dist/src/stories/utils/controls.utils.d.ts +0 -3
  83. package/dist/src/stories/utils/index.d.ts +0 -3
  84. package/dist/src/utils/calculations.utils.d.ts +0 -11
  85. package/dist/src/utils/callback.utils.d.ts +0 -2
  86. package/dist/src/utils/context.utils.d.ts +0 -4
  87. package/dist/src/utils/event.utils.d.ts +0 -1
  88. package/dist/src/utils/helpers.utils.d.ts +0 -2
  89. package/dist/src/utils/index.d.ts +0 -8
  90. package/dist/src/utils/ref.utils.d.ts +0 -2
  91. package/dist/src/utils/state.utils.d.ts +0 -3
  92. package/dist/src/utils/styles.utils.d.ts +0 -4
  93. package/jest.config.ts +0 -45
  94. package/rollup.config.js +0 -51
  95. package/src/.eslintrc.json +0 -90
  96. package/src/components/index.ts +0 -4
  97. package/src/components/keep-scale/keep-scale.tsx +0 -28
  98. package/src/components/mini-map/mini-map.tsx +0 -188
  99. package/src/components/mini-map/use-resize.hook.ts +0 -69
  100. package/src/components/transform-component/transform-component.module.css +0 -30
  101. package/src/components/transform-component/transform-component.tsx +0 -61
  102. package/src/components/transform-wrapper/transform-wrapper.tsx +0 -39
  103. package/src/constants/state.constants.ts +0 -77
  104. package/src/core/animations/animations.constants.ts +0 -78
  105. package/src/core/animations/animations.utils.ts +0 -114
  106. package/src/core/bounds/bounds.types.ts +0 -8
  107. package/src/core/bounds/bounds.utils.ts +0 -187
  108. package/src/core/double-click/double-click.logic.ts +0 -116
  109. package/src/core/handlers/handlers.logic.ts +0 -115
  110. package/src/core/handlers/handlers.utils.ts +0 -195
  111. package/src/core/instance.core.ts +0 -503
  112. package/src/core/pan/panning.logic.ts +0 -100
  113. package/src/core/pan/panning.utils.ts +0 -196
  114. package/src/core/pan/velocity.logic.ts +0 -149
  115. package/src/core/pan/velocity.utils.ts +0 -79
  116. package/src/core/pinch/pinch.logic.ts +0 -81
  117. package/src/core/pinch/pinch.utils.ts +0 -88
  118. package/src/core/wheel/wheel.logic.ts +0 -121
  119. package/src/core/wheel/wheel.utils.ts +0 -122
  120. package/src/core/zoom/zoom.logic.ts +0 -69
  121. package/src/core/zoom/zoom.utils.ts +0 -58
  122. package/src/hooks/index.ts +0 -4
  123. package/src/hooks/use-controls.tsx +0 -9
  124. package/src/hooks/use-transform-context.tsx +0 -13
  125. package/src/hooks/use-transform-effect.tsx +0 -22
  126. package/src/hooks/use-transform-init.tsx +0 -27
  127. package/src/index.ts +0 -6
  128. package/src/models/calculations.model.ts +0 -26
  129. package/src/models/context.model.ts +0 -199
  130. package/src/models/helpers.model.ts +0 -15
  131. package/src/models/index.ts +0 -3
  132. package/src/react-app-env.d.ts +0 -1
  133. package/src/stories/assets/big-image.jpeg +0 -0
  134. package/src/stories/assets/map.jpg +0 -0
  135. package/src/stories/assets/medium-image.jpg +0 -0
  136. package/src/stories/assets/pin.svg +0 -1
  137. package/src/stories/assets/small-image.jpg +0 -0
  138. package/src/stories/assets/svg-example.svg +0 -14
  139. package/src/stories/docs/Introduction.stories.mdx +0 -174
  140. package/src/stories/docs/handlers.stories.mdx +0 -48
  141. package/src/stories/docs/handlers.tsx +0 -107
  142. package/src/stories/docs/props.stories.mdx +0 -92
  143. package/src/stories/docs/props.tsx +0 -526
  144. package/src/stories/examples/content/content.stories.mdx +0 -121
  145. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -45
  146. package/src/stories/examples/content-rerendering/example.tsx +0 -73
  147. package/src/stories/examples/controls/controls.stories.mdx +0 -71
  148. package/src/stories/examples/image-big/image-big.stories.mdx +0 -43
  149. package/src/stories/examples/image-medium/image-medium.stories.mdx +0 -41
  150. package/src/stories/examples/image-responsive/example.tsx +0 -103
  151. package/src/stories/examples/image-responsive/image-responsive.stories.mdx +0 -32
  152. package/src/stories/examples/image-small/image-small.stories.mdx +0 -41
  153. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -46
  154. package/src/stories/examples/keep-scale/example.tsx +0 -92
  155. package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -45
  156. package/src/stories/examples/mini-map/example.tsx +0 -54
  157. package/src/stories/examples/mini-map/mini-map.stories.mdx +0 -33
  158. package/src/stories/examples/stress/example.tsx +0 -23
  159. package/src/stories/examples/stress/stress-test.stories.mdx +0 -28
  160. package/src/stories/examples/svg-zoom-to-element/creativity.svg +0 -143
  161. package/src/stories/examples/svg-zoom-to-element/example.tsx +0 -57
  162. package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
  163. package/src/stories/examples/zoom-to-element/example.tsx +0 -94
  164. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -28
  165. package/src/stories/hooks/use-controls.stories.mdx +0 -24
  166. package/src/stories/hooks/use-transform-context.stories.mdx +0 -15
  167. package/src/stories/hooks/use-transform-effect.stories.mdx +0 -29
  168. package/src/stories/hooks/use-transform-init.stories.mdx +0 -25
  169. package/src/stories/types/args.types.ts +0 -211
  170. package/src/stories/utils/args.utils.ts +0 -34
  171. package/src/stories/utils/code.utils.tsx +0 -24
  172. package/src/stories/utils/controls.utils.tsx +0 -43
  173. package/src/stories/utils/index.ts +0 -3
  174. package/src/stories/utils/styles.module.css +0 -34
  175. package/src/styles.css +0 -8
  176. package/src/typings.d.ts +0 -10
  177. package/src/utils/calculations.utils.ts +0 -16
  178. package/src/utils/callback.utils.ts +0 -11
  179. package/src/utils/context.utils.ts +0 -48
  180. package/src/utils/event.utils.ts +0 -22
  181. package/src/utils/helpers.utils.ts +0 -27
  182. package/src/utils/index.ts +0 -8
  183. package/src/utils/ref.utils.ts +0 -16
  184. package/src/utils/state.utils.ts +0 -40
  185. package/src/utils/styles.utils.ts +0 -44
  186. package/tsconfig.json +0 -33
package/dist/index.d.ts CHANGED
@@ -50,6 +50,7 @@ declare class ZoomPanPinch {
50
50
  wheelStopEventTimer: ReturnType<typeof setTimeout> | null;
51
51
  wheelAnimationTimer: ReturnType<typeof setTimeout> | null;
52
52
  isPanning: boolean;
53
+ isWheelPanning: boolean;
53
54
  startCoords: StartCoordsType;
54
55
  lastTouch: number | null;
55
56
  distance: null | number;
@@ -76,6 +77,7 @@ declare class ZoomPanPinch {
76
77
  handleInitializeWrapperEvents: (wrapper: HTMLDivElement) => void;
77
78
  handleInitialize: (contentComponent: HTMLDivElement) => void;
78
79
  onWheelZoom: (event: WheelEvent) => void;
80
+ onWheelPanning: (event: WheelEvent) => void;
79
81
  onPanningStart: (event: MouseEvent) => void;
80
82
  onPanning: (event: MouseEvent) => void;
81
83
  onPanningStop: (event: MouseEvent | TouchEvent) => void;
@@ -170,6 +172,7 @@ type ReactZoomPanPinchProps = {
170
172
  allowRightClickPan?: boolean;
171
173
  activationKeys?: string[];
172
174
  excluded?: string[];
175
+ wheelPanning?: boolean;
173
176
  };
174
177
  pinch?: {
175
178
  step?: number;
@@ -179,7 +182,7 @@ type ReactZoomPanPinchProps = {
179
182
  doubleClick?: {
180
183
  disabled?: boolean;
181
184
  step?: number;
182
- mode?: "zoomIn" | "zoomOut" | "reset";
185
+ mode?: "zoomIn" | "zoomOut" | "reset" | "toggle";
183
186
  animationTime?: number;
184
187
  animationType?: keyof typeof animations;
185
188
  excluded?: string[];
package/dist/index.esm.js CHANGED
@@ -279,7 +279,15 @@ var isPanningStartAllowed = function (contextInstance, event) {
279
279
  var excluded = contextInstance.setup.panning.excluded;
280
280
  var isInitialized = contextInstance.isInitialized, wrapperComponent = contextInstance.wrapperComponent;
281
281
  var target = event.target;
282
- var isWrapperChild = wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.contains(target);
282
+ var targetIsShadowDom = "shadowRoot" in target && "composedPath" in event;
283
+ var isWrapperChild = targetIsShadowDom
284
+ ? event.composedPath().some(function (el) {
285
+ if (!(el instanceof Element)) {
286
+ return false;
287
+ }
288
+ return wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.contains(el);
289
+ })
290
+ : wrapperComponent === null || wrapperComponent === void 0 ? void 0 : wrapperComponent.contains(target);
283
291
  var isAllowed = isInitialized && target && isWrapperChild;
284
292
  if (!isAllowed)
285
293
  return false;
@@ -670,6 +678,7 @@ var initialSetup = {
670
678
  allowLeftClickPan: true,
671
679
  allowMiddleClickPan: true,
672
680
  allowRightClickPan: true,
681
+ wheelPanning: false,
673
682
  activationKeys: [],
674
683
  excluded: [],
675
684
  },
@@ -1253,6 +1262,12 @@ var handleDoubleClickResetMode = function (contextInstance, event) {
1253
1262
  });
1254
1263
  handleDoubleClickStop(contextInstance, event);
1255
1264
  };
1265
+ function getDoubleClickScale(mode, scale) {
1266
+ if (mode === "toggle") {
1267
+ return scale === 1 ? 1 : -1;
1268
+ }
1269
+ return mode === "zoomOut" ? -1 : 1;
1270
+ }
1256
1271
  function handleDoubleClick(contextInstance, event) {
1257
1272
  var setup = contextInstance.setup, doubleClickStopEventTimer = contextInstance.doubleClickStopEventTimer, transformState = contextInstance.transformState, contentComponent = contextInstance.contentComponent;
1258
1273
  var scale = transformState.scale;
@@ -1267,7 +1282,7 @@ function handleDoubleClick(contextInstance, event) {
1267
1282
  }
1268
1283
  if (!contentComponent)
1269
1284
  return console.error("No ContentComponent found");
1270
- var delta = mode === "zoomOut" ? -1 : 1;
1285
+ var delta = getDoubleClickScale(mode, contextInstance.transformState.scale);
1271
1286
  var newScale = handleCalculateButtonZoom(contextInstance, delta, step);
1272
1287
  // stop execution when scale didn't change
1273
1288
  if (scale === newScale)
@@ -1314,6 +1329,7 @@ var ZoomPanPinch = /** @class */ (function () {
1314
1329
  this.wheelAnimationTimer = null;
1315
1330
  // panning helpers
1316
1331
  this.isPanning = false;
1332
+ this.isWheelPanning = false;
1317
1333
  this.startCoords = null;
1318
1334
  this.lastTouch = null;
1319
1335
  // pinch helpers
@@ -1341,14 +1357,16 @@ var ZoomPanPinch = /** @class */ (function () {
1341
1357
  _this.cleanupWindowEvents();
1342
1358
  };
1343
1359
  this.update = function (newProps) {
1360
+ _this.props = newProps;
1344
1361
  handleCalculateBounds(_this, _this.transformState.scale);
1345
1362
  _this.setup = createSetup(newProps);
1346
1363
  };
1347
1364
  this.initializeWindowEvents = function () {
1348
- var _a;
1365
+ var _a, _b;
1349
1366
  var passive = makePassiveEventOption();
1350
1367
  var currentDocument = (_a = _this.wrapperComponent) === null || _a === void 0 ? void 0 : _a.ownerDocument;
1351
1368
  var currentWindow = currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.defaultView;
1369
+ (_b = _this.wrapperComponent) === null || _b === void 0 ? void 0 : _b.addEventListener("wheel", _this.onWheelPanning, passive);
1352
1370
  // Panning on window to allow panning when mouse is out of component wrapper
1353
1371
  currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("mousedown", _this.onPanningStart, passive);
1354
1372
  currentWindow === null || currentWindow === void 0 ? void 0 : currentWindow.addEventListener("mousemove", _this.onPanning, passive);
@@ -1417,6 +1435,31 @@ var ZoomPanPinch = /** @class */ (function () {
1417
1435
  /// ///////
1418
1436
  // Pan
1419
1437
  /// ///////
1438
+ this.onWheelPanning = function (event) {
1439
+ var _a = _this.setup, disabled = _a.disabled, wheel = _a.wheel, panning = _a.panning;
1440
+ if (!_this.wrapperComponent ||
1441
+ !_this.contentComponent ||
1442
+ disabled ||
1443
+ !wheel.wheelDisabled ||
1444
+ panning.disabled ||
1445
+ !panning.wheelPanning ||
1446
+ event.ctrlKey) {
1447
+ return;
1448
+ }
1449
+ event.preventDefault();
1450
+ event.stopPropagation();
1451
+ var _b = _this.transformState, positionX = _b.positionX, positionY = _b.positionY;
1452
+ var mouseX = positionX - event.deltaX;
1453
+ var mouseY = positionY - event.deltaY;
1454
+ var newPositionX = panning.lockAxisX ? positionX : mouseX;
1455
+ var newPositionY = panning.lockAxisY ? positionY : mouseY;
1456
+ var _c = _this.setup.alignmentAnimation, sizeX = _c.sizeX, sizeY = _c.sizeY;
1457
+ var paddingValueX = getPaddingValue(_this, sizeX);
1458
+ var paddingValueY = getPaddingValue(_this, sizeY);
1459
+ if (newPositionX === positionX && newPositionY === positionY)
1460
+ return;
1461
+ handleNewPosition(_this, newPositionX, newPositionY, paddingValueX, paddingValueY);
1462
+ };
1420
1463
  this.onPanningStart = function (event) {
1421
1464
  var disabled = _this.setup.disabled;
1422
1465
  var onPanningStart = _this.props.onPanningStart;