react-zoom-pan-pinch 3.3.0 → 3.4.1
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 +46 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.esm.js +46 -3
- package/dist/index.esm.js.map +1 -1
- package/package.json +4 -1
- package/.eslintignore +0 -6
- package/.github/CODEOWNERS +0 -36
- package/.github/FUNDING.yml +0 -13
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/docs.yml +0 -34
- package/.github/workflows/release.yml +0 -46
- package/.github/workflows/tests.yml +0 -42
- package/.prettierrc +0 -10
- package/.releaserc.json +0 -63
- package/.storybook/main.js +0 -23
- package/.storybook/preview-head.html +0 -5
- package/.storybook/preview.js +0 -11
- package/.storybook/theme-overrides.css +0 -49
- package/CHANGELOG.md +0 -26
- package/Code_of_Conduct.md +0 -61
- package/Contributing.md +0 -236
- package/__tests__/features/props.spec.tsx +0 -11
- package/__tests__/features/rendering.spec.tsx +0 -36
- package/__tests__/shared/render.shared.tsx +0 -41
- package/__tests__/utils/controls.utils.tsx +0 -25
- package/__tests__/utils/example.tsx +0 -81
- package/commitlint.config.js +0 -1
- package/dist/__tests__/features/props.spec.d.ts +0 -1
- package/dist/__tests__/features/rendering.spec.d.ts +0 -1
- package/dist/__tests__/shared/render.shared.d.ts +0 -11
- package/dist/__tests__/utils/controls.utils.d.ts +0 -3
- package/dist/__tests__/utils/example.d.ts +0 -6
- package/dist/src/components/index.d.ts +0 -4
- package/dist/src/components/keep-scale/keep-scale.d.ts +0 -2
- package/dist/src/components/mini-map/mini-map.d.ts +0 -8
- package/dist/src/components/mini-map/use-resize.hook.d.ts +0 -8
- package/dist/src/components/transform-component/transform-component.d.ts +0 -12
- package/dist/src/components/transform-wrapper/transform-wrapper.d.ts +0 -5
- package/dist/src/constants/state.constants.d.ts +0 -3
- package/dist/src/core/animations/animations.constants.d.ts +0 -16
- package/dist/src/core/animations/animations.utils.d.ts +0 -4
- package/dist/src/core/bounds/bounds.types.d.ts +0 -8
- package/dist/src/core/bounds/bounds.utils.d.ts +0 -17
- package/dist/src/core/double-click/double-click.logic.d.ts +0 -5
- package/dist/src/core/handlers/handlers.logic.d.ts +0 -8
- package/dist/src/core/handlers/handlers.utils.d.ts +0 -14
- package/dist/src/core/instance.core.d.ts +0 -77
- package/dist/src/core/pan/panning.logic.d.ts +0 -5
- package/dist/src/core/pan/panning.utils.d.ts +0 -10
- package/dist/src/core/pan/velocity.logic.d.ts +0 -5
- package/dist/src/core/pan/velocity.utils.d.ts +0 -5
- package/dist/src/core/pinch/pinch.logic.d.ts +0 -4
- package/dist/src/core/pinch/pinch.utils.d.ts +0 -6
- package/dist/src/core/wheel/wheel.logic.d.ts +0 -4
- package/dist/src/core/wheel/wheel.utils.d.ts +0 -7
- package/dist/src/core/zoom/zoom.logic.d.ts +0 -3
- package/dist/src/core/zoom/zoom.utils.d.ts +0 -3
- package/dist/src/hooks/index.d.ts +0 -4
- package/dist/src/hooks/use-controls.d.ts +0 -2
- package/dist/src/hooks/use-transform-context.d.ts +0 -1
- package/dist/src/hooks/use-transform-effect.d.ts +0 -2
- package/dist/src/hooks/use-transform-init.d.ts +0 -2
- package/dist/src/index.d.ts +0 -5
- package/dist/src/models/calculations.model.d.ts +0 -25
- package/dist/src/models/context.model.d.ts +0 -127
- package/dist/src/models/helpers.model.d.ts +0 -5
- package/dist/src/models/index.d.ts +0 -3
- package/dist/src/stories/docs/handlers.d.ts +0 -12
- package/dist/src/stories/docs/props.d.ts +0 -14
- package/dist/src/stories/examples/content-rerendering/example.d.ts +0 -2
- package/dist/src/stories/examples/image-responsive/example.d.ts +0 -2
- package/dist/src/stories/examples/keep-scale/example.d.ts +0 -2
- package/dist/src/stories/examples/mini-map/example.d.ts +0 -1
- package/dist/src/stories/examples/stress/example.d.ts +0 -2
- package/dist/src/stories/examples/svg-zoom-to-element/example.d.ts +0 -2
- package/dist/src/stories/examples/zoom-to-element/example.d.ts +0 -2
- package/dist/src/stories/types/args.types.d.ts +0 -280
- package/dist/src/stories/utils/args.utils.d.ts +0 -3
- package/dist/src/stories/utils/code.utils.d.ts +0 -6
- package/dist/src/stories/utils/controls.utils.d.ts +0 -3
- package/dist/src/stories/utils/index.d.ts +0 -3
- package/dist/src/utils/calculations.utils.d.ts +0 -11
- package/dist/src/utils/callback.utils.d.ts +0 -2
- package/dist/src/utils/context.utils.d.ts +0 -4
- package/dist/src/utils/event.utils.d.ts +0 -1
- package/dist/src/utils/helpers.utils.d.ts +0 -2
- package/dist/src/utils/index.d.ts +0 -8
- package/dist/src/utils/ref.utils.d.ts +0 -2
- package/dist/src/utils/state.utils.d.ts +0 -3
- package/dist/src/utils/styles.utils.d.ts +0 -4
- package/jest.config.ts +0 -45
- package/rollup.config.js +0 -51
- package/src/.eslintrc.json +0 -90
- package/src/components/index.ts +0 -4
- package/src/components/keep-scale/keep-scale.tsx +0 -28
- package/src/components/mini-map/mini-map.tsx +0 -188
- package/src/components/mini-map/use-resize.hook.ts +0 -69
- package/src/components/transform-component/transform-component.module.css +0 -30
- package/src/components/transform-component/transform-component.tsx +0 -61
- package/src/components/transform-wrapper/transform-wrapper.tsx +0 -39
- package/src/constants/state.constants.ts +0 -77
- package/src/core/animations/animations.constants.ts +0 -78
- package/src/core/animations/animations.utils.ts +0 -114
- package/src/core/bounds/bounds.types.ts +0 -8
- package/src/core/bounds/bounds.utils.ts +0 -187
- package/src/core/double-click/double-click.logic.ts +0 -116
- package/src/core/handlers/handlers.logic.ts +0 -115
- package/src/core/handlers/handlers.utils.ts +0 -195
- package/src/core/instance.core.ts +0 -503
- package/src/core/pan/panning.logic.ts +0 -100
- package/src/core/pan/panning.utils.ts +0 -196
- package/src/core/pan/velocity.logic.ts +0 -149
- package/src/core/pan/velocity.utils.ts +0 -79
- package/src/core/pinch/pinch.logic.ts +0 -81
- package/src/core/pinch/pinch.utils.ts +0 -88
- package/src/core/wheel/wheel.logic.ts +0 -121
- package/src/core/wheel/wheel.utils.ts +0 -122
- package/src/core/zoom/zoom.logic.ts +0 -69
- package/src/core/zoom/zoom.utils.ts +0 -58
- package/src/hooks/index.ts +0 -4
- package/src/hooks/use-controls.tsx +0 -9
- package/src/hooks/use-transform-context.tsx +0 -13
- package/src/hooks/use-transform-effect.tsx +0 -22
- package/src/hooks/use-transform-init.tsx +0 -27
- package/src/index.ts +0 -6
- package/src/models/calculations.model.ts +0 -26
- package/src/models/context.model.ts +0 -199
- package/src/models/helpers.model.ts +0 -15
- package/src/models/index.ts +0 -3
- package/src/react-app-env.d.ts +0 -1
- 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 -174
- 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 -526
- package/src/stories/examples/content/content.stories.mdx +0 -121
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -45
- package/src/stories/examples/content-rerendering/example.tsx +0 -73
- package/src/stories/examples/controls/controls.stories.mdx +0 -71
- package/src/stories/examples/image-big/image-big.stories.mdx +0 -43
- package/src/stories/examples/image-medium/image-medium.stories.mdx +0 -41
- package/src/stories/examples/image-responsive/example.tsx +0 -103
- package/src/stories/examples/image-responsive/image-responsive.stories.mdx +0 -32
- package/src/stories/examples/image-small/image-small.stories.mdx +0 -41
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -46
- package/src/stories/examples/keep-scale/example.tsx +0 -92
- package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -45
- package/src/stories/examples/mini-map/example.tsx +0 -54
- package/src/stories/examples/mini-map/mini-map.stories.mdx +0 -33
- package/src/stories/examples/stress/example.tsx +0 -23
- 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 -94
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -28
- package/src/stories/hooks/use-controls.stories.mdx +0 -24
- package/src/stories/hooks/use-transform-context.stories.mdx +0 -15
- package/src/stories/hooks/use-transform-effect.stories.mdx +0 -29
- package/src/stories/hooks/use-transform-init.stories.mdx +0 -25
- package/src/stories/types/args.types.ts +0 -211
- package/src/stories/utils/args.utils.ts +0 -34
- package/src/stories/utils/code.utils.tsx +0 -24
- 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/src/styles.css +0 -8
- package/src/typings.d.ts +0 -10
- package/src/utils/calculations.utils.ts +0 -16
- package/src/utils/callback.utils.ts +0 -11
- package/src/utils/context.utils.ts +0 -48
- package/src/utils/event.utils.ts +0 -22
- package/src/utils/helpers.utils.ts +0 -27
- package/src/utils/index.ts +0 -8
- package/src/utils/ref.utils.ts +0 -16
- package/src/utils/state.utils.ts +0 -40
- package/src/utils/styles.utils.ts +0 -44
- package/tsconfig.json +0 -33
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
|
|
3
|
-
import { TransformComponent, TransformWrapper } from "components";
|
|
4
|
-
import { normalizeArgs } from "../../utils";
|
|
5
|
-
|
|
6
|
-
export const Example: React.FC<any> = (args: any) => {
|
|
7
|
-
const [firstBlock, setFirstBlock] = useState(false);
|
|
8
|
-
const [secondBlock, setSecondBlock] = useState(false);
|
|
9
|
-
const [thirdBlock, setThirdBlock] = useState(false);
|
|
10
|
-
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
const a = setInterval(() => {
|
|
13
|
-
setFirstBlock((prev) => !prev);
|
|
14
|
-
}, 1000);
|
|
15
|
-
const b = setInterval(() => {
|
|
16
|
-
setSecondBlock((prev) => !prev);
|
|
17
|
-
}, 3000);
|
|
18
|
-
const c = setInterval(() => {
|
|
19
|
-
setThirdBlock((prev) => !prev);
|
|
20
|
-
}, 12000);
|
|
21
|
-
return () => {
|
|
22
|
-
clearInterval(a);
|
|
23
|
-
clearInterval(b);
|
|
24
|
-
clearInterval(c);
|
|
25
|
-
};
|
|
26
|
-
}, []);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<TransformWrapper {...normalizeArgs(args)}>
|
|
30
|
-
<TransformComponent
|
|
31
|
-
wrapperStyle={{
|
|
32
|
-
width: "500px",
|
|
33
|
-
height: "500px",
|
|
34
|
-
maxWidth: "100%",
|
|
35
|
-
maxHeight: "calc(100vh - 50px)",
|
|
36
|
-
}}
|
|
37
|
-
>
|
|
38
|
-
<div
|
|
39
|
-
style={{
|
|
40
|
-
background: "#444",
|
|
41
|
-
color: "white",
|
|
42
|
-
padding: "50px",
|
|
43
|
-
minHeight: "300px",
|
|
44
|
-
width: "100%",
|
|
45
|
-
}}
|
|
46
|
-
>
|
|
47
|
-
<h2>Constantly rerendering content</h2>
|
|
48
|
-
|
|
49
|
-
{firstBlock ? <p>Content #1</p> : <p>Changed Content #1</p>}
|
|
50
|
-
|
|
51
|
-
{secondBlock ? <p>Content #2</p> : <p>Changed Content #2</p>}
|
|
52
|
-
|
|
53
|
-
{thirdBlock ? (
|
|
54
|
-
<p>Content #3</p>
|
|
55
|
-
) : (
|
|
56
|
-
<p>
|
|
57
|
-
Changed Content #3
|
|
58
|
-
<br />
|
|
59
|
-
<br />
|
|
60
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
|
61
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
62
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
63
|
-
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
64
|
-
reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
65
|
-
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
|
|
66
|
-
sunt in culpa qui officia deserunt mollit anim id est laborum
|
|
67
|
-
</p>
|
|
68
|
-
)}
|
|
69
|
-
</div>
|
|
70
|
-
</TransformComponent>
|
|
71
|
-
</TransformWrapper>
|
|
72
|
-
);
|
|
73
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
-
import { action } from "@storybook/addon-actions";
|
|
3
|
-
|
|
4
|
-
import { TransformWrapper, TransformComponent } from "../../../components";
|
|
5
|
-
import { argsTypes } from "../../types/args.types.ts";
|
|
6
|
-
import { normalizeArgs, Controls } from "../../utils";
|
|
7
|
-
|
|
8
|
-
import exampleImg from "../../assets/small-image.jpg";
|
|
9
|
-
|
|
10
|
-
export const Template = (args) => (
|
|
11
|
-
<TransformWrapper {...normalizeArgs(args)}>
|
|
12
|
-
{(utils) => (
|
|
13
|
-
<div>
|
|
14
|
-
<Controls {...utils} />
|
|
15
|
-
<TransformComponent
|
|
16
|
-
wrapperStyle={{ maxWidth: "100%", maxHeight: "calc(100vh - 50px)" }}
|
|
17
|
-
>
|
|
18
|
-
<div style={{ background: "#444", color: "white", padding: "50px" }}>
|
|
19
|
-
{JSON.stringify(utils.state, null, 4)}
|
|
20
|
-
<h1>No scrollbars needed</h1>
|
|
21
|
-
<h2>Use mouse or gestures to move around</h2>
|
|
22
|
-
<button
|
|
23
|
-
onClick={() => alert("You can still interact with click events!")}
|
|
24
|
-
>
|
|
25
|
-
Click me!
|
|
26
|
-
</button>
|
|
27
|
-
<p>
|
|
28
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
|
29
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
30
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
31
|
-
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
32
|
-
reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
33
|
-
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
|
|
34
|
-
sunt in culpa qui officia deserunt mollit anim id est laborum
|
|
35
|
-
</p>
|
|
36
|
-
<img src={exampleImg} alt="" />
|
|
37
|
-
<p>
|
|
38
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
|
39
|
-
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
|
40
|
-
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
|
41
|
-
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
42
|
-
reprehenderit in voluptate velit esse cillum dolore eu fugiat
|
|
43
|
-
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
|
|
44
|
-
sunt in culpa qui officia deserunt mollit anim id est laborum
|
|
45
|
-
</p>
|
|
46
|
-
</div>
|
|
47
|
-
</TransformComponent>
|
|
48
|
-
</div>
|
|
49
|
-
)}
|
|
50
|
-
</TransformWrapper>
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
<Meta
|
|
54
|
-
title="Examples/Controls"
|
|
55
|
-
component={TransformWrapper}
|
|
56
|
-
argTypes={argsTypes}
|
|
57
|
-
/>
|
|
58
|
-
|
|
59
|
-
# Controls
|
|
60
|
-
|
|
61
|
-
<br />
|
|
62
|
-
|
|
63
|
-
### Preview:
|
|
64
|
-
|
|
65
|
-
<Canvas>
|
|
66
|
-
<Story name="Controls">{(args) => <Template {...args} />}</Story>
|
|
67
|
-
</Canvas>
|
|
68
|
-
|
|
69
|
-
## Component API
|
|
70
|
-
|
|
71
|
-
<ArgsTable story="Controls" />
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
-
import { action } from "@storybook/addon-actions";
|
|
3
|
-
|
|
4
|
-
import { TransformWrapper, TransformComponent } from "../../../components";
|
|
5
|
-
import { argsTypes } from "../../types/args.types.ts";
|
|
6
|
-
import { normalizeArgs, Controls } from "../../utils";
|
|
7
|
-
|
|
8
|
-
import exampleImg from "../../assets/big-image.jpeg";
|
|
9
|
-
|
|
10
|
-
export const Template = (args) => (
|
|
11
|
-
<TransformWrapper {...normalizeArgs(args)}>
|
|
12
|
-
{(utils) => (
|
|
13
|
-
<div>
|
|
14
|
-
<Controls {...utils} />
|
|
15
|
-
<TransformComponent
|
|
16
|
-
wrapperStyle={{ maxWidth: "100%", maxHeight: "calc(100vh - 50px)" }}
|
|
17
|
-
>
|
|
18
|
-
<img src={exampleImg} alt="" />
|
|
19
|
-
</TransformComponent>
|
|
20
|
-
</div>
|
|
21
|
-
)}
|
|
22
|
-
</TransformWrapper>
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
<Meta
|
|
26
|
-
title="Examples/Big Image"
|
|
27
|
-
component={TransformWrapper}
|
|
28
|
-
argTypes={argsTypes}
|
|
29
|
-
/>
|
|
30
|
-
|
|
31
|
-
# Big Image
|
|
32
|
-
|
|
33
|
-
<br />
|
|
34
|
-
|
|
35
|
-
### Preview:
|
|
36
|
-
|
|
37
|
-
<Canvas>
|
|
38
|
-
<Story name="Big Image">{(args) => <Template {...args} />}</Story>
|
|
39
|
-
</Canvas>
|
|
40
|
-
|
|
41
|
-
## Component API
|
|
42
|
-
|
|
43
|
-
<ArgsTable story="Big Image" />
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
-
import { action } from "@storybook/addon-actions";
|
|
3
|
-
|
|
4
|
-
import { TransformWrapper, TransformComponent } from "../../../components";
|
|
5
|
-
import { argsTypes } from "../../types/args.types.ts";
|
|
6
|
-
import { normalizeArgs, Controls } from "../../utils";
|
|
7
|
-
|
|
8
|
-
import exampleImg from "../../assets/medium-image.jpg";
|
|
9
|
-
|
|
10
|
-
export const Template = (args) => (
|
|
11
|
-
<TransformWrapper {...normalizeArgs(args)}>
|
|
12
|
-
{(utils) => (
|
|
13
|
-
<div>
|
|
14
|
-
<Controls {...utils} />
|
|
15
|
-
<TransformComponent>
|
|
16
|
-
<img src={exampleImg} alt="" />
|
|
17
|
-
</TransformComponent>
|
|
18
|
-
</div>
|
|
19
|
-
)}
|
|
20
|
-
</TransformWrapper>
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
<Meta
|
|
24
|
-
title="Examples/Medium Image"
|
|
25
|
-
component={TransformWrapper}
|
|
26
|
-
argTypes={argsTypes}
|
|
27
|
-
/>
|
|
28
|
-
|
|
29
|
-
# Medium Image
|
|
30
|
-
|
|
31
|
-
<br />
|
|
32
|
-
|
|
33
|
-
### Preview:
|
|
34
|
-
|
|
35
|
-
<Canvas>
|
|
36
|
-
<Story name="Medium Image">{(args) => <Template {...args} />}</Story>
|
|
37
|
-
</Canvas>
|
|
38
|
-
|
|
39
|
-
## Component API
|
|
40
|
-
|
|
41
|
-
<ArgsTable story="Medium Image" />
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect, useMemo, useCallback } from "react";
|
|
2
|
-
|
|
3
|
-
import { TransformComponent, TransformWrapper } from "components";
|
|
4
|
-
import { normalizeArgs } from "stories/utils";
|
|
5
|
-
import exampleImg from "../../assets/medium-image.jpg";
|
|
6
|
-
|
|
7
|
-
export const Example: React.FC<any> = (args: any) => {
|
|
8
|
-
const src = exampleImg;
|
|
9
|
-
const alt = "example";
|
|
10
|
-
const backgroundColor = "black";
|
|
11
|
-
const scaleUp = true;
|
|
12
|
-
const zoomFactor = 8;
|
|
13
|
-
|
|
14
|
-
const [container, setContainer] = useState<HTMLDivElement | null>(null);
|
|
15
|
-
|
|
16
|
-
const [containerWidth, setContainerWidth] = useState<number>(0);
|
|
17
|
-
const [containerHeight, setContainerHeight] = useState<number>(0);
|
|
18
|
-
|
|
19
|
-
const [imageNaturalWidth, setImageNaturalWidth] = useState<number>(0);
|
|
20
|
-
const [imageNaturalHeight, setImageNaturalHeight] = useState<number>(0);
|
|
21
|
-
|
|
22
|
-
const imageScale = useMemo(() => {
|
|
23
|
-
if (
|
|
24
|
-
containerWidth === 0 ||
|
|
25
|
-
containerHeight === 0 ||
|
|
26
|
-
imageNaturalWidth === 0 ||
|
|
27
|
-
imageNaturalHeight === 0
|
|
28
|
-
)
|
|
29
|
-
return 0;
|
|
30
|
-
const scale = Math.min(
|
|
31
|
-
containerWidth / imageNaturalWidth,
|
|
32
|
-
containerHeight / imageNaturalHeight,
|
|
33
|
-
);
|
|
34
|
-
return scaleUp ? scale : Math.max(scale, 1);
|
|
35
|
-
}, [
|
|
36
|
-
scaleUp,
|
|
37
|
-
containerWidth,
|
|
38
|
-
containerHeight,
|
|
39
|
-
imageNaturalWidth,
|
|
40
|
-
imageNaturalHeight,
|
|
41
|
-
]);
|
|
42
|
-
|
|
43
|
-
const handleResize = useCallback(() => {
|
|
44
|
-
if (container !== null) {
|
|
45
|
-
const rect = container.getBoundingClientRect();
|
|
46
|
-
setContainerWidth(rect.width);
|
|
47
|
-
setContainerHeight(rect.height);
|
|
48
|
-
} else {
|
|
49
|
-
setContainerWidth(0);
|
|
50
|
-
setContainerHeight(0);
|
|
51
|
-
}
|
|
52
|
-
}, [container]);
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
handleResize();
|
|
56
|
-
window.addEventListener("resize", handleResize);
|
|
57
|
-
return () => {
|
|
58
|
-
window.removeEventListener("resize", handleResize);
|
|
59
|
-
};
|
|
60
|
-
}, [handleResize]);
|
|
61
|
-
|
|
62
|
-
const handleImageOnLoad = (image: HTMLImageElement) => {
|
|
63
|
-
setImageNaturalWidth(image.naturalWidth);
|
|
64
|
-
setImageNaturalHeight(image.naturalHeight);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
const image = new Image();
|
|
69
|
-
image.onload = () => handleImageOnLoad(image);
|
|
70
|
-
image.src = src;
|
|
71
|
-
}, [src]);
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<div
|
|
75
|
-
style={{
|
|
76
|
-
width: "100%",
|
|
77
|
-
height: "100%",
|
|
78
|
-
backgroundColor,
|
|
79
|
-
}}
|
|
80
|
-
ref={(el: HTMLDivElement | null) => setContainer(el)}
|
|
81
|
-
>
|
|
82
|
-
{imageScale > 0 && (
|
|
83
|
-
<TransformWrapper
|
|
84
|
-
key={`${containerWidth}x${containerHeight}`}
|
|
85
|
-
initialScale={imageScale}
|
|
86
|
-
minScale={imageScale}
|
|
87
|
-
maxScale={imageScale * zoomFactor}
|
|
88
|
-
centerOnInit
|
|
89
|
-
{...normalizeArgs(args)}
|
|
90
|
-
>
|
|
91
|
-
<TransformComponent
|
|
92
|
-
wrapperStyle={{
|
|
93
|
-
width: "100%",
|
|
94
|
-
height: "100%",
|
|
95
|
-
}}
|
|
96
|
-
>
|
|
97
|
-
<img alt={alt} src={src} />
|
|
98
|
-
</TransformComponent>
|
|
99
|
-
</TransformWrapper>
|
|
100
|
-
)}
|
|
101
|
-
</div>
|
|
102
|
-
);
|
|
103
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
-
import { action } from "@storybook/addon-actions";
|
|
3
|
-
|
|
4
|
-
import { TransformComponent, TransformWrapper } from "components";
|
|
5
|
-
import { argsTypes } from "../../types/args.types";
|
|
6
|
-
import { Example } from "./example";
|
|
7
|
-
|
|
8
|
-
export const Template = (args) => (
|
|
9
|
-
<div style={{ width: "80vw", height: "80vh" }}>
|
|
10
|
-
<Example {...args} />
|
|
11
|
-
</div>
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
<Meta
|
|
15
|
-
title="Examples/Responsive Image"
|
|
16
|
-
component={TransformWrapper}
|
|
17
|
-
argTypes={argsTypes}
|
|
18
|
-
/>
|
|
19
|
-
|
|
20
|
-
# Responsive Image
|
|
21
|
-
|
|
22
|
-
<br />
|
|
23
|
-
|
|
24
|
-
### Preview:
|
|
25
|
-
|
|
26
|
-
<Canvas>
|
|
27
|
-
<Story name="Responsive Image">{(args) => <Template {...args} />}</Story>
|
|
28
|
-
</Canvas>
|
|
29
|
-
|
|
30
|
-
## Component API
|
|
31
|
-
|
|
32
|
-
<ArgsTable story="Responsive Image" />
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
-
import { action } from "@storybook/addon-actions";
|
|
3
|
-
|
|
4
|
-
import { TransformWrapper, TransformComponent } from "../../../components";
|
|
5
|
-
import { argsTypes } from "../../types/args.types.ts";
|
|
6
|
-
import { normalizeArgs, Controls } from "../../utils";
|
|
7
|
-
|
|
8
|
-
import exampleImg from "../../assets/small-image.jpg";
|
|
9
|
-
|
|
10
|
-
export const Template = (args) => (
|
|
11
|
-
<TransformWrapper {...normalizeArgs(args)}>
|
|
12
|
-
{(utils) => (
|
|
13
|
-
<div>
|
|
14
|
-
<Controls {...utils} />
|
|
15
|
-
<TransformComponent>
|
|
16
|
-
<img src={exampleImg} alt="" />
|
|
17
|
-
</TransformComponent>
|
|
18
|
-
</div>
|
|
19
|
-
)}
|
|
20
|
-
</TransformWrapper>
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
<Meta
|
|
24
|
-
title="Examples/Small Image"
|
|
25
|
-
component={TransformWrapper}
|
|
26
|
-
argTypes={argsTypes}
|
|
27
|
-
/>
|
|
28
|
-
|
|
29
|
-
# Small Image
|
|
30
|
-
|
|
31
|
-
<br />
|
|
32
|
-
|
|
33
|
-
### Preview:
|
|
34
|
-
|
|
35
|
-
<Canvas>
|
|
36
|
-
<Story name="Small Image">{(args) => <Template {...args} />}</Story>
|
|
37
|
-
</Canvas>
|
|
38
|
-
|
|
39
|
-
## Component API
|
|
40
|
-
|
|
41
|
-
<ArgsTable story="Small Image" />
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
-
import { action } from "@storybook/addon-actions";
|
|
3
|
-
|
|
4
|
-
import { TransformWrapper, TransformComponent } from "../../../components";
|
|
5
|
-
import { argsTypes } from "../../types/args.types.ts";
|
|
6
|
-
import { normalizeArgs, Controls } from "../../utils";
|
|
7
|
-
|
|
8
|
-
import exampleImg from "../../assets/medium-image.jpg";
|
|
9
|
-
|
|
10
|
-
export const Template = (args) => (
|
|
11
|
-
<TransformWrapper
|
|
12
|
-
{...normalizeArgs(args)}
|
|
13
|
-
initialScale={0.4}
|
|
14
|
-
minScale={0.2}
|
|
15
|
-
centerOnInit={true}
|
|
16
|
-
>
|
|
17
|
-
{(utils) => (
|
|
18
|
-
<div>
|
|
19
|
-
<Controls {...utils} />
|
|
20
|
-
<TransformComponent>
|
|
21
|
-
<img src={exampleImg} alt="" />
|
|
22
|
-
</TransformComponent>
|
|
23
|
-
</div>
|
|
24
|
-
)}
|
|
25
|
-
</TransformWrapper>
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
<Meta
|
|
29
|
-
title="Examples/Zoomed Out"
|
|
30
|
-
component={TransformWrapper}
|
|
31
|
-
argTypes={argsTypes}
|
|
32
|
-
/>
|
|
33
|
-
|
|
34
|
-
# Zoomed Out
|
|
35
|
-
|
|
36
|
-
<br />
|
|
37
|
-
|
|
38
|
-
### Preview:
|
|
39
|
-
|
|
40
|
-
<Canvas>
|
|
41
|
-
<Story name="Zoomed Out">{(args) => <Template {...args} />}</Story>
|
|
42
|
-
</Canvas>
|
|
43
|
-
|
|
44
|
-
## Component API
|
|
45
|
-
|
|
46
|
-
<ArgsTable story="Zoomed Out" />
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { TransformComponent, TransformWrapper, KeepScale } from "components";
|
|
4
|
-
import { normalizeArgs } from "../../utils";
|
|
5
|
-
import exampleImg from "../../assets/map.jpg";
|
|
6
|
-
import { ReactComponent as Pin } from "../../assets/pin.svg";
|
|
7
|
-
|
|
8
|
-
export const Example: React.FC<any> = (args: any) => {
|
|
9
|
-
return (
|
|
10
|
-
<TransformWrapper {...normalizeArgs(args)} maxScale={100}>
|
|
11
|
-
<TransformComponent
|
|
12
|
-
wrapperStyle={{
|
|
13
|
-
width: "700px",
|
|
14
|
-
height: "500px",
|
|
15
|
-
maxWidth: "100%",
|
|
16
|
-
maxHeight: "calc(100vh - 50px)",
|
|
17
|
-
}}
|
|
18
|
-
>
|
|
19
|
-
<div
|
|
20
|
-
style={{
|
|
21
|
-
position: "relative",
|
|
22
|
-
background: "#999",
|
|
23
|
-
}}
|
|
24
|
-
>
|
|
25
|
-
<h2>Pins will keep the initial scale with KeepScale component</h2>
|
|
26
|
-
|
|
27
|
-
<img
|
|
28
|
-
style={{ width: "600px", height: "300px" }}
|
|
29
|
-
src={exampleImg}
|
|
30
|
-
alt=""
|
|
31
|
-
/>
|
|
32
|
-
<div
|
|
33
|
-
style={{
|
|
34
|
-
position: "absolute",
|
|
35
|
-
top: "50%",
|
|
36
|
-
left: "50%",
|
|
37
|
-
transform: "translate(-50%, -50%)",
|
|
38
|
-
zIndex: 2,
|
|
39
|
-
marginLeft: "-200px",
|
|
40
|
-
}}
|
|
41
|
-
>
|
|
42
|
-
<KeepScale>
|
|
43
|
-
<Pin fill="red" style={{ width: "20px", height: "20px" }} />
|
|
44
|
-
</KeepScale>
|
|
45
|
-
</div>
|
|
46
|
-
<div
|
|
47
|
-
style={{
|
|
48
|
-
position: "absolute",
|
|
49
|
-
top: "50%",
|
|
50
|
-
left: "50%",
|
|
51
|
-
transform: "translate(-50%, -50%)",
|
|
52
|
-
zIndex: 2,
|
|
53
|
-
marginLeft: "200px",
|
|
54
|
-
}}
|
|
55
|
-
>
|
|
56
|
-
<KeepScale>
|
|
57
|
-
<Pin fill="red" style={{ width: "20px", height: "20px" }} />
|
|
58
|
-
</KeepScale>
|
|
59
|
-
</div>
|
|
60
|
-
<div
|
|
61
|
-
style={{
|
|
62
|
-
position: "absolute",
|
|
63
|
-
top: "50%",
|
|
64
|
-
left: "50%",
|
|
65
|
-
transform: "translate(-50%, -50%)",
|
|
66
|
-
zIndex: 2,
|
|
67
|
-
marginBottom: "150px",
|
|
68
|
-
}}
|
|
69
|
-
>
|
|
70
|
-
<KeepScale>
|
|
71
|
-
<Pin fill="red" style={{ width: "20px", height: "20px" }} />
|
|
72
|
-
</KeepScale>
|
|
73
|
-
</div>
|
|
74
|
-
<div
|
|
75
|
-
style={{
|
|
76
|
-
position: "absolute",
|
|
77
|
-
top: "50%",
|
|
78
|
-
left: "50%",
|
|
79
|
-
transform: "translate(-50%, -50%)",
|
|
80
|
-
zIndex: 2,
|
|
81
|
-
marginTop: "100px",
|
|
82
|
-
}}
|
|
83
|
-
>
|
|
84
|
-
<KeepScale>
|
|
85
|
-
<Pin fill="red" style={{ width: "20px", height: "20px" }} />
|
|
86
|
-
</KeepScale>
|
|
87
|
-
</div>
|
|
88
|
-
</div>
|
|
89
|
-
</TransformComponent>
|
|
90
|
-
</TransformWrapper>
|
|
91
|
-
);
|
|
92
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
-
import { action } from "@storybook/addon-actions";
|
|
3
|
-
|
|
4
|
-
import { TransformWrapper, TransformComponent } from "../../../components";
|
|
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/Keep scale"
|
|
12
|
-
component={TransformWrapper}
|
|
13
|
-
argTypes={{
|
|
14
|
-
...argsTypes,
|
|
15
|
-
"wheel.excluded": {
|
|
16
|
-
...argsTypes["wheel.excluded"],
|
|
17
|
-
defaultValue: ["wheelDisabled"],
|
|
18
|
-
},
|
|
19
|
-
"panning.excluded": {
|
|
20
|
-
...argsTypes["panning.excluded"],
|
|
21
|
-
defaultValue: ["panningDisabled"],
|
|
22
|
-
},
|
|
23
|
-
"pinch.excluded": {
|
|
24
|
-
...argsTypes["pinch.excluded"],
|
|
25
|
-
defaultValue: ["pinchDisabled"],
|
|
26
|
-
},
|
|
27
|
-
centerOnInit: {
|
|
28
|
-
defaultValue: true,
|
|
29
|
-
},
|
|
30
|
-
}}
|
|
31
|
-
/>
|
|
32
|
-
|
|
33
|
-
# Keep scale
|
|
34
|
-
|
|
35
|
-
<br />
|
|
36
|
-
|
|
37
|
-
### Preview:
|
|
38
|
-
|
|
39
|
-
<Canvas>
|
|
40
|
-
<Story name="Keep scale">{(args) => <Template {...args} />}</Story>
|
|
41
|
-
</Canvas>
|
|
42
|
-
|
|
43
|
-
## Component API
|
|
44
|
-
|
|
45
|
-
<ArgsTable story="Keep scale" />
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { MiniMap, TransformComponent, TransformWrapper } from "components";
|
|
4
|
-
import { Controls, normalizeArgs } from "stories/utils";
|
|
5
|
-
|
|
6
|
-
export const Template = (args: any) => {
|
|
7
|
-
const element = (
|
|
8
|
-
<div style={{ background: "#666", color: "white", padding: "50px" }}>
|
|
9
|
-
<p>
|
|
10
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
|
|
11
|
-
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
|
|
12
|
-
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
|
|
13
|
-
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
|
|
14
|
-
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
|
|
15
|
-
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
|
|
16
|
-
mollit anim id est laborum
|
|
17
|
-
</p>
|
|
18
|
-
<p>
|
|
19
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
|
|
20
|
-
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
|
|
21
|
-
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
|
|
22
|
-
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
|
|
23
|
-
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
|
|
24
|
-
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
|
|
25
|
-
mollit anim id est laborum
|
|
26
|
-
</p>
|
|
27
|
-
</div>
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<TransformWrapper {...normalizeArgs(args)}>
|
|
32
|
-
{(utils) => (
|
|
33
|
-
<div>
|
|
34
|
-
<div
|
|
35
|
-
style={{
|
|
36
|
-
position: "fixed",
|
|
37
|
-
zIndex: 5,
|
|
38
|
-
top: "50px",
|
|
39
|
-
right: "50px",
|
|
40
|
-
}}
|
|
41
|
-
>
|
|
42
|
-
<MiniMap width={200}>{element}</MiniMap>
|
|
43
|
-
</div>
|
|
44
|
-
<Controls {...utils} />
|
|
45
|
-
<TransformComponent
|
|
46
|
-
wrapperStyle={{ maxWidth: "100%", maxHeight: "calc(100vh - 50px)" }}
|
|
47
|
-
>
|
|
48
|
-
{element}
|
|
49
|
-
</TransformComponent>
|
|
50
|
-
</div>
|
|
51
|
-
)}
|
|
52
|
-
</TransformWrapper>
|
|
53
|
-
);
|
|
54
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
|
|
2
|
-
import { action } from "@storybook/addon-actions";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
TransformWrapper,
|
|
6
|
-
TransformComponent,
|
|
7
|
-
MiniMap,
|
|
8
|
-
} from "../../../components";
|
|
9
|
-
import { argsTypes } from "../../types/args.types.ts";
|
|
10
|
-
import { normalizeArgs, Controls } from "../../utils";
|
|
11
|
-
import { Template } from "./example";
|
|
12
|
-
|
|
13
|
-
import exampleImg from "../../assets/small-image.jpg";
|
|
14
|
-
|
|
15
|
-
<Meta
|
|
16
|
-
title="Examples/Mini Map"
|
|
17
|
-
component={TransformWrapper}
|
|
18
|
-
argTypes={argsTypes}
|
|
19
|
-
/>
|
|
20
|
-
|
|
21
|
-
# Mini Map
|
|
22
|
-
|
|
23
|
-
<br />
|
|
24
|
-
|
|
25
|
-
### Preview:
|
|
26
|
-
|
|
27
|
-
<Canvas>
|
|
28
|
-
<Story name="Mini Map">{(args) => <Template {...args} />}</Story>
|
|
29
|
-
</Canvas>
|
|
30
|
-
|
|
31
|
-
## Component API
|
|
32
|
-
|
|
33
|
-
<ArgsTable story="Mini Map" />
|