react-zoom-pan-pinch 2.2.0 → 2.3.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/components/transform-component.d.ts +10 -0
- package/dist/components/transform-wrapper.d.ts +8 -0
- package/dist/constants/state.constants.d.ts +6 -0
- package/dist/core/animations/animations.constants.d.ts +16 -0
- package/dist/core/animations/animations.utils.d.ts +4 -0
- package/dist/core/bounds/bounds.types.d.ts +8 -0
- package/dist/core/bounds/bounds.utils.d.ts +15 -0
- package/dist/core/double-click/double-click.logic.d.ts +3 -0
- package/dist/core/handlers/handlers.logic.d.ts +8 -0
- package/dist/core/handlers/handlers.utils.d.ts +13 -0
- package/dist/core/instance.core.d.ts +68 -0
- package/dist/core/pan/panning.logic.d.ts +5 -0
- package/dist/core/pan/panning.utils.d.ts +10 -0
- package/dist/core/pan/velocity.logic.d.ts +5 -0
- package/dist/core/pan/velocity.utils.d.ts +5 -0
- package/dist/core/pinch/pinch.logic.d.ts +4 -0
- package/dist/core/pinch/pinch.utils.d.ts +6 -0
- package/dist/core/wheel/wheel.logic.d.ts +4 -0
- package/dist/core/wheel/wheel.utils.d.ts +7 -0
- package/dist/core/zoom/zoom.logic.d.ts +3 -0
- package/dist/core/zoom/zoom.utils.d.ts +3 -0
- package/dist/hooks/use-transform-context.d.ts +3 -0
- package/dist/index.cjs.js +278 -267
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +63 -57
- package/dist/index.esm.js +278 -267
- package/dist/index.esm.js.map +1 -1
- package/dist/models/calculations.model.d.ts +25 -0
- package/dist/models/context.model.d.ts +117 -0
- package/dist/models/helpers.model.d.ts +5 -0
- package/dist/models/index.d.ts +3 -0
- package/dist/stories/docs/handlers.d.ts +12 -0
- package/dist/stories/docs/props.d.ts +14 -0
- package/dist/stories/examples/content-rerendering/example.d.ts +2 -0
- package/dist/stories/examples/stress/example.d.ts +2 -0
- package/dist/stories/examples/zoom-to-element/example.d.ts +2 -0
- package/dist/stories/types/args.types.d.ts +268 -0
- package/dist/stories/utils/args.utils.d.ts +3 -0
- package/dist/stories/utils/code.utils.d.ts +6 -0
- package/dist/stories/utils/controls.utils.d.ts +3 -0
- package/dist/stories/utils/index.d.ts +3 -0
- package/dist/utils/calculations.utils.d.ts +11 -0
- package/dist/utils/callback.utils.d.ts +2 -0
- package/dist/utils/context.utils.d.ts +2 -0
- package/dist/utils/event.utils.d.ts +1 -0
- package/dist/utils/helpers.utils.d.ts +2 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/state.utils.d.ts +3 -0
- package/dist/utils/styles.utils.d.ts +3 -0
- package/package.json +30 -25
- package/src/.eslintrc.json +90 -0
- package/src/components/transform-component.tsx +2 -1
- package/src/components/transform-wrapper.tsx +27 -5
- package/src/constants/state.constants.ts +0 -2
- package/src/core/animations/animations.constants.ts +14 -12
- package/src/core/animations/animations.utils.ts +15 -11
- package/src/core/bounds/bounds.utils.ts +20 -20
- package/src/core/double-click/double-click.logic.ts +6 -12
- package/src/core/handlers/handlers.logic.ts +98 -89
- package/src/core/handlers/handlers.utils.ts +22 -24
- package/src/{components/transform-context.tsx → core/instance.core.ts} +85 -118
- package/src/core/pan/panning.logic.ts +20 -19
- package/src/core/pan/panning.utils.ts +4 -7
- package/src/core/pan/velocity.logic.ts +1 -0
- package/src/core/pinch/pinch.logic.ts +4 -6
- package/src/core/pinch/pinch.utils.ts +2 -2
- package/src/core/wheel/wheel.logic.ts +1 -0
- package/src/core/wheel/wheel.utils.ts +12 -11
- package/src/core/zoom/zoom.logic.ts +29 -29
- package/src/core/zoom/zoom.utils.ts +2 -2
- package/src/hooks/use-transform-context.tsx +3 -2
- package/src/models/context.model.ts +6 -2
- package/src/stories/docs/handlers.tsx +30 -30
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +3 -0
- package/src/stories/examples/content-rerendering/example.tsx +1 -1
- package/src/stories/examples/stress/example.tsx +24 -0
- package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
- package/src/stories/examples/zoom-to-element/example.tsx +4 -0
- package/src/stories/utils/code.utils.tsx +1 -0
- package/src/stories/utils/controls.utils.tsx +21 -4
- package/src/stories/utils/styles.module.css +5 -0
- package/src/utils/styles.utils.ts +9 -1
- package/src/.eslintrc.js +0 -36
|
@@ -16,36 +16,6 @@ export type ComponentProps = Record<
|
|
|
16
16
|
| Record<string, Omit<ControlsFnOptionsType, "name" | "isObjectRow">>
|
|
17
17
|
>;
|
|
18
18
|
|
|
19
|
-
export const getHandlersTable = (): ControlsFnOptionsType[] => {
|
|
20
|
-
return Object.keys(handlersTable).reduce<ControlsFnOptionsType[]>(
|
|
21
|
-
(acc, key) => {
|
|
22
|
-
if (Array.isArray(handlersTable[key]?.type)) {
|
|
23
|
-
acc.push({
|
|
24
|
-
...handlersTable[key],
|
|
25
|
-
name: key,
|
|
26
|
-
});
|
|
27
|
-
} else {
|
|
28
|
-
Object.keys(handlersTable[key]).forEach((prop) => {
|
|
29
|
-
acc.push({
|
|
30
|
-
...handlersTable[key][prop],
|
|
31
|
-
isObjectRow: key === prop,
|
|
32
|
-
name:
|
|
33
|
-
key === prop ? (
|
|
34
|
-
<b>{prop}</b>
|
|
35
|
-
) : (
|
|
36
|
-
<>
|
|
37
|
-
{key}.<b>{prop}</b>
|
|
38
|
-
</>
|
|
39
|
-
),
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return acc;
|
|
44
|
-
},
|
|
45
|
-
[],
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
19
|
export const handlersTable: ComponentProps = {
|
|
50
20
|
zoomIn: {
|
|
51
21
|
type: ["function(step, animationTime, animationName)"],
|
|
@@ -105,3 +75,33 @@ export const handlersTable: ComponentProps = {
|
|
|
105
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.",
|
|
106
76
|
},
|
|
107
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
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React, { useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import { TransformWrapper } from "../../../components/transform-wrapper";
|
|
4
|
+
import { TransformComponent } from "../../../components/transform-component";
|
|
5
|
+
import { normalizeArgs } from "../../utils";
|
|
6
|
+
import exampleImg from "../../assets/small-image.jpg";
|
|
7
|
+
|
|
8
|
+
import styles from "../../utils/styles.module.css";
|
|
9
|
+
|
|
10
|
+
export const Example: React.FC<any> = (args: any) => {
|
|
11
|
+
const ref = useRef<any>(null);
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<TransformWrapper {...normalizeArgs(args)} ref={ref}>
|
|
15
|
+
<TransformComponent>
|
|
16
|
+
<div className={styles.grid}>
|
|
17
|
+
{Array.from(Array(1000).keys()).map((key) => (
|
|
18
|
+
<img key={key} src={exampleImg} alt="" />
|
|
19
|
+
))}
|
|
20
|
+
</div>
|
|
21
|
+
</TransformComponent>
|
|
22
|
+
</TransformWrapper>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
+
import { action } from "@storybook/addon-actions";
|
|
3
|
+
|
|
4
|
+
import { TransformWrapper } from "../../../components/transform-wrapper";
|
|
5
|
+
import { argsTypes } from "../../types/args.types";
|
|
6
|
+
import { Example } from "./example";
|
|
7
|
+
|
|
8
|
+
export const Template = (args) => <Example {...args} />;
|
|
9
|
+
|
|
10
|
+
<Meta
|
|
11
|
+
title="Examples/Stress test"
|
|
12
|
+
component={TransformWrapper}
|
|
13
|
+
argTypes={argsTypes}
|
|
14
|
+
/>
|
|
15
|
+
|
|
16
|
+
# Stress test
|
|
17
|
+
|
|
18
|
+
<br />
|
|
19
|
+
|
|
20
|
+
### Preview:
|
|
21
|
+
|
|
22
|
+
<Canvas>
|
|
23
|
+
<Story name="Stress test">{(args) => <Template {...args} />}</Story>
|
|
24
|
+
</Canvas>
|
|
25
|
+
|
|
26
|
+
## Component API
|
|
27
|
+
|
|
28
|
+
<ArgsTable story="Stress test" />
|
|
@@ -13,24 +13,28 @@ export const Example: React.FC<any> = (args: any) => {
|
|
|
13
13
|
<>
|
|
14
14
|
<div>
|
|
15
15
|
<button
|
|
16
|
+
type="button"
|
|
16
17
|
className={styles.controlBtn}
|
|
17
18
|
onClick={() => zoomToElement("element1")}
|
|
18
19
|
>
|
|
19
20
|
Zoom to element 1
|
|
20
21
|
</button>
|
|
21
22
|
<button
|
|
23
|
+
type="button"
|
|
22
24
|
className={styles.controlBtn}
|
|
23
25
|
onClick={() => zoomToElement("element2")}
|
|
24
26
|
>
|
|
25
27
|
Zoom to element 2
|
|
26
28
|
</button>
|
|
27
29
|
<button
|
|
30
|
+
type="button"
|
|
28
31
|
className={styles.controlBtn}
|
|
29
32
|
onClick={() => zoomToElement("element3")}
|
|
30
33
|
>
|
|
31
34
|
Zoom to element 3
|
|
32
35
|
</button>
|
|
33
36
|
<button
|
|
37
|
+
type="button"
|
|
34
38
|
className={styles.controlBtn}
|
|
35
39
|
onClick={() => resetTransform()}
|
|
36
40
|
>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
|
|
2
3
|
import { ReactZoomPanPinchRef } from "../../models/context.model";
|
|
3
4
|
|
|
4
5
|
import styles from "./styles.module.css";
|
|
@@ -10,16 +11,32 @@ export const Controls: React.FC<ReactZoomPanPinchRef> = ({
|
|
|
10
11
|
centerView,
|
|
11
12
|
}: ReactZoomPanPinchRef) => (
|
|
12
13
|
<div className={styles.controlPanel}>
|
|
13
|
-
<button
|
|
14
|
+
<button
|
|
15
|
+
type="button"
|
|
16
|
+
className={styles.controlBtn}
|
|
17
|
+
onClick={() => zoomIn()}
|
|
18
|
+
>
|
|
14
19
|
Zoom In +
|
|
15
20
|
</button>
|
|
16
|
-
<button
|
|
21
|
+
<button
|
|
22
|
+
type="button"
|
|
23
|
+
className={styles.controlBtn}
|
|
24
|
+
onClick={() => zoomOut()}
|
|
25
|
+
>
|
|
17
26
|
Zoom Out -
|
|
18
27
|
</button>
|
|
19
|
-
<button
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
className={styles.controlBtn}
|
|
31
|
+
onClick={() => resetTransform()}
|
|
32
|
+
>
|
|
20
33
|
Reset
|
|
21
34
|
</button>
|
|
22
|
-
<button
|
|
35
|
+
<button
|
|
36
|
+
type="button"
|
|
37
|
+
className={styles.controlBtn}
|
|
38
|
+
onClick={() => centerView()}
|
|
39
|
+
>
|
|
23
40
|
Center
|
|
24
41
|
</button>
|
|
25
42
|
</div>
|
|
@@ -5,7 +5,15 @@ export const getTransformStyles = (
|
|
|
5
5
|
y: number,
|
|
6
6
|
scale: number,
|
|
7
7
|
): string => {
|
|
8
|
-
|
|
8
|
+
// The shorthand for matrix does not work for Safari hence the need to explicitly use matrix3d
|
|
9
|
+
// Refer to https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix
|
|
10
|
+
const a = scale;
|
|
11
|
+
const b = 0;
|
|
12
|
+
const c = 0;
|
|
13
|
+
const d = scale;
|
|
14
|
+
const tx = x;
|
|
15
|
+
const ty = y;
|
|
16
|
+
return `matrix3d(${a}, ${b}, 0, 0, ${c}, ${d}, 0, 0, 0, 0, 1, 0, ${tx}, ${ty}, 0, 1)`;
|
|
9
17
|
};
|
|
10
18
|
|
|
11
19
|
export const getCenterPosition = (
|
package/src/.eslintrc.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root: true,
|
|
3
|
-
parser: "@typescript-eslint/parser",
|
|
4
|
-
plugins: ["react", "react-hooks", "prettier", "@typescript-eslint"],
|
|
5
|
-
extends: [
|
|
6
|
-
"plugin:react/recommended",
|
|
7
|
-
"plugin:@typescript-eslint/recommended",
|
|
8
|
-
],
|
|
9
|
-
parserOptions: {
|
|
10
|
-
sourceType: "module",
|
|
11
|
-
ecmaFeatures: {
|
|
12
|
-
jsx: true,
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
rules: {
|
|
16
|
-
"react/jsx-uses-react": "error",
|
|
17
|
-
"react/jsx-uses-vars": "error",
|
|
18
|
-
"no-console": ["error", { allow: ["warn", "error"] }],
|
|
19
|
-
"no-unused-vars": "off",
|
|
20
|
-
"@typescript-eslint/no-unused-vars": "off",
|
|
21
|
-
"@typescript-eslint/no-unused-vars-experimental": "error",
|
|
22
|
-
"react/no-unescaped-entities": 0,
|
|
23
|
-
"react/display-name": 0,
|
|
24
|
-
"react/jsx-filename-extension": [
|
|
25
|
-
2,
|
|
26
|
-
{ extensions: [".js", ".jsx", ".ts", ".tsx"] },
|
|
27
|
-
],
|
|
28
|
-
},
|
|
29
|
-
settings: {
|
|
30
|
-
"import/resolver": {
|
|
31
|
-
node: {
|
|
32
|
-
moduleDirectory: ["node_modules", "src/"],
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
};
|