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
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { ReactZoomPanPinchHandlers } from "../../models/context.model";
|
|
3
|
-
export type ControlsFnOptionsType = {
|
|
4
|
-
name: React.ReactNode;
|
|
5
|
-
type: string[];
|
|
6
|
-
parameters: string[];
|
|
7
|
-
description: string;
|
|
8
|
-
isObjectRow?: boolean;
|
|
9
|
-
};
|
|
10
|
-
export type ComponentProps = Record<keyof ReactZoomPanPinchHandlers, Omit<ControlsFnOptionsType, "name" | "isObjectRow"> | Record<string, Omit<ControlsFnOptionsType, "name" | "isObjectRow">>>;
|
|
11
|
-
export declare const handlersTable: ComponentProps;
|
|
12
|
-
export declare const getHandlersTable: () => ControlsFnOptionsType[];
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { ReactZoomPanPinchProps } from "models";
|
|
3
|
-
export type ControlsOptionsType = {
|
|
4
|
-
name: React.ReactNode;
|
|
5
|
-
type: string[];
|
|
6
|
-
defaultValue: string;
|
|
7
|
-
description: string;
|
|
8
|
-
isObjectRow?: boolean;
|
|
9
|
-
};
|
|
10
|
-
export type ComponentProps = Record<keyof Omit<ReactZoomPanPinchProps, "children">, Omit<ControlsOptionsType, "name" | "isObjectRow"> | Record<string, Omit<ControlsOptionsType, "name" | "isObjectRow">>>;
|
|
11
|
-
export declare const componentPropsTable: Record<string, Omit<ControlsOptionsType, "name">>;
|
|
12
|
-
export declare const wrapperPropsTable: ComponentProps;
|
|
13
|
-
export declare const componentProps: ControlsOptionsType[];
|
|
14
|
-
export declare const wrapperProps: ControlsOptionsType[];
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
export declare const argsTypes: {
|
|
2
|
-
wheel: {
|
|
3
|
-
table: {
|
|
4
|
-
disable: boolean;
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
"wheel.step": {
|
|
8
|
-
defaultValue: number;
|
|
9
|
-
control: {
|
|
10
|
-
type: string;
|
|
11
|
-
min: number;
|
|
12
|
-
};
|
|
13
|
-
table: {
|
|
14
|
-
defaultValue: {
|
|
15
|
-
summary: string;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
"wheel.disabled": {
|
|
20
|
-
defaultValue: NonNullable<boolean | undefined>;
|
|
21
|
-
control: {
|
|
22
|
-
type: string;
|
|
23
|
-
};
|
|
24
|
-
table: {
|
|
25
|
-
defaultValue: {
|
|
26
|
-
summary: string;
|
|
27
|
-
};
|
|
28
|
-
type: {
|
|
29
|
-
summary: string;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
"wheel.wheelDisabled": {
|
|
34
|
-
defaultValue: NonNullable<boolean | undefined>;
|
|
35
|
-
control: {
|
|
36
|
-
type: string;
|
|
37
|
-
};
|
|
38
|
-
table: {
|
|
39
|
-
defaultValue: {
|
|
40
|
-
summary: string;
|
|
41
|
-
};
|
|
42
|
-
type: {
|
|
43
|
-
summary: string;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
"wheel.touchPadDisabled": {
|
|
48
|
-
defaultValue: NonNullable<boolean | undefined>;
|
|
49
|
-
control: {
|
|
50
|
-
type: string;
|
|
51
|
-
};
|
|
52
|
-
table: {
|
|
53
|
-
defaultValue: {
|
|
54
|
-
summary: string;
|
|
55
|
-
};
|
|
56
|
-
type: {
|
|
57
|
-
summary: string;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
"wheel.activationKeys": {
|
|
62
|
-
defaultValue: import("../../models").DeepNonNullableArray<string>;
|
|
63
|
-
control: {
|
|
64
|
-
type: string;
|
|
65
|
-
};
|
|
66
|
-
table: {
|
|
67
|
-
defaultValue: {
|
|
68
|
-
summary: string;
|
|
69
|
-
};
|
|
70
|
-
type: {
|
|
71
|
-
summary: string;
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
"wheel.excluded": {
|
|
76
|
-
defaultValue: import("../../models").DeepNonNullableArray<string>;
|
|
77
|
-
control: {
|
|
78
|
-
type: string;
|
|
79
|
-
};
|
|
80
|
-
table: {
|
|
81
|
-
defaultValue: {
|
|
82
|
-
summary: string;
|
|
83
|
-
};
|
|
84
|
-
type: {
|
|
85
|
-
summary: string;
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
panning: {
|
|
90
|
-
table: {
|
|
91
|
-
disable: boolean;
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
"panning.disabled": {
|
|
95
|
-
defaultValue: NonNullable<boolean | undefined>;
|
|
96
|
-
control: {
|
|
97
|
-
type: string;
|
|
98
|
-
};
|
|
99
|
-
table: {
|
|
100
|
-
defaultValue: {
|
|
101
|
-
summary: string;
|
|
102
|
-
};
|
|
103
|
-
type: {
|
|
104
|
-
summary: string;
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
"panning.velocityDisabled": {
|
|
109
|
-
defaultValue: NonNullable<boolean | undefined>;
|
|
110
|
-
control: {
|
|
111
|
-
type: string;
|
|
112
|
-
};
|
|
113
|
-
table: {
|
|
114
|
-
defaultValue: {
|
|
115
|
-
summary: string;
|
|
116
|
-
};
|
|
117
|
-
type: {
|
|
118
|
-
summary: string;
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
"panning.lockAxisX": {
|
|
123
|
-
defaultValue: NonNullable<boolean | undefined>;
|
|
124
|
-
control: {
|
|
125
|
-
type: string;
|
|
126
|
-
};
|
|
127
|
-
table: {
|
|
128
|
-
defaultValue: {
|
|
129
|
-
summary: string;
|
|
130
|
-
};
|
|
131
|
-
type: {
|
|
132
|
-
summary: string;
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
"panning.lockAxisY": {
|
|
137
|
-
defaultValue: NonNullable<boolean | undefined>;
|
|
138
|
-
control: {
|
|
139
|
-
type: string;
|
|
140
|
-
};
|
|
141
|
-
table: {
|
|
142
|
-
defaultValue: {
|
|
143
|
-
summary: string;
|
|
144
|
-
};
|
|
145
|
-
type: {
|
|
146
|
-
summary: string;
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
"panning.activationKeys": {
|
|
151
|
-
defaultValue: import("../../models").DeepNonNullableArray<string>;
|
|
152
|
-
control: {
|
|
153
|
-
type: string;
|
|
154
|
-
};
|
|
155
|
-
table: {
|
|
156
|
-
defaultValue: {
|
|
157
|
-
summary: string;
|
|
158
|
-
};
|
|
159
|
-
type: {
|
|
160
|
-
summary: string;
|
|
161
|
-
};
|
|
162
|
-
};
|
|
163
|
-
};
|
|
164
|
-
"panning.excluded": {
|
|
165
|
-
defaultValue: import("../../models").DeepNonNullableArray<string>;
|
|
166
|
-
control: {
|
|
167
|
-
type: string;
|
|
168
|
-
};
|
|
169
|
-
table: {
|
|
170
|
-
defaultValue: {
|
|
171
|
-
summary: string;
|
|
172
|
-
};
|
|
173
|
-
type: {
|
|
174
|
-
summary: string;
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
pinch: {
|
|
179
|
-
table: {
|
|
180
|
-
disable: boolean;
|
|
181
|
-
};
|
|
182
|
-
};
|
|
183
|
-
"pinch.step": {
|
|
184
|
-
defaultValue: number;
|
|
185
|
-
control: {
|
|
186
|
-
type: string;
|
|
187
|
-
min: number;
|
|
188
|
-
};
|
|
189
|
-
table: {
|
|
190
|
-
defaultValue: {
|
|
191
|
-
summary: string;
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
|
-
"pinch.disabled": {
|
|
196
|
-
defaultValue: NonNullable<boolean | undefined>;
|
|
197
|
-
control: {
|
|
198
|
-
type: string;
|
|
199
|
-
};
|
|
200
|
-
table: {
|
|
201
|
-
defaultValue: {
|
|
202
|
-
summary: string;
|
|
203
|
-
};
|
|
204
|
-
type: {
|
|
205
|
-
summary: string;
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
"pinch.excluded": {
|
|
210
|
-
defaultValue: import("../../models").DeepNonNullableArray<string>;
|
|
211
|
-
control: {
|
|
212
|
-
type: string;
|
|
213
|
-
};
|
|
214
|
-
table: {
|
|
215
|
-
defaultValue: {
|
|
216
|
-
summary: string;
|
|
217
|
-
};
|
|
218
|
-
type: {
|
|
219
|
-
summary: string;
|
|
220
|
-
};
|
|
221
|
-
};
|
|
222
|
-
};
|
|
223
|
-
doubleClick: {
|
|
224
|
-
table: {
|
|
225
|
-
disable: boolean;
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
"doubleClick.step": {
|
|
229
|
-
defaultValue: number;
|
|
230
|
-
control: {
|
|
231
|
-
type: string;
|
|
232
|
-
min: number;
|
|
233
|
-
};
|
|
234
|
-
table: {
|
|
235
|
-
defaultValue: {
|
|
236
|
-
summary: string;
|
|
237
|
-
};
|
|
238
|
-
};
|
|
239
|
-
};
|
|
240
|
-
"doubleClick.disabled": {
|
|
241
|
-
defaultValue: NonNullable<boolean | undefined>;
|
|
242
|
-
control: {
|
|
243
|
-
type: string;
|
|
244
|
-
};
|
|
245
|
-
table: {
|
|
246
|
-
defaultValue: {
|
|
247
|
-
summary: string;
|
|
248
|
-
};
|
|
249
|
-
type: {
|
|
250
|
-
summary: string;
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
"doubleClick.excluded": {
|
|
255
|
-
defaultValue: import("../../models").DeepNonNullableArray<string>;
|
|
256
|
-
control: {
|
|
257
|
-
type: string;
|
|
258
|
-
};
|
|
259
|
-
table: {
|
|
260
|
-
defaultValue: {
|
|
261
|
-
summary: string;
|
|
262
|
-
};
|
|
263
|
-
type: {
|
|
264
|
-
summary: string;
|
|
265
|
-
};
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useCallback,
|
|
3
|
-
useEffect,
|
|
4
|
-
useImperativeHandle,
|
|
5
|
-
useRef,
|
|
6
|
-
useState,
|
|
7
|
-
} from "react";
|
|
8
|
-
|
|
9
|
-
import { ZoomPanPinch } from "../core/instance.core";
|
|
10
|
-
import { ReactZoomPanPinchProps, ReactZoomPanPinchRef } from "../models";
|
|
11
|
-
import { getContext } from "../utils";
|
|
12
|
-
|
|
13
|
-
export const Context = React.createContext<ZoomPanPinch>(null as any);
|
|
14
|
-
|
|
15
|
-
const getContent = (
|
|
16
|
-
children: ReactZoomPanPinchProps["children"],
|
|
17
|
-
ctx: ReactZoomPanPinchRef,
|
|
18
|
-
) => {
|
|
19
|
-
if (typeof children === "function") {
|
|
20
|
-
return children(ctx);
|
|
21
|
-
}
|
|
22
|
-
return children;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const TransformWrapper = React.forwardRef(
|
|
26
|
-
(
|
|
27
|
-
props: Omit<ReactZoomPanPinchProps, "ref">,
|
|
28
|
-
ref: React.Ref<ReactZoomPanPinchRef>,
|
|
29
|
-
) => {
|
|
30
|
-
const [, forceUpdate] = useState(0);
|
|
31
|
-
const { children } = props;
|
|
32
|
-
const instance = useRef(new ZoomPanPinch(props)).current;
|
|
33
|
-
|
|
34
|
-
const content = getContent(props.children, getContext(instance));
|
|
35
|
-
|
|
36
|
-
const handleOnChange = useCallback(() => {
|
|
37
|
-
if (typeof children === "function") {
|
|
38
|
-
forceUpdate((prev) => prev + 1);
|
|
39
|
-
}
|
|
40
|
-
}, [children]);
|
|
41
|
-
|
|
42
|
-
useImperativeHandle(ref, () => getContext(instance), [instance]);
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
instance.update(props);
|
|
46
|
-
}, [instance, props]);
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
return instance.onChange(handleOnChange);
|
|
50
|
-
}, [instance, props, handleOnChange]);
|
|
51
|
-
|
|
52
|
-
return <Context.Provider value={instance}>{content}</Context.Provider>;
|
|
53
|
-
},
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
export default TransformWrapper;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg enable-background="new 0 0 24 24" height="512" viewBox="0 0 24 24" width="512" xmlns="http://www.w3.org/2000/svg"><path d="m12 0c-4.962 0-9 4.066-9 9.065 0 7.103 8.154 14.437 8.501 14.745.143.127.321.19.499.19s.356-.063.499-.189c.347-.309 8.501-7.643 8.501-14.746 0-4.999-4.038-9.065-9-9.065zm0 14c-2.757 0-5-2.243-5-5s2.243-5 5-5 5 2.243 5 5-2.243 5-5 5z"/></svg>
|
|
Binary file
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<svg version="1.1"
|
|
2
|
-
baseProfile="full"
|
|
3
|
-
width="300" height="200"
|
|
4
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
5
|
-
id="example-svg"
|
|
6
|
-
>
|
|
7
|
-
|
|
8
|
-
<rect width="100%" height="100%" fill="red" />
|
|
9
|
-
|
|
10
|
-
<circle cx="150" cy="100" r="80" fill="green" />
|
|
11
|
-
|
|
12
|
-
<text x="150" y="125" font-size="30" text-anchor="middle" fill="white" id="text-svg">Example</text>
|
|
13
|
-
|
|
14
|
-
</svg>
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { Meta } from "@storybook/addon-docs/blocks";
|
|
2
|
-
|
|
3
|
-
<Meta title="Docs/Introduction" />
|
|
4
|
-
|
|
5
|
-
# React-zoom-pan-pinch
|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/react-zoom-pan-pinch)
|
|
8
|
-

|
|
9
|
-
[](https://standardjs.com)
|
|
10
|
-

|
|
11
|
-

|
|
12
|
-

|
|
13
|
-
|
|
14
|
-
> Super fast and light react npm package for zooming, panning and pinching html
|
|
15
|
-
> elements in easy way
|
|
16
|
-
|
|
17
|
-
<br />
|
|
18
|
-
<br />
|
|
19
|
-
|
|
20
|
-
## Features
|
|
21
|
-
|
|
22
|
-
- 🚀 Fast and easy to use
|
|
23
|
-
- 🏭 Light, without external dependencies
|
|
24
|
-
- 💎 Mobile gestures, touchpad gestures and desktop mouse events support
|
|
25
|
-
- 🎁 Powerful context usage, which gives you a lot of freedom
|
|
26
|
-
- 🔧 Highly customizable
|
|
27
|
-
- 👑 Animations and many options
|
|
28
|
-
|
|
29
|
-
## Install
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
npm install --save react-zoom-pan-pinch
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
or
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
yarn add react-zoom-pan-pinch
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Usage
|
|
42
|
-
|
|
43
|
-
```jsx
|
|
44
|
-
import React, { Component } from "react";
|
|
45
|
-
|
|
46
|
-
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
|
|
47
|
-
|
|
48
|
-
class Example extends Component {
|
|
49
|
-
render() {
|
|
50
|
-
return (
|
|
51
|
-
<TransformWrapper>
|
|
52
|
-
<TransformComponent>
|
|
53
|
-
<img src="image.jpg" alt="test" />
|
|
54
|
-
</TransformComponent>
|
|
55
|
-
</TransformWrapper>
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
or
|
|
62
|
-
|
|
63
|
-
```jsx
|
|
64
|
-
import React, { Component } from "react";
|
|
65
|
-
|
|
66
|
-
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
|
|
67
|
-
|
|
68
|
-
class Example extends Component {
|
|
69
|
-
render() {
|
|
70
|
-
return (
|
|
71
|
-
<TransformWrapper
|
|
72
|
-
initialScale={1}
|
|
73
|
-
initialPositionX={200}
|
|
74
|
-
initialPositionY={100}
|
|
75
|
-
>
|
|
76
|
-
{({ zoomIn, zoomOut, resetTransform, ...rest }) => (
|
|
77
|
-
<React.Fragment>
|
|
78
|
-
<div className="tools">
|
|
79
|
-
<button onClick={() => zoomIn()}>+</button>
|
|
80
|
-
<button onClick={() => zoomOut()}>-</button>
|
|
81
|
-
<button onClick={() => resetTransform()}>x</button>
|
|
82
|
-
</div>
|
|
83
|
-
<TransformComponent>
|
|
84
|
-
<img src="image.jpg" alt="test" />
|
|
85
|
-
<div>Example text</div>
|
|
86
|
-
</TransformComponent>
|
|
87
|
-
</React.Fragment>
|
|
88
|
-
)}
|
|
89
|
-
</TransformWrapper>
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## License
|
|
96
|
-
|
|
97
|
-
MIT © [prc5](https://github.com/prc5)
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Meta } from "@storybook/addon-docs/blocks";
|
|
2
|
-
|
|
3
|
-
import { getHandlersTable } from "./handlers.tsx";
|
|
4
|
-
import { Code } from "../utils";
|
|
5
|
-
|
|
6
|
-
<Meta title="Docs/Handlers" />
|
|
7
|
-
|
|
8
|
-
# Handlers
|
|
9
|
-
|
|
10
|
-
List of additionaly added handlers - you can acces them via ref or render props
|
|
11
|
-
|
|
12
|
-
<table className="handlers-table">
|
|
13
|
-
<thead>
|
|
14
|
-
<tr>
|
|
15
|
-
<th>
|
|
16
|
-
Name
|
|
17
|
-
</th>
|
|
18
|
-
<th>
|
|
19
|
-
Type
|
|
20
|
-
</th>
|
|
21
|
-
<th>
|
|
22
|
-
Default
|
|
23
|
-
</th>
|
|
24
|
-
<th>
|
|
25
|
-
Description
|
|
26
|
-
</th>
|
|
27
|
-
</tr>
|
|
28
|
-
</thead>
|
|
29
|
-
<tbody>
|
|
30
|
-
{getHandlersTable().map(row => (
|
|
31
|
-
<tr className={row.isObjectRow ? "is-object-row" : ""}>
|
|
32
|
-
<td>
|
|
33
|
-
{row.name}
|
|
34
|
-
</td>
|
|
35
|
-
<td>
|
|
36
|
-
{row.type.map(type => (<Code code={type} />))}
|
|
37
|
-
</td>
|
|
38
|
-
<td>
|
|
39
|
-
{row.parameters.map(param => (<Code code={param} />))}
|
|
40
|
-
</td>
|
|
41
|
-
<td>
|
|
42
|
-
{row.description}
|
|
43
|
-
</td>
|
|
44
|
-
</tr>
|
|
45
|
-
))}
|
|
46
|
-
</tbody>
|
|
47
|
-
|
|
48
|
-
</table>
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { ReactZoomPanPinchHandlers } from "../../models/context.model";
|
|
4
|
-
|
|
5
|
-
export type ControlsFnOptionsType = {
|
|
6
|
-
name: React.ReactNode;
|
|
7
|
-
type: string[];
|
|
8
|
-
parameters: string[];
|
|
9
|
-
description: string;
|
|
10
|
-
isObjectRow?: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type ComponentProps = Record<
|
|
14
|
-
keyof ReactZoomPanPinchHandlers,
|
|
15
|
-
| Omit<ControlsFnOptionsType, "name" | "isObjectRow">
|
|
16
|
-
| Record<string, Omit<ControlsFnOptionsType, "name" | "isObjectRow">>
|
|
17
|
-
>;
|
|
18
|
-
|
|
19
|
-
export const handlersTable: ComponentProps = {
|
|
20
|
-
zoomIn: {
|
|
21
|
-
type: ["function(step, animationTime, animationName)"],
|
|
22
|
-
parameters: [
|
|
23
|
-
"step: number = 0.5",
|
|
24
|
-
"animationTime: number = 300",
|
|
25
|
-
"animationName: string = easeOut",
|
|
26
|
-
],
|
|
27
|
-
description: "Function used for zoom in button",
|
|
28
|
-
},
|
|
29
|
-
zoomOut: {
|
|
30
|
-
type: ["function(step, animationTime, animationName)"],
|
|
31
|
-
parameters: [
|
|
32
|
-
"step: number = 0.5",
|
|
33
|
-
"animationTime: number = 300",
|
|
34
|
-
"animationName: string = easeOut",
|
|
35
|
-
],
|
|
36
|
-
description: "Function used for zoom out button",
|
|
37
|
-
},
|
|
38
|
-
setTransform: {
|
|
39
|
-
type: ["function(x, y, scale, animationTime, animationName)"],
|
|
40
|
-
parameters: [
|
|
41
|
-
"x: number",
|
|
42
|
-
"y: number",
|
|
43
|
-
"scale: number",
|
|
44
|
-
"animationTime: number = 300",
|
|
45
|
-
"animationName: string = easeOut",
|
|
46
|
-
],
|
|
47
|
-
description: "Function used for custom transformation animation",
|
|
48
|
-
},
|
|
49
|
-
resetTransform: {
|
|
50
|
-
type: ["function(animationTime, animationName)"],
|
|
51
|
-
parameters: [
|
|
52
|
-
"animationTime: number = 300",
|
|
53
|
-
"animationName: string = easeOut",
|
|
54
|
-
],
|
|
55
|
-
description: "Function used for reset button",
|
|
56
|
-
},
|
|
57
|
-
centerView: {
|
|
58
|
-
type: ["function(scale, animationTime, animationName)"],
|
|
59
|
-
parameters: [
|
|
60
|
-
"scale: number = undefined",
|
|
61
|
-
"animationTime: number = 300",
|
|
62
|
-
"animationName: string = easeOut",
|
|
63
|
-
],
|
|
64
|
-
description: "Function used for centering the content component",
|
|
65
|
-
},
|
|
66
|
-
zoomToElement: {
|
|
67
|
-
type: ["function(node, customZoom, animationTime, animationName)"],
|
|
68
|
-
parameters: [
|
|
69
|
-
"node: HTMLElement | string",
|
|
70
|
-
"customScale: number = undefined",
|
|
71
|
-
"animationTime: number = 300",
|
|
72
|
-
"animationName: string = easeOut",
|
|
73
|
-
],
|
|
74
|
-
description:
|
|
75
|
-
"This function make a transition for certain node provided to the function(as node element or it's id string). It allows only to zoom elements with offsetWidth and offsetHeight properties - since SVG's doesn't have those, it is impossible to perform it on such elements.",
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const getHandlersTable = (): ControlsFnOptionsType[] => {
|
|
80
|
-
return Object.keys(handlersTable).reduce<ControlsFnOptionsType[]>(
|
|
81
|
-
(acc, key) => {
|
|
82
|
-
if (Array.isArray(handlersTable[key]?.type)) {
|
|
83
|
-
acc.push({
|
|
84
|
-
...handlersTable[key],
|
|
85
|
-
name: key,
|
|
86
|
-
});
|
|
87
|
-
} else {
|
|
88
|
-
Object.keys(handlersTable[key]).forEach((prop) => {
|
|
89
|
-
acc.push({
|
|
90
|
-
...handlersTable[key][prop],
|
|
91
|
-
isObjectRow: key === prop,
|
|
92
|
-
name:
|
|
93
|
-
key === prop ? (
|
|
94
|
-
<b>{prop}</b>
|
|
95
|
-
) : (
|
|
96
|
-
<>
|
|
97
|
-
{key}.<b>{prop}</b>
|
|
98
|
-
</>
|
|
99
|
-
),
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
return acc;
|
|
104
|
-
},
|
|
105
|
-
[],
|
|
106
|
-
);
|
|
107
|
-
};
|