react-zoom-pan-pinch 3.6.1 → 4.0.0
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 +770 -277
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +116 -22
- package/dist/index.esm.js +766 -269
- package/dist/index.esm.js.map +1 -1
- package/package.json +73 -60
- package/src/components/index.ts +5 -0
- package/src/components/keep-scale/keep-scale.tsx +28 -0
- package/src/components/mini-map/mini-map.tsx +292 -0
- package/src/components/mini-map/use-resize.hook.ts +74 -0
- package/src/components/transform-component/transform-component.module.css +43 -0
- package/src/components/transform-component/transform-component.tsx +96 -0
- package/src/components/transform-wrapper/transform-wrapper.tsx +39 -0
- package/src/components/virtualize/virtualize.tsx +133 -0
- package/src/components/virtualize/virtualize.utils.ts +104 -0
- package/src/constants/state.constants.ts +99 -0
- package/src/core/animations/animations.constants.ts +78 -0
- package/src/core/animations/animations.utils.ts +115 -0
- package/src/core/bounds/bounds.types.ts +8 -0
- package/src/core/bounds/bounds.utils.ts +226 -0
- package/src/core/double-click/double-click.logic.ts +127 -0
- package/src/core/handlers/handlers.logic.ts +122 -0
- package/src/core/handlers/handlers.utils.ts +243 -0
- package/src/core/instance.core.ts +704 -0
- package/src/core/pan/panning.logic.ts +122 -0
- package/src/core/pan/panning.utils.ts +216 -0
- package/src/core/pan/velocity.logic.ts +187 -0
- package/src/core/pan/velocity.utils.ts +83 -0
- package/src/core/pinch/pinch.logic.ts +139 -0
- package/src/core/pinch/pinch.utils.ts +95 -0
- package/src/core/wheel/wheel.logic.ts +161 -0
- package/src/core/wheel/wheel.utils.ts +157 -0
- package/src/core/zoom/zoom.logic.ts +71 -0
- package/src/core/zoom/zoom.utils.ts +62 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/use-controls.tsx +9 -0
- package/src/hooks/use-transform-component.tsx +30 -0
- package/src/hooks/use-transform-context.tsx +13 -0
- package/src/hooks/use-transform-effect.tsx +22 -0
- package/src/hooks/use-transform-init.tsx +28 -0
- package/src/hooks/use-zoom-pan-pinch.tsx +48 -0
- package/src/index.ts +6 -0
- package/src/models/calculations.model.ts +34 -0
- package/src/models/context.model.ts +218 -0
- package/src/models/helpers.model.ts +15 -0
- package/src/models/index.ts +3 -0
- package/src/react-app-env.d.ts +1 -0
- 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 +1 -0
- package/src/stories/assets/small-image.jpg +0 -0
- package/src/stories/assets/svg-example.svg +14 -0
- package/src/stories/docs/DocTable.tsx +59 -0
- package/src/stories/docs/HandlerCards.tsx +102 -0
- package/src/stories/docs/Introduction.stories.mdx +135 -0
- package/src/stories/docs/PropTable.tsx +116 -0
- package/src/stories/docs/docs.module.css +370 -0
- package/src/stories/docs/handlers.stories.mdx +7 -0
- package/src/stories/docs/handlers.tsx +111 -0
- package/src/stories/docs/props.stories.mdx +11 -0
- package/src/stories/docs/props.tsx +571 -0
- package/src/stories/examples/axis-lock/axis-lock.stories.mdx +35 -0
- package/src/stories/examples/axis-lock/example.tsx +114 -0
- package/src/stories/examples/bounds/bounds.data.tsx +191 -0
- package/src/stories/examples/bounds/bounds.stories.mdx +99 -0
- package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +206 -0
- package/src/stories/examples/cinema/cinema-data.tsx +578 -0
- package/src/stories/examples/cinema/cinema.stories.mdx +30 -0
- package/src/stories/examples/cinema/example.tsx +378 -0
- package/src/stories/examples/cinema/image.png +0 -0
- package/src/stories/examples/content/content.stories.mdx +172 -0
- package/src/stories/examples/content/mixed-content.data.tsx +624 -0
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +34 -0
- package/src/stories/examples/content-rerendering/example.tsx +631 -0
- package/src/stories/examples/controls/controls.stories.mdx +120 -0
- package/src/stories/examples/image/example.tsx +149 -0
- package/src/stories/examples/image/image.stories.mdx +46 -0
- package/src/stories/examples/image-annotations/example.tsx +1442 -0
- package/src/stories/examples/image-annotations/image-annotations.stories.mdx +39 -0
- package/src/stories/examples/image-responsive/example.tsx +152 -0
- package/src/stories/examples/image-responsive/image-responsive.stories.mdx +51 -0
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +107 -0
- package/src/stories/examples/initial-transform/example.tsx +233 -0
- package/src/stories/examples/initial-transform/initial-transform.stories.mdx +37 -0
- package/src/stories/examples/keep-scale/example.tsx +882 -0
- package/src/stories/examples/keep-scale/keep-scale.stories.mdx +30 -0
- package/src/stories/examples/keep-scale/map.stories.mdx +28 -0
- package/src/stories/examples/medical-viewer/chest-xray.tsx +246 -0
- package/src/stories/examples/medical-viewer/example.tsx +690 -0
- package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +49 -0
- package/src/stories/examples/mini-map/example.tsx +122 -0
- package/src/stories/examples/mini-map/mini-map.stories.mdx +26 -0
- package/src/stories/examples/miro/example.tsx +1573 -0
- package/src/stories/examples/miro/miro.stories.mdx +31 -0
- package/src/stories/examples/padding/example.tsx +147 -0
- package/src/stories/examples/padding/padding.stories.mdx +35 -0
- package/src/stories/examples/product-card/example.tsx +594 -0
- package/src/stories/examples/product-card/product-card.stories.mdx +29 -0
- package/src/stories/examples/stadium/example.tsx +1040 -0
- package/src/stories/examples/stadium/stadium-data.ts +224 -0
- package/src/stories/examples/stadium/stadium.stories.mdx +32 -0
- package/src/stories/examples/stress/example.tsx +59 -0
- package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
- package/src/stories/examples/svg-zoom-to-element/creativity.svg +143 -0
- package/src/stories/examples/svg-zoom-to-element/example.tsx +95 -0
- package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +28 -0
- package/src/stories/examples/text-selection/example.tsx +221 -0
- package/src/stories/examples/text-selection/text-selection.stories.mdx +31 -0
- package/src/stories/examples/velocity/example.tsx +908 -0
- package/src/stories/examples/velocity/velocity.stories.mdx +35 -0
- package/src/stories/examples/virtualize/example.tsx +239 -0
- package/src/stories/examples/virtualize/virtualize.stories.mdx +84 -0
- package/src/stories/examples/zoom-to-element/example.tsx +219 -0
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +31 -0
- package/src/stories/hooks/use-controls.stories.mdx +86 -0
- package/src/stories/hooks/use-transform-component.stories.mdx +108 -0
- package/src/stories/hooks/use-transform-context.stories.mdx +92 -0
- package/src/stories/hooks/use-transform-effect.stories.mdx +114 -0
- package/src/stories/hooks/use-transform-init.stories.mdx +105 -0
- package/src/stories/types/args.types.ts +192 -0
- package/src/stories/utils/args.utils.ts +35 -0
- package/src/stories/utils/bounds-overlay.tsx +168 -0
- package/src/stories/utils/code.utils.tsx +22 -0
- package/src/stories/utils/controls.utils.tsx +347 -0
- package/src/stories/utils/index.ts +5 -0
- package/src/stories/utils/styles.module.css +223 -0
- package/src/stories/utils/viewer.styles.ts +34 -0
- package/src/styles.css +8 -0
- package/src/typings.d.ts +21 -0
- package/src/utils/calculations.utils.ts +16 -0
- package/src/utils/callback.utils.ts +11 -0
- package/src/utils/context.utils.ts +49 -0
- package/src/utils/event.utils.ts +38 -0
- package/src/utils/helpers.utils.ts +22 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/ref.utils.ts +32 -0
- package/src/utils/state.utils.ts +77 -0
- package/src/utils/styles.utils.ts +49 -0
|
@@ -0,0 +1,578 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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" />
|