react-zoom-pan-pinch 4.0.0 → 4.0.2
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 +4 -3
- 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,95 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { TransformComponent, TransformWrapper } from "components";
|
|
4
|
-
import {
|
|
5
|
-
Controls,
|
|
6
|
-
NumberedTargetIcon,
|
|
7
|
-
normalizeArgs,
|
|
8
|
-
viewerChrome,
|
|
9
|
-
} from "../../utils";
|
|
10
|
-
import { ReactComponent as Creativity } from "./creativity.svg";
|
|
11
|
-
|
|
12
|
-
const ZOOMABLE_IDS = ["element1", "element2", "element3"];
|
|
13
|
-
|
|
14
|
-
function findZoomableId(el: HTMLElement | SVGElement | null): string | null {
|
|
15
|
-
let node = el;
|
|
16
|
-
while (node) {
|
|
17
|
-
if (node.id && ZOOMABLE_IDS.includes(node.id)) return node.id;
|
|
18
|
-
node = node.parentElement as HTMLElement | null;
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const Example: React.FC<any> = (args: any) => {
|
|
24
|
-
return (
|
|
25
|
-
<div style={{ fontFamily: "system-ui, -apple-system, sans-serif" }}>
|
|
26
|
-
<style>{`
|
|
27
|
-
#element1, #element2, #element3 {
|
|
28
|
-
cursor: pointer;
|
|
29
|
-
transition: filter 0.2s ease, opacity 0.2s ease;
|
|
30
|
-
}
|
|
31
|
-
#element1:hover, #element2:hover, #element3:hover {
|
|
32
|
-
filter: brightness(1.3) drop-shadow(0 0 6px rgba(99, 102, 241, 0.6));
|
|
33
|
-
opacity: 0.85;
|
|
34
|
-
}
|
|
35
|
-
`}</style>
|
|
36
|
-
<TransformWrapper {...normalizeArgs(args)} centerOnInit>
|
|
37
|
-
{(utils) => {
|
|
38
|
-
const handleSvgClick = (e: React.MouseEvent) => {
|
|
39
|
-
const id = findZoomableId(e.target as HTMLElement);
|
|
40
|
-
if (id) utils.zoomToElement(id);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<>
|
|
45
|
-
<Controls
|
|
46
|
-
{...utils}
|
|
47
|
-
extraButtons={[
|
|
48
|
-
{
|
|
49
|
-
label: "Focus element 1",
|
|
50
|
-
icon: <NumberedTargetIcon n={1} />,
|
|
51
|
-
onClick: () => utils.zoomToElement("element1"),
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
label: "Focus element 2",
|
|
55
|
-
icon: <NumberedTargetIcon n={2} />,
|
|
56
|
-
onClick: () => utils.zoomToElement("element2"),
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
label: "Focus element 3",
|
|
60
|
-
icon: <NumberedTargetIcon n={3} />,
|
|
61
|
-
onClick: () => utils.zoomToElement("element3"),
|
|
62
|
-
},
|
|
63
|
-
]}
|
|
64
|
-
/>
|
|
65
|
-
<TransformComponent
|
|
66
|
-
wrapperStyle={{
|
|
67
|
-
width: "500px",
|
|
68
|
-
height: "500px",
|
|
69
|
-
maxWidth: "80vw",
|
|
70
|
-
maxHeight: "75vh",
|
|
71
|
-
...viewerChrome,
|
|
72
|
-
}}
|
|
73
|
-
>
|
|
74
|
-
<div
|
|
75
|
-
role="button"
|
|
76
|
-
tabIndex={0}
|
|
77
|
-
aria-label="Click an SVG element to zoom to it"
|
|
78
|
-
onClick={handleSvgClick}
|
|
79
|
-
onKeyDown={(e) => {
|
|
80
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
81
|
-
e.preventDefault();
|
|
82
|
-
handleSvgClick(e as unknown as React.MouseEvent);
|
|
83
|
-
}
|
|
84
|
-
}}
|
|
85
|
-
>
|
|
86
|
-
<Creativity style={{ width: "100%" }} />
|
|
87
|
-
</div>
|
|
88
|
-
</TransformComponent>
|
|
89
|
-
</>
|
|
90
|
-
);
|
|
91
|
-
}}
|
|
92
|
-
</TransformWrapper>
|
|
93
|
-
</div>
|
|
94
|
-
);
|
|
95
|
-
};
|
|
@@ -1,28 +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";
|
|
5
|
-
import { Example } from "./example";
|
|
6
|
-
|
|
7
|
-
export const Template = (args) => <Example {...args} />;
|
|
8
|
-
|
|
9
|
-
<Meta
|
|
10
|
-
title="Advanced/SVG Zoom To Element"
|
|
11
|
-
component={TransformWrapper}
|
|
12
|
-
argTypes={argsTypes}
|
|
13
|
-
/>
|
|
14
|
-
|
|
15
|
-
# SVG Zoom To Element
|
|
16
|
-
|
|
17
|
-
Target elements **inside an SVG** by their `id` attribute. The control bar
|
|
18
|
-
buttons zoom to three different paths within the illustration. This works the
|
|
19
|
-
same way as HTML element targeting — `zoomToElement` finds the element by its
|
|
20
|
-
`id` and calculates the bounding box to frame it in view.
|
|
21
|
-
|
|
22
|
-
<Canvas>
|
|
23
|
-
<Story name="SVG Zoom To Element">{(args) => <Template {...args} />}</Story>
|
|
24
|
-
</Canvas>
|
|
25
|
-
|
|
26
|
-
## Component API
|
|
27
|
-
|
|
28
|
-
<ArgsTable story="SVG Zoom To Element" />
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { TransformWrapper, TransformComponent } from "../../../components";
|
|
4
|
-
import { Controls, normalizeArgs, viewerChrome } from "../../utils";
|
|
5
|
-
|
|
6
|
-
const font = 'Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
|
|
7
|
-
|
|
8
|
-
const SELECTABLE_CLASS = "selectable";
|
|
9
|
-
|
|
10
|
-
const codeStyle: React.CSSProperties = {
|
|
11
|
-
padding: "2px 6px",
|
|
12
|
-
borderRadius: 4,
|
|
13
|
-
background: "#e7e5e4",
|
|
14
|
-
color: "#c2410c",
|
|
15
|
-
fontSize: 12,
|
|
16
|
-
fontWeight: 600,
|
|
17
|
-
fontFamily: "'SF Mono', 'Fira Code', ui-monospace, monospace",
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const Example: React.FC<Record<string, unknown>> = (args) => {
|
|
21
|
-
const normalized = normalizeArgs(args);
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<div style={{ fontFamily: font, maxWidth: 720 }}>
|
|
25
|
-
<TransformWrapper
|
|
26
|
-
{...normalized}
|
|
27
|
-
centerOnInit
|
|
28
|
-
centerZoomedOut
|
|
29
|
-
panning={{ ...normalized.panning, excluded: [SELECTABLE_CLASS] }}
|
|
30
|
-
trackPadPanning={{ disabled: false }}
|
|
31
|
-
>
|
|
32
|
-
{(utils) => (
|
|
33
|
-
<div style={{ position: "relative" }}>
|
|
34
|
-
<Controls {...utils} />
|
|
35
|
-
<TransformComponent
|
|
36
|
-
wrapperStyle={{
|
|
37
|
-
...viewerChrome,
|
|
38
|
-
width: "100%",
|
|
39
|
-
height: "clamp(420px, 65vh, 600px)",
|
|
40
|
-
}}
|
|
41
|
-
contentStyle={{ width: 640 }}
|
|
42
|
-
>
|
|
43
|
-
<article
|
|
44
|
-
className={SELECTABLE_CLASS}
|
|
45
|
-
style={{
|
|
46
|
-
width: 640,
|
|
47
|
-
padding: "44px 48px",
|
|
48
|
-
boxSizing: "border-box",
|
|
49
|
-
background: "#fafaf9",
|
|
50
|
-
borderRadius: 12,
|
|
51
|
-
color: "#1c1917",
|
|
52
|
-
userSelect: "text",
|
|
53
|
-
cursor: "text",
|
|
54
|
-
}}
|
|
55
|
-
>
|
|
56
|
-
<div
|
|
57
|
-
style={{
|
|
58
|
-
display: "inline-block",
|
|
59
|
-
padding: "3px 10px",
|
|
60
|
-
borderRadius: 5,
|
|
61
|
-
background: "#e0e7ff",
|
|
62
|
-
color: "#4338ca",
|
|
63
|
-
fontSize: 10,
|
|
64
|
-
fontWeight: 700,
|
|
65
|
-
letterSpacing: "0.06em",
|
|
66
|
-
textTransform: "uppercase",
|
|
67
|
-
marginBottom: 16,
|
|
68
|
-
}}
|
|
69
|
-
>
|
|
70
|
-
Documentation
|
|
71
|
-
</div>
|
|
72
|
-
|
|
73
|
-
<h1
|
|
74
|
-
style={{
|
|
75
|
-
margin: "0 0 8px",
|
|
76
|
-
fontSize: 28,
|
|
77
|
-
fontWeight: 800,
|
|
78
|
-
letterSpacing: "-0.03em",
|
|
79
|
-
lineHeight: 1.2,
|
|
80
|
-
color: "#0c0a09",
|
|
81
|
-
}}
|
|
82
|
-
>
|
|
83
|
-
Text Selection
|
|
84
|
-
</h1>
|
|
85
|
-
|
|
86
|
-
<p
|
|
87
|
-
style={{
|
|
88
|
-
margin: "0 0 24px",
|
|
89
|
-
fontSize: 14,
|
|
90
|
-
lineHeight: 1.7,
|
|
91
|
-
color: "#57534e",
|
|
92
|
-
}}
|
|
93
|
-
>
|
|
94
|
-
By default the library disables text selection because
|
|
95
|
-
click-and-drag is used for panning. To allow text selection
|
|
96
|
-
inside specific areas, use the{" "}
|
|
97
|
-
<code style={codeStyle}>panning.excluded</code> option with a
|
|
98
|
-
CSS class name.
|
|
99
|
-
</p>
|
|
100
|
-
|
|
101
|
-
<div
|
|
102
|
-
style={{
|
|
103
|
-
padding: "16px 20px",
|
|
104
|
-
borderRadius: 8,
|
|
105
|
-
background: "#1e293b",
|
|
106
|
-
color: "#e2e8f0",
|
|
107
|
-
fontFamily:
|
|
108
|
-
"'SF Mono', 'Fira Code', ui-monospace, monospace",
|
|
109
|
-
fontSize: 12,
|
|
110
|
-
lineHeight: 1.7,
|
|
111
|
-
marginBottom: 24,
|
|
112
|
-
overflowX: "auto",
|
|
113
|
-
whiteSpace: "pre",
|
|
114
|
-
}}
|
|
115
|
-
>
|
|
116
|
-
{`<TransformWrapper
|
|
117
|
-
panning={{ excluded: ["selectable"] }}
|
|
118
|
-
>
|
|
119
|
-
<TransformComponent>
|
|
120
|
-
<article className="selectable">
|
|
121
|
-
<p>You can select this text!</p>
|
|
122
|
-
</article>
|
|
123
|
-
</TransformComponent>
|
|
124
|
-
</TransformWrapper>`}
|
|
125
|
-
</div>
|
|
126
|
-
|
|
127
|
-
<h2
|
|
128
|
-
style={{
|
|
129
|
-
margin: "0 0 12px",
|
|
130
|
-
fontSize: 18,
|
|
131
|
-
fontWeight: 700,
|
|
132
|
-
letterSpacing: "-0.02em",
|
|
133
|
-
color: "#1c1917",
|
|
134
|
-
}}
|
|
135
|
-
>
|
|
136
|
-
How it works
|
|
137
|
-
</h2>
|
|
138
|
-
|
|
139
|
-
<p
|
|
140
|
-
style={{
|
|
141
|
-
margin: "0 0 16px",
|
|
142
|
-
fontSize: 14,
|
|
143
|
-
lineHeight: 1.7,
|
|
144
|
-
color: "#57534e",
|
|
145
|
-
}}
|
|
146
|
-
>
|
|
147
|
-
The <code style={codeStyle}>excluded</code> array accepts CSS
|
|
148
|
-
class names. Any pointer event that originates on — or inside
|
|
149
|
-
— an element carrying that class is ignored by the panning
|
|
150
|
-
handler. This lets native browser text selection work normally
|
|
151
|
-
while all other areas remain pannable.
|
|
152
|
-
</p>
|
|
153
|
-
|
|
154
|
-
<ul
|
|
155
|
-
style={{
|
|
156
|
-
margin: "0 0 24px",
|
|
157
|
-
padding: "0 0 0 20px",
|
|
158
|
-
fontSize: 14,
|
|
159
|
-
lineHeight: 1.8,
|
|
160
|
-
color: "#57534e",
|
|
161
|
-
}}
|
|
162
|
-
>
|
|
163
|
-
<li>
|
|
164
|
-
<strong style={{ color: "#1c1917" }}>Click and drag</strong>{" "}
|
|
165
|
-
on this text to select it — panning is suppressed.
|
|
166
|
-
</li>
|
|
167
|
-
<li>
|
|
168
|
-
<strong style={{ color: "#1c1917" }}>Scroll wheel</strong>{" "}
|
|
169
|
-
zooms in/out, and{" "}
|
|
170
|
-
<strong style={{ color: "#1c1917" }}>
|
|
171
|
-
trackpad panning
|
|
172
|
-
</strong>{" "}
|
|
173
|
-
works normally (only click-drag is excluded).
|
|
174
|
-
</li>
|
|
175
|
-
<li>
|
|
176
|
-
<strong style={{ color: "#1c1917" }}>Ctrl+A / Cmd+A</strong>{" "}
|
|
177
|
-
selects all text inside the article.
|
|
178
|
-
</li>
|
|
179
|
-
</ul>
|
|
180
|
-
|
|
181
|
-
<div
|
|
182
|
-
style={{
|
|
183
|
-
padding: "14px 18px",
|
|
184
|
-
borderRadius: 8,
|
|
185
|
-
background: "#fef3c7",
|
|
186
|
-
border: "1px solid #fde68a",
|
|
187
|
-
fontSize: 13,
|
|
188
|
-
lineHeight: 1.6,
|
|
189
|
-
color: "#92400e",
|
|
190
|
-
}}
|
|
191
|
-
>
|
|
192
|
-
<strong>Tip:</strong> You can combine exclusions — add both{" "}
|
|
193
|
-
<code
|
|
194
|
-
style={{
|
|
195
|
-
...codeStyle,
|
|
196
|
-
background: "#fde68a",
|
|
197
|
-
color: "#78350f",
|
|
198
|
-
}}
|
|
199
|
-
>
|
|
200
|
-
panningDisabled
|
|
201
|
-
</code>{" "}
|
|
202
|
-
and{" "}
|
|
203
|
-
<code
|
|
204
|
-
style={{
|
|
205
|
-
...codeStyle,
|
|
206
|
-
background: "#fde68a",
|
|
207
|
-
color: "#78350f",
|
|
208
|
-
}}
|
|
209
|
-
>
|
|
210
|
-
wheelDisabled
|
|
211
|
-
</code>{" "}
|
|
212
|
-
to block both gestures on the same element.
|
|
213
|
-
</div>
|
|
214
|
-
</article>
|
|
215
|
-
</TransformComponent>
|
|
216
|
-
</div>
|
|
217
|
-
)}
|
|
218
|
-
</TransformWrapper>
|
|
219
|
-
</div>
|
|
220
|
-
);
|
|
221
|
-
};
|
|
@@ -1,31 +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) => <Example {...args} />;
|
|
8
|
-
|
|
9
|
-
<Meta
|
|
10
|
-
title="Basic/Text Selection"
|
|
11
|
-
component={TransformWrapper}
|
|
12
|
-
argTypes={argsTypes}
|
|
13
|
-
/>
|
|
14
|
-
|
|
15
|
-
# Text Selection
|
|
16
|
-
|
|
17
|
-
Allow users to **select and copy text** inside zoomable content. By default,
|
|
18
|
-
click-and-drag triggers panning, which prevents native text selection. Adding
|
|
19
|
-
a CSS class to the `panning.excluded` array tells the library to ignore
|
|
20
|
-
pointer events on that element — restoring normal browser text selection.
|
|
21
|
-
|
|
22
|
-
Try it: **click and drag** over the article text below to select it. Scroll
|
|
23
|
-
to zoom in, then select zoomed-in text — it works at every scale.
|
|
24
|
-
|
|
25
|
-
<Canvas>
|
|
26
|
-
<Story name="Text Selection">{(args) => <Template {...args} />}</Story>
|
|
27
|
-
</Canvas>
|
|
28
|
-
|
|
29
|
-
## Component API
|
|
30
|
-
|
|
31
|
-
<ArgsTable story="Text Selection" />
|