react-zoom-pan-pinch 2.6.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +6 -0
- package/.github/CODEOWNERS +36 -0
- package/.github/FUNDING.yml +13 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/workflows/docs.yml +27 -0
- package/.github/workflows/release.yml +46 -0
- package/.github/workflows/tests.yml +42 -0
- package/.prettierrc +10 -0
- package/.releaserc.json +63 -0
- package/CHANGELOG.md +12 -0
- package/Code_of_Conduct.md +61 -0
- package/Contributing.md +236 -0
- package/README.md +119 -88
- package/commitlint.config.js +1 -0
- package/dist/index.cjs.js +206 -35
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +100 -77
- package/dist/index.esm.js +203 -37
- package/dist/index.esm.js.map +1 -1
- package/dist/src/components/index.d.ts +4 -0
- package/dist/src/components/mini-map/mini-map.d.ts +7 -0
- package/dist/{components → src/components/transform-component}/transform-component.d.ts +1 -1
- package/dist/{components → src/components/transform-wrapper}/transform-wrapper.d.ts +3 -4
- package/dist/{core → src/core}/instance.core.d.ts +5 -0
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/use-controls.d.ts +2 -0
- package/dist/src/hooks/use-transform-context.d.ts +1 -0
- package/dist/src/hooks/use-transform-effect.d.ts +2 -0
- package/dist/src/hooks/use-transform-init.d.ts +2 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/{models → src/models}/context.model.d.ts +6 -2
- package/dist/src/utils/context.utils.d.ts +4 -0
- package/package.json +35 -15
- package/rollup.config.js +51 -0
- package/src/components/index.ts +4 -0
- package/src/components/{keep-scale.tsx → keep-scale/keep-scale.tsx} +2 -2
- package/src/components/mini-map/mini-map.tsx +155 -0
- package/src/components/{transform-component.tsx → transform-component/transform-component.tsx} +1 -3
- package/src/components/transform-wrapper/transform-wrapper.tsx +39 -0
- package/src/core/instance.core.ts +18 -1
- package/src/hooks/index.ts +4 -0
- package/src/hooks/use-controls.tsx +9 -0
- package/src/hooks/use-transform-context.tsx +4 -15
- package/src/hooks/use-transform-effect.tsx +22 -0
- package/src/hooks/use-transform-init.tsx +29 -0
- package/src/index.ts +2 -4
- package/src/models/context.model.ts +11 -2
- package/src/utils/context.utils.ts +24 -3
- package/tsconfig.json +32 -0
- package/dist/hooks/use-transform-context.d.ts +0 -3
- package/dist/stories/docs/handlers.d.ts +0 -12
- package/dist/stories/docs/props.d.ts +0 -14
- package/dist/stories/examples/content-rerendering/example.d.ts +0 -2
- package/dist/stories/examples/keep-scale/example.d.ts +0 -2
- package/dist/stories/examples/stress/example.d.ts +0 -2
- package/dist/stories/examples/svg-zoom-to-element/example.d.ts +0 -2
- package/dist/stories/examples/zoom-to-element/example.d.ts +0 -2
- package/dist/stories/types/args.types.d.ts +0 -268
- package/dist/stories/utils/args.utils.d.ts +0 -3
- package/dist/stories/utils/code.utils.d.ts +0 -6
- package/dist/stories/utils/controls.utils.d.ts +0 -3
- package/dist/stories/utils/index.d.ts +0 -3
- package/dist/utils/context.utils.d.ts +0 -2
- package/src/components/transform-wrapper.tsx +0 -56
- package/src/stories/assets/big-image.jpeg +0 -0
- package/src/stories/assets/map.jpg +0 -0
- package/src/stories/assets/medium-image.jpg +0 -0
- package/src/stories/assets/pin.svg +0 -1
- package/src/stories/assets/small-image.jpg +0 -0
- package/src/stories/assets/svg-example.svg +0 -14
- package/src/stories/docs/Introduction.stories.mdx +0 -97
- package/src/stories/docs/handlers.stories.mdx +0 -48
- package/src/stories/docs/handlers.tsx +0 -107
- package/src/stories/docs/props.stories.mdx +0 -92
- package/src/stories/docs/props.tsx +0 -496
- package/src/stories/examples/content/content.stories.mdx +0 -122
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -45
- package/src/stories/examples/content-rerendering/example.tsx +0 -74
- package/src/stories/examples/controls/controls.stories.mdx +0 -72
- package/src/stories/examples/image-big/image-big.stories.mdx +0 -44
- package/src/stories/examples/image-medium/image-medium.stories.mdx +0 -42
- package/src/stories/examples/image-small/image-small.stories.mdx +0 -42
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -47
- package/src/stories/examples/keep-scale/example.tsx +0 -94
- package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -45
- package/src/stories/examples/stress/example.tsx +0 -24
- package/src/stories/examples/stress/stress-test.stories.mdx +0 -28
- package/src/stories/examples/svg-zoom-to-element/creativity.svg +0 -143
- package/src/stories/examples/svg-zoom-to-element/example.tsx +0 -57
- package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
- package/src/stories/examples/zoom-to-element/example.tsx +0 -95
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -28
- package/src/stories/types/args.types.ts +0 -201
- package/src/stories/utils/args.utils.ts +0 -34
- package/src/stories/utils/code.utils.tsx +0 -22
- package/src/stories/utils/controls.utils.tsx +0 -43
- package/src/stories/utils/index.ts +0 -3
- package/src/stories/utils/styles.module.css +0 -34
- /package/dist/{components → src/components/keep-scale}/keep-scale.d.ts +0 -0
- /package/dist/{constants → src/constants}/state.constants.d.ts +0 -0
- /package/dist/{core → src/core}/animations/animations.constants.d.ts +0 -0
- /package/dist/{core → src/core}/animations/animations.utils.d.ts +0 -0
- /package/dist/{core → src/core}/bounds/bounds.types.d.ts +0 -0
- /package/dist/{core → src/core}/bounds/bounds.utils.d.ts +0 -0
- /package/dist/{core → src/core}/double-click/double-click.logic.d.ts +0 -0
- /package/dist/{core → src/core}/handlers/handlers.logic.d.ts +0 -0
- /package/dist/{core → src/core}/handlers/handlers.utils.d.ts +0 -0
- /package/dist/{core → src/core}/pan/panning.logic.d.ts +0 -0
- /package/dist/{core → src/core}/pan/panning.utils.d.ts +0 -0
- /package/dist/{core → src/core}/pan/velocity.logic.d.ts +0 -0
- /package/dist/{core → src/core}/pan/velocity.utils.d.ts +0 -0
- /package/dist/{core → src/core}/pinch/pinch.logic.d.ts +0 -0
- /package/dist/{core → src/core}/pinch/pinch.utils.d.ts +0 -0
- /package/dist/{core → src/core}/wheel/wheel.logic.d.ts +0 -0
- /package/dist/{core → src/core}/wheel/wheel.utils.d.ts +0 -0
- /package/dist/{core → src/core}/zoom/zoom.logic.d.ts +0 -0
- /package/dist/{core → src/core}/zoom/zoom.utils.d.ts +0 -0
- /package/dist/{models → src/models}/calculations.model.d.ts +0 -0
- /package/dist/{models → src/models}/helpers.model.d.ts +0 -0
- /package/dist/{models → src/models}/index.d.ts +0 -0
- /package/dist/{utils → src/utils}/calculations.utils.d.ts +0 -0
- /package/dist/{utils → src/utils}/callback.utils.d.ts +0 -0
- /package/dist/{utils → src/utils}/event.utils.d.ts +0 -0
- /package/dist/{utils → src/utils}/helpers.utils.d.ts +0 -0
- /package/dist/{utils → src/utils}/index.d.ts +0 -0
- /package/dist/{utils → src/utils}/ref.utils.d.ts +0 -0
- /package/dist/{utils → src/utils}/state.utils.d.ts +0 -0
- /package/dist/{utils → src/utils}/styles.utils.d.ts +0 -0
- /package/src/components/{transform-component.module.css → transform-component/transform-component.module.css} +0 -0
package/README.md
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
# 🖼 React Zoom Pan Pinch
|
|
2
|
+
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://bettertyped.com/">
|
|
5
|
+
<img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
|
|
6
|
+
</a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/react-zoom-pan-pinch">
|
|
8
|
+
<img src="https://custom-icon-badges.demolab.com/npm/v/react-zoom-pan-pinch.svg?logo=npm&color=e22121"/>
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://github.com/prc5/react-zoom-pan-pinch">
|
|
11
|
+
<img src="https://custom-icon-badges.demolab.com/github/stars/prc5/react-zoom-pan-pinch?logo=star" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://github.com/prc5/react-zoom-pan-pinch/blob/main/License.md">
|
|
14
|
+
<img src="https://custom-icon-badges.demolab.com/github/license/prc5/react-zoom-pan-pinch?logo=law&color=yellow" />
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://github.com/semantic-release/semantic-release">
|
|
17
|
+
<img src="https://custom-icon-badges.demolab.com/badge/semver-commitzen-e10079?logo=semantic-release&color=e76f51" />
|
|
18
|
+
</a>
|
|
19
|
+
<a href="https://www.npmjs.com/package/react-zoom-pan-pinch">
|
|
20
|
+
<img src="https://custom-icon-badges.demolab.com/npm/dm/react-zoom-pan-pinch?logoColor=fff&logo=trending-up" />
|
|
21
|
+
</a>
|
|
22
|
+
<a href="https://www.npmjs.com/package/react-zoom-pan-pinch">
|
|
23
|
+
<img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/react-zoom-pan-pinch?color=E10098&logo=package" />
|
|
24
|
+
</a>
|
|
25
|
+
<a href="https://github.com/prc5/react-zoom-pan-pinch">
|
|
26
|
+
<img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
|
|
27
|
+
</a>
|
|
28
|
+
<a href="https://hits.sh/github.com/prc5/react-zoom-pan-pinch/">
|
|
29
|
+
<img src="https://hits.sh/github.com/prc5/react-zoom-pan-pinch.svg?color=64BC4B&logo=bookmeter" />
|
|
30
|
+
</a>
|
|
31
|
+
<a href="https://twitter.com/maciej_pyrc">
|
|
32
|
+
<img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/maciej_pyrc?label=Follow%20&style=social"/>
|
|
33
|
+
</a>
|
|
34
|
+
</p>
|
|
9
35
|
|
|
10
36
|
> Super fast and light react npm package for zooming, panning and pinching html
|
|
11
37
|
> elements in easy way
|
|
@@ -13,45 +39,46 @@
|
|
|
13
39
|
- [Demo](https://prc5.github.io/react-zoom-pan-pinch/?path=/story/examples-big-image--big-image)
|
|
14
40
|
- [Docs](https://prc5.github.io/react-zoom-pan-pinch/?path=/story/docs-props--page)
|
|
15
41
|
|
|
16
|
-
## Features
|
|
42
|
+
## Key Features
|
|
17
43
|
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
44
|
+
- 🚀 Fast and easy to use
|
|
45
|
+
- 🏭 Light, without external dependencies
|
|
46
|
+
- 💎 Mobile gestures, touchpad gestures and desktop mouse events support
|
|
47
|
+
- 🎁 Powerful context usage, which gives you a lot of freedom
|
|
48
|
+
- 🔧 Highly customizable
|
|
49
|
+
- 👑 Animations and Utils to create own tools
|
|
50
|
+
- 🔮 Advanced hooks and components
|
|
24
51
|
|
|
25
|
-
##
|
|
52
|
+
## Help me keep working on this project ❤️
|
|
26
53
|
|
|
27
|
-
|
|
28
|
-
npm install --save react-zoom-pan-pinch
|
|
29
|
-
```
|
|
54
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/prc5)
|
|
30
55
|
|
|
31
|
-
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
32
59
|
|
|
33
60
|
```bash
|
|
61
|
+
npm install --save react-zoom-pan-pinch
|
|
62
|
+
or
|
|
34
63
|
yarn add react-zoom-pan-pinch
|
|
35
64
|
```
|
|
36
65
|
|
|
37
|
-
##
|
|
66
|
+
## Examples
|
|
38
67
|
|
|
39
68
|
```jsx
|
|
40
69
|
import React, { Component } from "react";
|
|
41
70
|
|
|
42
71
|
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
|
|
43
72
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
}
|
|
73
|
+
const Example = () => {
|
|
74
|
+
return (
|
|
75
|
+
<TransformWrapper>
|
|
76
|
+
<TransformComponent>
|
|
77
|
+
<img src="image.jpg" alt="test" />
|
|
78
|
+
</TransformComponent>
|
|
79
|
+
</TransformWrapper>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
55
82
|
```
|
|
56
83
|
|
|
57
84
|
or
|
|
@@ -61,74 +88,78 @@ import React, { Component } from "react";
|
|
|
61
88
|
|
|
62
89
|
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
|
|
63
90
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
<
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
}
|
|
91
|
+
const Example = () => {
|
|
92
|
+
return (
|
|
93
|
+
<TransformWrapper
|
|
94
|
+
initialScale={1}
|
|
95
|
+
initialPositionX={200}
|
|
96
|
+
initialPositionY={100}
|
|
97
|
+
>
|
|
98
|
+
{({ zoomIn, zoomOut, resetTransform, ...rest }) => (
|
|
99
|
+
<React.Fragment>
|
|
100
|
+
<div className="tools">
|
|
101
|
+
<button onClick={() => zoomIn()}>+</button>
|
|
102
|
+
<button onClick={() => zoomOut()}>-</button>
|
|
103
|
+
<button onClick={() => resetTransform()}>x</button>
|
|
104
|
+
</div>
|
|
105
|
+
<TransformComponent>
|
|
106
|
+
<img src="image.jpg" alt="test" />
|
|
107
|
+
<div>Example text</div>
|
|
108
|
+
</TransformComponent>
|
|
109
|
+
</React.Fragment>
|
|
110
|
+
)}
|
|
111
|
+
</TransformWrapper>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
89
114
|
```
|
|
90
115
|
|
|
91
116
|
or
|
|
92
117
|
|
|
93
118
|
```tsx
|
|
94
119
|
import React, { useRef } from "react";
|
|
95
|
-
import {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const zoomToImage = ()=>{
|
|
101
|
-
const { zoomToElement } = transformComponentRef.current
|
|
102
|
-
zoomToElement('imgExample')
|
|
103
|
-
}
|
|
120
|
+
import {
|
|
121
|
+
TransformWrapper,
|
|
122
|
+
TransformComponent,
|
|
123
|
+
ReactZoomPanPinchRef,
|
|
124
|
+
} from "react-zoom-pan-pinch";
|
|
104
125
|
|
|
105
|
-
const
|
|
126
|
+
const Controls = ({ zoomIn, zoomOut, resetTransform }) => (
|
|
106
127
|
<>
|
|
107
128
|
<button onClick={() => zoomIn()}>+</button>
|
|
108
129
|
<button onClick={() => zoomOut()}>-</button>
|
|
109
130
|
<button onClick={() => resetTransform()}>x</button>
|
|
110
131
|
</>
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const Component = () => {
|
|
135
|
+
const transformComponentRef = useRef<ReactZoomPanPinchRef | null>(null);
|
|
136
|
+
|
|
137
|
+
const zoomToImage = () => {
|
|
138
|
+
if (transformComponentRef.current) {
|
|
139
|
+
const { zoomToElement } = transformComponentRef.current;
|
|
140
|
+
zoomToElement("imgExample");
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<TransformWrapper
|
|
146
|
+
initialScale={1}
|
|
147
|
+
initialPositionX={200}
|
|
148
|
+
initialPositionY={100}
|
|
149
|
+
ref={transformComponentRef}
|
|
150
|
+
>
|
|
151
|
+
{(utils) => (
|
|
152
|
+
<React.Fragment>
|
|
153
|
+
<Controls {...utils} />
|
|
154
|
+
<TransformComponent>
|
|
155
|
+
<img src="image.jpg" alt="test" id="imgExample" />
|
|
156
|
+
<div onClick={zoomToImage}>Example text</div>
|
|
157
|
+
</TransformComponent>
|
|
158
|
+
</React.Fragment>
|
|
159
|
+
)}
|
|
160
|
+
</TransformWrapper>
|
|
161
|
+
);
|
|
162
|
+
};
|
|
132
163
|
```
|
|
133
164
|
|
|
134
165
|
## License
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = { extends: ["@commitlint/config-conventional"] };
|
package/dist/index.cjs.js
CHANGED
|
@@ -620,6 +620,18 @@ var __assign = function() {
|
|
|
620
620
|
return __assign.apply(this, arguments);
|
|
621
621
|
};
|
|
622
622
|
|
|
623
|
+
function __rest(s, e) {
|
|
624
|
+
var t = {};
|
|
625
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
626
|
+
t[p] = s[p];
|
|
627
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
628
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
629
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
630
|
+
t[p[i]] = s[p[i]];
|
|
631
|
+
}
|
|
632
|
+
return t;
|
|
633
|
+
}
|
|
634
|
+
|
|
623
635
|
function __spreadArray(to, from, pack) {
|
|
624
636
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
625
637
|
if (ar || !(i in from)) {
|
|
@@ -882,10 +894,9 @@ var zoomToElement = function (contextInstance) {
|
|
|
882
894
|
};
|
|
883
895
|
};
|
|
884
896
|
|
|
885
|
-
var
|
|
897
|
+
var getControls = function (contextInstance) {
|
|
886
898
|
return {
|
|
887
899
|
instance: contextInstance,
|
|
888
|
-
state: contextInstance.transformState,
|
|
889
900
|
zoomIn: zoomIn(contextInstance),
|
|
890
901
|
zoomOut: zoomOut(contextInstance),
|
|
891
902
|
setTransform: setTransform(contextInstance),
|
|
@@ -894,6 +905,18 @@ var getContext = function (contextInstance) {
|
|
|
894
905
|
zoomToElement: zoomToElement(contextInstance),
|
|
895
906
|
};
|
|
896
907
|
};
|
|
908
|
+
var getState = function (contextInstance) {
|
|
909
|
+
return {
|
|
910
|
+
instance: contextInstance,
|
|
911
|
+
state: contextInstance.transformState,
|
|
912
|
+
};
|
|
913
|
+
};
|
|
914
|
+
var getContext = function (contextInstance) {
|
|
915
|
+
var ref = {};
|
|
916
|
+
Object.assign(ref, getState(contextInstance));
|
|
917
|
+
Object.assign(ref, getControls(contextInstance));
|
|
918
|
+
return ref;
|
|
919
|
+
};
|
|
897
920
|
|
|
898
921
|
// We want to make event listeners non-passive, and to do so have to check
|
|
899
922
|
// that browsers support EventListenerOptions in the first place.
|
|
@@ -1278,6 +1301,7 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1278
1301
|
var _this = this;
|
|
1279
1302
|
this.mounted = true;
|
|
1280
1303
|
this.onChangeCallbacks = new Set();
|
|
1304
|
+
this.onInitCallbacks = new Set();
|
|
1281
1305
|
// Components
|
|
1282
1306
|
this.wrapperComponent = null;
|
|
1283
1307
|
this.contentComponent = null;
|
|
@@ -1360,10 +1384,12 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1360
1384
|
this.handleInitialize = function (contentComponent) {
|
|
1361
1385
|
var centerOnInit = _this.setup.centerOnInit;
|
|
1362
1386
|
_this.applyTransformation();
|
|
1387
|
+
_this.onInitCallbacks.forEach(function (callback) { return callback(getContext(_this)); });
|
|
1363
1388
|
if (centerOnInit) {
|
|
1364
1389
|
_this.setCenter();
|
|
1365
1390
|
_this.observer = new ResizeObserver(function () {
|
|
1366
1391
|
var _a;
|
|
1392
|
+
_this.onInitCallbacks.forEach(function (callback) { return callback(getContext(_this)); });
|
|
1367
1393
|
_this.setCenter();
|
|
1368
1394
|
(_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
1369
1395
|
});
|
|
@@ -1597,6 +1623,9 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1597
1623
|
this.getContext = function () {
|
|
1598
1624
|
return getContext(_this);
|
|
1599
1625
|
};
|
|
1626
|
+
/**
|
|
1627
|
+
* Hooks
|
|
1628
|
+
*/
|
|
1600
1629
|
this.onChange = function (callback) {
|
|
1601
1630
|
if (!_this.onChangeCallbacks.has(callback)) {
|
|
1602
1631
|
_this.onChangeCallbacks.add(callback);
|
|
@@ -1605,6 +1634,14 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1605
1634
|
_this.onChangeCallbacks.delete(callback);
|
|
1606
1635
|
};
|
|
1607
1636
|
};
|
|
1637
|
+
this.onInit = function (callback) {
|
|
1638
|
+
if (!_this.onInitCallbacks.has(callback)) {
|
|
1639
|
+
_this.onInitCallbacks.add(callback);
|
|
1640
|
+
}
|
|
1641
|
+
return function () {
|
|
1642
|
+
_this.onInitCallbacks.delete(callback);
|
|
1643
|
+
};
|
|
1644
|
+
};
|
|
1608
1645
|
/**
|
|
1609
1646
|
* Initialization
|
|
1610
1647
|
*/
|
|
@@ -1617,7 +1654,8 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1617
1654
|
_this.handleInitialize(contentComponent);
|
|
1618
1655
|
_this.initializeWindowEvents();
|
|
1619
1656
|
_this.isInitialized = true;
|
|
1620
|
-
|
|
1657
|
+
var ctx = getContext(_this);
|
|
1658
|
+
handleCallback(ctx, undefined, _this.props.onInit);
|
|
1621
1659
|
};
|
|
1622
1660
|
this.props = props;
|
|
1623
1661
|
this.setup = createSetup(this.props);
|
|
@@ -1634,25 +1672,133 @@ var getContent = function (children, ctx) {
|
|
|
1634
1672
|
return children;
|
|
1635
1673
|
};
|
|
1636
1674
|
var TransformWrapper = React__default["default"].forwardRef(function (props, ref) {
|
|
1637
|
-
var _a = React.useState(0), forceUpdate = _a[1];
|
|
1638
|
-
var children = props.children;
|
|
1639
1675
|
var instance = React.useRef(new ZoomPanPinch(props)).current;
|
|
1640
|
-
var content = getContent(props.children,
|
|
1641
|
-
|
|
1642
|
-
if (typeof children === "function") {
|
|
1643
|
-
forceUpdate(function (prev) { return prev + 1; });
|
|
1644
|
-
}
|
|
1645
|
-
}, [children]);
|
|
1646
|
-
React.useImperativeHandle(ref, function () { return getContext(instance); }, [instance]);
|
|
1676
|
+
var content = getContent(props.children, getControls(instance));
|
|
1677
|
+
React.useImperativeHandle(ref, function () { return getControls(instance); }, [instance]);
|
|
1647
1678
|
React.useEffect(function () {
|
|
1648
1679
|
instance.update(props);
|
|
1649
1680
|
}, [instance, props]);
|
|
1650
|
-
React.useEffect(function () {
|
|
1651
|
-
return instance.onChange(handleOnChange);
|
|
1652
|
-
}, [instance, props, handleOnChange]);
|
|
1653
1681
|
return React__default["default"].createElement(Context.Provider, { value: instance }, content);
|
|
1654
1682
|
});
|
|
1655
1683
|
|
|
1684
|
+
var KeepScale = React__default["default"].forwardRef(function (props, ref) {
|
|
1685
|
+
var localRef = React.useRef(null);
|
|
1686
|
+
var instance = React.useContext(Context);
|
|
1687
|
+
React.useEffect(function () {
|
|
1688
|
+
return instance.onChange(function (ctx) {
|
|
1689
|
+
if (localRef.current) {
|
|
1690
|
+
var positionX = 0;
|
|
1691
|
+
var positionY = 0;
|
|
1692
|
+
localRef.current.style.transform = instance.handleTransformStyles(positionX, positionY, 1 / ctx.instance.transformState.scale);
|
|
1693
|
+
}
|
|
1694
|
+
});
|
|
1695
|
+
}, [instance]);
|
|
1696
|
+
return React__default["default"].createElement("div", __assign({}, props, { ref: mergeRefs([localRef, ref]) }));
|
|
1697
|
+
});
|
|
1698
|
+
|
|
1699
|
+
var previewStyles = {
|
|
1700
|
+
position: "absolute",
|
|
1701
|
+
zIndex: 2,
|
|
1702
|
+
top: "0px",
|
|
1703
|
+
left: "0px",
|
|
1704
|
+
boxSizing: "border-box",
|
|
1705
|
+
border: "3px solid red",
|
|
1706
|
+
transformOrigin: "0% 0%",
|
|
1707
|
+
boxShadow: "rgba(0,0,0,0.2) 0 0 0 10000000px",
|
|
1708
|
+
};
|
|
1709
|
+
var MiniMap = function (_a) {
|
|
1710
|
+
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];
|
|
1712
|
+
var instance = useTransformContext();
|
|
1713
|
+
var wrapperRef = React.useRef(null);
|
|
1714
|
+
var previewRef = React.useRef(null);
|
|
1715
|
+
var getContentSize = function () {
|
|
1716
|
+
if (instance.contentComponent) {
|
|
1717
|
+
return {
|
|
1718
|
+
width: instance.contentComponent.offsetWidth,
|
|
1719
|
+
height: instance.contentComponent.offsetHeight,
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
return {
|
|
1723
|
+
width: 0,
|
|
1724
|
+
height: 0,
|
|
1725
|
+
};
|
|
1726
|
+
};
|
|
1727
|
+
var computeMiniMapScale = function () {
|
|
1728
|
+
var contentSize = getContentSize();
|
|
1729
|
+
var scaleX = width / contentSize.width;
|
|
1730
|
+
var scaleY = height / contentSize.height;
|
|
1731
|
+
var scale = scaleY > scaleX ? scaleX : scaleY;
|
|
1732
|
+
return scale;
|
|
1733
|
+
};
|
|
1734
|
+
var computeMiniMapSize = function () {
|
|
1735
|
+
var contentSize = getContentSize();
|
|
1736
|
+
var scaleX = width / contentSize.width;
|
|
1737
|
+
var scaleY = height / contentSize.height;
|
|
1738
|
+
if (scaleY > scaleX) {
|
|
1739
|
+
return { width: width, height: contentSize.height * scaleX };
|
|
1740
|
+
}
|
|
1741
|
+
return { width: contentSize.width * scaleY, height: height };
|
|
1742
|
+
};
|
|
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
|
+
var computeMiniMapStyle = function () {
|
|
1751
|
+
var scale = computeMiniMapScale();
|
|
1752
|
+
return {
|
|
1753
|
+
transform: "scale(".concat(scale || 1, ")"),
|
|
1754
|
+
transformOrigin: "0% 0%",
|
|
1755
|
+
position: "absolute",
|
|
1756
|
+
boxSizing: "border-box",
|
|
1757
|
+
zIndex: 1,
|
|
1758
|
+
overflow: "hidden",
|
|
1759
|
+
};
|
|
1760
|
+
};
|
|
1761
|
+
var transformMiniMap = function () {
|
|
1762
|
+
var style = computeWrapperStyle();
|
|
1763
|
+
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");
|
|
1767
|
+
}
|
|
1768
|
+
if (previewRef.current) {
|
|
1769
|
+
var scale = computeMiniMapScale();
|
|
1770
|
+
var previewScale = scale * (1 / instance.transformState.scale);
|
|
1771
|
+
var transform = instance.handleTransformStyles(-instance.transformState.positionX * previewScale, -instance.transformState.positionY * previewScale, 1);
|
|
1772
|
+
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");
|
|
1775
|
+
}
|
|
1776
|
+
};
|
|
1777
|
+
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
|
+
transformMiniMap();
|
|
1787
|
+
};
|
|
1788
|
+
useTransformEffect(function () {
|
|
1789
|
+
transformMiniMap();
|
|
1790
|
+
});
|
|
1791
|
+
useTransformInit(function () {
|
|
1792
|
+
initialize();
|
|
1793
|
+
});
|
|
1794
|
+
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 || "") }),
|
|
1798
|
+
React__default["default"].createElement("div", __assign({}, rest, { ref: wrapperRef, className: "rzpp-wrapper" }), children),
|
|
1799
|
+
React__default["default"].createElement("div", { className: "rzpp-preview", ref: previewRef, style: previewStyles })));
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1656
1802
|
function styleInject(css, ref) {
|
|
1657
1803
|
if ( ref === void 0 ) ref = {};
|
|
1658
1804
|
var insertAt = ref.insertAt;
|
|
@@ -1680,8 +1826,8 @@ function styleInject(css, ref) {
|
|
|
1680
1826
|
}
|
|
1681
1827
|
}
|
|
1682
1828
|
|
|
1683
|
-
var css_248z = ".transform-component-
|
|
1684
|
-
var styles = {"wrapper":"transform-component-
|
|
1829
|
+
var css_248z = ".transform-component-module_wrapper__SPB86 {\n position: relative;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n overflow: hidden;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -khtml-user-select: none; /* Konqueror HTML */\n -moz-user-select: none; /* Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none;\n margin: 0;\n padding: 0;\n}\n.transform-component-module_content__FBWxo {\n display: flex;\n flex-wrap: wrap;\n width: -moz-fit-content;\n width: fit-content;\n height: -moz-fit-content;\n height: fit-content;\n margin: 0;\n padding: 0;\n transform-origin: 0% 0%;\n}\n.transform-component-module_content__FBWxo img {\n pointer-events: none;\n}\n";
|
|
1830
|
+
var styles = {"wrapper":"transform-component-module_wrapper__SPB86","content":"transform-component-module_content__FBWxo"};
|
|
1685
1831
|
styleInject(css_248z);
|
|
1686
1832
|
|
|
1687
1833
|
var TransformComponent = function (_a) {
|
|
@@ -1703,38 +1849,63 @@ var TransformComponent = function (_a) {
|
|
|
1703
1849
|
|
|
1704
1850
|
var useTransformContext = function () {
|
|
1705
1851
|
var libraryContext = React.useContext(Context);
|
|
1706
|
-
var _a = React.useState(getContext(libraryContext || {})), values = _a[0], setValues = _a[1];
|
|
1707
1852
|
if (!libraryContext) {
|
|
1708
1853
|
throw new Error("Transform context mus be placed inside TransformWrapper");
|
|
1709
1854
|
}
|
|
1855
|
+
return libraryContext;
|
|
1856
|
+
};
|
|
1857
|
+
|
|
1858
|
+
var useControls = function () {
|
|
1859
|
+
var libraryContext = useTransformContext();
|
|
1860
|
+
return getControls(libraryContext);
|
|
1861
|
+
};
|
|
1862
|
+
|
|
1863
|
+
var useTransformInit = function (callback) {
|
|
1864
|
+
var libraryContext = useTransformContext();
|
|
1710
1865
|
React.useEffect(function () {
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1866
|
+
var unmountCallback;
|
|
1867
|
+
var unmount;
|
|
1868
|
+
if (libraryContext.contentComponent && libraryContext.wrapperComponent) {
|
|
1869
|
+
console.warn(333);
|
|
1870
|
+
unmountCallback = callback(getState(libraryContext));
|
|
1871
|
+
}
|
|
1872
|
+
else {
|
|
1873
|
+
console.warn(444);
|
|
1874
|
+
unmount = libraryContext.onInit(function (ref) {
|
|
1875
|
+
unmountCallback = callback(getState(ref.instance));
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
return function () {
|
|
1879
|
+
unmount === null || unmount === void 0 ? void 0 : unmount();
|
|
1880
|
+
unmountCallback === null || unmountCallback === void 0 ? void 0 : unmountCallback();
|
|
1881
|
+
};
|
|
1882
|
+
}, []);
|
|
1716
1883
|
};
|
|
1717
1884
|
|
|
1718
|
-
var
|
|
1719
|
-
var
|
|
1720
|
-
var instance = React.useContext(Context);
|
|
1885
|
+
var useTransformEffect = function (callback) {
|
|
1886
|
+
var libraryContext = useTransformContext();
|
|
1721
1887
|
React.useEffect(function () {
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
var positionY = 0;
|
|
1726
|
-
localRef.current.style.transform = instance.handleTransformStyles(positionX, positionY, 1 / ctx.state.scale);
|
|
1727
|
-
}
|
|
1888
|
+
var unmountCallback;
|
|
1889
|
+
var unmount = libraryContext.onChange(function (ref) {
|
|
1890
|
+
unmountCallback = callback(getState(ref.instance));
|
|
1728
1891
|
});
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1892
|
+
return function () {
|
|
1893
|
+
unmount();
|
|
1894
|
+
unmountCallback === null || unmountCallback === void 0 ? void 0 : unmountCallback();
|
|
1895
|
+
};
|
|
1896
|
+
}, [callback, libraryContext]);
|
|
1897
|
+
};
|
|
1732
1898
|
|
|
1899
|
+
exports.Context = Context;
|
|
1733
1900
|
exports.KeepScale = KeepScale;
|
|
1901
|
+
exports.MiniMap = MiniMap;
|
|
1734
1902
|
exports.TransformComponent = TransformComponent;
|
|
1735
1903
|
exports.TransformWrapper = TransformWrapper;
|
|
1736
1904
|
exports.getCenterPosition = getCenterPosition;
|
|
1737
1905
|
exports.getMatrixTransformStyles = getMatrixTransformStyles;
|
|
1738
1906
|
exports.getTransformStyles = getTransformStyles;
|
|
1907
|
+
exports.useControls = useControls;
|
|
1739
1908
|
exports.useTransformContext = useTransformContext;
|
|
1909
|
+
exports.useTransformEffect = useTransformEffect;
|
|
1910
|
+
exports.useTransformInit = useTransformInit;
|
|
1740
1911
|
//# sourceMappingURL=index.cjs.js.map
|