react-zoom-pan-pinch 4.0.0 → 4.0.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/package.json +3 -2
- 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/DocTable.tsx +0 -59
- package/src/stories/docs/HandlerCards.tsx +0 -102
- package/src/stories/docs/Introduction.stories.mdx +0 -135
- package/src/stories/docs/PropTable.tsx +0 -116
- package/src/stories/docs/docs.module.css +0 -370
- package/src/stories/docs/handlers.stories.mdx +0 -7
- package/src/stories/docs/handlers.tsx +0 -111
- package/src/stories/docs/props.stories.mdx +0 -11
- package/src/stories/docs/props.tsx +0 -571
- package/src/stories/examples/axis-lock/axis-lock.stories.mdx +0 -35
- package/src/stories/examples/axis-lock/example.tsx +0 -114
- package/src/stories/examples/bounds/bounds.data.tsx +0 -191
- package/src/stories/examples/bounds/bounds.stories.mdx +0 -99
- package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +0 -206
- package/src/stories/examples/cinema/cinema-data.tsx +0 -578
- package/src/stories/examples/cinema/cinema.stories.mdx +0 -30
- package/src/stories/examples/cinema/example.tsx +0 -378
- package/src/stories/examples/cinema/image.png +0 -0
- package/src/stories/examples/content/content.stories.mdx +0 -172
- package/src/stories/examples/content/mixed-content.data.tsx +0 -624
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -34
- package/src/stories/examples/content-rerendering/example.tsx +0 -631
- package/src/stories/examples/controls/controls.stories.mdx +0 -120
- package/src/stories/examples/image/example.tsx +0 -149
- package/src/stories/examples/image/image.stories.mdx +0 -46
- package/src/stories/examples/image-annotations/example.tsx +0 -1442
- package/src/stories/examples/image-annotations/image-annotations.stories.mdx +0 -39
- package/src/stories/examples/image-responsive/example.tsx +0 -152
- package/src/stories/examples/image-responsive/image-responsive.stories.mdx +0 -51
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -107
- package/src/stories/examples/initial-transform/example.tsx +0 -233
- package/src/stories/examples/initial-transform/initial-transform.stories.mdx +0 -37
- package/src/stories/examples/keep-scale/example.tsx +0 -882
- package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -30
- package/src/stories/examples/keep-scale/map.stories.mdx +0 -28
- package/src/stories/examples/medical-viewer/chest-xray.tsx +0 -246
- package/src/stories/examples/medical-viewer/example.tsx +0 -690
- package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +0 -49
- package/src/stories/examples/mini-map/example.tsx +0 -122
- package/src/stories/examples/mini-map/mini-map.stories.mdx +0 -26
- package/src/stories/examples/miro/example.tsx +0 -1573
- package/src/stories/examples/miro/miro.stories.mdx +0 -31
- package/src/stories/examples/padding/example.tsx +0 -147
- package/src/stories/examples/padding/padding.stories.mdx +0 -35
- package/src/stories/examples/product-card/example.tsx +0 -594
- package/src/stories/examples/product-card/product-card.stories.mdx +0 -29
- package/src/stories/examples/stadium/example.tsx +0 -1040
- package/src/stories/examples/stadium/stadium-data.ts +0 -224
- package/src/stories/examples/stadium/stadium.stories.mdx +0 -32
- package/src/stories/examples/stress/example.tsx +0 -59
- 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 -95
- package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
- package/src/stories/examples/text-selection/example.tsx +0 -221
- package/src/stories/examples/text-selection/text-selection.stories.mdx +0 -31
- package/src/stories/examples/velocity/example.tsx +0 -908
- package/src/stories/examples/velocity/velocity.stories.mdx +0 -35
- package/src/stories/examples/virtualize/example.tsx +0 -239
- package/src/stories/examples/virtualize/virtualize.stories.mdx +0 -84
- package/src/stories/examples/zoom-to-element/example.tsx +0 -219
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -31
- package/src/stories/hooks/use-controls.stories.mdx +0 -86
- package/src/stories/hooks/use-transform-component.stories.mdx +0 -108
- package/src/stories/hooks/use-transform-context.stories.mdx +0 -92
- package/src/stories/hooks/use-transform-effect.stories.mdx +0 -114
- package/src/stories/hooks/use-transform-init.stories.mdx +0 -105
- package/src/stories/types/args.types.ts +0 -192
- package/src/stories/utils/args.utils.ts +0 -35
- package/src/stories/utils/bounds-overlay.tsx +0 -168
- package/src/stories/utils/code.utils.tsx +0 -22
- package/src/stories/utils/controls.utils.tsx +0 -347
- package/src/stories/utils/index.ts +0 -5
- package/src/stories/utils/styles.module.css +0 -223
- package/src/stories/utils/viewer.styles.ts +0 -34
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, ArgsTable, Canvas } from "@storybook/blocks";
|
|
2
|
-
|
|
3
|
-
import { TransformWrapper, TransformComponent } from "../../../components";
|
|
4
|
-
import { argsTypes } from "../../types/args.types.ts";
|
|
5
|
-
import { normalizeArgs, Controls, viewerChrome } from "../../utils";
|
|
6
|
-
import { useTransformComponent } from "../../../hooks";
|
|
7
|
-
|
|
8
|
-
import exampleImg from "../../assets/small-image.jpg";
|
|
9
|
-
|
|
10
|
-
export const StateBadge = () => {
|
|
11
|
-
return useTransformComponent(({ state }) => (
|
|
12
|
-
<div
|
|
13
|
-
style={{
|
|
14
|
-
position: "absolute",
|
|
15
|
-
bottom: 16,
|
|
16
|
-
right: 16,
|
|
17
|
-
zIndex: 10,
|
|
18
|
-
padding: "8px 14px",
|
|
19
|
-
borderRadius: 10,
|
|
20
|
-
background: "rgba(10, 10, 18, 0.85)",
|
|
21
|
-
backdropFilter: "blur(12px)",
|
|
22
|
-
WebkitBackdropFilter: "blur(12px)",
|
|
23
|
-
border: "1px solid rgba(255,255,255,0.08)",
|
|
24
|
-
fontFamily: "'SF Mono', 'Fira Code', monospace",
|
|
25
|
-
fontSize: 11,
|
|
26
|
-
color: "rgba(255,255,255,0.6)",
|
|
27
|
-
lineHeight: 1.7,
|
|
28
|
-
userSelect: "none",
|
|
29
|
-
pointerEvents: "none",
|
|
30
|
-
}}
|
|
31
|
-
>
|
|
32
|
-
<div><span style={{ color: "#667eea" }}>scale</span>: {state.scale.toFixed(3)}</div>
|
|
33
|
-
<div><span style={{ color: "#43e97b" }}>posX</span>: {state.positionX.toFixed(1)}</div>
|
|
34
|
-
<div><span style={{ color: "#f093fb" }}>posY</span>: {state.positionY.toFixed(1)}</div>
|
|
35
|
-
</div>
|
|
36
|
-
));
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const Template = (args) => (
|
|
40
|
-
<div style={{ fontFamily: "system-ui, -apple-system, sans-serif" }}>
|
|
41
|
-
<TransformWrapper {...normalizeArgs(args)}>
|
|
42
|
-
{(utils) => (
|
|
43
|
-
<>
|
|
44
|
-
<Controls {...utils} />
|
|
45
|
-
<div style={{ position: "relative", display: "inline-block" }}>
|
|
46
|
-
<TransformComponent
|
|
47
|
-
wrapperStyle={{
|
|
48
|
-
...viewerChrome,
|
|
49
|
-
width: "500px",
|
|
50
|
-
height: "500px",
|
|
51
|
-
maxWidth: "80vw",
|
|
52
|
-
maxHeight: "75vh",
|
|
53
|
-
}}
|
|
54
|
-
>
|
|
55
|
-
<div style={{ padding: 32 }}>
|
|
56
|
-
<h2 style={{ margin: "0 0 16px", fontSize: 18, fontWeight: 700, color: "rgba(255,255,255,0.9)" }}>
|
|
57
|
-
Interactive Content
|
|
58
|
-
</h2>
|
|
59
|
-
<p style={{ margin: "0 0 16px", fontSize: 13, lineHeight: 1.6, color: "rgba(255,255,255,0.5)" }}>
|
|
60
|
-
Pan and zoom this panel using mouse, trackpad, or touch gestures.
|
|
61
|
-
The floating controls provide programmatic zoom, reset, and center actions.
|
|
62
|
-
The state badge in the corner shows real-time transform values.
|
|
63
|
-
</p>
|
|
64
|
-
<div
|
|
65
|
-
style={{
|
|
66
|
-
borderRadius: 10,
|
|
67
|
-
overflow: "hidden",
|
|
68
|
-
border: "1px solid rgba(255,255,255,0.06)",
|
|
69
|
-
marginBottom: 16,
|
|
70
|
-
}}
|
|
71
|
-
>
|
|
72
|
-
<img src={exampleImg} alt="" style={{ display: "block", width: "100%" }} />
|
|
73
|
-
</div>
|
|
74
|
-
<button
|
|
75
|
-
type="button"
|
|
76
|
-
onClick={() => alert("Click events work inside transformed content!")}
|
|
77
|
-
style={{
|
|
78
|
-
padding: "8px 20px",
|
|
79
|
-
borderRadius: 8,
|
|
80
|
-
border: "1px solid rgba(255,255,255,0.15)",
|
|
81
|
-
background: "rgba(255,255,255,0.06)",
|
|
82
|
-
color: "rgba(255,255,255,0.7)",
|
|
83
|
-
fontSize: 12,
|
|
84
|
-
fontWeight: 600,
|
|
85
|
-
cursor: "pointer",
|
|
86
|
-
fontFamily: "inherit",
|
|
87
|
-
}}
|
|
88
|
-
>
|
|
89
|
-
Click me
|
|
90
|
-
</button>
|
|
91
|
-
</div>
|
|
92
|
-
</TransformComponent>
|
|
93
|
-
<StateBadge />
|
|
94
|
-
</div>
|
|
95
|
-
</>
|
|
96
|
-
)}
|
|
97
|
-
</TransformWrapper>
|
|
98
|
-
</div>
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
<Meta
|
|
102
|
-
title="Components/Controls"
|
|
103
|
-
component={TransformWrapper}
|
|
104
|
-
argTypes={argsTypes}
|
|
105
|
-
/>
|
|
106
|
-
|
|
107
|
-
# Controls
|
|
108
|
-
|
|
109
|
-
The **Controls** component provides a floating toolbar with zoom in, zoom out,
|
|
110
|
-
reset, and center actions. It uses the render-props pattern to access the
|
|
111
|
-
transform API. The state badge demonstrates `useTransformComponent` for
|
|
112
|
-
real-time state display.
|
|
113
|
-
|
|
114
|
-
<Canvas>
|
|
115
|
-
<Story name="Controls">{(args) => <Template {...args} />}</Story>
|
|
116
|
-
</Canvas>
|
|
117
|
-
|
|
118
|
-
## Component API
|
|
119
|
-
|
|
120
|
-
<ArgsTable story="Controls" />
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import React, { useState, useCallback } from "react";
|
|
2
|
-
|
|
3
|
-
import { TransformWrapper, TransformComponent } from "../../../components";
|
|
4
|
-
import { Controls, normalizeArgs, viewerChrome } from "../../utils";
|
|
5
|
-
import { useTransformComponent } from "../../../hooks";
|
|
6
|
-
import smallImg from "../../assets/small-image.jpg";
|
|
7
|
-
import mediumImg from "../../assets/medium-image.jpg";
|
|
8
|
-
import bigImg from "../../assets/big-image.jpeg";
|
|
9
|
-
|
|
10
|
-
const SIZES = [
|
|
11
|
-
{ key: "small", label: "Small", src: smallImg },
|
|
12
|
-
{ key: "medium", label: "Medium", src: mediumImg },
|
|
13
|
-
{ key: "big", label: "Big", src: bigImg },
|
|
14
|
-
] as const;
|
|
15
|
-
|
|
16
|
-
type SizeKey = (typeof SIZES)[number]["key"];
|
|
17
|
-
|
|
18
|
-
function DimensionsBadge() {
|
|
19
|
-
return useTransformComponent(({ state }) => (
|
|
20
|
-
<div
|
|
21
|
-
style={{
|
|
22
|
-
position: "absolute",
|
|
23
|
-
bottom: 16,
|
|
24
|
-
right: 16,
|
|
25
|
-
zIndex: 10,
|
|
26
|
-
padding: "5px 12px",
|
|
27
|
-
borderRadius: 8,
|
|
28
|
-
background: "rgba(10, 10, 18, 0.78)",
|
|
29
|
-
backdropFilter: "blur(12px)",
|
|
30
|
-
WebkitBackdropFilter: "blur(12px)",
|
|
31
|
-
border: "1px solid rgba(255,255,255,0.1)",
|
|
32
|
-
color: "rgba(255,255,255,0.7)",
|
|
33
|
-
fontSize: 11,
|
|
34
|
-
fontWeight: 600,
|
|
35
|
-
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
36
|
-
letterSpacing: "0.02em",
|
|
37
|
-
userSelect: "none",
|
|
38
|
-
pointerEvents: "none",
|
|
39
|
-
}}
|
|
40
|
-
>
|
|
41
|
-
{state.scale.toFixed(2)}x
|
|
42
|
-
</div>
|
|
43
|
-
));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const Example: React.FC<any> = (args: any) => {
|
|
47
|
-
const [activeSize, setActiveSize] = useState<SizeKey>("medium");
|
|
48
|
-
|
|
49
|
-
const activeEntry = SIZES.find((s) => s.key === activeSize)!;
|
|
50
|
-
|
|
51
|
-
const handleSizeChange = useCallback((key: SizeKey) => {
|
|
52
|
-
setActiveSize(key);
|
|
53
|
-
}, []);
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<div
|
|
57
|
-
style={{
|
|
58
|
-
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
59
|
-
display: "flex",
|
|
60
|
-
flexDirection: "column",
|
|
61
|
-
width: "100%",
|
|
62
|
-
height: "100%",
|
|
63
|
-
minHeight: 0,
|
|
64
|
-
maxWidth: "100%",
|
|
65
|
-
boxSizing: "border-box",
|
|
66
|
-
}}
|
|
67
|
-
>
|
|
68
|
-
<TransformWrapper {...normalizeArgs(args)} key={activeSize} centerOnInit>
|
|
69
|
-
{(utils) => (
|
|
70
|
-
<div
|
|
71
|
-
style={{
|
|
72
|
-
flex: 1,
|
|
73
|
-
minHeight: 0,
|
|
74
|
-
width: "100%",
|
|
75
|
-
position: "relative",
|
|
76
|
-
}}
|
|
77
|
-
>
|
|
78
|
-
<Controls {...utils} position="top-center" />
|
|
79
|
-
<DimensionsBadge />
|
|
80
|
-
<TransformComponent
|
|
81
|
-
wrapperStyle={{
|
|
82
|
-
position: "absolute",
|
|
83
|
-
inset: 0,
|
|
84
|
-
width: "100%",
|
|
85
|
-
height: "100%",
|
|
86
|
-
...viewerChrome,
|
|
87
|
-
}}
|
|
88
|
-
>
|
|
89
|
-
<img
|
|
90
|
-
src={activeEntry.src}
|
|
91
|
-
alt={`${activeEntry.label} preview`}
|
|
92
|
-
style={{ display: "block" }}
|
|
93
|
-
/>
|
|
94
|
-
</TransformComponent>
|
|
95
|
-
</div>
|
|
96
|
-
)}
|
|
97
|
-
</TransformWrapper>
|
|
98
|
-
|
|
99
|
-
<div
|
|
100
|
-
style={{
|
|
101
|
-
display: "inline-flex",
|
|
102
|
-
alignItems: "center",
|
|
103
|
-
alignSelf: "center",
|
|
104
|
-
gap: 2,
|
|
105
|
-
marginTop: 12,
|
|
106
|
-
flexShrink: 0,
|
|
107
|
-
padding: 4,
|
|
108
|
-
borderRadius: 12,
|
|
109
|
-
background: "rgba(15, 15, 20, 0.72)",
|
|
110
|
-
backdropFilter: "blur(16px) saturate(1.6)",
|
|
111
|
-
WebkitBackdropFilter: "blur(16px) saturate(1.6)",
|
|
112
|
-
border: "1px solid rgba(255,255,255,0.08)",
|
|
113
|
-
boxShadow:
|
|
114
|
-
"0 2px 8px rgba(0,0,0,0.3), 0 0 0 0.5px rgba(255,255,255,0.04) inset",
|
|
115
|
-
}}
|
|
116
|
-
>
|
|
117
|
-
{SIZES.map((size) => {
|
|
118
|
-
const isActive = activeSize === size.key;
|
|
119
|
-
return (
|
|
120
|
-
<button
|
|
121
|
-
key={size.key}
|
|
122
|
-
type="button"
|
|
123
|
-
onClick={() => handleSizeChange(size.key)}
|
|
124
|
-
style={{
|
|
125
|
-
display: "flex",
|
|
126
|
-
alignItems: "center",
|
|
127
|
-
justifyContent: "center",
|
|
128
|
-
height: 32,
|
|
129
|
-
padding: "0 16px",
|
|
130
|
-
border: "none",
|
|
131
|
-
borderRadius: 8,
|
|
132
|
-
background: isActive ? "rgba(255,255,255,0.12)" : "transparent",
|
|
133
|
-
color: isActive ? "#fff" : "rgba(255,255,255,0.5)",
|
|
134
|
-
fontSize: 12,
|
|
135
|
-
fontWeight: 600,
|
|
136
|
-
letterSpacing: "0.02em",
|
|
137
|
-
cursor: "pointer",
|
|
138
|
-
fontFamily: "inherit",
|
|
139
|
-
transition: "background 0.15s ease, color 0.15s ease",
|
|
140
|
-
}}
|
|
141
|
-
>
|
|
142
|
-
{size.label}
|
|
143
|
-
</button>
|
|
144
|
-
);
|
|
145
|
-
})}
|
|
146
|
-
</div>
|
|
147
|
-
</div>
|
|
148
|
-
);
|
|
149
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, ArgsTable, Canvas } from "@storybook/blocks";
|
|
2
|
-
|
|
3
|
-
import { TransformWrapper } from "../../../components";
|
|
4
|
-
import { argsTypes } from "../../types/args.types.ts";
|
|
5
|
-
import { Example } from "./example";
|
|
6
|
-
|
|
7
|
-
export const Template = (args) => (
|
|
8
|
-
<div
|
|
9
|
-
style={{
|
|
10
|
-
width: "100%",
|
|
11
|
-
maxWidth: 640,
|
|
12
|
-
height: "min(420px, 52vh)",
|
|
13
|
-
margin: "0 auto",
|
|
14
|
-
boxSizing: "border-box",
|
|
15
|
-
}}
|
|
16
|
-
>
|
|
17
|
-
<Example {...args} />
|
|
18
|
-
</div>
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
<Meta
|
|
22
|
-
title="Basic/Image"
|
|
23
|
-
component={TransformWrapper}
|
|
24
|
-
argTypes={argsTypes}
|
|
25
|
-
/>
|
|
26
|
-
|
|
27
|
-
# Image
|
|
28
|
-
|
|
29
|
-
The most common use-case: wrap an **image** in `TransformWrapper` and
|
|
30
|
-
`TransformComponent` to make it zoomable and pannable. The preview is sized like
|
|
31
|
-
**Responsive Image** so it stays inside the Storybook canvas (`max-width` 640px,
|
|
32
|
-
`height: min(420px, 52vh)`). The viewer fills that area; use the **tab switcher**
|
|
33
|
-
below to swap between three image sizes and see how the library handles
|
|
34
|
-
different content dimensions.
|
|
35
|
-
|
|
36
|
-
Pan by dragging, zoom with the scroll wheel or pinch gesture, and use the
|
|
37
|
-
floating controls to zoom in, zoom out, reset, or center the view. The scale
|
|
38
|
-
badge in the corner tracks the current zoom level in real time.
|
|
39
|
-
|
|
40
|
-
<Canvas>
|
|
41
|
-
<Story name="Image">{(args) => <Template {...args} />}</Story>
|
|
42
|
-
</Canvas>
|
|
43
|
-
|
|
44
|
-
## Component API
|
|
45
|
-
|
|
46
|
-
<ArgsTable story="Image" />
|