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/dist/index.d.ts
CHANGED
|
@@ -30,11 +30,91 @@ declare const resetTransform: (contextInstance: ReactZoomPanPinchContext) => (an
|
|
|
30
30
|
declare const centerView: (contextInstance: ReactZoomPanPinchContext) => (scale?: number, animationTime?: number, animationType?: keyof typeof animations) => void;
|
|
31
31
|
declare const zoomToElement: (contextInstance: ReactZoomPanPinchContext) => (node: HTMLElement | string, scale?: number, animationTime?: number, animationType?: keyof typeof animations) => void;
|
|
32
32
|
|
|
33
|
+
type StartCoordsType = {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
} | null;
|
|
37
|
+
declare class ZoomPanPinch {
|
|
38
|
+
props: ReactZoomPanPinchProps;
|
|
39
|
+
mounted: boolean;
|
|
40
|
+
transformState: ReactZoomPanPinchState;
|
|
41
|
+
setup: LibrarySetup;
|
|
42
|
+
observer?: ResizeObserver;
|
|
43
|
+
onChangeCallbacks: Set<(ctx: ReactZoomPanPinchRef) => void>;
|
|
44
|
+
onInitCallbacks: Set<(ctx: ReactZoomPanPinchRef) => void>;
|
|
45
|
+
wrapperComponent: HTMLDivElement | null;
|
|
46
|
+
contentComponent: HTMLDivElement | null;
|
|
47
|
+
isInitialized: boolean;
|
|
48
|
+
bounds: BoundsType | null;
|
|
49
|
+
previousWheelEvent: WheelEvent | null;
|
|
50
|
+
wheelStopEventTimer: ReturnType<typeof setTimeout> | null;
|
|
51
|
+
wheelAnimationTimer: ReturnType<typeof setTimeout> | null;
|
|
52
|
+
isPanning: boolean;
|
|
53
|
+
startCoords: StartCoordsType;
|
|
54
|
+
lastTouch: number | null;
|
|
55
|
+
distance: null | number;
|
|
56
|
+
lastDistance: null | number;
|
|
57
|
+
pinchStartDistance: null | number;
|
|
58
|
+
pinchStartScale: null | number;
|
|
59
|
+
pinchMidpoint: null | PositionType;
|
|
60
|
+
doubleClickStopEventTimer: ReturnType<typeof setTimeout> | null;
|
|
61
|
+
velocity: VelocityType | null;
|
|
62
|
+
velocityTime: number | null;
|
|
63
|
+
lastMousePosition: PositionType | null;
|
|
64
|
+
animate: boolean;
|
|
65
|
+
animation: AnimationType | null;
|
|
66
|
+
maxBounds: BoundsType | null;
|
|
67
|
+
pressedKeys: {
|
|
68
|
+
[key: string]: boolean;
|
|
69
|
+
};
|
|
70
|
+
constructor(props: ReactZoomPanPinchProps);
|
|
71
|
+
mount: () => void;
|
|
72
|
+
unmount: () => void;
|
|
73
|
+
update: (newProps: ReactZoomPanPinchProps) => void;
|
|
74
|
+
initializeWindowEvents: () => void;
|
|
75
|
+
cleanupWindowEvents: () => void;
|
|
76
|
+
handleInitializeWrapperEvents: (wrapper: HTMLDivElement) => void;
|
|
77
|
+
handleInitialize: (contentComponent: HTMLDivElement) => void;
|
|
78
|
+
onWheelZoom: (event: WheelEvent) => void;
|
|
79
|
+
onPanningStart: (event: MouseEvent) => void;
|
|
80
|
+
onPanning: (event: MouseEvent) => void;
|
|
81
|
+
onPanningStop: (event: MouseEvent | TouchEvent) => void;
|
|
82
|
+
onPinchStart: (event: TouchEvent) => void;
|
|
83
|
+
onPinch: (event: TouchEvent) => void;
|
|
84
|
+
onPinchStop: (event: TouchEvent) => void;
|
|
85
|
+
onTouchPanningStart: (event: TouchEvent) => void;
|
|
86
|
+
onTouchPanning: (event: TouchEvent) => void;
|
|
87
|
+
onTouchPanningStop: (event: TouchEvent) => void;
|
|
88
|
+
onDoubleClick: (event: MouseEvent | TouchEvent) => void;
|
|
89
|
+
clearPanning: (event: MouseEvent) => void;
|
|
90
|
+
setKeyPressed: (e: KeyboardEvent) => void;
|
|
91
|
+
setKeyUnPressed: (e: KeyboardEvent) => void;
|
|
92
|
+
isPressingKeys: (keys: string[]) => boolean;
|
|
93
|
+
setTransformState: (scale: number, positionX: number, positionY: number) => void;
|
|
94
|
+
setCenter: () => void;
|
|
95
|
+
handleTransformStyles: (x: number, y: number, scale: number) => string;
|
|
96
|
+
applyTransformation: () => void;
|
|
97
|
+
getContext: () => ReactZoomPanPinchRef;
|
|
98
|
+
/**
|
|
99
|
+
* Hooks
|
|
100
|
+
*/
|
|
101
|
+
onChange: (callback: (ref: ReactZoomPanPinchRef) => void) => () => void;
|
|
102
|
+
onInit: (callback: (ref: ReactZoomPanPinchRef) => void) => () => void;
|
|
103
|
+
/**
|
|
104
|
+
* Initialization
|
|
105
|
+
*/
|
|
106
|
+
init: (wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => void;
|
|
107
|
+
}
|
|
108
|
+
|
|
33
109
|
type ReactZoomPanPinchContext = typeof ZoomPanPinch.prototype;
|
|
34
|
-
type
|
|
110
|
+
type ReactZoomPanPinchContextState = {
|
|
35
111
|
instance: ReactZoomPanPinchContext;
|
|
36
112
|
state: ReactZoomPanPinchState;
|
|
113
|
+
};
|
|
114
|
+
type ReactZoomPanPinchContentRef = {
|
|
115
|
+
instance: ReactZoomPanPinchContext;
|
|
37
116
|
} & ReactZoomPanPinchHandlers;
|
|
117
|
+
type ReactZoomPanPinchRef = ReactZoomPanPinchContextState & ReactZoomPanPinchHandlers;
|
|
38
118
|
type ReactZoomPanPinchState = {
|
|
39
119
|
previousScale: number;
|
|
40
120
|
scale: number;
|
|
@@ -53,7 +133,7 @@ type ReactZoomPanPinchRefProps = {
|
|
|
53
133
|
setRef: (context: ReactZoomPanPinchRef) => void;
|
|
54
134
|
} & Omit<ReactZoomPanPinchProps, "ref">;
|
|
55
135
|
type ReactZoomPanPinchProps = {
|
|
56
|
-
children?: React.ReactNode | ((ref:
|
|
136
|
+
children?: React.ReactNode | ((ref: ReactZoomPanPinchContentRef) => React.ReactNode);
|
|
57
137
|
ref?: React.Ref<ReactZoomPanPinchRef>;
|
|
58
138
|
initialScale?: number;
|
|
59
139
|
initialPositionX?: number;
|
|
@@ -170,78 +250,22 @@ type BoundsType = {
|
|
|
170
250
|
};
|
|
171
251
|
type AnimationType = () => void | number;
|
|
172
252
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
declare
|
|
178
|
-
props: ReactZoomPanPinchProps;
|
|
179
|
-
mounted: boolean;
|
|
180
|
-
transformState: ReactZoomPanPinchState;
|
|
181
|
-
setup: LibrarySetup;
|
|
182
|
-
observer?: ResizeObserver;
|
|
183
|
-
onChangeCallbacks: Set<(ctx: ReactZoomPanPinchRef) => void>;
|
|
184
|
-
wrapperComponent: HTMLDivElement | null;
|
|
185
|
-
contentComponent: HTMLDivElement | null;
|
|
186
|
-
isInitialized: boolean;
|
|
187
|
-
bounds: BoundsType | null;
|
|
188
|
-
previousWheelEvent: WheelEvent | null;
|
|
189
|
-
wheelStopEventTimer: ReturnType<typeof setTimeout> | null;
|
|
190
|
-
wheelAnimationTimer: ReturnType<typeof setTimeout> | null;
|
|
191
|
-
isPanning: boolean;
|
|
192
|
-
startCoords: StartCoordsType;
|
|
193
|
-
lastTouch: number | null;
|
|
194
|
-
distance: null | number;
|
|
195
|
-
lastDistance: null | number;
|
|
196
|
-
pinchStartDistance: null | number;
|
|
197
|
-
pinchStartScale: null | number;
|
|
198
|
-
pinchMidpoint: null | PositionType;
|
|
199
|
-
doubleClickStopEventTimer: ReturnType<typeof setTimeout> | null;
|
|
200
|
-
velocity: VelocityType | null;
|
|
201
|
-
velocityTime: number | null;
|
|
202
|
-
lastMousePosition: PositionType | null;
|
|
203
|
-
animate: boolean;
|
|
204
|
-
animation: AnimationType | null;
|
|
205
|
-
maxBounds: BoundsType | null;
|
|
206
|
-
pressedKeys: {
|
|
207
|
-
[key: string]: boolean;
|
|
208
|
-
};
|
|
209
|
-
constructor(props: ReactZoomPanPinchProps);
|
|
210
|
-
mount: () => void;
|
|
211
|
-
unmount: () => void;
|
|
212
|
-
update: (newProps: ReactZoomPanPinchProps) => void;
|
|
213
|
-
initializeWindowEvents: () => void;
|
|
214
|
-
cleanupWindowEvents: () => void;
|
|
215
|
-
handleInitializeWrapperEvents: (wrapper: HTMLDivElement) => void;
|
|
216
|
-
handleInitialize: (contentComponent: HTMLDivElement) => void;
|
|
217
|
-
onWheelZoom: (event: WheelEvent) => void;
|
|
218
|
-
onPanningStart: (event: MouseEvent) => void;
|
|
219
|
-
onPanning: (event: MouseEvent) => void;
|
|
220
|
-
onPanningStop: (event: MouseEvent | TouchEvent) => void;
|
|
221
|
-
onPinchStart: (event: TouchEvent) => void;
|
|
222
|
-
onPinch: (event: TouchEvent) => void;
|
|
223
|
-
onPinchStop: (event: TouchEvent) => void;
|
|
224
|
-
onTouchPanningStart: (event: TouchEvent) => void;
|
|
225
|
-
onTouchPanning: (event: TouchEvent) => void;
|
|
226
|
-
onTouchPanningStop: (event: TouchEvent) => void;
|
|
227
|
-
onDoubleClick: (event: MouseEvent | TouchEvent) => void;
|
|
228
|
-
clearPanning: (event: MouseEvent) => void;
|
|
229
|
-
setKeyPressed: (e: KeyboardEvent) => void;
|
|
230
|
-
setKeyUnPressed: (e: KeyboardEvent) => void;
|
|
231
|
-
isPressingKeys: (keys: string[]) => boolean;
|
|
232
|
-
setTransformState: (scale: number, positionX: number, positionY: number) => void;
|
|
233
|
-
setCenter: () => void;
|
|
234
|
-
handleTransformStyles: (x: number, y: number, scale: number) => string;
|
|
235
|
-
applyTransformation: () => void;
|
|
236
|
-
getContext: () => ReactZoomPanPinchRef;
|
|
237
|
-
onChange: (callback: (ref: ReactZoomPanPinchRef) => void) => () => void;
|
|
238
|
-
/**
|
|
239
|
-
* Initialization
|
|
240
|
-
*/
|
|
241
|
-
init: (wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => void;
|
|
242
|
-
}
|
|
253
|
+
declare const useControls: () => ReactZoomPanPinchContentRef;
|
|
254
|
+
|
|
255
|
+
declare const useTransformInit: (callback: (ref: ReactZoomPanPinchContextState) => void | (() => void)) => void;
|
|
256
|
+
|
|
257
|
+
declare const useTransformEffect: (callback: (ref: ReactZoomPanPinchContextState) => void | (() => void)) => void;
|
|
243
258
|
|
|
244
|
-
declare const
|
|
259
|
+
declare const useTransformContext: () => ZoomPanPinch;
|
|
260
|
+
|
|
261
|
+
declare const KeepScale: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
262
|
+
|
|
263
|
+
type MiniMapProps = {
|
|
264
|
+
width?: number;
|
|
265
|
+
height?: number;
|
|
266
|
+
children: React.ReactNode;
|
|
267
|
+
} & React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
268
|
+
declare const MiniMap: React.FC<MiniMapProps>;
|
|
245
269
|
|
|
246
270
|
type Props = {
|
|
247
271
|
children: React.ReactNode;
|
|
@@ -254,12 +278,11 @@ type Props = {
|
|
|
254
278
|
};
|
|
255
279
|
declare const TransformComponent: React.FC<Props>;
|
|
256
280
|
|
|
257
|
-
declare const
|
|
258
|
-
|
|
259
|
-
declare const KeepScale: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
281
|
+
declare const Context: React.Context<ZoomPanPinch>;
|
|
282
|
+
declare const TransformWrapper: React.ForwardRefExoticComponent<Omit<ReactZoomPanPinchProps, "ref"> & React.RefAttributes<ReactZoomPanPinchContentRef>>;
|
|
260
283
|
|
|
261
284
|
declare const getTransformStyles: (x: number, y: number, scale: number) => string;
|
|
262
285
|
declare const getMatrixTransformStyles: (x: number, y: number, scale: number) => string;
|
|
263
286
|
declare const getCenterPosition: (scale: number, wrapperComponent: HTMLDivElement, contentComponent: HTMLDivElement) => StateType;
|
|
264
287
|
|
|
265
|
-
export { AnimationType, BoundsType, KeepScale, LibrarySetup, PositionType, ReactZoomPanPinchComponentHelpers, ReactZoomPanPinchContext, ReactZoomPanPinchHandlers, ReactZoomPanPinchProps, ReactZoomPanPinchRef, ReactZoomPanPinchRefProps, ReactZoomPanPinchState, SizeType, StateType, TransformComponent, TransformWrapper, VelocityType, getCenterPosition, getMatrixTransformStyles, getTransformStyles, useTransformContext };
|
|
288
|
+
export { AnimationType, BoundsType, Context, KeepScale, LibrarySetup, MiniMap, MiniMapProps, PositionType, ReactZoomPanPinchComponentHelpers, ReactZoomPanPinchContentRef, ReactZoomPanPinchContext, ReactZoomPanPinchContextState, ReactZoomPanPinchHandlers, ReactZoomPanPinchProps, ReactZoomPanPinchRef, ReactZoomPanPinchRefProps, ReactZoomPanPinchState, SizeType, StateType, TransformComponent, TransformWrapper, VelocityType, getCenterPosition, getMatrixTransformStyles, getTransformStyles, useControls, useTransformContext, useTransformEffect, useTransformInit };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useRef, useImperativeHandle, useEffect, useContext, useState, useMemo } from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Rounds number to given decimal
|
|
@@ -612,6 +612,18 @@ var __assign = function() {
|
|
|
612
612
|
return __assign.apply(this, arguments);
|
|
613
613
|
};
|
|
614
614
|
|
|
615
|
+
function __rest(s, e) {
|
|
616
|
+
var t = {};
|
|
617
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
618
|
+
t[p] = s[p];
|
|
619
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
620
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
621
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
622
|
+
t[p[i]] = s[p[i]];
|
|
623
|
+
}
|
|
624
|
+
return t;
|
|
625
|
+
}
|
|
626
|
+
|
|
615
627
|
function __spreadArray(to, from, pack) {
|
|
616
628
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
617
629
|
if (ar || !(i in from)) {
|
|
@@ -874,10 +886,9 @@ var zoomToElement = function (contextInstance) {
|
|
|
874
886
|
};
|
|
875
887
|
};
|
|
876
888
|
|
|
877
|
-
var
|
|
889
|
+
var getControls = function (contextInstance) {
|
|
878
890
|
return {
|
|
879
891
|
instance: contextInstance,
|
|
880
|
-
state: contextInstance.transformState,
|
|
881
892
|
zoomIn: zoomIn(contextInstance),
|
|
882
893
|
zoomOut: zoomOut(contextInstance),
|
|
883
894
|
setTransform: setTransform(contextInstance),
|
|
@@ -886,6 +897,18 @@ var getContext = function (contextInstance) {
|
|
|
886
897
|
zoomToElement: zoomToElement(contextInstance),
|
|
887
898
|
};
|
|
888
899
|
};
|
|
900
|
+
var getState = function (contextInstance) {
|
|
901
|
+
return {
|
|
902
|
+
instance: contextInstance,
|
|
903
|
+
state: contextInstance.transformState,
|
|
904
|
+
};
|
|
905
|
+
};
|
|
906
|
+
var getContext = function (contextInstance) {
|
|
907
|
+
var ref = {};
|
|
908
|
+
Object.assign(ref, getState(contextInstance));
|
|
909
|
+
Object.assign(ref, getControls(contextInstance));
|
|
910
|
+
return ref;
|
|
911
|
+
};
|
|
889
912
|
|
|
890
913
|
// We want to make event listeners non-passive, and to do so have to check
|
|
891
914
|
// that browsers support EventListenerOptions in the first place.
|
|
@@ -1270,6 +1293,7 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1270
1293
|
var _this = this;
|
|
1271
1294
|
this.mounted = true;
|
|
1272
1295
|
this.onChangeCallbacks = new Set();
|
|
1296
|
+
this.onInitCallbacks = new Set();
|
|
1273
1297
|
// Components
|
|
1274
1298
|
this.wrapperComponent = null;
|
|
1275
1299
|
this.contentComponent = null;
|
|
@@ -1352,10 +1376,12 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1352
1376
|
this.handleInitialize = function (contentComponent) {
|
|
1353
1377
|
var centerOnInit = _this.setup.centerOnInit;
|
|
1354
1378
|
_this.applyTransformation();
|
|
1379
|
+
_this.onInitCallbacks.forEach(function (callback) { return callback(getContext(_this)); });
|
|
1355
1380
|
if (centerOnInit) {
|
|
1356
1381
|
_this.setCenter();
|
|
1357
1382
|
_this.observer = new ResizeObserver(function () {
|
|
1358
1383
|
var _a;
|
|
1384
|
+
_this.onInitCallbacks.forEach(function (callback) { return callback(getContext(_this)); });
|
|
1359
1385
|
_this.setCenter();
|
|
1360
1386
|
(_a = _this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
1361
1387
|
});
|
|
@@ -1589,6 +1615,9 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1589
1615
|
this.getContext = function () {
|
|
1590
1616
|
return getContext(_this);
|
|
1591
1617
|
};
|
|
1618
|
+
/**
|
|
1619
|
+
* Hooks
|
|
1620
|
+
*/
|
|
1592
1621
|
this.onChange = function (callback) {
|
|
1593
1622
|
if (!_this.onChangeCallbacks.has(callback)) {
|
|
1594
1623
|
_this.onChangeCallbacks.add(callback);
|
|
@@ -1597,6 +1626,14 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1597
1626
|
_this.onChangeCallbacks.delete(callback);
|
|
1598
1627
|
};
|
|
1599
1628
|
};
|
|
1629
|
+
this.onInit = function (callback) {
|
|
1630
|
+
if (!_this.onInitCallbacks.has(callback)) {
|
|
1631
|
+
_this.onInitCallbacks.add(callback);
|
|
1632
|
+
}
|
|
1633
|
+
return function () {
|
|
1634
|
+
_this.onInitCallbacks.delete(callback);
|
|
1635
|
+
};
|
|
1636
|
+
};
|
|
1600
1637
|
/**
|
|
1601
1638
|
* Initialization
|
|
1602
1639
|
*/
|
|
@@ -1609,7 +1646,8 @@ var ZoomPanPinch = /** @class */ (function () {
|
|
|
1609
1646
|
_this.handleInitialize(contentComponent);
|
|
1610
1647
|
_this.initializeWindowEvents();
|
|
1611
1648
|
_this.isInitialized = true;
|
|
1612
|
-
|
|
1649
|
+
var ctx = getContext(_this);
|
|
1650
|
+
handleCallback(ctx, undefined, _this.props.onInit);
|
|
1613
1651
|
};
|
|
1614
1652
|
this.props = props;
|
|
1615
1653
|
this.setup = createSetup(this.props);
|
|
@@ -1626,25 +1664,133 @@ var getContent = function (children, ctx) {
|
|
|
1626
1664
|
return children;
|
|
1627
1665
|
};
|
|
1628
1666
|
var TransformWrapper = React.forwardRef(function (props, ref) {
|
|
1629
|
-
var _a = useState(0), forceUpdate = _a[1];
|
|
1630
|
-
var children = props.children;
|
|
1631
1667
|
var instance = useRef(new ZoomPanPinch(props)).current;
|
|
1632
|
-
var content = getContent(props.children,
|
|
1633
|
-
|
|
1634
|
-
if (typeof children === "function") {
|
|
1635
|
-
forceUpdate(function (prev) { return prev + 1; });
|
|
1636
|
-
}
|
|
1637
|
-
}, [children]);
|
|
1638
|
-
useImperativeHandle(ref, function () { return getContext(instance); }, [instance]);
|
|
1668
|
+
var content = getContent(props.children, getControls(instance));
|
|
1669
|
+
useImperativeHandle(ref, function () { return getControls(instance); }, [instance]);
|
|
1639
1670
|
useEffect(function () {
|
|
1640
1671
|
instance.update(props);
|
|
1641
1672
|
}, [instance, props]);
|
|
1642
|
-
useEffect(function () {
|
|
1643
|
-
return instance.onChange(handleOnChange);
|
|
1644
|
-
}, [instance, props, handleOnChange]);
|
|
1645
1673
|
return React.createElement(Context.Provider, { value: instance }, content);
|
|
1646
1674
|
});
|
|
1647
1675
|
|
|
1676
|
+
var KeepScale = React.forwardRef(function (props, ref) {
|
|
1677
|
+
var localRef = useRef(null);
|
|
1678
|
+
var instance = useContext(Context);
|
|
1679
|
+
useEffect(function () {
|
|
1680
|
+
return instance.onChange(function (ctx) {
|
|
1681
|
+
if (localRef.current) {
|
|
1682
|
+
var positionX = 0;
|
|
1683
|
+
var positionY = 0;
|
|
1684
|
+
localRef.current.style.transform = instance.handleTransformStyles(positionX, positionY, 1 / ctx.instance.transformState.scale);
|
|
1685
|
+
}
|
|
1686
|
+
});
|
|
1687
|
+
}, [instance]);
|
|
1688
|
+
return React.createElement("div", __assign({}, props, { ref: mergeRefs([localRef, ref]) }));
|
|
1689
|
+
});
|
|
1690
|
+
|
|
1691
|
+
var previewStyles = {
|
|
1692
|
+
position: "absolute",
|
|
1693
|
+
zIndex: 2,
|
|
1694
|
+
top: "0px",
|
|
1695
|
+
left: "0px",
|
|
1696
|
+
boxSizing: "border-box",
|
|
1697
|
+
border: "3px solid red",
|
|
1698
|
+
transformOrigin: "0% 0%",
|
|
1699
|
+
boxShadow: "rgba(0,0,0,0.2) 0 0 0 10000000px",
|
|
1700
|
+
};
|
|
1701
|
+
var MiniMap = function (_a) {
|
|
1702
|
+
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"]);
|
|
1703
|
+
var _d = useState({ width: 0, height: 0 }), size = _d[0], setSize = _d[1];
|
|
1704
|
+
var instance = useTransformContext();
|
|
1705
|
+
var wrapperRef = useRef(null);
|
|
1706
|
+
var previewRef = useRef(null);
|
|
1707
|
+
var getContentSize = function () {
|
|
1708
|
+
if (instance.contentComponent) {
|
|
1709
|
+
return {
|
|
1710
|
+
width: instance.contentComponent.offsetWidth,
|
|
1711
|
+
height: instance.contentComponent.offsetHeight,
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
return {
|
|
1715
|
+
width: 0,
|
|
1716
|
+
height: 0,
|
|
1717
|
+
};
|
|
1718
|
+
};
|
|
1719
|
+
var computeMiniMapScale = function () {
|
|
1720
|
+
var contentSize = getContentSize();
|
|
1721
|
+
var scaleX = width / contentSize.width;
|
|
1722
|
+
var scaleY = height / contentSize.height;
|
|
1723
|
+
var scale = scaleY > scaleX ? scaleX : scaleY;
|
|
1724
|
+
return scale;
|
|
1725
|
+
};
|
|
1726
|
+
var computeMiniMapSize = function () {
|
|
1727
|
+
var contentSize = getContentSize();
|
|
1728
|
+
var scaleX = width / contentSize.width;
|
|
1729
|
+
var scaleY = height / contentSize.height;
|
|
1730
|
+
if (scaleY > scaleX) {
|
|
1731
|
+
return { width: width, height: contentSize.height * scaleX };
|
|
1732
|
+
}
|
|
1733
|
+
return { width: contentSize.width * scaleY, height: height };
|
|
1734
|
+
};
|
|
1735
|
+
var computeWrapperStyle = function () {
|
|
1736
|
+
var _a, _b;
|
|
1737
|
+
return {
|
|
1738
|
+
width: ((_a = instance.contentComponent) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0,
|
|
1739
|
+
height: ((_b = instance.contentComponent) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0,
|
|
1740
|
+
};
|
|
1741
|
+
};
|
|
1742
|
+
var computeMiniMapStyle = function () {
|
|
1743
|
+
var scale = computeMiniMapScale();
|
|
1744
|
+
return {
|
|
1745
|
+
transform: "scale(".concat(scale || 1, ")"),
|
|
1746
|
+
transformOrigin: "0% 0%",
|
|
1747
|
+
position: "absolute",
|
|
1748
|
+
boxSizing: "border-box",
|
|
1749
|
+
zIndex: 1,
|
|
1750
|
+
overflow: "hidden",
|
|
1751
|
+
};
|
|
1752
|
+
};
|
|
1753
|
+
var transformMiniMap = function () {
|
|
1754
|
+
var style = computeWrapperStyle();
|
|
1755
|
+
if (wrapperRef.current) {
|
|
1756
|
+
wrapperRef.current.style.width = "".concat(style.width, "px");
|
|
1757
|
+
wrapperRef.current.style.width = "".concat(style.width, "px");
|
|
1758
|
+
wrapperRef.current.style.height = "".concat(style.height, "px");
|
|
1759
|
+
}
|
|
1760
|
+
if (previewRef.current) {
|
|
1761
|
+
var scale = computeMiniMapScale();
|
|
1762
|
+
var previewScale = scale * (1 / instance.transformState.scale);
|
|
1763
|
+
var transform = instance.handleTransformStyles(-instance.transformState.positionX * previewScale, -instance.transformState.positionY * previewScale, 1);
|
|
1764
|
+
previewRef.current.style.transform = transform;
|
|
1765
|
+
previewRef.current.style.width = "".concat(style.width * previewScale, "px");
|
|
1766
|
+
previewRef.current.style.height = "".concat(style.height * previewScale, "px");
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
var initialize = function () {
|
|
1770
|
+
var style = computeMiniMapStyle();
|
|
1771
|
+
var initSize = computeMiniMapSize();
|
|
1772
|
+
setSize(initSize);
|
|
1773
|
+
Object.keys(style).forEach(function (key) {
|
|
1774
|
+
if (wrapperRef.current) {
|
|
1775
|
+
wrapperRef.current.style[key] = style[key];
|
|
1776
|
+
}
|
|
1777
|
+
});
|
|
1778
|
+
transformMiniMap();
|
|
1779
|
+
};
|
|
1780
|
+
useTransformEffect(function () {
|
|
1781
|
+
transformMiniMap();
|
|
1782
|
+
});
|
|
1783
|
+
useTransformInit(function () {
|
|
1784
|
+
initialize();
|
|
1785
|
+
});
|
|
1786
|
+
var wrapperStyle = useMemo(function () {
|
|
1787
|
+
return __assign(__assign({}, size), { position: "relative", zIndex: 2, overflow: "hidden" });
|
|
1788
|
+
}, [size]);
|
|
1789
|
+
return (React.createElement("div", __assign({}, rest, { style: wrapperStyle, className: "rzpp-mini-map ".concat(rest.className || "") }),
|
|
1790
|
+
React.createElement("div", __assign({}, rest, { ref: wrapperRef, className: "rzpp-wrapper" }), children),
|
|
1791
|
+
React.createElement("div", { className: "rzpp-preview", ref: previewRef, style: previewStyles })));
|
|
1792
|
+
};
|
|
1793
|
+
|
|
1648
1794
|
function styleInject(css, ref) {
|
|
1649
1795
|
if ( ref === void 0 ) ref = {};
|
|
1650
1796
|
var insertAt = ref.insertAt;
|
|
@@ -1672,8 +1818,8 @@ function styleInject(css, ref) {
|
|
|
1672
1818
|
}
|
|
1673
1819
|
}
|
|
1674
1820
|
|
|
1675
|
-
var css_248z = ".transform-component-
|
|
1676
|
-
var styles = {"wrapper":"transform-component-
|
|
1821
|
+
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";
|
|
1822
|
+
var styles = {"wrapper":"transform-component-module_wrapper__SPB86","content":"transform-component-module_content__FBWxo"};
|
|
1677
1823
|
styleInject(css_248z);
|
|
1678
1824
|
|
|
1679
1825
|
var TransformComponent = function (_a) {
|
|
@@ -1695,32 +1841,52 @@ var TransformComponent = function (_a) {
|
|
|
1695
1841
|
|
|
1696
1842
|
var useTransformContext = function () {
|
|
1697
1843
|
var libraryContext = useContext(Context);
|
|
1698
|
-
var _a = useState(getContext(libraryContext || {})), values = _a[0], setValues = _a[1];
|
|
1699
1844
|
if (!libraryContext) {
|
|
1700
1845
|
throw new Error("Transform context mus be placed inside TransformWrapper");
|
|
1701
1846
|
}
|
|
1847
|
+
return libraryContext;
|
|
1848
|
+
};
|
|
1849
|
+
|
|
1850
|
+
var useControls = function () {
|
|
1851
|
+
var libraryContext = useTransformContext();
|
|
1852
|
+
return getControls(libraryContext);
|
|
1853
|
+
};
|
|
1854
|
+
|
|
1855
|
+
var useTransformInit = function (callback) {
|
|
1856
|
+
var libraryContext = useTransformContext();
|
|
1702
1857
|
useEffect(function () {
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1858
|
+
var unmountCallback;
|
|
1859
|
+
var unmount;
|
|
1860
|
+
if (libraryContext.contentComponent && libraryContext.wrapperComponent) {
|
|
1861
|
+
console.warn(333);
|
|
1862
|
+
unmountCallback = callback(getState(libraryContext));
|
|
1863
|
+
}
|
|
1864
|
+
else {
|
|
1865
|
+
console.warn(444);
|
|
1866
|
+
unmount = libraryContext.onInit(function (ref) {
|
|
1867
|
+
unmountCallback = callback(getState(ref.instance));
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
return function () {
|
|
1871
|
+
unmount === null || unmount === void 0 ? void 0 : unmount();
|
|
1872
|
+
unmountCallback === null || unmountCallback === void 0 ? void 0 : unmountCallback();
|
|
1873
|
+
};
|
|
1874
|
+
}, []);
|
|
1708
1875
|
};
|
|
1709
1876
|
|
|
1710
|
-
var
|
|
1711
|
-
var
|
|
1712
|
-
var instance = useContext(Context);
|
|
1877
|
+
var useTransformEffect = function (callback) {
|
|
1878
|
+
var libraryContext = useTransformContext();
|
|
1713
1879
|
useEffect(function () {
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
var positionY = 0;
|
|
1718
|
-
localRef.current.style.transform = instance.handleTransformStyles(positionX, positionY, 1 / ctx.state.scale);
|
|
1719
|
-
}
|
|
1880
|
+
var unmountCallback;
|
|
1881
|
+
var unmount = libraryContext.onChange(function (ref) {
|
|
1882
|
+
unmountCallback = callback(getState(ref.instance));
|
|
1720
1883
|
});
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1884
|
+
return function () {
|
|
1885
|
+
unmount();
|
|
1886
|
+
unmountCallback === null || unmountCallback === void 0 ? void 0 : unmountCallback();
|
|
1887
|
+
};
|
|
1888
|
+
}, [callback, libraryContext]);
|
|
1889
|
+
};
|
|
1724
1890
|
|
|
1725
|
-
export { KeepScale, TransformComponent, TransformWrapper, getCenterPosition, getMatrixTransformStyles, getTransformStyles, useTransformContext };
|
|
1891
|
+
export { Context, KeepScale, MiniMap, TransformComponent, TransformWrapper, getCenterPosition, getMatrixTransformStyles, getTransformStyles, useControls, useTransformContext, useTransformEffect, useTransformInit };
|
|
1726
1892
|
//# sourceMappingURL=index.esm.js.map
|