-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintModule.jsx
More file actions
348 lines (339 loc) · 10.8 KB
/
PrintModule.jsx
File metadata and controls
348 lines (339 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
import React, { useEffect, useState } from "react";
const A4_WIDTH = 796;
const A4_HEIGHT = 1123;
const BASE_LETTER_HEIGHT = 96;
const LETTER_SCALE = 0.5;
const getLineHeight = (line) => {
if (!line || line.length === 0) return BASE_LETTER_HEIGHT;
return Math.max(
...line.map((l) => (l.height ? l.height * LETTER_SCALE : BASE_LETTER_HEIGHT))
);
};
export default function PrintModule({ lines, onBack }) {
const [pageW, setPageW] = useState(A4_WIDTH);
const [animReady, setAnimReady] = useState(false);
// Dynamiczne skalowanie dwóch kartek w oknie
useEffect(() => {
function handleResize() {
const maxW = window.innerWidth * 0.95;
const stopkaH = 40 + 18;
const maxH = window.innerHeight - stopkaH - 32;
// Cała szerokość na DWA A4 + margines między nimi
const cards = 2 * A4_WIDTH + 48;
const byHeight = maxH * (cards / (1.5 * A4_HEIGHT));
setPageW(Math.min(A4_WIDTH, (maxW - 48) / 2, byHeight / 2, A4_WIDTH));
}
handleResize();
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
}, []);
const scale = pageW / A4_WIDTH;
const pageH = pageW * (A4_HEIGHT / A4_WIDTH);
const clampH = 320 * scale;
const [clampTop, setClampTop] = useState(pageH - clampH);
useEffect(() => {
setClampTop(pageH - clampH);
const t = setTimeout(() => setClampTop(-clampH), 1000);
return () => clearTimeout(t);
}, [pageH]);
useEffect(() => {
const t = setTimeout(() => setAnimReady(true), 1500);
return () => clearTimeout(t);
}, []);
// Lustrzane odbicie: linie od dołu, każda linia od końca i flipped poziomo
const mirroredLines = [...lines];
return (
<div
style={{
minHeight: "100vh",
width: "100vw",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "stretch",
overflow: "visible",
boxSizing: "border-box"
}}
>
<div
style={{
flex: "1 1 auto",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
minHeight: 0,
width: "100%",
overflow: "visible",
position: "relative",
}}
>
<div
style={{
display: "flex",
flexDirection: "row",
gap: 88 * scale,
justifyContent: "center",
alignItems: "center",
width: "100%",
minHeight: pageH
}}
>
{/* Kartka A4 LEWA */}
<div
style={{
background: "none",
border: "none",
borderRadius: 0,
width: pageW,
height: pageH,
boxShadow: "0 6px 48px #0003",
position: "relative",
overflow: "visible",
display: "flex",
flexDirection: "column",
alignItems: "flex-end",
justifyContent: "flex-start",
paddingTop: 200 * scale,
paddingRight: 270 * scale
}}
>
<img
src="/assets/korektor.png"
alt="korektor"
style={{
position: "absolute",
top: -400 * scale,
left: 0,
width: "100%",
height: pageH + 800 * scale,
objectFit: "cover",
pointerEvents: "none",
transform: "translateY(11.5%) scale(0.85)",
transformOrigin: "top left",
zIndex: 0
}}
/>
<img
src="/assets/docisk.png"
alt="docisk"
style={{
position: "absolute",
left: `-${230 * scale}px`,
top: clampTop,
width: `calc(100% + ${300 * scale}px)`,
height: `calc(100% * ${scale}px)`,
transition: "top 1s ease-in-out",
zIndex: 2
}}
/>
{lines.map((line, i) => {
const lineHeight = getLineHeight(line);
return (
<div
key={i}
style={{
position: "relative",
zIndex: 1,
display: "flex",
flexDirection: "row",
alignItems: "flex-start",
justifyContent: "flex-end",
margin: `${0 * scale}px 0 ${12 * scale}px 0`,
minHeight: lineHeight * scale,
maxWidth: "100%"
}}
>
{line.map((letter, j) => (
<img
key={j}
src={letter.img}
alt={letter.char}
width={letter.width * LETTER_SCALE * scale}
height={
(letter.height
? letter.height * LETTER_SCALE
: BASE_LETTER_HEIGHT) * scale
}
style={{ marginLeft: 0 * scale }}
draggable={false}
/>
))}
</div>
);
})}
</div>
{/* Kartka A4 PRAWA (Lustrzane odbicie) */}
<div
style={{
background: "#fff",
width: pageW,
height: pageH,
boxShadow: "none",
border: "none",
borderRadius: 0,
position: "relative",
overflow: "hidden",
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
justifyContent: "flex-start",
transform: animReady
? "translateX(0) rotateX(0deg)"
: `translateX(-${pageW + 48 * scale}px) rotateX(180deg)`,
"--dx": `${pageW + 48 * scale}px`,
animation: animReady
? "right-page-flip 1s ease forwards"
: "none",
transformStyle: "preserve-3d",
backfaceVisibility: "hidden"
}}
>
<div
style={{
width: "100%",
height: "100%",
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
justifyContent: "flex-start",
paddingTop: 80 * scale,
paddingLeft: 60 * scale
}}
>
{mirroredLines.map((line, i) => {
const lineHeight = getLineHeight(line);
return (
<div
key={i}
style={{
transform: "scaleX(-1)",
display: "flex",
flexDirection: "row",
alignItems: "flex-start",
justifyContent: "flex-start",
margin: `${0 * scale}px 0 ${12 * scale}px 0`,
minHeight: lineHeight * scale,
filter: "invert(1)",
maxWidth: "100%"
}}
>
{[...line].map((letter, j) => (
<img
key={j}
src={letter.img}
alt={letter.char}
width={letter.width * LETTER_SCALE * scale}
height={
(letter.height
? letter.height * LETTER_SCALE
: BASE_LETTER_HEIGHT) * scale
}
draggable={false}
/>
))}
</div>
);
})}
</div>
</div>
</div>
{/* Panel boczny (lewy) */}
<div
style={{
position: "absolute",
left: 10,
bottom: 70,
zIndex: 10,
display: "flex",
flexDirection: "column",
}}
>
<button
onClick={onBack}
style={{
background: "#222",
color: "#fff",
border: "2px solid #888",
borderRadius: "10%",
width: 39,
height: 39,
fontSize: 24,
fontWeight: "bold",
cursor: "pointer",
boxShadow: "2px 2px 8px #0002",
outline: "none",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
title="Powrót"
aria-label="Powrót"
>
<span
style={{
display: "inline-block",
transform: "rotate(180deg) translateY(2px)",
fontFamily: "Arial, sans-serif",
}}
>
→
</span>
</button>
</div>
</div>
{/* STOPKA */}
<p
style={{
width: "100%",
background: "#000",
color: "#969498",
textAlign: "center",
fontSize: 13,
letterSpacing: 0.2,
fontFamily: "inherit",
padding: "12px 0 8px 0",
flexShrink: 0,
marginTop: "auto",
marginBottom: "0px",
userSelect: "none"
}}
>
<b>ZECER</b> - {" "}
<a
href="https://mkalodz.pl"
target="_blank"
rel="noopener"
style={{
color: "#fafafa",
textDecoration: "none",
transition: "color 0.45s"
}}
onMouseEnter={e => (e.target.style.color = "#ff0000")}
onMouseLeave={e => (e.target.style.color = "#969498")}
onTouchStart={e => (e.target.style.color = "#ff0000")}
onTouchEnd={e => (e.target.style.color = "#969498")}
>
| MKA Łódź
</a>
| code:{" "}
<a
href="https://peterwolf.pl"
target="_blank"
rel="noopener"
style={{
color: "#fafafa",
textDecoration: "none",
transition: "color 0.45s"
}}
onMouseEnter={e => (e.target.style.color = "#ff0000")}
onMouseLeave={e => (e.target.style.color = "#969498")}
onTouchStart={e => (e.target.style.color = "#ff0000")}
onTouchEnd={e => (e.target.style.color = "#969498")}
>
peterwolf.pl
</a>
</p>
</div>
);
}