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.
Files changed (82) hide show
  1. package/package.json +4 -3
  2. package/src/stories/assets/big-image.jpeg +0 -0
  3. package/src/stories/assets/map.jpg +0 -0
  4. package/src/stories/assets/medium-image.jpg +0 -0
  5. package/src/stories/assets/pin.svg +0 -1
  6. package/src/stories/assets/small-image.jpg +0 -0
  7. package/src/stories/assets/svg-example.svg +0 -14
  8. package/src/stories/docs/DocTable.tsx +0 -59
  9. package/src/stories/docs/HandlerCards.tsx +0 -102
  10. package/src/stories/docs/Introduction.stories.mdx +0 -135
  11. package/src/stories/docs/PropTable.tsx +0 -116
  12. package/src/stories/docs/docs.module.css +0 -370
  13. package/src/stories/docs/handlers.stories.mdx +0 -7
  14. package/src/stories/docs/handlers.tsx +0 -111
  15. package/src/stories/docs/props.stories.mdx +0 -11
  16. package/src/stories/docs/props.tsx +0 -571
  17. package/src/stories/examples/axis-lock/axis-lock.stories.mdx +0 -35
  18. package/src/stories/examples/axis-lock/example.tsx +0 -114
  19. package/src/stories/examples/bounds/bounds.data.tsx +0 -191
  20. package/src/stories/examples/bounds/bounds.stories.mdx +0 -99
  21. package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +0 -206
  22. package/src/stories/examples/cinema/cinema-data.tsx +0 -578
  23. package/src/stories/examples/cinema/cinema.stories.mdx +0 -30
  24. package/src/stories/examples/cinema/example.tsx +0 -378
  25. package/src/stories/examples/cinema/image.png +0 -0
  26. package/src/stories/examples/content/content.stories.mdx +0 -172
  27. package/src/stories/examples/content/mixed-content.data.tsx +0 -624
  28. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -34
  29. package/src/stories/examples/content-rerendering/example.tsx +0 -631
  30. package/src/stories/examples/controls/controls.stories.mdx +0 -120
  31. package/src/stories/examples/image/example.tsx +0 -149
  32. package/src/stories/examples/image/image.stories.mdx +0 -46
  33. package/src/stories/examples/image-annotations/example.tsx +0 -1442
  34. package/src/stories/examples/image-annotations/image-annotations.stories.mdx +0 -39
  35. package/src/stories/examples/image-responsive/example.tsx +0 -152
  36. package/src/stories/examples/image-responsive/image-responsive.stories.mdx +0 -51
  37. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -107
  38. package/src/stories/examples/initial-transform/example.tsx +0 -233
  39. package/src/stories/examples/initial-transform/initial-transform.stories.mdx +0 -37
  40. package/src/stories/examples/keep-scale/example.tsx +0 -882
  41. package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -30
  42. package/src/stories/examples/keep-scale/map.stories.mdx +0 -28
  43. package/src/stories/examples/medical-viewer/chest-xray.tsx +0 -246
  44. package/src/stories/examples/medical-viewer/example.tsx +0 -690
  45. package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +0 -49
  46. package/src/stories/examples/mini-map/example.tsx +0 -122
  47. package/src/stories/examples/mini-map/mini-map.stories.mdx +0 -26
  48. package/src/stories/examples/miro/example.tsx +0 -1573
  49. package/src/stories/examples/miro/miro.stories.mdx +0 -31
  50. package/src/stories/examples/padding/example.tsx +0 -147
  51. package/src/stories/examples/padding/padding.stories.mdx +0 -35
  52. package/src/stories/examples/product-card/example.tsx +0 -594
  53. package/src/stories/examples/product-card/product-card.stories.mdx +0 -29
  54. package/src/stories/examples/stadium/example.tsx +0 -1040
  55. package/src/stories/examples/stadium/stadium-data.ts +0 -224
  56. package/src/stories/examples/stadium/stadium.stories.mdx +0 -32
  57. package/src/stories/examples/stress/example.tsx +0 -59
  58. package/src/stories/examples/stress/stress-test.stories.mdx +0 -28
  59. package/src/stories/examples/svg-zoom-to-element/creativity.svg +0 -143
  60. package/src/stories/examples/svg-zoom-to-element/example.tsx +0 -95
  61. package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
  62. package/src/stories/examples/text-selection/example.tsx +0 -221
  63. package/src/stories/examples/text-selection/text-selection.stories.mdx +0 -31
  64. package/src/stories/examples/velocity/example.tsx +0 -908
  65. package/src/stories/examples/velocity/velocity.stories.mdx +0 -35
  66. package/src/stories/examples/virtualize/example.tsx +0 -239
  67. package/src/stories/examples/virtualize/virtualize.stories.mdx +0 -84
  68. package/src/stories/examples/zoom-to-element/example.tsx +0 -219
  69. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -31
  70. package/src/stories/hooks/use-controls.stories.mdx +0 -86
  71. package/src/stories/hooks/use-transform-component.stories.mdx +0 -108
  72. package/src/stories/hooks/use-transform-context.stories.mdx +0 -92
  73. package/src/stories/hooks/use-transform-effect.stories.mdx +0 -114
  74. package/src/stories/hooks/use-transform-init.stories.mdx +0 -105
  75. package/src/stories/types/args.types.ts +0 -192
  76. package/src/stories/utils/args.utils.ts +0 -35
  77. package/src/stories/utils/bounds-overlay.tsx +0 -168
  78. package/src/stories/utils/code.utils.tsx +0 -22
  79. package/src/stories/utils/controls.utils.tsx +0 -347
  80. package/src/stories/utils/index.ts +0 -5
  81. package/src/stories/utils/styles.module.css +0 -223
  82. package/src/stories/utils/viewer.styles.ts +0 -34
@@ -1,378 +0,0 @@
1
- import React, { useState, useRef } from "react";
2
-
3
- import { TransformWrapper, TransformComponent } from "../../../components";
4
- import { normalizeArgs, Controls, CloseIcon, viewerChrome } from "../../utils";
5
- import {
6
- CinemaLayout,
7
- CATEGORY_STYLES,
8
- CANVAS_WIDTH,
9
- CANVAS_HEIGHT,
10
- ROWS,
11
- OCCUPIED,
12
- } from "./cinema-data";
13
- import type { SeatInfo } from "./cinema-data";
14
-
15
- type Api = {
16
- zoomToElement: (id: string, scale?: number) => void;
17
- resetTransform: () => void;
18
- zoomIn: () => void;
19
- zoomOut: () => void;
20
- };
21
-
22
- function SeatBadge({ seat }: { seat: SeatInfo | null }) {
23
- if (!seat) return null;
24
- const cat = CATEGORY_STYLES[seat.category];
25
-
26
- return (
27
- <div
28
- style={{
29
- position: "absolute",
30
- top: 30,
31
- left: 300,
32
- zIndex: 10,
33
- padding: "6px 14px",
34
- borderRadius: 10,
35
- background: "rgba(10, 10, 18, 0.82)",
36
- backdropFilter: "blur(12px)",
37
- WebkitBackdropFilter: "blur(12px)",
38
- border: `1px solid ${cat.border}`,
39
- display: "flex",
40
- alignItems: "center",
41
- gap: 10,
42
- fontFamily: "system-ui, -apple-system, sans-serif",
43
- }}
44
- >
45
- <span
46
- style={{
47
- width: 10,
48
- height: 10,
49
- borderRadius: 3,
50
- background: cat.bg,
51
- flexShrink: 0,
52
- }}
53
- />
54
- <span
55
- style={{
56
- color: "#fff",
57
- fontSize: 12,
58
- fontWeight: 600,
59
- whiteSpace: "nowrap",
60
- }}
61
- >
62
- Row {seat.row} · Seat {seat.number}
63
- </span>
64
- <span
65
- style={{
66
- color: "rgba(255,255,255,0.5)",
67
- fontSize: 11,
68
- whiteSpace: "nowrap",
69
- }}
70
- >
71
- {cat.label} · {cat.price}
72
- </span>
73
- </div>
74
- );
75
- }
76
-
77
- function SeatMap({
78
- selectedId,
79
- onSelect,
80
- onReset,
81
- }: {
82
- selectedId: string | null;
83
- onSelect: (seat: SeatInfo) => void;
84
- onReset: () => void;
85
- }) {
86
- return (
87
- <div style={{ maxWidth: 800, marginTop: 20 }}>
88
- <div
89
- style={{
90
- display: "flex",
91
- alignItems: "center",
92
- justifyContent: "space-between",
93
- marginBottom: 12,
94
- }}
95
- >
96
- <span
97
- style={{
98
- fontSize: 12,
99
- fontWeight: 600,
100
- color: "#888",
101
- letterSpacing: "1px",
102
- textTransform: "uppercase",
103
- }}
104
- >
105
- Select a seat
106
- </span>
107
-
108
- <div style={{ display: "flex", gap: 14, alignItems: "center" }}>
109
- {(["standard", "premium", "vip"] as const).map((cat) => (
110
- <span
111
- key={cat}
112
- style={{
113
- display: "flex",
114
- alignItems: "center",
115
- gap: 5,
116
- fontSize: 11,
117
- color: "#777",
118
- }}
119
- >
120
- <span
121
- style={{
122
- width: 8,
123
- height: 8,
124
- borderRadius: 2,
125
- background: CATEGORY_STYLES[cat].border,
126
- }}
127
- />
128
- {CATEGORY_STYLES[cat].label}
129
- </span>
130
- ))}
131
- <span
132
- style={{
133
- display: "flex",
134
- alignItems: "center",
135
- gap: 5,
136
- fontSize: 11,
137
- color: "#555",
138
- }}
139
- >
140
- <span
141
- style={{
142
- width: 8,
143
- height: 8,
144
- borderRadius: 2,
145
- background: "#374151",
146
- opacity: 0.4,
147
- }}
148
- />
149
- Taken
150
- </span>
151
- </div>
152
- </div>
153
-
154
- <div
155
- style={{
156
- background: "#0c0c1a",
157
- borderRadius: 10,
158
- padding: "16px 12px",
159
- display: "flex",
160
- flexDirection: "column",
161
- gap: 4,
162
- alignItems: "center",
163
- }}
164
- >
165
- <div
166
- style={{
167
- width: 120,
168
- height: 3,
169
- borderRadius: 2,
170
- background: "rgba(180, 200, 255, 0.25)",
171
- marginBottom: 10,
172
- }}
173
- />
174
- <span
175
- style={{
176
- fontSize: 9,
177
- color: "rgba(255,255,255,0.2)",
178
- letterSpacing: 4,
179
- textTransform: "uppercase",
180
- marginBottom: 8,
181
- }}
182
- >
183
- Screen
184
- </span>
185
-
186
- {ROWS.map((row) => (
187
- <div
188
- key={row.label}
189
- style={{
190
- display: "flex",
191
- alignItems: "center",
192
- gap: 2,
193
- }}
194
- >
195
- <span
196
- style={{
197
- width: 16,
198
- fontSize: 10,
199
- fontWeight: 600,
200
- color: "rgba(255,255,255,0.2)",
201
- textAlign: "right",
202
- marginRight: 4,
203
- flexShrink: 0,
204
- }}
205
- >
206
- {row.label}
207
- </span>
208
-
209
- {Array.from({ length: row.count }, (_, i) => {
210
- const num = i + 1;
211
- const seatId = `seat-${row.label}-${num}`;
212
- const lookupId = `${row.label}-${num}`;
213
- const occupied = OCCUPIED.has(lookupId);
214
- const selected = selectedId === seatId;
215
- const cat = CATEGORY_STYLES[row.category];
216
- const [leftSection, centerSection] = row.sections;
217
- const isAisle =
218
- num === leftSection + 1 ||
219
- num === leftSection + centerSection + 1;
220
-
221
- let seatBg: string;
222
- if (occupied) {
223
- seatBg = "rgba(55, 65, 81, 0.3)";
224
- } else if (selected) {
225
- seatBg = "#059669";
226
- } else {
227
- seatBg = cat.border;
228
- }
229
-
230
- return (
231
- <button
232
- key={seatId}
233
- type="button"
234
- title={
235
- occupied
236
- ? `${row.label}${num} — Taken`
237
- : `${row.label}${num} — ${cat.label}`
238
- }
239
- onClick={() => {
240
- if (!occupied) {
241
- onSelect({
242
- id: seatId,
243
- row: row.label,
244
- number: num,
245
- category: row.category,
246
- });
247
- }
248
- }}
249
- style={{
250
- width: 18,
251
- height: 18,
252
- padding: 0,
253
- borderRadius: 3,
254
- border: selected
255
- ? "2px solid #34d399"
256
- : "1px solid transparent",
257
- background: seatBg,
258
- opacity: occupied ? 0.35 : 1,
259
- cursor: occupied ? "default" : "pointer",
260
- fontSize: 7,
261
- fontWeight: 700,
262
- color: occupied
263
- ? "rgba(255,255,255,0.15)"
264
- : "rgba(255,255,255,0.7)",
265
- fontFamily: "inherit",
266
- display: "flex",
267
- alignItems: "center",
268
- justifyContent: "center",
269
- marginLeft: isAisle ? 6 : 0,
270
- }}
271
- >
272
- {num}
273
- </button>
274
- );
275
- })}
276
- </div>
277
- ))}
278
-
279
- {selectedId && (
280
- <button
281
- type="button"
282
- onClick={onReset}
283
- style={{
284
- marginTop: 10,
285
- padding: "5px 16px",
286
- borderRadius: 6,
287
- border: "1px solid rgba(255,255,255,0.15)",
288
- background: "rgba(255,255,255,0.06)",
289
- color: "#aaa",
290
- fontSize: 11,
291
- fontWeight: 600,
292
- cursor: "pointer",
293
- fontFamily: "inherit",
294
- }}
295
- >
296
- Reset view
297
- </button>
298
- )}
299
- </div>
300
- </div>
301
- );
302
- }
303
-
304
- export const Example: React.FC<any> = (args: any) => {
305
- const [selectedSeat, setSelectedSeat] = useState<SeatInfo | null>(null);
306
- const apiRef = useRef<Api | null>(null);
307
-
308
- const handleSeatSelect = (seat: SeatInfo) => {
309
- setSelectedSeat(seat);
310
- apiRef.current?.zoomToElement(seat.id, 4);
311
- };
312
-
313
- const handleReset = () => {
314
- setSelectedSeat(null);
315
- apiRef.current?.resetTransform();
316
- };
317
-
318
- return (
319
- <div style={{ fontFamily: "system-ui, -apple-system, sans-serif" }}>
320
- <TransformWrapper
321
- {...normalizeArgs(args)}
322
- initialScale={0.5}
323
- minScale={0.5}
324
- maxScale={8}
325
- limitToBounds
326
- centerZoomedOut
327
- centerOnInit
328
- >
329
- {(api) => {
330
- apiRef.current = api;
331
- return (
332
- <>
333
- <Controls
334
- {...api}
335
- extraButtons={
336
- selectedSeat
337
- ? [
338
- {
339
- label: "Deselect seat",
340
- icon: <CloseIcon />,
341
- onClick: handleReset,
342
- },
343
- ]
344
- : []
345
- }
346
- />
347
- <SeatBadge seat={selectedSeat} />
348
- <TransformComponent
349
- wrapperStyle={{
350
- ...viewerChrome,
351
- width: "800px",
352
- maxWidth: "100%",
353
- height: "600px",
354
- maxHeight: "70vh",
355
- }}
356
- contentStyle={{
357
- width: CANVAS_WIDTH,
358
- height: CANVAS_HEIGHT,
359
- }}
360
- >
361
- <CinemaLayout
362
- selectedSeat={selectedSeat?.id ?? null}
363
- onSeatClick={handleSeatSelect}
364
- />
365
- </TransformComponent>
366
- </>
367
- );
368
- }}
369
- </TransformWrapper>
370
-
371
- <SeatMap
372
- selectedId={selectedSeat?.id ?? null}
373
- onSelect={handleSeatSelect}
374
- onReset={handleReset}
375
- />
376
- </div>
377
- );
378
- };
@@ -1,172 +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 { DocTable } from "../../docs/DocTable.tsx";
7
- import { MixedContent } from "./mixed-content.data";
8
-
9
- export const Template = (args) => {
10
- const normalized = normalizeArgs(args);
11
- return (
12
- <TransformWrapper
13
- {...normalized}
14
- panning={{ excluded: ["panningDisabled"], ...normalized.panning }}
15
- wheel={{ excluded: ["wheelDisabled"], ...normalized.wheel }}
16
- pinch={{ excluded: ["pinchDisabled"], ...normalized.pinch }}
17
- >
18
- {(utils) => (
19
- <div style={{ fontFamily: "system-ui, -apple-system, sans-serif", position: "relative" }}>
20
- <Controls {...utils} position="bottom-left" />
21
- <TransformComponent
22
- wrapperStyle={{
23
- ...viewerChrome,
24
- width: "600px",
25
- height: "520px",
26
- maxWidth: "85vw",
27
- maxHeight: "80vh",
28
- }}
29
- contentStyle={{
30
- width: "100%",
31
- }}
32
- >
33
- <MixedContent />
34
- </TransformComponent>
35
- </div>
36
- )}
37
- </TransformWrapper>
38
- );
39
- };
40
-
41
- <Meta
42
- title="Basic/Mixed Content"
43
- component={TransformWrapper}
44
- argTypes={{
45
- ...argsTypes,
46
- "wheel.excluded": {
47
- ...argsTypes["wheel.excluded"],
48
- defaultValue: ["wheelDisabled"],
49
- },
50
- "panning.excluded": {
51
- ...argsTypes["panning.excluded"],
52
- defaultValue: ["panningDisabled"],
53
- },
54
- "pinch.excluded": {
55
- ...argsTypes["pinch.excluded"],
56
- defaultValue: ["pinchDisabled"],
57
- },
58
- }}
59
- />
60
-
61
- # Mixed Content
62
-
63
- Real-world zoomable interfaces rarely contain a single image—they hold
64
- **dashboards, text, charts, buttons, scrollable lists**, and other interactive
65
- widgets. This story proves the library handles them all, including **gesture
66
- exclusion zones** that let parts of the content opt out of specific
67
- interactions.
68
-
69
- ## Why exclusion zones matter
70
-
71
- When your transformed content contains scrollable areas, clickable controls,
72
- or embedded widgets, you often need to **prevent certain gestures from
73
- reaching the library** on specific elements. Without exclusion, a user trying
74
- to scroll a list would instead pan the entire canvas—or a pinch to zoom an
75
- embedded map would zoom the outer viewport.
76
-
77
- The library solves this with the **`excluded` array** available on `panning`,
78
- `wheel`, `pinch`, and `doubleClick` options. Pass one or more **CSS class
79
- names**; any event that originates on (or inside) an element carrying that
80
- class is silently ignored by that gesture handler.
81
-
82
- ## How it works
83
-
84
- ```tsx
85
- <TransformWrapper
86
- panning={{ excluded: ["panningDisabled"] }}
87
- wheel={{ excluded: ["wheelDisabled"] }}
88
- pinch={{ excluded: ["pinchDisabled"] }}
89
- >
90
- <TransformComponent>
91
- <div className="panningDisabled">
92
- {/* Drag here does NOT pan the canvas */}
93
- <ScrollableList />
94
- </div>
95
- <div className="wheelDisabled">
96
- {/* Mouse wheel here does NOT zoom */}
97
- <SomeWidget />
98
- </div>
99
- <div className="pinchDisabled">
100
- {/* Touch pinch here does NOT zoom */}
101
- <EmbeddedMap />
102
- </div>
103
- <p>Normal content — all gestures work here</p>
104
- </TransformComponent>
105
- </TransformWrapper>
106
- ```
107
-
108
- <DocTable
109
- columns={[
110
- { header: "Prop" },
111
- { header: "Gesture blocked", style: "type" },
112
- { header: "Typical use case", style: "text" },
113
- ]}
114
- rows={[
115
- ["panning.excluded", "Click-and-drag", "Scrollable lists, text selection, draggable widgets"],
116
- ["wheel.excluded", "Mouse wheel / trackpad scroll", "Dropdowns, inner scroll containers, code editors"],
117
- ["pinch.excluded", "Two-finger pinch", "Embedded maps, multi-touch canvases, sliders"],
118
- ["doubleClick.excluded", "Double-click zoom", "Editable text, buttons that need double-click"],
119
- ]}
120
- />
121
-
122
- > **No JavaScript wiring required.** Add the CSS class to the element (or a
123
- > parent), and the library reads it from the event target's class list at
124
- > interaction time. Classes are checked via `classList.contains()`, so they
125
- > work on any depth of nesting.
126
-
127
- ## Try it
128
-
129
- Pan, zoom, and pinch the dashboard below. Then interact with the **dashed
130
- exclusion zones** — notice how the specific gesture is suppressed inside each
131
- one while everything else still works normally. Use the controls to zoom in
132
- and out programmatically.
133
-
134
- <Canvas>
135
- <Story name="Mixed Content">{(args) => <Template {...args} />}</Story>
136
- </Canvas>
137
-
138
- ## Combining exclusions
139
-
140
- You can stack multiple exclusion classes on a single element to block several
141
- gestures at once:
142
-
143
- ```tsx
144
- <div className="panningDisabled wheelDisabled">
145
- {/* Both panning AND wheel zoom are blocked here */}
146
- </div>
147
- ```
148
-
149
- The exclusion is **per-gesture**, so unrelated gestures still pass through.
150
- For example, an element with `panningDisabled` still responds to wheel zoom
151
- and pinch zoom.
152
-
153
- ## Common patterns
154
-
155
- **Scrollable sidebar inside a zoomable canvas** — wrap the sidebar in a
156
- `panningDisabled wheelDisabled` container so vertical scrolling and wheel
157
- events stay local.
158
-
159
- **Interactive form controls** — add `panningDisabled` to the form wrapper so
160
- users can click inputs, drag sliders, and select text without moving the
161
- canvas.
162
-
163
- **Nested zoomable region** — add `pinchDisabled wheelDisabled` to the inner
164
- region and attach a second `TransformWrapper` inside it for independent zoom
165
- control.
166
-
167
- ## Component API
168
-
169
- Use the controls below to toggle individual gesture settings and see how they
170
- affect interaction with the dashboard.
171
-
172
- <ArgsTable story="Mixed Content" />