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.
Files changed (82) hide show
  1. package/package.json +3 -2
  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,578 +0,0 @@
1
- import React from "react";
2
-
3
- export const CANVAS_WIDTH = 1400;
4
- export const CANVAS_HEIGHT = 950;
5
-
6
- const CX = CANVAS_WIDTH / 2;
7
- const SEAT_SIZE = 30;
8
- const SEAT_GAP = 6;
9
- const AISLE_GAP = 24;
10
-
11
- type Category = "premium" | "standard" | "vip";
12
-
13
- interface RowDef {
14
- label: string;
15
- count: number;
16
- y: number;
17
- category: Category;
18
- curve: number;
19
- sections: [number, number, number];
20
- }
21
-
22
- export const ROWS: RowDef[] = [
23
- {
24
- label: "A",
25
- count: 10,
26
- y: 220,
27
- category: "premium",
28
- curve: 12,
29
- sections: [2, 6, 2],
30
- },
31
- {
32
- label: "B",
33
- count: 14,
34
- y: 268,
35
- category: "premium",
36
- curve: 10,
37
- sections: [3, 8, 3],
38
- },
39
- {
40
- label: "C",
41
- count: 16,
42
- y: 316,
43
- category: "standard",
44
- curve: 9,
45
- sections: [4, 8, 4],
46
- },
47
- {
48
- label: "D",
49
- count: 18,
50
- y: 364,
51
- category: "standard",
52
- curve: 8,
53
- sections: [4, 10, 4],
54
- },
55
- {
56
- label: "E",
57
- count: 20,
58
- y: 412,
59
- category: "standard",
60
- curve: 7,
61
- sections: [5, 10, 5],
62
- },
63
- {
64
- label: "F",
65
- count: 22,
66
- y: 460,
67
- category: "standard",
68
- curve: 6,
69
- sections: [5, 12, 5],
70
- },
71
- {
72
- label: "G",
73
- count: 22,
74
- y: 510,
75
- category: "standard",
76
- curve: 5,
77
- sections: [5, 12, 5],
78
- },
79
- {
80
- label: "H",
81
- count: 24,
82
- y: 568,
83
- category: "vip",
84
- curve: 4,
85
- sections: [6, 12, 6],
86
- },
87
- {
88
- label: "I",
89
- count: 24,
90
- y: 616,
91
- category: "vip",
92
- curve: 3.5,
93
- sections: [6, 12, 6],
94
- },
95
- {
96
- label: "J",
97
- count: 22,
98
- y: 674,
99
- category: "standard",
100
- curve: 3,
101
- sections: [5, 12, 5],
102
- },
103
- {
104
- label: "K",
105
- count: 20,
106
- y: 722,
107
- category: "standard",
108
- curve: 2.5,
109
- sections: [5, 10, 5],
110
- },
111
- ];
112
-
113
- export const CATEGORY_STYLES: Record<
114
- Category,
115
- { bg: string; border: string; glow: string; label: string; price: string }
116
- > = {
117
- premium: {
118
- bg: "linear-gradient(145deg, #7c3aed, #6d28d9)",
119
- border: "#8b5cf6",
120
- glow: "rgba(139, 92, 246, 0.6)",
121
- label: "Premium",
122
- price: "$25",
123
- },
124
- standard: {
125
- bg: "linear-gradient(145deg, #2563eb, #1d4ed8)",
126
- border: "#3b82f6",
127
- glow: "rgba(59, 130, 246, 0.4)",
128
- label: "Standard",
129
- price: "$15",
130
- },
131
- vip: {
132
- bg: "linear-gradient(145deg, #d97706, #b45309)",
133
- border: "#f59e0b",
134
- glow: "rgba(245, 158, 11, 0.6)",
135
- label: "VIP",
136
- price: "$40",
137
- },
138
- };
139
-
140
- const SELECTED_STYLE = {
141
- bg: "linear-gradient(145deg, #10b981, #059669)",
142
- border: "#34d399",
143
- glow: "rgba(16, 185, 129, 0.8)",
144
- };
145
-
146
- const OCCUPIED_STYLE = {
147
- bg: "linear-gradient(145deg, #1f2937, #111827)",
148
- border: "#374151",
149
- glow: "none",
150
- };
151
-
152
- export const OCCUPIED = new Set([
153
- "A-3",
154
- "A-7",
155
- "B-2",
156
- "B-5",
157
- "B-9",
158
- "B-12",
159
- "C-1",
160
- "C-6",
161
- "C-11",
162
- "C-15",
163
- "D-3",
164
- "D-8",
165
- "D-14",
166
- "E-2",
167
- "E-7",
168
- "E-12",
169
- "E-18",
170
- "F-4",
171
- "F-10",
172
- "F-15",
173
- "F-20",
174
- "G-1",
175
- "G-6",
176
- "G-13",
177
- "G-17",
178
- "G-22",
179
- "H-3",
180
- "H-9",
181
- "H-15",
182
- "H-19",
183
- "H-23",
184
- "I-2",
185
- "I-7",
186
- "I-12",
187
- "I-18",
188
- "I-24",
189
- "J-4",
190
- "J-11",
191
- "J-16",
192
- "J-20",
193
- "K-3",
194
- "K-8",
195
- "K-13",
196
- "K-18",
197
- ]);
198
-
199
- export interface SeatInfo {
200
- id: string;
201
- row: string;
202
- number: number;
203
- category: Category;
204
- }
205
-
206
- interface CinemaLayoutProps {
207
- selectedSeat: string | null;
208
- onSeatClick: (seat: SeatInfo) => void;
209
- }
210
-
211
- function computeRowPositions(
212
- row: RowDef,
213
- ): { x: number; y: number; seatNum: number }[] {
214
- const [left, center, right] = row.sections;
215
- const step = SEAT_SIZE + SEAT_GAP;
216
- const totalWidth = row.count * step - SEAT_GAP + 2 * AISLE_GAP;
217
- const startX = CX - totalWidth / 2;
218
-
219
- const positions: { x: number; y: number; seatNum: number }[] = [];
220
- let cx = startX;
221
- let num = 1;
222
-
223
- for (let i = 0; i < left; i += 1, num += 1) {
224
- positions.push({ x: cx, y: row.y, seatNum: num });
225
- cx += step;
226
- }
227
- cx += AISLE_GAP;
228
-
229
- for (let i = 0; i < center; i += 1, num += 1) {
230
- positions.push({ x: cx, y: row.y, seatNum: num });
231
- cx += step;
232
- }
233
- cx += AISLE_GAP;
234
-
235
- for (let i = 0; i < right; i += 1, num += 1) {
236
- positions.push({ x: cx, y: row.y, seatNum: num });
237
- cx += step;
238
- }
239
-
240
- const halfWidth = totalWidth / 2;
241
- return positions.map((p) => {
242
- const norm = (p.x + SEAT_SIZE / 2 - CX) / (halfWidth || 1);
243
- return { ...p, y: p.y + row.curve * norm * norm };
244
- });
245
- }
246
-
247
- function Screen() {
248
- return (
249
- <div
250
- style={{
251
- position: "absolute",
252
- top: 55,
253
- left: "50%",
254
- transform: "translateX(-50%)",
255
- }}
256
- >
257
- <svg
258
- width="660"
259
- height="65"
260
- viewBox="0 0 660 65"
261
- style={{ display: "block" }}
262
- >
263
- <defs>
264
- <linearGradient id="scr-g" x1="0" y1="0" x2="0" y2="1">
265
- <stop offset="0%" stopColor="#d0ddff" stopOpacity="0.85" />
266
- <stop offset="100%" stopColor="#5a7cba" stopOpacity="0.3" />
267
- </linearGradient>
268
- </defs>
269
- <path
270
- d="M 30 52 Q 330 2 630 52"
271
- fill="none"
272
- stroke="url(#scr-g)"
273
- strokeWidth="5"
274
- strokeLinecap="round"
275
- />
276
- </svg>
277
-
278
- <span
279
- style={{
280
- position: "absolute",
281
- bottom: -22,
282
- left: "50%",
283
- transform: "translateX(-50%)",
284
- color: "rgba(255,255,255,0.25)",
285
- fontSize: 12,
286
- fontWeight: 600,
287
- letterSpacing: "10px",
288
- textTransform: "uppercase",
289
- userSelect: "none",
290
- pointerEvents: "none",
291
- }}
292
- >
293
- Screen
294
- </span>
295
- </div>
296
- );
297
- }
298
-
299
- function getSeatStyle(
300
- selected: boolean,
301
- occupied: boolean,
302
- category: Category,
303
- ) {
304
- if (selected) return SELECTED_STYLE;
305
- if (occupied) return OCCUPIED_STYLE;
306
- return CATEGORY_STYLES[category];
307
- }
308
-
309
- function SeatEl({
310
- id,
311
- x,
312
- y,
313
- seatNum,
314
- category,
315
- occupied,
316
- selected,
317
- onClick,
318
- }: {
319
- id: string;
320
- x: number;
321
- y: number;
322
- seatNum: number;
323
- category: Category;
324
- occupied: boolean;
325
- selected: boolean;
326
- onClick: () => void;
327
- }) {
328
- const sty = getSeatStyle(selected, occupied, category);
329
-
330
- return (
331
- <div
332
- id={id}
333
- role="button"
334
- tabIndex={0}
335
- onClick={onClick}
336
- onKeyDown={(e) => {
337
- if (e.key === "Enter" || e.key === " ") {
338
- e.preventDefault();
339
- onClick();
340
- }
341
- }}
342
- style={{
343
- position: "absolute",
344
- left: x,
345
- top: y,
346
- width: SEAT_SIZE,
347
- height: SEAT_SIZE,
348
- borderRadius: "8px 8px 4px 4px",
349
- background: sty.bg,
350
- border: `1.5px solid ${sty.border}`,
351
- cursor: occupied ? "default" : "pointer",
352
- boxShadow: selected
353
- ? `0 0 18px ${sty.glow}, 0 0 6px ${sty.glow}`
354
- : undefined,
355
- opacity: occupied ? 0.35 : 1,
356
- zIndex: selected ? 5 : 1,
357
- display: "flex",
358
- alignItems: "center",
359
- justifyContent: "center",
360
- }}
361
- >
362
- <span
363
- style={{
364
- color: occupied ? "rgba(255,255,255,0.2)" : "rgba(255,255,255,0.65)",
365
- fontSize: 9,
366
- fontWeight: 700,
367
- userSelect: "none",
368
- pointerEvents: "none",
369
- fontFamily: "system-ui, sans-serif",
370
- }}
371
- >
372
- {seatNum}
373
- </span>
374
- </div>
375
- );
376
- }
377
-
378
- function Legend() {
379
- const items: { cat?: Category; label: string; occupied?: boolean }[] = [
380
- { cat: "standard", label: `Standard — $15` },
381
- { cat: "premium", label: `Premium — $25` },
382
- { cat: "vip", label: `VIP — $40` },
383
- { label: "Occupied", occupied: true },
384
- ];
385
-
386
- return (
387
- <div
388
- style={{
389
- position: "absolute",
390
- top: 28,
391
- right: 36,
392
- display: "flex",
393
- flexDirection: "column",
394
- gap: 8,
395
- }}
396
- >
397
- {items.map((item) => {
398
- const sty = item.occupied ? OCCUPIED_STYLE : CATEGORY_STYLES[item.cat!];
399
- return (
400
- <div
401
- key={item.label}
402
- style={{ display: "flex", alignItems: "center", gap: 8 }}
403
- >
404
- <div
405
- style={{
406
- width: 14,
407
- height: 14,
408
- borderRadius: 4,
409
- background: sty.bg,
410
- border: `1px solid ${sty.border}`,
411
- opacity: item.occupied ? 0.35 : 1,
412
- flexShrink: 0,
413
- }}
414
- />
415
- <span
416
- style={{
417
- color: item.occupied
418
- ? "rgba(255,255,255,0.3)"
419
- : "rgba(255,255,255,0.5)",
420
- fontSize: 11,
421
- fontWeight: 500,
422
- whiteSpace: "nowrap",
423
- userSelect: "none",
424
- }}
425
- >
426
- {item.label}
427
- </span>
428
- </div>
429
- );
430
- })}
431
- </div>
432
- );
433
- }
434
-
435
- function ExitSign({ x, y }: { x: number; y: number }) {
436
- return (
437
- <div
438
- style={{
439
- position: "absolute",
440
- left: x,
441
- top: y,
442
- display: "flex",
443
- alignItems: "center",
444
- gap: 4,
445
- pointerEvents: "none",
446
- userSelect: "none",
447
- }}
448
- >
449
- <div
450
- style={{
451
- width: 18,
452
- height: 18,
453
- borderRadius: 3,
454
- background: "rgba(16, 185, 129, 0.15)",
455
- border: "1px solid rgba(16, 185, 129, 0.3)",
456
- display: "flex",
457
- alignItems: "center",
458
- justifyContent: "center",
459
- }}
460
- >
461
- <span
462
- style={{
463
- color: "rgba(16, 185, 129, 0.6)",
464
- fontSize: 8,
465
- fontWeight: 800,
466
- letterSpacing: "0.5px",
467
- }}
468
- >
469
- ➜
470
- </span>
471
- </div>
472
- <span
473
- style={{
474
- color: "rgba(16, 185, 129, 0.35)",
475
- fontSize: 9,
476
- fontWeight: 700,
477
- letterSpacing: "2px",
478
- textTransform: "uppercase",
479
- }}
480
- >
481
- Exit
482
- </span>
483
- </div>
484
- );
485
- }
486
-
487
- export function CinemaLayout({ selectedSeat, onSeatClick }: CinemaLayoutProps) {
488
- return (
489
- <div
490
- style={{
491
- position: "relative",
492
- width: CANVAS_WIDTH,
493
- height: CANVAS_HEIGHT,
494
- background:
495
- "radial-gradient(ellipse at 50% 8%, #1a1033 0%, #0c0a1a 50%, #060612 100%)",
496
- fontFamily: "'Inter', system-ui, -apple-system, sans-serif",
497
- }}
498
- >
499
- <Screen />
500
-
501
- {ROWS.map((row) => (
502
- <span
503
- key={`lbl-${row.label}`}
504
- style={{
505
- position: "absolute",
506
- left: 55,
507
- top: row.y + SEAT_SIZE / 2,
508
- transform: "translateY(-50%)",
509
- color: "rgba(255,255,255,0.2)",
510
- fontSize: 13,
511
- fontWeight: 600,
512
- letterSpacing: "1px",
513
- userSelect: "none",
514
- pointerEvents: "none",
515
- }}
516
- >
517
- {row.label}
518
- </span>
519
- ))}
520
-
521
- {ROWS.map((row) => {
522
- const positions = computeRowPositions(row);
523
- return positions.map((pos) => {
524
- const seatId = `seat-${row.label}-${pos.seatNum}`;
525
- const lookupId = `${row.label}-${pos.seatNum}`;
526
- const occupied = OCCUPIED.has(lookupId);
527
- const selected = selectedSeat === seatId;
528
-
529
- return (
530
- <SeatEl
531
- key={seatId}
532
- id={seatId}
533
- x={pos.x}
534
- y={pos.y}
535
- seatNum={pos.seatNum}
536
- category={row.category}
537
- occupied={occupied}
538
- selected={selected}
539
- onClick={() => {
540
- if (!occupied) {
541
- onSeatClick({
542
- id: seatId,
543
- row: row.label,
544
- number: pos.seatNum,
545
- category: row.category,
546
- });
547
- }
548
- }}
549
- />
550
- );
551
- });
552
- })}
553
-
554
- <Legend />
555
-
556
- <ExitSign x={80} y={440} />
557
- <ExitSign x={CANVAS_WIDTH - 120} y={440} />
558
-
559
- <span
560
- style={{
561
- position: "absolute",
562
- bottom: 35,
563
- left: "50%",
564
- transform: "translateX(-50%)",
565
- color: "rgba(255,255,255,0.1)",
566
- fontSize: 11,
567
- fontWeight: 600,
568
- letterSpacing: "8px",
569
- textTransform: "uppercase",
570
- userSelect: "none",
571
- pointerEvents: "none",
572
- }}
573
- >
574
- Grand Cinema Hall
575
- </span>
576
- </div>
577
- );
578
- }
@@ -1,30 +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="Examples/Cinema"
11
- component={TransformWrapper}
12
- argTypes={argsTypes}
13
- />
14
-
15
- # Cinema
16
-
17
- Zoom, pan, and click on any available seat to focus on it. Use the controls or
18
- pinch / scroll to navigate the hall.
19
-
20
- <br />
21
-
22
- ### Preview:
23
-
24
- <Canvas>
25
- <Story name="Cinema">{(args) => <Template {...args} />}</Story>
26
- </Canvas>
27
-
28
- ## Component API
29
-
30
- <ArgsTable story="Cinema" />