react-zoom-pan-pinch 3.7.0 → 4.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/dist/index.cjs.js +785 -310
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +117 -23
- package/dist/index.esm.js +781 -302
- package/dist/index.esm.js.map +1 -1
- package/package.json +73 -62
- package/src/components/index.ts +5 -0
- package/src/components/keep-scale/keep-scale.tsx +28 -0
- package/src/components/mini-map/mini-map.tsx +292 -0
- package/src/components/mini-map/use-resize.hook.ts +74 -0
- package/src/components/transform-component/transform-component.module.css +43 -0
- package/src/components/transform-component/transform-component.tsx +96 -0
- package/src/components/transform-wrapper/transform-wrapper.tsx +39 -0
- package/src/components/virtualize/virtualize.tsx +133 -0
- package/src/components/virtualize/virtualize.utils.ts +104 -0
- package/src/constants/state.constants.ts +99 -0
- package/src/core/animations/animations.constants.ts +78 -0
- package/src/core/animations/animations.utils.ts +115 -0
- package/src/core/bounds/bounds.types.ts +8 -0
- package/src/core/bounds/bounds.utils.ts +226 -0
- package/src/core/double-click/double-click.logic.ts +127 -0
- package/src/core/handlers/handlers.logic.ts +122 -0
- package/src/core/handlers/handlers.utils.ts +243 -0
- package/src/core/instance.core.ts +704 -0
- package/src/core/pan/panning.logic.ts +122 -0
- package/src/core/pan/panning.utils.ts +216 -0
- package/src/core/pan/velocity.logic.ts +187 -0
- package/src/core/pan/velocity.utils.ts +83 -0
- package/src/core/pinch/pinch.logic.ts +139 -0
- package/src/core/pinch/pinch.utils.ts +95 -0
- package/src/core/wheel/wheel.logic.ts +161 -0
- package/src/core/wheel/wheel.utils.ts +157 -0
- package/src/core/zoom/zoom.logic.ts +71 -0
- package/src/core/zoom/zoom.utils.ts +62 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/use-controls.tsx +9 -0
- package/src/hooks/use-transform-component.tsx +30 -0
- package/src/hooks/use-transform-context.tsx +13 -0
- package/src/hooks/use-transform-effect.tsx +22 -0
- package/src/hooks/use-transform-init.tsx +28 -0
- package/src/hooks/use-zoom-pan-pinch.tsx +48 -0
- package/src/index.ts +6 -0
- package/src/models/calculations.model.ts +34 -0
- package/src/models/context.model.ts +218 -0
- package/src/models/helpers.model.ts +15 -0
- package/src/models/index.ts +3 -0
- package/src/react-app-env.d.ts +1 -0
- 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 +1 -0
- package/src/stories/assets/small-image.jpg +0 -0
- package/src/stories/assets/svg-example.svg +14 -0
- package/src/stories/docs/DocTable.tsx +59 -0
- package/src/stories/docs/HandlerCards.tsx +102 -0
- package/src/stories/docs/Introduction.stories.mdx +135 -0
- package/src/stories/docs/PropTable.tsx +116 -0
- package/src/stories/docs/docs.module.css +370 -0
- package/src/stories/docs/handlers.stories.mdx +7 -0
- package/src/stories/docs/handlers.tsx +111 -0
- package/src/stories/docs/props.stories.mdx +11 -0
- package/src/stories/docs/props.tsx +571 -0
- package/src/stories/examples/axis-lock/axis-lock.stories.mdx +35 -0
- package/src/stories/examples/axis-lock/example.tsx +114 -0
- package/src/stories/examples/bounds/bounds.data.tsx +191 -0
- package/src/stories/examples/bounds/bounds.stories.mdx +99 -0
- package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +206 -0
- package/src/stories/examples/cinema/cinema-data.tsx +578 -0
- package/src/stories/examples/cinema/cinema.stories.mdx +30 -0
- package/src/stories/examples/cinema/example.tsx +378 -0
- package/src/stories/examples/cinema/image.png +0 -0
- package/src/stories/examples/content/content.stories.mdx +172 -0
- package/src/stories/examples/content/mixed-content.data.tsx +624 -0
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +34 -0
- package/src/stories/examples/content-rerendering/example.tsx +631 -0
- package/src/stories/examples/controls/controls.stories.mdx +120 -0
- package/src/stories/examples/image/example.tsx +149 -0
- package/src/stories/examples/image/image.stories.mdx +46 -0
- package/src/stories/examples/image-annotations/example.tsx +1442 -0
- package/src/stories/examples/image-annotations/image-annotations.stories.mdx +39 -0
- package/src/stories/examples/image-responsive/example.tsx +152 -0
- package/src/stories/examples/image-responsive/image-responsive.stories.mdx +51 -0
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +107 -0
- package/src/stories/examples/initial-transform/example.tsx +233 -0
- package/src/stories/examples/initial-transform/initial-transform.stories.mdx +37 -0
- package/src/stories/examples/keep-scale/example.tsx +882 -0
- package/src/stories/examples/keep-scale/keep-scale.stories.mdx +30 -0
- package/src/stories/examples/keep-scale/map.stories.mdx +28 -0
- package/src/stories/examples/medical-viewer/chest-xray.tsx +246 -0
- package/src/stories/examples/medical-viewer/example.tsx +690 -0
- package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +49 -0
- package/src/stories/examples/mini-map/example.tsx +122 -0
- package/src/stories/examples/mini-map/mini-map.stories.mdx +26 -0
- package/src/stories/examples/miro/example.tsx +1573 -0
- package/src/stories/examples/miro/miro.stories.mdx +31 -0
- package/src/stories/examples/padding/example.tsx +147 -0
- package/src/stories/examples/padding/padding.stories.mdx +35 -0
- package/src/stories/examples/product-card/example.tsx +594 -0
- package/src/stories/examples/product-card/product-card.stories.mdx +29 -0
- package/src/stories/examples/stadium/example.tsx +1040 -0
- package/src/stories/examples/stadium/stadium-data.ts +224 -0
- package/src/stories/examples/stadium/stadium.stories.mdx +32 -0
- package/src/stories/examples/stress/example.tsx +59 -0
- package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
- package/src/stories/examples/svg-zoom-to-element/creativity.svg +143 -0
- package/src/stories/examples/svg-zoom-to-element/example.tsx +95 -0
- package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +28 -0
- package/src/stories/examples/text-selection/example.tsx +221 -0
- package/src/stories/examples/text-selection/text-selection.stories.mdx +31 -0
- package/src/stories/examples/velocity/example.tsx +908 -0
- package/src/stories/examples/velocity/velocity.stories.mdx +35 -0
- package/src/stories/examples/virtualize/example.tsx +239 -0
- package/src/stories/examples/virtualize/virtualize.stories.mdx +84 -0
- package/src/stories/examples/zoom-to-element/example.tsx +219 -0
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +31 -0
- package/src/stories/hooks/use-controls.stories.mdx +86 -0
- package/src/stories/hooks/use-transform-component.stories.mdx +108 -0
- package/src/stories/hooks/use-transform-context.stories.mdx +92 -0
- package/src/stories/hooks/use-transform-effect.stories.mdx +114 -0
- package/src/stories/hooks/use-transform-init.stories.mdx +105 -0
- package/src/stories/types/args.types.ts +192 -0
- package/src/stories/utils/args.utils.ts +35 -0
- package/src/stories/utils/bounds-overlay.tsx +168 -0
- package/src/stories/utils/code.utils.tsx +22 -0
- package/src/stories/utils/controls.utils.tsx +347 -0
- package/src/stories/utils/index.ts +5 -0
- package/src/stories/utils/styles.module.css +223 -0
- package/src/stories/utils/viewer.styles.ts +34 -0
- package/src/styles.css +8 -0
- package/src/typings.d.ts +21 -0
- package/src/utils/calculations.utils.ts +16 -0
- package/src/utils/callback.utils.ts +11 -0
- package/src/utils/context.utils.ts +49 -0
- package/src/utils/event.utils.ts +38 -0
- package/src/utils/helpers.utils.ts +22 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/ref.utils.ts +32 -0
- package/src/utils/state.utils.ts +77 -0
- package/src/utils/styles.utils.ts +49 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { useTransformContext } from "./use-transform-context";
|
|
4
|
+
import { getState } from "utils";
|
|
5
|
+
import { ReactZoomPanPinchContextState } from "../models";
|
|
6
|
+
|
|
7
|
+
export function useTransformComponent<T>(
|
|
8
|
+
callback: (state: ReactZoomPanPinchContextState) => T,
|
|
9
|
+
): T {
|
|
10
|
+
const libraryContext = useTransformContext();
|
|
11
|
+
|
|
12
|
+
const [transformRender, setTransformRender] = useState<T>(
|
|
13
|
+
callback(getState(libraryContext)),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
let mounted = true;
|
|
18
|
+
const unmount = libraryContext.onChange((ref) => {
|
|
19
|
+
if (mounted) {
|
|
20
|
+
setTransformRender(callback(getState(ref.instance)));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return () => {
|
|
24
|
+
unmount();
|
|
25
|
+
mounted = false;
|
|
26
|
+
};
|
|
27
|
+
}, [callback, libraryContext]);
|
|
28
|
+
|
|
29
|
+
return transformRender;
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
|
|
3
|
+
import { Context } from "components";
|
|
4
|
+
|
|
5
|
+
export const useTransformContext = () => {
|
|
6
|
+
const libraryContext = useContext(Context);
|
|
7
|
+
|
|
8
|
+
if (!libraryContext) {
|
|
9
|
+
throw new Error("Transform context must be placed inside TransformWrapper");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return libraryContext;
|
|
13
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
import { getState } from "utils";
|
|
4
|
+
import { ReactZoomPanPinchContextState } from "../models";
|
|
5
|
+
import { useTransformContext } from "./use-transform-context";
|
|
6
|
+
|
|
7
|
+
export const useTransformEffect = (
|
|
8
|
+
callback: (ref: ReactZoomPanPinchContextState) => void | (() => void),
|
|
9
|
+
): void => {
|
|
10
|
+
const libraryContext = useTransformContext();
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
let unmountCallback: void | (() => void);
|
|
14
|
+
const unmount = libraryContext.onChange((ref) => {
|
|
15
|
+
unmountCallback = callback(getState(ref.instance));
|
|
16
|
+
});
|
|
17
|
+
return () => {
|
|
18
|
+
unmount();
|
|
19
|
+
unmountCallback?.();
|
|
20
|
+
};
|
|
21
|
+
}, [callback, libraryContext]);
|
|
22
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
import { getState } from "utils";
|
|
4
|
+
import { ReactZoomPanPinchContextState } from "../models";
|
|
5
|
+
import { useTransformContext } from "./use-transform-context";
|
|
6
|
+
|
|
7
|
+
export const useTransformInit = (
|
|
8
|
+
callback: (ref: ReactZoomPanPinchContextState) => void | (() => void),
|
|
9
|
+
): void => {
|
|
10
|
+
const libraryContext = useTransformContext();
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
let unmountCallback: void | (() => void);
|
|
14
|
+
let unmount: void | (() => void);
|
|
15
|
+
if (libraryContext.contentComponent && libraryContext.wrapperComponent) {
|
|
16
|
+
unmountCallback = callback(getState(libraryContext));
|
|
17
|
+
} else {
|
|
18
|
+
unmount = libraryContext.onInit((ref) => {
|
|
19
|
+
unmountCallback = callback(getState(ref.instance));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return () => {
|
|
23
|
+
unmount?.();
|
|
24
|
+
unmountCallback?.();
|
|
25
|
+
};
|
|
26
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
+
}, []);
|
|
28
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import { initialSetup } from "constants/state.constants";
|
|
4
|
+
import { ZoomPanPinch } from "core/instance.core";
|
|
5
|
+
import { ReactZoomPanPinchProps, ReactZoomPanPinchRef } from "models";
|
|
6
|
+
|
|
7
|
+
export const useZoomPanPinch = (props?: ReactZoomPanPinchProps) => {
|
|
8
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
9
|
+
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
10
|
+
const instance = useRef(new ZoomPanPinch({ ...initialSetup, ...props }));
|
|
11
|
+
|
|
12
|
+
const useTransformCallback = useRef<
|
|
13
|
+
(data: {
|
|
14
|
+
positionX: number;
|
|
15
|
+
positionY: number;
|
|
16
|
+
scale: number;
|
|
17
|
+
previousScale: number;
|
|
18
|
+
ref: ReactZoomPanPinchRef;
|
|
19
|
+
}) => void
|
|
20
|
+
>(() => {});
|
|
21
|
+
|
|
22
|
+
useLayoutEffect(() => {
|
|
23
|
+
const inst = instance.current;
|
|
24
|
+
if (contentRef.current && wrapperRef.current) {
|
|
25
|
+
inst.init(wrapperRef.current, contentRef.current);
|
|
26
|
+
}
|
|
27
|
+
const unmount = inst.onTransform((data) => {
|
|
28
|
+
useTransformCallback.current(data);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
inst.cleanupWindowEvents();
|
|
33
|
+
unmount();
|
|
34
|
+
};
|
|
35
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
const useTransform = (callback: typeof useTransformCallback.current) => {
|
|
39
|
+
useTransformCallback.current = callback;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
contentRef,
|
|
44
|
+
wrapperRef,
|
|
45
|
+
instance,
|
|
46
|
+
useTransform,
|
|
47
|
+
};
|
|
48
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type SizeType = {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type PositionType = {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type StateType = { scale: number; positionX: number; positionY: number };
|
|
12
|
+
|
|
13
|
+
export type VelocityType = {
|
|
14
|
+
velocityX: number;
|
|
15
|
+
velocityY: number;
|
|
16
|
+
total: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type BoundsType = {
|
|
20
|
+
minPositionX: number;
|
|
21
|
+
maxPositionX: number;
|
|
22
|
+
minPositionY: number;
|
|
23
|
+
maxPositionY: number;
|
|
24
|
+
scaleWidthFactor: number;
|
|
25
|
+
scaleHeightFactor: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type AnimationType = () => void | number;
|
|
29
|
+
|
|
30
|
+
export enum DeviceType {
|
|
31
|
+
TRACK_PAD = "track_pad",
|
|
32
|
+
MOUSE = "mouse",
|
|
33
|
+
TOUCH = "touch",
|
|
34
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { animations } from "../core/animations/animations.constants";
|
|
4
|
+
import { DeepNonNullable } from "./helpers.model";
|
|
5
|
+
import {
|
|
6
|
+
centerView,
|
|
7
|
+
resetTransform,
|
|
8
|
+
setTransform,
|
|
9
|
+
zoomIn,
|
|
10
|
+
zoomOut,
|
|
11
|
+
zoomToElement,
|
|
12
|
+
} from "../core/handlers/handlers.logic";
|
|
13
|
+
import { ZoomPanPinch } from "../core/instance.core";
|
|
14
|
+
|
|
15
|
+
export type ReactZoomPanPinchContext = typeof ZoomPanPinch.prototype;
|
|
16
|
+
|
|
17
|
+
export type ReactZoomPanPinchContextState = {
|
|
18
|
+
instance: ReactZoomPanPinchContext;
|
|
19
|
+
state: ReactZoomPanPinchState;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ReactZoomPanPinchContentRef = {
|
|
23
|
+
instance: ReactZoomPanPinchContext;
|
|
24
|
+
state: ReactZoomPanPinchState;
|
|
25
|
+
} & ReactZoomPanPinchHandlers;
|
|
26
|
+
|
|
27
|
+
export type ReactZoomPanPinchRef = ReactZoomPanPinchContextState &
|
|
28
|
+
ReactZoomPanPinchHandlers;
|
|
29
|
+
|
|
30
|
+
export type ReactZoomPanPinchState = {
|
|
31
|
+
previousScale: number;
|
|
32
|
+
scale: number;
|
|
33
|
+
positionX: number;
|
|
34
|
+
positionY: number;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ReactZoomPanPinchHandlers = {
|
|
38
|
+
zoomIn: ReturnType<typeof zoomIn>;
|
|
39
|
+
zoomOut: ReturnType<typeof zoomOut>;
|
|
40
|
+
setTransform: ReturnType<typeof setTransform>;
|
|
41
|
+
resetTransform: ReturnType<typeof resetTransform>;
|
|
42
|
+
centerView: ReturnType<typeof centerView>;
|
|
43
|
+
zoomToElement: ReturnType<typeof zoomToElement>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type ReactZoomPanPinchRefProps = {
|
|
47
|
+
setRef: (context: ReactZoomPanPinchRef) => void;
|
|
48
|
+
} & Omit<ReactZoomPanPinchProps, "ref">;
|
|
49
|
+
|
|
50
|
+
export type ReactZoomPanPinchProps = {
|
|
51
|
+
children?:
|
|
52
|
+
| React.ReactNode
|
|
53
|
+
| ((ref: ReactZoomPanPinchContentRef) => React.ReactNode);
|
|
54
|
+
ref?: React.Ref<ReactZoomPanPinchRef>;
|
|
55
|
+
detached?: boolean;
|
|
56
|
+
initialScale?: number;
|
|
57
|
+
initialPositionX?: number;
|
|
58
|
+
initialPositionY?: number;
|
|
59
|
+
disabled?: boolean;
|
|
60
|
+
minPositionX?: null | number;
|
|
61
|
+
maxPositionX?: null | number;
|
|
62
|
+
minPositionY?: null | number;
|
|
63
|
+
maxPositionY?: null | number;
|
|
64
|
+
minScale?: number;
|
|
65
|
+
maxScale?: number;
|
|
66
|
+
limitToBounds?: boolean;
|
|
67
|
+
centerZoomedOut?: boolean;
|
|
68
|
+
centerOnInit?: boolean;
|
|
69
|
+
disablePadding?: boolean;
|
|
70
|
+
customTransform?: (x: number, y: number, scale: number) => string;
|
|
71
|
+
smooth?: boolean;
|
|
72
|
+
wheel?: {
|
|
73
|
+
step?: number;
|
|
74
|
+
disabled?: boolean;
|
|
75
|
+
wheelDisabled?: boolean;
|
|
76
|
+
touchPadDisabled?: boolean;
|
|
77
|
+
activationKeys?: string[] | ((keys: string[]) => boolean);
|
|
78
|
+
excluded?: string[];
|
|
79
|
+
};
|
|
80
|
+
panning?: {
|
|
81
|
+
disabled?: boolean;
|
|
82
|
+
velocityDisabled?: boolean;
|
|
83
|
+
lockAxisX?: boolean;
|
|
84
|
+
lockAxisY?: boolean;
|
|
85
|
+
allowLeftClickPan?: boolean;
|
|
86
|
+
allowMiddleClickPan?: boolean;
|
|
87
|
+
allowRightClickPan?: boolean;
|
|
88
|
+
activationKeys?: string[] | ((keys: string[]) => boolean);
|
|
89
|
+
excluded?: string[];
|
|
90
|
+
};
|
|
91
|
+
pinch?: {
|
|
92
|
+
step?: number;
|
|
93
|
+
disabled?: boolean;
|
|
94
|
+
allowPanning?: boolean;
|
|
95
|
+
excluded?: string[];
|
|
96
|
+
};
|
|
97
|
+
trackPadPanning?: {
|
|
98
|
+
disabled?: boolean;
|
|
99
|
+
velocityDisabled?: boolean;
|
|
100
|
+
lockAxisX?: boolean;
|
|
101
|
+
lockAxisY?: boolean;
|
|
102
|
+
activationKeys?: string[] | ((keys: string[]) => boolean);
|
|
103
|
+
excluded?: string[];
|
|
104
|
+
};
|
|
105
|
+
doubleClick?: {
|
|
106
|
+
disabled?: boolean;
|
|
107
|
+
step?: number;
|
|
108
|
+
mode?: "zoomIn" | "zoomOut" | "reset" | "toggle";
|
|
109
|
+
animationTime?: number;
|
|
110
|
+
animationType?: keyof typeof animations;
|
|
111
|
+
excluded?: string[];
|
|
112
|
+
};
|
|
113
|
+
zoomAnimation?: {
|
|
114
|
+
disabled?: boolean;
|
|
115
|
+
size?: number;
|
|
116
|
+
animationTime?: number;
|
|
117
|
+
animationType?: keyof typeof animations;
|
|
118
|
+
};
|
|
119
|
+
autoAlignment?: {
|
|
120
|
+
disabled?: boolean;
|
|
121
|
+
sizeX?: number;
|
|
122
|
+
sizeY?: number;
|
|
123
|
+
animationTime?: number;
|
|
124
|
+
velocityAlignmentTime?: number;
|
|
125
|
+
animationType?: keyof typeof animations;
|
|
126
|
+
};
|
|
127
|
+
velocityAnimation?: {
|
|
128
|
+
disabled?: boolean;
|
|
129
|
+
sensitivityTouch?: number;
|
|
130
|
+
sensitivityMouse?: number;
|
|
131
|
+
maxStrengthMouse?: number;
|
|
132
|
+
maxStrengthTouch?: number;
|
|
133
|
+
inertia?: number;
|
|
134
|
+
animationTime?: number;
|
|
135
|
+
maxAnimationTime?: number;
|
|
136
|
+
animationType?: keyof typeof animations;
|
|
137
|
+
};
|
|
138
|
+
onWheelStart?: (ref: ReactZoomPanPinchRef, event: WheelEvent) => void;
|
|
139
|
+
onWheel?: (ref: ReactZoomPanPinchRef, event: WheelEvent) => void;
|
|
140
|
+
onWheelStop?: (ref: ReactZoomPanPinchRef, event: WheelEvent) => void;
|
|
141
|
+
onPanningStart?: (
|
|
142
|
+
ref: ReactZoomPanPinchRef,
|
|
143
|
+
event: TouchEvent | MouseEvent,
|
|
144
|
+
) => void;
|
|
145
|
+
onPanning?: (
|
|
146
|
+
ref: ReactZoomPanPinchRef,
|
|
147
|
+
event: TouchEvent | MouseEvent,
|
|
148
|
+
) => void;
|
|
149
|
+
onPanningStop?: (
|
|
150
|
+
ref: ReactZoomPanPinchRef,
|
|
151
|
+
event: TouchEvent | MouseEvent,
|
|
152
|
+
) => void;
|
|
153
|
+
onPinchStart?: (ref: ReactZoomPanPinchRef, event: TouchEvent) => void;
|
|
154
|
+
onPinch?: (ref: ReactZoomPanPinchRef, event: TouchEvent) => void;
|
|
155
|
+
onPinchStop?: (ref: ReactZoomPanPinchRef, event: TouchEvent) => void;
|
|
156
|
+
onZoomStart?: (
|
|
157
|
+
ref: ReactZoomPanPinchRef,
|
|
158
|
+
event: TouchEvent | MouseEvent,
|
|
159
|
+
) => void;
|
|
160
|
+
onZoom?: (ref: ReactZoomPanPinchRef, event: TouchEvent | MouseEvent) => void;
|
|
161
|
+
onZoomStop?: (
|
|
162
|
+
ref: ReactZoomPanPinchRef,
|
|
163
|
+
event: TouchEvent | MouseEvent,
|
|
164
|
+
) => void;
|
|
165
|
+
onTransform?: (
|
|
166
|
+
ref: ReactZoomPanPinchRef,
|
|
167
|
+
state: { scale: number; positionX: number; positionY: number },
|
|
168
|
+
) => void;
|
|
169
|
+
onInit?: (ref: ReactZoomPanPinchRef) => void;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export type ReactZoomPanPinchComponentHelpers = {
|
|
173
|
+
setComponents: (wrapper: HTMLDivElement, content: HTMLDivElement) => void;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export type LibrarySetup = Pick<
|
|
177
|
+
ReactZoomPanPinchProps,
|
|
178
|
+
"minPositionX" | "maxPositionX" | "minPositionY" | "maxPositionY"
|
|
179
|
+
> &
|
|
180
|
+
DeepNonNullable<
|
|
181
|
+
Omit<
|
|
182
|
+
ReactZoomPanPinchProps,
|
|
183
|
+
| "ref"
|
|
184
|
+
| "initialScale"
|
|
185
|
+
| "initialPositionX"
|
|
186
|
+
| "initialPositionY"
|
|
187
|
+
| "minPositionX"
|
|
188
|
+
| "maxPositionX"
|
|
189
|
+
| "minPositionY"
|
|
190
|
+
| "maxPositionY"
|
|
191
|
+
| "children"
|
|
192
|
+
| "defaultPositionX"
|
|
193
|
+
| "defaultPositionY"
|
|
194
|
+
| "defaultScale"
|
|
195
|
+
| "wrapperClass"
|
|
196
|
+
| "contentClass"
|
|
197
|
+
| "onWheelStart"
|
|
198
|
+
| "onWheel"
|
|
199
|
+
| "onWheelStop"
|
|
200
|
+
| "onPanningStart"
|
|
201
|
+
| "onPanning"
|
|
202
|
+
| "onPanningStop"
|
|
203
|
+
| "onPinchStart"
|
|
204
|
+
| "onPinch"
|
|
205
|
+
| "onPinchStop"
|
|
206
|
+
| "onZoomStart"
|
|
207
|
+
| "onZoom"
|
|
208
|
+
| "onZoomStop"
|
|
209
|
+
| "onTransform"
|
|
210
|
+
| "onInit"
|
|
211
|
+
| "customTransform"
|
|
212
|
+
>
|
|
213
|
+
>;
|
|
214
|
+
|
|
215
|
+
export type ReactZoomPanPinchBaseClasses = {
|
|
216
|
+
wrapperClass: string;
|
|
217
|
+
contentClass: string;
|
|
218
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
+
|
|
3
|
+
export type DeepNonNullable<T> = T extends (...args: any[]) => any
|
|
4
|
+
? T
|
|
5
|
+
: T extends any[]
|
|
6
|
+
? DeepNonNullableArray<T[number]>
|
|
7
|
+
: T extends object
|
|
8
|
+
? DeepNonNullableObject<T>
|
|
9
|
+
: T;
|
|
10
|
+
|
|
11
|
+
export type DeepNonNullableArray<T> = Array<DeepNonNullable<NonNullable<T>>>;
|
|
12
|
+
|
|
13
|
+
export type DeepNonNullableObject<T> = {
|
|
14
|
+
[P in keyof T]-?: DeepNonNullable<NonNullable<T[P]>>;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="react-scripts" />
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
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
|
|
@@ -0,0 +1,14 @@
|
|
|
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>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* eslint-disable react/no-array-index-key, no-nested-ternary */
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import styles from "./docs.module.css";
|
|
5
|
+
|
|
6
|
+
export type DocTableColumn = {
|
|
7
|
+
header: string;
|
|
8
|
+
style?: "name" | "type" | "default" | "text";
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function DocTable({
|
|
12
|
+
columns,
|
|
13
|
+
rows,
|
|
14
|
+
}: {
|
|
15
|
+
columns: DocTableColumn[];
|
|
16
|
+
rows: string[][];
|
|
17
|
+
}) {
|
|
18
|
+
return (
|
|
19
|
+
<table className={styles.docTable}>
|
|
20
|
+
<thead>
|
|
21
|
+
<tr className={styles.docTableHeadRow}>
|
|
22
|
+
{columns.map((col, i) => (
|
|
23
|
+
<th key={i} className={styles.docTableTh}>
|
|
24
|
+
{col.header}
|
|
25
|
+
</th>
|
|
26
|
+
))}
|
|
27
|
+
</tr>
|
|
28
|
+
</thead>
|
|
29
|
+
<tbody>
|
|
30
|
+
{rows.map((row, ri) => (
|
|
31
|
+
<tr
|
|
32
|
+
key={ri}
|
|
33
|
+
className={
|
|
34
|
+
ri % 2 === 1 ? styles.docTableRowAlt : styles.docTableRow
|
|
35
|
+
}
|
|
36
|
+
>
|
|
37
|
+
{row.map((cell, ci) => {
|
|
38
|
+
const colStyle =
|
|
39
|
+
columns[ci]?.style ?? (ci === 0 ? "name" : "text");
|
|
40
|
+
const cls =
|
|
41
|
+
colStyle === "name"
|
|
42
|
+
? styles.docTableCellName
|
|
43
|
+
: colStyle === "type"
|
|
44
|
+
? styles.docTableCellType
|
|
45
|
+
: colStyle === "default"
|
|
46
|
+
? styles.docTableCellDefault
|
|
47
|
+
: styles.docTableCellText;
|
|
48
|
+
return (
|
|
49
|
+
<td key={ci} className={cls}>
|
|
50
|
+
{cell}
|
|
51
|
+
</td>
|
|
52
|
+
);
|
|
53
|
+
})}
|
|
54
|
+
</tr>
|
|
55
|
+
))}
|
|
56
|
+
</tbody>
|
|
57
|
+
</table>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/* eslint-disable react/no-array-index-key */
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import type { ControlsFnOptionsType } from "./handlers";
|
|
5
|
+
|
|
6
|
+
import styles from "./docs.module.css";
|
|
7
|
+
|
|
8
|
+
function parseParam(raw: string) {
|
|
9
|
+
const eqIdx = raw.indexOf("=");
|
|
10
|
+
const colonIdx = raw.indexOf(":");
|
|
11
|
+
|
|
12
|
+
if (colonIdx === -1) return { name: raw.trim(), type: "", def: "" };
|
|
13
|
+
|
|
14
|
+
const name = raw.slice(0, colonIdx).trim();
|
|
15
|
+
let type: string;
|
|
16
|
+
let def = "";
|
|
17
|
+
|
|
18
|
+
if (eqIdx !== -1 && eqIdx > colonIdx) {
|
|
19
|
+
type = raw.slice(colonIdx + 1, eqIdx).trim();
|
|
20
|
+
def = raw.slice(eqIdx + 1).trim();
|
|
21
|
+
} else {
|
|
22
|
+
type = raw.slice(colonIdx + 1).trim();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return { name, type, def };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function HandlerCards({ rows }: { rows: ControlsFnOptionsType[] }) {
|
|
29
|
+
return (
|
|
30
|
+
<div className={styles.container}>
|
|
31
|
+
<div className={styles.sectionTitle}>
|
|
32
|
+
<span className={styles.sectionTitleAccent} />
|
|
33
|
+
Handlers
|
|
34
|
+
</div>
|
|
35
|
+
<p className={styles.handlersIntro}>
|
|
36
|
+
Methods available via <strong>render props</strong>,{" "}
|
|
37
|
+
<strong>ref</strong>, or the{" "}
|
|
38
|
+
<span className={styles.handlersIntroHook}>useControls</span> hook. Each
|
|
39
|
+
handler triggers an animated transition on the transform state.
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
<div className={styles.handlerGrid}>
|
|
43
|
+
{rows.map((row, i) => (
|
|
44
|
+
<div key={i} className={styles.handlerCard}>
|
|
45
|
+
<div className={styles.handlerCardHeader}>
|
|
46
|
+
<span className={styles.handlerName}>
|
|
47
|
+
{row.name}(
|
|
48
|
+
{row.parameters && row.parameters.length > 0 && (
|
|
49
|
+
<span className={styles.handlerNameParams}>
|
|
50
|
+
{"{ "}
|
|
51
|
+
{row.parameters
|
|
52
|
+
.map((raw) => parseParam(raw).name)
|
|
53
|
+
.join(", ")}
|
|
54
|
+
{" }"}
|
|
55
|
+
</span>
|
|
56
|
+
)}
|
|
57
|
+
)
|
|
58
|
+
</span>
|
|
59
|
+
<span className={styles.handlerBadge}>Method</span>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<div className={styles.handlerCardBody}>
|
|
63
|
+
{row.description && (
|
|
64
|
+
<p className={styles.handlerDescription}>{row.description}</p>
|
|
65
|
+
)}
|
|
66
|
+
|
|
67
|
+
{row.parameters && row.parameters.length > 0 && (
|
|
68
|
+
<table className={styles.paramsTable}>
|
|
69
|
+
<thead>
|
|
70
|
+
<tr>
|
|
71
|
+
<th className={styles.paramsTableHeader}>Param</th>
|
|
72
|
+
<th className={styles.paramsTableHeader}>Type</th>
|
|
73
|
+
<th className={styles.paramsTableHeader}>Default</th>
|
|
74
|
+
</tr>
|
|
75
|
+
</thead>
|
|
76
|
+
<tbody>
|
|
77
|
+
{row.parameters.map((raw, j) => {
|
|
78
|
+
const p = parseParam(raw);
|
|
79
|
+
return (
|
|
80
|
+
<tr key={j}>
|
|
81
|
+
<td className={styles.paramsTableCellName}>
|
|
82
|
+
{p.name}
|
|
83
|
+
</td>
|
|
84
|
+
<td className={styles.paramsTableCellType}>
|
|
85
|
+
{p.type}
|
|
86
|
+
</td>
|
|
87
|
+
<td className={styles.paramsTableCellDefault}>
|
|
88
|
+
{p.def || "—"}
|
|
89
|
+
</td>
|
|
90
|
+
</tr>
|
|
91
|
+
);
|
|
92
|
+
})}
|
|
93
|
+
</tbody>
|
|
94
|
+
</table>
|
|
95
|
+
)}
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
))}
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|