react-zoom-pan-pinch 3.0.1 → 3.0.3

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/.storybook/main.js +23 -0
  2. package/.storybook/preview-head.html +5 -0
  3. package/.storybook/preview.js +11 -0
  4. package/.storybook/theme-overrides.css +49 -0
  5. package/README.md +7 -2
  6. package/__tests__/features/props.spec.tsx +11 -0
  7. package/__tests__/features/rendering.spec.tsx +36 -0
  8. package/__tests__/shared/render.shared.tsx +41 -0
  9. package/__tests__/utils/controls.utils.tsx +25 -0
  10. package/__tests__/utils/example.tsx +81 -0
  11. package/dist/__tests__/features/props.spec.d.ts +1 -0
  12. package/dist/__tests__/features/rendering.spec.d.ts +1 -0
  13. package/dist/__tests__/shared/render.shared.d.ts +11 -0
  14. package/dist/__tests__/utils/controls.utils.d.ts +3 -0
  15. package/dist/__tests__/utils/example.d.ts +6 -0
  16. package/dist/index.cjs.js +92 -34
  17. package/dist/index.cjs.js.map +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.esm.js +93 -35
  20. package/dist/index.esm.js.map +1 -1
  21. package/dist/src/components/mini-map/mini-map.d.ts +1 -1
  22. package/dist/src/components/mini-map/use-resize.hook.d.ts +8 -0
  23. package/dist/src/stories/docs/handlers.d.ts +12 -0
  24. package/dist/src/stories/docs/props.d.ts +14 -0
  25. package/dist/src/stories/examples/content-rerendering/example.d.ts +2 -0
  26. package/dist/src/stories/examples/image-responsive/example.d.ts +2 -0
  27. package/dist/src/stories/examples/keep-scale/example.d.ts +2 -0
  28. package/dist/src/stories/examples/mini-map/example.d.ts +1 -0
  29. package/dist/src/stories/examples/stress/example.d.ts +2 -0
  30. package/dist/src/stories/examples/svg-zoom-to-element/example.d.ts +2 -0
  31. package/dist/src/stories/examples/zoom-to-element/example.d.ts +2 -0
  32. package/dist/src/stories/types/args.types.d.ts +268 -0
  33. package/dist/src/stories/utils/args.utils.d.ts +3 -0
  34. package/dist/src/stories/utils/code.utils.d.ts +6 -0
  35. package/dist/src/stories/utils/controls.utils.d.ts +3 -0
  36. package/dist/src/stories/utils/index.d.ts +3 -0
  37. package/jest.config.ts +45 -0
  38. package/package.json +1 -1
  39. package/src/components/mini-map/mini-map.tsx +60 -33
  40. package/src/components/mini-map/use-resize.hook.ts +69 -0
  41. package/src/hooks/use-transform-init.tsx +0 -2
  42. package/src/stories/assets/big-image.jpeg +0 -0
  43. package/src/stories/assets/map.jpg +0 -0
  44. package/src/stories/assets/medium-image.jpg +0 -0
  45. package/src/stories/assets/pin.svg +1 -0
  46. package/src/stories/assets/small-image.jpg +0 -0
  47. package/src/stories/assets/svg-example.svg +14 -0
  48. package/src/stories/docs/Introduction.stories.mdx +174 -0
  49. package/src/stories/docs/handlers.stories.mdx +48 -0
  50. package/src/stories/docs/handlers.tsx +107 -0
  51. package/src/stories/docs/props.stories.mdx +92 -0
  52. package/src/stories/docs/props.tsx +496 -0
  53. package/src/stories/examples/content/content.stories.mdx +121 -0
  54. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +45 -0
  55. package/src/stories/examples/content-rerendering/example.tsx +73 -0
  56. package/src/stories/examples/controls/controls.stories.mdx +71 -0
  57. package/src/stories/examples/image-big/image-big.stories.mdx +43 -0
  58. package/src/stories/examples/image-medium/image-medium.stories.mdx +41 -0
  59. package/src/stories/examples/image-responsive/example.tsx +103 -0
  60. package/src/stories/examples/image-responsive/image-responsive.stories.mdx +32 -0
  61. package/src/stories/examples/image-small/image-small.stories.mdx +41 -0
  62. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +46 -0
  63. package/src/stories/examples/keep-scale/example.tsx +92 -0
  64. package/src/stories/examples/keep-scale/keep-scale.stories.mdx +45 -0
  65. package/src/stories/examples/mini-map/example.tsx +54 -0
  66. package/src/stories/examples/mini-map/mini-map.stories.mdx +33 -0
  67. package/src/stories/examples/stress/example.tsx +23 -0
  68. package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
  69. package/src/stories/examples/svg-zoom-to-element/creativity.svg +143 -0
  70. package/src/stories/examples/svg-zoom-to-element/example.tsx +57 -0
  71. package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +28 -0
  72. package/src/stories/examples/zoom-to-element/example.tsx +94 -0
  73. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +28 -0
  74. package/src/stories/hooks/use-controls.stories.mdx +24 -0
  75. package/src/stories/hooks/use-transform-context.stories.mdx +15 -0
  76. package/src/stories/hooks/use-transform-effect.stories.mdx +29 -0
  77. package/src/stories/hooks/use-transform-init.stories.mdx +25 -0
  78. package/src/stories/types/args.types.ts +201 -0
  79. package/src/stories/utils/args.utils.ts +34 -0
  80. package/src/stories/utils/code.utils.tsx +24 -0
  81. package/src/stories/utils/controls.utils.tsx +43 -0
  82. package/src/stories/utils/index.ts +3 -0
  83. package/src/stories/utils/styles.module.css +34 -0
@@ -0,0 +1,23 @@
1
+ module.exports = {
2
+ stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|ts|tsx)"],
3
+ addons: [
4
+ "@storybook/addon-links",
5
+ "@storybook/addon-essentials",
6
+ "@storybook/preset-create-react-app",
7
+ "@storybook/addon-storysource",
8
+ "@storybook/addon-a11y",
9
+ ],
10
+ core: {
11
+ builder: "webpack5",
12
+ },
13
+ framework: "@storybook/react",
14
+ webpackFinal: (webpackConfig) => {
15
+ const scopePluginIndex = webpackConfig.resolve.plugins.findIndex(
16
+ ({ constructor }) =>
17
+ constructor && constructor.name === "ModuleScopePlugin",
18
+ );
19
+
20
+ webpackConfig.resolve.plugins.splice(scopePluginIndex, 1);
21
+ return webpackConfig;
22
+ },
23
+ };
@@ -0,0 +1,5 @@
1
+ <link rel="preconnect" href="https://fonts.gstatic.com" />
2
+ <link
3
+ href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100&display=swap"
4
+ rel="stylesheet"
5
+ />
@@ -0,0 +1,11 @@
1
+ import "./theme-overrides.css";
2
+
3
+ export const parameters = {
4
+ actions: { argTypesRegex: "^on[A-Z].*" },
5
+ controls: {
6
+ matchers: {
7
+ color: /(background|color)$/i,
8
+ date: /Date$/,
9
+ },
10
+ },
11
+ };
@@ -0,0 +1,49 @@
1
+ body {
2
+ font-family: "Poppins", sans-serif;
3
+ font-style: normal;
4
+ font-weight: normal;
5
+ font-size: 13px;
6
+ line-height: 130%;
7
+ font-style: normal;
8
+ -webkit-font-smoothing: antialiased;
9
+ -moz-osx-font-smoothing: grayscale;
10
+ }
11
+
12
+ body .sbdocs {
13
+ max-width: unset;
14
+ }
15
+
16
+ .react-transform-wrapper {
17
+ background-color: rgba(0, 0, 0, 0.3);
18
+ }
19
+
20
+ body td > pre.prism-code {
21
+ background: transparent !important;
22
+ overflow: auto;
23
+ }
24
+
25
+ .props-table {
26
+ width: 100%;
27
+ }
28
+
29
+ .props-table th {
30
+ text-align: left;
31
+ }
32
+
33
+ .is-object-row td {
34
+ background: #d8e2f5;
35
+ border-top: 2px solid rgb(173 173 173) !important;
36
+ }
37
+
38
+ .react-transform-wrapper {
39
+ max-width: 80vw;
40
+ max-height: 80vh;
41
+ }
42
+
43
+ .handlers-table {
44
+ width: 100%;
45
+ }
46
+
47
+ .handlers-table th {
48
+ text-align: left;
49
+ }
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # 🖼 React Zoom Pan Pinch
2
2
 
3
+ > Super fast and light react npm package for zooming, panning and pinching html
4
+ > elements in easy way
5
+
3
6
  <p>
4
7
  <a href="https://bettertyped.com/">
5
8
  <img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
@@ -33,8 +36,10 @@
33
36
  </a>
34
37
  </p>
35
38
 
36
- > Super fast and light react npm package for zooming, panning and pinching html
37
- > elements in easy way
39
+ Do you like this library? Try out other projects
40
+ **[⚡Hyper Fetch](https://github.com/BetterTyped/hyper-fetch)**
41
+
42
+ #### Sources
38
43
 
39
44
  - [Demo](https://prc5.github.io/react-zoom-pan-pinch/?path=/story/examples-big-image--big-image)
40
45
  - [Docs](https://prc5.github.io/react-zoom-pan-pinch/?path=/story/docs-props--page)
@@ -0,0 +1,11 @@
1
+ import { renderExample } from "../shared/render.shared";
2
+
3
+ describe("Library components", () => {
4
+ describe("When library components have been rendered", () => {
5
+ test("it renders transform component without errors", () => {
6
+ const { content, wrapper } = renderExample();
7
+ expect(content).toBeDefined();
8
+ expect(wrapper).toBeDefined();
9
+ });
10
+ });
11
+ });
@@ -0,0 +1,36 @@
1
+ import { renderExample } from "../shared/render.shared";
2
+
3
+ describe("Example view", () => {
4
+ describe("When example view has been rendered", () => {
5
+ test("it renders entire example without errors", () => {
6
+ const { wrapper } = renderExample();
7
+
8
+ expect(wrapper).toBeDefined();
9
+ });
10
+ test("it renders center in button without errors", () => {
11
+ const { center } = renderExample();
12
+
13
+ expect(center).toBeDefined();
14
+ });
15
+ test("it renders zoom in button without errors", () => {
16
+ const { zoomInBtn } = renderExample();
17
+
18
+ expect(zoomInBtn).toBeDefined();
19
+ });
20
+ test("it renders zoom out button without errors", () => {
21
+ const { zoomOutBtn } = renderExample();
22
+
23
+ expect(zoomOutBtn).toBeDefined();
24
+ });
25
+ test("it renders reset button without errors", () => {
26
+ const { resetBtn } = renderExample();
27
+
28
+ expect(resetBtn).toBeDefined();
29
+ });
30
+ test("it renders transform component without errors", () => {
31
+ const { content } = renderExample();
32
+
33
+ expect(content).toBeDefined();
34
+ });
35
+ });
36
+ });
@@ -0,0 +1,41 @@
1
+ import React from "react";
2
+ import { render, screen } from "@testing-library/react";
3
+
4
+ import { ReactZoomPanPinchProps } from "../../src";
5
+ import { Example } from "../utils/example";
6
+
7
+ export const renderExample = (props?: ReactZoomPanPinchProps) => {
8
+ let renders = 0;
9
+ let renderPropsValues = {};
10
+
11
+ render(
12
+ <Example
13
+ {...props}
14
+ onRender={() => {
15
+ renders += 1;
16
+ }}
17
+ onRenderProps={(ref) => {
18
+ renderPropsValues = ref;
19
+ }}
20
+ />,
21
+ );
22
+ // controls buttons
23
+ const zoomInBtn = screen.getByTestId("zoom-in");
24
+ const zoomOutBtn = screen.getByTestId("zoom-out");
25
+ const resetBtn = screen.getByTestId("reset");
26
+ const center = screen.getByTestId("center");
27
+ // containers
28
+ const content = screen.getByTestId("content");
29
+ const wrapper = screen.getByTestId("wrapper");
30
+
31
+ return {
32
+ renders,
33
+ renderPropsValues,
34
+ zoomInBtn,
35
+ zoomOutBtn,
36
+ resetBtn,
37
+ center,
38
+ content,
39
+ wrapper,
40
+ };
41
+ };
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+
3
+ import { ReactZoomPanPinchContentRef } from "../../src";
4
+
5
+ export const Controls: React.FC<ReactZoomPanPinchContentRef> = ({
6
+ zoomIn,
7
+ zoomOut,
8
+ resetTransform,
9
+ centerView,
10
+ }: ReactZoomPanPinchContentRef) => (
11
+ <div>
12
+ <button type="button" onClick={() => zoomIn()} data-testid="zoom-in">
13
+ Zoom In +
14
+ </button>
15
+ <button type="button" onClick={() => zoomOut()} data-testid="zoom-out">
16
+ Zoom Out -
17
+ </button>
18
+ <button type="button" onClick={() => resetTransform()} data-testid="reset">
19
+ Reset
20
+ </button>
21
+ <button type="button" onClick={() => centerView()} data-testid="center">
22
+ Center
23
+ </button>
24
+ </div>
25
+ );
@@ -0,0 +1,81 @@
1
+ import React from "react";
2
+
3
+ import {
4
+ TransformWrapper,
5
+ TransformComponent,
6
+ ReactZoomPanPinchProps,
7
+ ReactZoomPanPinchContentRef,
8
+ } from "../../src";
9
+ import { Controls } from "./controls.utils";
10
+
11
+ export const Example = (options: {
12
+ props?: ReactZoomPanPinchProps;
13
+ onRender: () => void;
14
+ onRenderProps: (ref: ReactZoomPanPinchContentRef) => void;
15
+ }) => {
16
+ const { props = {}, onRender, onRenderProps } = options;
17
+
18
+ onRender();
19
+
20
+ return (
21
+ <TransformWrapper {...props}>
22
+ {(utils) => (
23
+ <div>
24
+ {onRenderProps(utils)}
25
+ <Controls {...utils} />
26
+ <TransformComponent
27
+ wrapperProps={
28
+ {
29
+ "data-testid": "wrapper",
30
+ } as React.HTMLAttributes<HTMLDivElement>
31
+ }
32
+ contentProps={
33
+ {
34
+ "data-testid": "content",
35
+ } as React.HTMLAttributes<HTMLDivElement>
36
+ }
37
+ wrapperStyle={{
38
+ width: "500px",
39
+ height: "500px",
40
+ maxWidth: "100%",
41
+ maxHeight: "calc(100vh - 50px)",
42
+ }}
43
+ >
44
+ <div
45
+ style={{ background: "#444", color: "white", padding: "50px" }}
46
+ >
47
+ <h1>Title</h1>
48
+ <h2>Subtitle</h2>
49
+ <button
50
+ type="button"
51
+ onClick={() =>
52
+ alert("You can still interact with click events!")
53
+ }
54
+ >
55
+ Click me!
56
+ </button>
57
+ <p>
58
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
59
+ eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
60
+ enim ad minim veniam, quis nostrud exercitation ullamco laboris
61
+ nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
62
+ in reprehenderit in voluptate velit esse cillum dolore eu fugiat
63
+ nulla pariatur. Excepteur sint occaecat cupidatat non proident,
64
+ sunt in culpa qui officia deserunt mollit anim id est laborum
65
+ </p>
66
+ <p>
67
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
68
+ eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
69
+ enim ad minim veniam, quis nostrud exercitation ullamco laboris
70
+ nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
71
+ in reprehenderit in voluptate velit esse cillum dolore eu fugiat
72
+ nulla pariatur. Excepteur sint occaecat cupidatat non proident,
73
+ sunt in culpa qui officia deserunt mollit anim id est laborum
74
+ </p>
75
+ </div>
76
+ </TransformComponent>
77
+ </div>
78
+ )}
79
+ </TransformWrapper>
80
+ );
81
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { ReactZoomPanPinchProps } from "../../src";
2
+ export declare const renderExample: (props?: ReactZoomPanPinchProps) => {
3
+ renders: number;
4
+ renderPropsValues: {};
5
+ zoomInBtn: HTMLElement;
6
+ zoomOutBtn: HTMLElement;
7
+ resetBtn: HTMLElement;
8
+ center: HTMLElement;
9
+ content: HTMLElement;
10
+ wrapper: HTMLElement;
11
+ };
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { ReactZoomPanPinchContentRef } from "../../src";
3
+ export declare const Controls: React.FC<ReactZoomPanPinchContentRef>;
@@ -0,0 +1,6 @@
1
+ import { ReactZoomPanPinchProps, ReactZoomPanPinchContentRef } from "../../src";
2
+ export declare const Example: (options: {
3
+ props?: ReactZoomPanPinchProps | undefined;
4
+ onRender: () => void;
5
+ onRenderProps: (ref: ReactZoomPanPinchContentRef) => void;
6
+ }) => JSX.Element;
package/dist/index.cjs.js CHANGED
@@ -1696,6 +1696,48 @@ var KeepScale = React__default["default"].forwardRef(function (props, ref) {
1696
1696
  return React__default["default"].createElement("div", __assign({}, props, { ref: mergeRefs([localRef, ref]) }));
1697
1697
  });
1698
1698
 
1699
+ var initialElementRect = {
1700
+ width: 0,
1701
+ height: 0,
1702
+ y: 0,
1703
+ x: 0,
1704
+ top: 0,
1705
+ bottom: 0,
1706
+ left: 0,
1707
+ right: 0,
1708
+ };
1709
+ var useResize = function (ref, onResize, dependencies) {
1710
+ var resizeObserverRef = React.useRef();
1711
+ var rectRef = React.useRef(initialElementRect);
1712
+ var didUnmount = React.useRef(false);
1713
+ React.useLayoutEffect(function () {
1714
+ var _a;
1715
+ didUnmount.current = false;
1716
+ if (ref) {
1717
+ resizeObserverRef.current = new ResizeObserver(function (entries) {
1718
+ var newSize = ref.getBoundingClientRect();
1719
+ if (!Array.isArray(entries) ||
1720
+ !entries.length ||
1721
+ didUnmount.current ||
1722
+ (newSize.width === rectRef.current.width &&
1723
+ newSize.height === rectRef.current.height))
1724
+ return;
1725
+ onResize(newSize, ref);
1726
+ rectRef.current = newSize;
1727
+ });
1728
+ (_a = resizeObserverRef.current) === null || _a === void 0 ? void 0 : _a.observe(ref);
1729
+ }
1730
+ return function () {
1731
+ var _a;
1732
+ didUnmount.current = true;
1733
+ if (ref) {
1734
+ (_a = resizeObserverRef.current) === null || _a === void 0 ? void 0 : _a.unobserve(ref);
1735
+ }
1736
+ };
1737
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1738
+ }, __spreadArray([onResize, ref], dependencies, true));
1739
+ };
1740
+
1699
1741
  var previewStyles = {
1700
1742
  position: "absolute",
1701
1743
  zIndex: 2,
@@ -1708,29 +1750,32 @@ var previewStyles = {
1708
1750
  };
1709
1751
  var MiniMap = function (_a) {
1710
1752
  var _b = _a.width, width = _b === void 0 ? 200 : _b, _c = _a.height, height = _c === void 0 ? 200 : _c, children = _a.children, rest = __rest(_a, ["width", "height", "children"]);
1711
- var _d = React.useState({ width: 0, height: 0 }), size = _d[0], setSize = _d[1];
1753
+ var _d = React.useState(false), initialized = _d[0], setInitialized = _d[1];
1712
1754
  var instance = useTransformContext();
1755
+ var miniMapInstance = React.useRef(null);
1756
+ var mainRef = React.useRef(null);
1713
1757
  var wrapperRef = React.useRef(null);
1714
1758
  var previewRef = React.useRef(null);
1715
- var getContentSize = function () {
1759
+ var getContentSize = React.useCallback(function () {
1716
1760
  if (instance.contentComponent) {
1761
+ var rect = instance.contentComponent.getBoundingClientRect();
1717
1762
  return {
1718
- width: instance.contentComponent.offsetWidth,
1719
- height: instance.contentComponent.offsetHeight,
1763
+ width: rect.width / instance.transformState.scale,
1764
+ height: rect.height / instance.transformState.scale,
1720
1765
  };
1721
1766
  }
1722
1767
  return {
1723
1768
  width: 0,
1724
1769
  height: 0,
1725
1770
  };
1726
- };
1727
- var computeMiniMapScale = function () {
1771
+ }, [instance.contentComponent, instance.transformState.scale]);
1772
+ var computeMiniMapScale = React.useCallback(function () {
1728
1773
  var contentSize = getContentSize();
1729
1774
  var scaleX = width / contentSize.width;
1730
1775
  var scaleY = height / contentSize.height;
1731
1776
  var scale = scaleY > scaleX ? scaleX : scaleY;
1732
1777
  return scale;
1733
- };
1778
+ }, [getContentSize, height, width]);
1734
1779
  var computeMiniMapSize = function () {
1735
1780
  var contentSize = getContentSize();
1736
1781
  var scaleX = width / contentSize.width;
@@ -1740,16 +1785,9 @@ var MiniMap = function (_a) {
1740
1785
  }
1741
1786
  return { width: contentSize.width * scaleY, height: height };
1742
1787
  };
1743
- var computeWrapperStyle = function () {
1744
- var _a, _b;
1745
- return {
1746
- width: ((_a = instance.contentComponent) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0,
1747
- height: ((_b = instance.contentComponent) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0,
1748
- };
1749
- };
1750
1788
  var computeMiniMapStyle = function () {
1751
1789
  var scale = computeMiniMapScale();
1752
- return {
1790
+ var style = {
1753
1791
  transform: "scale(".concat(scale || 1, ")"),
1754
1792
  transformOrigin: "0% 0%",
1755
1793
  position: "absolute",
@@ -1757,32 +1795,35 @@ var MiniMap = function (_a) {
1757
1795
  zIndex: 1,
1758
1796
  overflow: "hidden",
1759
1797
  };
1798
+ Object.keys(style).forEach(function (key) {
1799
+ if (wrapperRef.current) {
1800
+ wrapperRef.current.style[key] = style[key];
1801
+ }
1802
+ });
1760
1803
  };
1761
1804
  var transformMiniMap = function () {
1762
- var style = computeWrapperStyle();
1805
+ computeMiniMapStyle();
1806
+ var miniSize = computeMiniMapSize();
1807
+ var wrapSize = getContentSize();
1763
1808
  if (wrapperRef.current) {
1764
- wrapperRef.current.style.width = "".concat(style.width, "px");
1765
- wrapperRef.current.style.width = "".concat(style.width, "px");
1766
- wrapperRef.current.style.height = "".concat(style.height, "px");
1809
+ wrapperRef.current.style.width = "".concat(wrapSize.width, "px");
1810
+ wrapperRef.current.style.height = "".concat(wrapSize.height, "px");
1811
+ }
1812
+ if (mainRef.current) {
1813
+ mainRef.current.style.width = "".concat(miniSize.width, "px");
1814
+ mainRef.current.style.height = "".concat(miniSize.height, "px");
1767
1815
  }
1768
1816
  if (previewRef.current) {
1817
+ var size = getContentSize();
1769
1818
  var scale = computeMiniMapScale();
1770
1819
  var previewScale = scale * (1 / instance.transformState.scale);
1771
1820
  var transform = instance.handleTransformStyles(-instance.transformState.positionX * previewScale, -instance.transformState.positionY * previewScale, 1);
1772
1821
  previewRef.current.style.transform = transform;
1773
- previewRef.current.style.width = "".concat(style.width * previewScale, "px");
1774
- previewRef.current.style.height = "".concat(style.height * previewScale, "px");
1822
+ previewRef.current.style.width = "".concat(size.width * previewScale, "px");
1823
+ previewRef.current.style.height = "".concat(size.height * previewScale, "px");
1775
1824
  }
1776
1825
  };
1777
1826
  var initialize = function () {
1778
- var style = computeMiniMapStyle();
1779
- var initSize = computeMiniMapSize();
1780
- setSize(initSize);
1781
- Object.keys(style).forEach(function (key) {
1782
- if (wrapperRef.current) {
1783
- wrapperRef.current.style[key] = style[key];
1784
- }
1785
- });
1786
1827
  transformMiniMap();
1787
1828
  };
1788
1829
  useTransformEffect(function () {
@@ -1790,11 +1831,30 @@ var MiniMap = function (_a) {
1790
1831
  });
1791
1832
  useTransformInit(function () {
1792
1833
  initialize();
1834
+ setInitialized(true);
1793
1835
  });
1836
+ useResize(instance.contentComponent, initialize, [initialized]);
1837
+ React.useEffect(function () {
1838
+ return instance.onChange(function (zpp) {
1839
+ var scale = computeMiniMapScale();
1840
+ if (miniMapInstance.current) {
1841
+ miniMapInstance.current.instance.transformState.scale =
1842
+ zpp.instance.transformState.scale;
1843
+ miniMapInstance.current.instance.transformState.positionX =
1844
+ zpp.instance.transformState.positionX * scale;
1845
+ miniMapInstance.current.instance.transformState.positionY =
1846
+ zpp.instance.transformState.positionY * scale;
1847
+ }
1848
+ });
1849
+ }, [computeMiniMapScale, instance, miniMapInstance]);
1794
1850
  var wrapperStyle = React.useMemo(function () {
1795
- return __assign(__assign({}, size), { position: "relative", zIndex: 2, overflow: "hidden" });
1796
- }, [size]);
1797
- return (React__default["default"].createElement("div", __assign({}, rest, { style: wrapperStyle, className: "rzpp-mini-map ".concat(rest.className || "") }),
1851
+ return {
1852
+ position: "relative",
1853
+ zIndex: 2,
1854
+ overflow: "hidden",
1855
+ };
1856
+ }, []);
1857
+ return (React__default["default"].createElement("div", __assign({}, rest, { ref: mainRef, style: wrapperStyle, className: "rzpp-mini-map ".concat(rest.className || "") }),
1798
1858
  React__default["default"].createElement("div", __assign({}, rest, { ref: wrapperRef, className: "rzpp-wrapper" }), children),
1799
1859
  React__default["default"].createElement("div", { className: "rzpp-preview", ref: previewRef, style: previewStyles })));
1800
1860
  };
@@ -1866,11 +1926,9 @@ var useTransformInit = function (callback) {
1866
1926
  var unmountCallback;
1867
1927
  var unmount;
1868
1928
  if (libraryContext.contentComponent && libraryContext.wrapperComponent) {
1869
- console.warn(333);
1870
1929
  unmountCallback = callback(getState(libraryContext));
1871
1930
  }
1872
1931
  else {
1873
- console.warn(444);
1874
1932
  unmount = libraryContext.onInit(function (ref) {
1875
1933
  unmountCallback = callback(getState(ref.instance));
1876
1934
  });