cynx-lib 1.3.84 → 1.3.85
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/gen.js +77 -77
- package/package.json +5 -1
- package/ui/components/Drawer.jsx +208 -208
- package/ui/components/Pagination.jsx +145 -145
- package/ui/components/PrivacyBlur.jsx +603 -603
- package/utils/index.cjs +5 -0
- package/utils/index.js +22 -20
- package/utils/utils/duration.js +139 -139
- package/utils/utils/oidc.js +214 -214
- package/utils/utils/realtime.js +1634 -1634
- package/utils/utils/session.cjs +15 -2
- package/utils/utils/session.js +67 -58
- package/utils/utils/session_manager.cjs +490 -0
- package/utils/utils/session_manager.js +549 -0
- package/utils/utils/storage.js +393 -393
- package/utils/utils/ui.js +111 -111
- package/vue/components/Badge.vue +79 -79
- package/vue/components/Button.vue +209 -209
- package/vue/components/Checkbox.vue +103 -103
- package/vue/components/CircularProgress.vue +383 -383
- package/vue/components/Divider.vue +94 -94
- package/vue/components/Drawer.vue +243 -243
- package/vue/components/InfoBadge.vue +223 -223
- package/vue/components/Input.vue +341 -341
- package/vue/components/LinearProgress.vue +268 -268
- package/vue/components/Modal.vue +226 -226
- package/vue/components/Pagination.vue +199 -199
- package/vue/components/Select.vue +713 -713
- package/vue/components/Sidebar.vue +955 -955
- package/vue/components/Skeleton.vue +91 -91
- package/vue/components/Spinner.vue +263 -263
- package/vue/components/StatusTag.vue +89 -89
- package/vue/components/TabBar.vue +176 -176
- package/vue/components/Table.vue +388 -388
- package/vue/components/TimePicker.vue +399 -399
- package/vue/components/Toggle.vue +115 -115
- package/vue/components/XTable.vue +119 -119
- package/vue/composables/useAutoSkeletonRows.ts +71 -71
- package/vue/index.d.ts +67 -67
- package/vue/index.js +86 -86
|
@@ -1,603 +1,603 @@
|
|
|
1
|
-
import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
-
import { Eye, EyeOff } from 'lucide-react';
|
|
3
|
-
|
|
4
|
-
function useIsDarkMode() {
|
|
5
|
-
const [isDark, setIsDark] = useState(false);
|
|
6
|
-
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const checkDark = () => {
|
|
9
|
-
if (typeof document === 'undefined') return false;
|
|
10
|
-
const root = document.documentElement;
|
|
11
|
-
const theme = root.getAttribute('data-theme') || document.body.getAttribute('data-theme');
|
|
12
|
-
if (theme === 'dark') return true;
|
|
13
|
-
if (theme === 'light' || theme === 'amber') return false;
|
|
14
|
-
const textColor = window.getComputedStyle(document.body).color;
|
|
15
|
-
const m = textColor.match(/\d+/g);
|
|
16
|
-
if (m && m.length >= 3) {
|
|
17
|
-
const b = (Number(m[0]) * 299 + Number(m[1]) * 587 + Number(m[2]) * 114) / 1000;
|
|
18
|
-
return b > 128;
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
setIsDark(checkDark());
|
|
24
|
-
|
|
25
|
-
const observer = new MutationObserver(() => {
|
|
26
|
-
setIsDark(checkDark());
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'class'] });
|
|
30
|
-
return () => observer.disconnect();
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
return isDark;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Telegram-style Shared Singleton Tiling Engine
|
|
37
|
-
class SpoilerEngine {
|
|
38
|
-
constructor() {
|
|
39
|
-
this.subscribers = new Map();
|
|
40
|
-
this.tileCanvas = null;
|
|
41
|
-
this.tileCtx = null;
|
|
42
|
-
this.tileSize = 200;
|
|
43
|
-
this.particles = [];
|
|
44
|
-
this.animId = null;
|
|
45
|
-
this.speedMultiplier = 1.8;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
initTile() {
|
|
49
|
-
if (this.tileCanvas) return;
|
|
50
|
-
if (typeof document === 'undefined') return;
|
|
51
|
-
|
|
52
|
-
this.tileCanvas = document.createElement('canvas');
|
|
53
|
-
this.tileCanvas.width = this.tileSize;
|
|
54
|
-
this.tileCanvas.height = this.tileSize;
|
|
55
|
-
this.tileCtx = this.tileCanvas.getContext('2d');
|
|
56
|
-
|
|
57
|
-
// 220 dense sparkling micro-particles inside a 200x200 seamless tile
|
|
58
|
-
const count = 220;
|
|
59
|
-
this.particles = [];
|
|
60
|
-
for (let i = 0; i < count; i++) {
|
|
61
|
-
const isMicro = Math.random() < 0.7;
|
|
62
|
-
this.particles.push({
|
|
63
|
-
x: Math.random() * this.tileSize,
|
|
64
|
-
y: Math.random() * this.tileSize,
|
|
65
|
-
size: isMicro ? (Math.random() * 0.4 + 0.6) : (Math.random() * 0.5 + 1.0),
|
|
66
|
-
phase: Math.random() * Math.PI * 2,
|
|
67
|
-
speed: Math.random() * 0.05 + 0.02,
|
|
68
|
-
baseAlpha: Math.random() * 0.55 + 0.35,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
updateSpeed() {
|
|
74
|
-
if (this.subscribers.size === 0) return;
|
|
75
|
-
let maxSpeed = 1.8;
|
|
76
|
-
for (const s of this.subscribers.values()) {
|
|
77
|
-
if (typeof s === 'number' && s > 0) {
|
|
78
|
-
maxSpeed = Math.max(maxSpeed, s);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
this.speedMultiplier = maxSpeed;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
subscribe(callback, speed = 1.8) {
|
|
85
|
-
this.subscribers.set(callback, speed);
|
|
86
|
-
this.updateSpeed();
|
|
87
|
-
if (this.subscribers.size === 1) {
|
|
88
|
-
this.start();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
unsubscribe(callback) {
|
|
93
|
-
this.subscribers.delete(callback);
|
|
94
|
-
this.updateSpeed();
|
|
95
|
-
if (this.subscribers.size === 0) {
|
|
96
|
-
this.stop();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
start() {
|
|
101
|
-
this.initTile();
|
|
102
|
-
if (this.animId) return;
|
|
103
|
-
|
|
104
|
-
const loop = () => {
|
|
105
|
-
this.renderTile();
|
|
106
|
-
for (const cb of this.subscribers.keys()) {
|
|
107
|
-
cb(this.tileCanvas);
|
|
108
|
-
}
|
|
109
|
-
this.animId = requestAnimationFrame(loop);
|
|
110
|
-
};
|
|
111
|
-
this.animId = requestAnimationFrame(loop);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
stop() {
|
|
115
|
-
if (this.animId) {
|
|
116
|
-
cancelAnimationFrame(this.animId);
|
|
117
|
-
this.animId = null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
renderTile() {
|
|
122
|
-
const ctx = this.tileCtx;
|
|
123
|
-
if (!ctx) return;
|
|
124
|
-
ctx.clearRect(0, 0, this.tileSize, this.tileSize);
|
|
125
|
-
|
|
126
|
-
const mult = this.speedMultiplier;
|
|
127
|
-
// Fast batch drawing of sparkling white particles with speed multiplier
|
|
128
|
-
for (let i = 0; i < this.particles.length; i++) {
|
|
129
|
-
const p = this.particles[i];
|
|
130
|
-
p.phase += p.speed * mult;
|
|
131
|
-
|
|
132
|
-
p.x += Math.sin(p.phase) * (0.05 * mult);
|
|
133
|
-
p.y += Math.cos(p.phase) * (0.05 * mult);
|
|
134
|
-
if (p.x < 0) p.x = this.tileSize;
|
|
135
|
-
if (p.x > this.tileSize) p.x = 0;
|
|
136
|
-
if (p.y < 0) p.y = this.tileSize;
|
|
137
|
-
if (p.y > this.tileSize) p.y = 0;
|
|
138
|
-
|
|
139
|
-
const shimmer = Math.sin(p.phase) * 0.35;
|
|
140
|
-
const alpha = Math.max(0.12, Math.min(1, p.baseAlpha + shimmer));
|
|
141
|
-
|
|
142
|
-
ctx.beginPath();
|
|
143
|
-
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
|
144
|
-
ctx.fillStyle = `rgba(255, 255, 255, ${alpha})`;
|
|
145
|
-
ctx.fill();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const spoilerEngine = new SpoilerEngine();
|
|
151
|
-
|
|
152
|
-
function SpoilerCanvas({
|
|
153
|
-
active,
|
|
154
|
-
isBursting,
|
|
155
|
-
burstOrigin,
|
|
156
|
-
onBurstComplete,
|
|
157
|
-
isDark,
|
|
158
|
-
shimmerSpeed,
|
|
159
|
-
}) {
|
|
160
|
-
const canvasRef = useRef(null);
|
|
161
|
-
const sizeRef = useRef({ width: 0, height: 0, dpr: 1 });
|
|
162
|
-
const animBurstRef = useRef(null);
|
|
163
|
-
|
|
164
|
-
// Resize handling with devicePixelRatio for crisp Retina rendering
|
|
165
|
-
useEffect(() => {
|
|
166
|
-
const canvas = canvasRef.current;
|
|
167
|
-
if (!canvas) return;
|
|
168
|
-
const parent = canvas.parentElement;
|
|
169
|
-
if (!parent) return;
|
|
170
|
-
|
|
171
|
-
const ro = new ResizeObserver((entries) => {
|
|
172
|
-
for (const entry of entries) {
|
|
173
|
-
const rect = entry.contentRect;
|
|
174
|
-
if (rect.width > 0 && rect.height > 0) {
|
|
175
|
-
const dpr = window.devicePixelRatio || 1;
|
|
176
|
-
canvas.width = Math.floor(rect.width * dpr);
|
|
177
|
-
canvas.height = Math.floor(rect.height * dpr);
|
|
178
|
-
canvas.style.width = `${rect.width}px`;
|
|
179
|
-
canvas.style.height = `${rect.height}px`;
|
|
180
|
-
sizeRef.current = { width: rect.width, height: rect.height, dpr };
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
ro.observe(parent);
|
|
186
|
-
return () => ro.disconnect();
|
|
187
|
-
}, []);
|
|
188
|
-
|
|
189
|
-
// Shared Tiling Loop (Hardware accelerated repeat - 0.01ms draw call)
|
|
190
|
-
useEffect(() => {
|
|
191
|
-
if (!active || isBursting) return;
|
|
192
|
-
|
|
193
|
-
const draw = (tileCanvas) => {
|
|
194
|
-
const canvas = canvasRef.current;
|
|
195
|
-
if (!canvas) return;
|
|
196
|
-
const ctx = canvas.getContext('2d');
|
|
197
|
-
if (!ctx) return;
|
|
198
|
-
const { width, height, dpr } = sizeRef.current;
|
|
199
|
-
if (!width || !height) return;
|
|
200
|
-
|
|
201
|
-
ctx.save();
|
|
202
|
-
ctx.scale(dpr, dpr);
|
|
203
|
-
ctx.clearRect(0, 0, width, height);
|
|
204
|
-
|
|
205
|
-
// Frosted veil: slate-silver in light mode, obsidian in dark mode
|
|
206
|
-
ctx.fillStyle = isDark
|
|
207
|
-
? 'rgba(12, 16, 22, 0.78)'
|
|
208
|
-
: 'rgba(92, 100, 114, 0.46)';
|
|
209
|
-
ctx.fillRect(0, 0, width, height);
|
|
210
|
-
|
|
211
|
-
// Instant hardware texture fill from single shared tile
|
|
212
|
-
const pattern = ctx.createPattern(tileCanvas, 'repeat');
|
|
213
|
-
if (pattern) {
|
|
214
|
-
ctx.fillStyle = pattern;
|
|
215
|
-
ctx.fillRect(0, 0, width, height);
|
|
216
|
-
}
|
|
217
|
-
ctx.restore();
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
spoilerEngine.subscribe(draw, shimmerSpeed);
|
|
221
|
-
return () => spoilerEngine.unsubscribe(draw);
|
|
222
|
-
}, [active, isBursting, isDark, shimmerSpeed]);
|
|
223
|
-
|
|
224
|
-
// Burst Dispersal on Click (lasts only ~300ms, then shuts down)
|
|
225
|
-
useEffect(() => {
|
|
226
|
-
if (!isBursting) return;
|
|
227
|
-
const canvas = canvasRef.current;
|
|
228
|
-
if (!canvas) return;
|
|
229
|
-
const ctx = canvas.getContext('2d');
|
|
230
|
-
if (!ctx) return;
|
|
231
|
-
const { width, height, dpr } = sizeRef.current;
|
|
232
|
-
|
|
233
|
-
const startTime = performance.now();
|
|
234
|
-
const duration = 280;
|
|
235
|
-
const originX = burstOrigin?.x ?? (width / 2);
|
|
236
|
-
const originY = burstOrigin?.y ?? (height / 2);
|
|
237
|
-
|
|
238
|
-
const burstParticles = [];
|
|
239
|
-
for (let i = 0; i < 70; i++) {
|
|
240
|
-
const angle = Math.random() * Math.PI * 2;
|
|
241
|
-
const speed = Math.random() * 8 + 3;
|
|
242
|
-
burstParticles.push({
|
|
243
|
-
x: originX + (Math.random() - 0.5) * 30,
|
|
244
|
-
y: originY + (Math.random() - 0.5) * 30,
|
|
245
|
-
vx: Math.cos(angle) * speed,
|
|
246
|
-
vy: Math.sin(angle) * speed,
|
|
247
|
-
size: Math.random() * 1.2 + 0.8,
|
|
248
|
-
alpha: 1,
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const animateBurst = (now) => {
|
|
253
|
-
const progress = Math.min(1, (now - startTime) / duration);
|
|
254
|
-
const fade = 1 - progress;
|
|
255
|
-
|
|
256
|
-
ctx.save();
|
|
257
|
-
ctx.scale(dpr, dpr);
|
|
258
|
-
ctx.clearRect(0, 0, width, height);
|
|
259
|
-
|
|
260
|
-
// Fading veil
|
|
261
|
-
ctx.fillStyle = isDark
|
|
262
|
-
? `rgba(12, 16, 22, ${0.78 * fade})`
|
|
263
|
-
: `rgba(92, 100, 114, ${0.46 * fade})`;
|
|
264
|
-
ctx.fillRect(0, 0, width, height);
|
|
265
|
-
|
|
266
|
-
// Outward radiating sparkles
|
|
267
|
-
for (const p of burstParticles) {
|
|
268
|
-
p.x += p.vx;
|
|
269
|
-
p.y += p.vy;
|
|
270
|
-
p.vx *= 0.94;
|
|
271
|
-
p.vy *= 0.94;
|
|
272
|
-
p.alpha = Math.max(0, p.alpha * 0.93);
|
|
273
|
-
|
|
274
|
-
ctx.beginPath();
|
|
275
|
-
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
|
276
|
-
ctx.fillStyle = `rgba(255, 255, 255, ${p.alpha * fade})`;
|
|
277
|
-
ctx.fill();
|
|
278
|
-
}
|
|
279
|
-
ctx.restore();
|
|
280
|
-
|
|
281
|
-
if (progress < 1) {
|
|
282
|
-
animBurstRef.current = requestAnimationFrame(animateBurst);
|
|
283
|
-
} else {
|
|
284
|
-
if (onBurstComplete) onBurstComplete();
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
animBurstRef.current = requestAnimationFrame(animateBurst);
|
|
289
|
-
return () => {
|
|
290
|
-
if (animBurstRef.current) cancelAnimationFrame(animBurstRef.current);
|
|
291
|
-
};
|
|
292
|
-
}, [isBursting, burstOrigin, isDark]);
|
|
293
|
-
|
|
294
|
-
return (
|
|
295
|
-
<canvas
|
|
296
|
-
ref={canvasRef}
|
|
297
|
-
style={{
|
|
298
|
-
position: 'absolute',
|
|
299
|
-
inset: 0,
|
|
300
|
-
width: '100%',
|
|
301
|
-
height: '100%',
|
|
302
|
-
pointerEvents: 'none',
|
|
303
|
-
borderRadius: 'inherit',
|
|
304
|
-
zIndex: 2,
|
|
305
|
-
transition: 'opacity 0.25s ease',
|
|
306
|
-
}}
|
|
307
|
-
/>
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function getPlacementStyles(position) {
|
|
312
|
-
switch (position) {
|
|
313
|
-
case 'top':
|
|
314
|
-
return { alignItems: 'center', justifyContent: 'flex-start', paddingTop: 24 };
|
|
315
|
-
case 'top-left':
|
|
316
|
-
return { alignItems: 'flex-start', justifyContent: 'flex-start', padding: 20 };
|
|
317
|
-
case 'top-right':
|
|
318
|
-
return { alignItems: 'flex-end', justifyContent: 'flex-start', padding: 20 };
|
|
319
|
-
case 'bottom':
|
|
320
|
-
return { alignItems: 'center', justifyContent: 'flex-end', paddingBottom: 24 };
|
|
321
|
-
case 'bottom-left':
|
|
322
|
-
return { alignItems: 'flex-start', justifyContent: 'flex-end', padding: 20 };
|
|
323
|
-
case 'bottom-right':
|
|
324
|
-
return { alignItems: 'flex-end', justifyContent: 'flex-end', padding: 20 };
|
|
325
|
-
case 'center':
|
|
326
|
-
default:
|
|
327
|
-
return { alignItems: 'center', justifyContent: 'center' };
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
export default function PrivacyBlur({
|
|
332
|
-
active = false,
|
|
333
|
-
blur = 6,
|
|
334
|
-
spoiler = false,
|
|
335
|
-
shimmerSpeed,
|
|
336
|
-
showBadge = true,
|
|
337
|
-
showCountdown = false,
|
|
338
|
-
showRevealButton = false,
|
|
339
|
-
position = 'center',
|
|
340
|
-
icon,
|
|
341
|
-
badgeIcon,
|
|
342
|
-
countdownIcon,
|
|
343
|
-
text,
|
|
344
|
-
subtext,
|
|
345
|
-
revealable = false,
|
|
346
|
-
interactive,
|
|
347
|
-
revealDuration,
|
|
348
|
-
revealText = 'Показать',
|
|
349
|
-
hideText = 'Скрыть',
|
|
350
|
-
onReveal,
|
|
351
|
-
onHide,
|
|
352
|
-
style,
|
|
353
|
-
contentStyle,
|
|
354
|
-
className,
|
|
355
|
-
children,
|
|
356
|
-
}) {
|
|
357
|
-
const isDark = useIsDarkMode();
|
|
358
|
-
const isRevealable = Boolean(revealable || interactive);
|
|
359
|
-
const [tempRevealed, setTempRevealed] = useState(false);
|
|
360
|
-
const [timeLeft, setTimeLeft] = useState(0);
|
|
361
|
-
const [isBursting, setIsBursting] = useState(false);
|
|
362
|
-
const [burstOrigin, setBurstOrigin] = useState(null);
|
|
363
|
-
|
|
364
|
-
const containerRef = useRef(null);
|
|
365
|
-
const timerRef = useRef(null);
|
|
366
|
-
|
|
367
|
-
const clearTimer = () => {
|
|
368
|
-
if (timerRef.current) {
|
|
369
|
-
clearInterval(timerRef.current);
|
|
370
|
-
timerRef.current = null;
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
useEffect(() => {
|
|
375
|
-
if (!active) {
|
|
376
|
-
clearTimer();
|
|
377
|
-
setTempRevealed(false);
|
|
378
|
-
setIsBursting(false);
|
|
379
|
-
setTimeLeft(0);
|
|
380
|
-
}
|
|
381
|
-
}, [active]);
|
|
382
|
-
|
|
383
|
-
useEffect(() => {
|
|
384
|
-
return () => clearTimer();
|
|
385
|
-
}, []);
|
|
386
|
-
|
|
387
|
-
const finishReveal = () => {
|
|
388
|
-
const hasDuration = revealDuration !== undefined && revealDuration !== null && revealDuration !== false;
|
|
389
|
-
if (hasDuration) {
|
|
390
|
-
const duration = typeof revealDuration === 'number' && revealDuration > 0 ? revealDuration : 5;
|
|
391
|
-
clearTimer();
|
|
392
|
-
setTempRevealed(true);
|
|
393
|
-
setTimeLeft(duration);
|
|
394
|
-
|
|
395
|
-
timerRef.current = setInterval(() => {
|
|
396
|
-
setTimeLeft((prev) => {
|
|
397
|
-
if (prev <= 1) {
|
|
398
|
-
clearTimer();
|
|
399
|
-
setTempRevealed(false);
|
|
400
|
-
if (onHide) onHide();
|
|
401
|
-
return 0;
|
|
402
|
-
}
|
|
403
|
-
return prev - 1;
|
|
404
|
-
});
|
|
405
|
-
}, 1000);
|
|
406
|
-
} else {
|
|
407
|
-
if (onReveal) onReveal();
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
const handleReveal = (e) => {
|
|
412
|
-
if (e) e.stopPropagation();
|
|
413
|
-
if (!isRevealable || isBursting) return;
|
|
414
|
-
|
|
415
|
-
if (spoiler) {
|
|
416
|
-
let origin = null;
|
|
417
|
-
if (e && typeof e.clientX === 'number' && typeof e.clientY === 'number' && containerRef.current) {
|
|
418
|
-
const rect = containerRef.current.getBoundingClientRect();
|
|
419
|
-
origin = {
|
|
420
|
-
x: Math.max(0, Math.min(rect.width, e.clientX - rect.left)),
|
|
421
|
-
y: Math.max(0, Math.min(rect.height, e.clientY - rect.top)),
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
setBurstOrigin(origin);
|
|
425
|
-
setIsBursting(true);
|
|
426
|
-
} else {
|
|
427
|
-
finishReveal();
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
const handleBurstComplete = () => {
|
|
432
|
-
setIsBursting(false);
|
|
433
|
-
finishReveal();
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
const handleHideNow = (e) => {
|
|
437
|
-
if (e) e.stopPropagation();
|
|
438
|
-
clearTimer();
|
|
439
|
-
setTempRevealed(false);
|
|
440
|
-
setIsBursting(false);
|
|
441
|
-
setTimeLeft(0);
|
|
442
|
-
if (onHide) onHide();
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
const effectiveBadgeIcon = badgeIcon || icon;
|
|
446
|
-
const blurValue = typeof blur === 'number' ? `${blur}px` : blur;
|
|
447
|
-
const isBlurred = active && !tempRevealed;
|
|
448
|
-
const hasOverlay = showBadge && Boolean(text || effectiveBadgeIcon || (isRevealable && showRevealButton));
|
|
449
|
-
const placementStyles = getPlacementStyles(position);
|
|
450
|
-
|
|
451
|
-
return (
|
|
452
|
-
<div
|
|
453
|
-
ref={containerRef}
|
|
454
|
-
className={className}
|
|
455
|
-
onClick={isBlurred && isRevealable ? handleReveal : undefined}
|
|
456
|
-
style={{
|
|
457
|
-
position: 'relative',
|
|
458
|
-
width: '100%',
|
|
459
|
-
height: '100%',
|
|
460
|
-
minHeight: '100%',
|
|
461
|
-
display: 'flex',
|
|
462
|
-
flexDirection: 'column',
|
|
463
|
-
flex: 1,
|
|
464
|
-
overflow: 'hidden',
|
|
465
|
-
cursor: isBlurred && isRevealable ? 'pointer' : 'default',
|
|
466
|
-
...style,
|
|
467
|
-
}}
|
|
468
|
-
>
|
|
469
|
-
<div
|
|
470
|
-
style={{
|
|
471
|
-
width: '100%',
|
|
472
|
-
height: '100%',
|
|
473
|
-
display: 'flex',
|
|
474
|
-
flexDirection: 'column',
|
|
475
|
-
flex: 1,
|
|
476
|
-
filter: isBlurred && !isBursting ? `blur(${blurValue})` : 'none',
|
|
477
|
-
userSelect: isBlurred ? 'none' : 'auto',
|
|
478
|
-
pointerEvents: isBlurred ? 'none' : 'auto',
|
|
479
|
-
transition: 'filter 0.3s ease, opacity 0.25s ease',
|
|
480
|
-
opacity: isBlurred ? (isBursting ? 0.9 : 0.6) : 1,
|
|
481
|
-
...contentStyle,
|
|
482
|
-
}}
|
|
483
|
-
>
|
|
484
|
-
{children}
|
|
485
|
-
</div>
|
|
486
|
-
|
|
487
|
-
{spoiler && isBlurred && (
|
|
488
|
-
<SpoilerCanvas
|
|
489
|
-
active={isBlurred}
|
|
490
|
-
isBursting={isBursting}
|
|
491
|
-
burstOrigin={burstOrigin}
|
|
492
|
-
onBurstComplete={handleBurstComplete}
|
|
493
|
-
isDark={isDark}
|
|
494
|
-
shimmerSpeed={shimmerSpeed}
|
|
495
|
-
/>
|
|
496
|
-
)}
|
|
497
|
-
|
|
498
|
-
{isBlurred && hasOverlay && (
|
|
499
|
-
<div
|
|
500
|
-
style={{
|
|
501
|
-
position: 'absolute',
|
|
502
|
-
inset: 0,
|
|
503
|
-
width: '100%',
|
|
504
|
-
height: '100%',
|
|
505
|
-
display: 'flex',
|
|
506
|
-
flexDirection: 'column',
|
|
507
|
-
gap: 6,
|
|
508
|
-
padding: 12,
|
|
509
|
-
boxSizing: 'border-box',
|
|
510
|
-
zIndex: 3,
|
|
511
|
-
pointerEvents: isRevealable ? 'auto' : 'none',
|
|
512
|
-
opacity: isBursting ? 0 : 1,
|
|
513
|
-
transition: 'opacity 0.2s ease',
|
|
514
|
-
...placementStyles,
|
|
515
|
-
}}
|
|
516
|
-
>
|
|
517
|
-
<div
|
|
518
|
-
onClick={isRevealable ? handleReveal : undefined}
|
|
519
|
-
style={{
|
|
520
|
-
display: 'inline-flex',
|
|
521
|
-
alignItems: 'center',
|
|
522
|
-
gap: 8,
|
|
523
|
-
padding: '6px 14px',
|
|
524
|
-
borderRadius: 'var(--rads)',
|
|
525
|
-
background: 'var(--surface)',
|
|
526
|
-
border: '1px solid var(--border-light)',
|
|
527
|
-
boxShadow: 'var(--shadow)',
|
|
528
|
-
color: 'var(--primary-text)',
|
|
529
|
-
fontSize: '.76rem',
|
|
530
|
-
fontWeight: 600,
|
|
531
|
-
cursor: isRevealable ? 'pointer' : 'default',
|
|
532
|
-
backdropFilter: 'blur(8px)',
|
|
533
|
-
WebkitBackdropFilter: 'blur(8px)',
|
|
534
|
-
transition: 'all 0.2s ease',
|
|
535
|
-
maxWidth: '90%',
|
|
536
|
-
userSelect: 'none',
|
|
537
|
-
}}
|
|
538
|
-
>
|
|
539
|
-
<span style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0, alignSelf: 'center' }}>
|
|
540
|
-
{effectiveBadgeIcon || <EyeOff size={14} style={{ color: 'var(--muted)' }} />}
|
|
541
|
-
</span>
|
|
542
|
-
{text && <span style={{ whiteSpace: 'normal', wordBreak: 'break-word', lineHeight: 1.35 }}>{text}</span>}
|
|
543
|
-
{isRevealable && showRevealButton && (
|
|
544
|
-
<span style={{ fontSize: '.7rem', color: 'var(--accent)', textDecoration: 'underline', marginLeft: 4, flexShrink: 0, whiteSpace: 'nowrap', alignSelf: 'center' }}>
|
|
545
|
-
{revealText}
|
|
546
|
-
</span>
|
|
547
|
-
)}
|
|
548
|
-
</div>
|
|
549
|
-
{subtext && (
|
|
550
|
-
<span style={{ fontSize: '.68rem', color: 'var(--muted)', textAlign: 'center' }}>
|
|
551
|
-
{subtext}
|
|
552
|
-
</span>
|
|
553
|
-
)}
|
|
554
|
-
</div>
|
|
555
|
-
)}
|
|
556
|
-
|
|
557
|
-
{active && tempRevealed && showCountdown && (
|
|
558
|
-
<div
|
|
559
|
-
style={{
|
|
560
|
-
position: 'absolute',
|
|
561
|
-
top: 8,
|
|
562
|
-
right: 8,
|
|
563
|
-
display: 'inline-flex',
|
|
564
|
-
alignItems: 'center',
|
|
565
|
-
gap: 6,
|
|
566
|
-
padding: '3px 8px',
|
|
567
|
-
borderRadius: 'var(--rads)',
|
|
568
|
-
background: 'var(--surface)',
|
|
569
|
-
border: '1px solid var(--border-light)',
|
|
570
|
-
boxShadow: 'var(--shadow)',
|
|
571
|
-
fontSize: '.7rem',
|
|
572
|
-
fontWeight: 600,
|
|
573
|
-
color: 'var(--muted)',
|
|
574
|
-
zIndex: 4,
|
|
575
|
-
userSelect: 'none',
|
|
576
|
-
backdropFilter: 'blur(8px)',
|
|
577
|
-
WebkitBackdropFilter: 'blur(8px)',
|
|
578
|
-
}}
|
|
579
|
-
>
|
|
580
|
-
<span style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
|
|
581
|
-
{countdownIcon || <Eye size={12} style={{ color: 'var(--accent)' }} />}
|
|
582
|
-
</span>
|
|
583
|
-
<span style={{ whiteSpace: 'nowrap' }}>Скроется через {timeLeft}с</span>
|
|
584
|
-
<span
|
|
585
|
-
onClick={handleHideNow}
|
|
586
|
-
style={{
|
|
587
|
-
color: 'var(--accent)',
|
|
588
|
-
textDecoration: 'underline',
|
|
589
|
-
marginLeft: 4,
|
|
590
|
-
cursor: 'pointer',
|
|
591
|
-
flexShrink: 0,
|
|
592
|
-
whiteSpace: 'nowrap',
|
|
593
|
-
}}
|
|
594
|
-
>
|
|
595
|
-
{hideText}
|
|
596
|
-
</span>
|
|
597
|
-
</div>
|
|
598
|
-
)}
|
|
599
|
-
</div>
|
|
600
|
-
);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
export { PrivacyBlur };
|
|
1
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import { Eye, EyeOff } from 'lucide-react';
|
|
3
|
+
|
|
4
|
+
function useIsDarkMode() {
|
|
5
|
+
const [isDark, setIsDark] = useState(false);
|
|
6
|
+
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const checkDark = () => {
|
|
9
|
+
if (typeof document === 'undefined') return false;
|
|
10
|
+
const root = document.documentElement;
|
|
11
|
+
const theme = root.getAttribute('data-theme') || document.body.getAttribute('data-theme');
|
|
12
|
+
if (theme === 'dark') return true;
|
|
13
|
+
if (theme === 'light' || theme === 'amber') return false;
|
|
14
|
+
const textColor = window.getComputedStyle(document.body).color;
|
|
15
|
+
const m = textColor.match(/\d+/g);
|
|
16
|
+
if (m && m.length >= 3) {
|
|
17
|
+
const b = (Number(m[0]) * 299 + Number(m[1]) * 587 + Number(m[2]) * 114) / 1000;
|
|
18
|
+
return b > 128;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
setIsDark(checkDark());
|
|
24
|
+
|
|
25
|
+
const observer = new MutationObserver(() => {
|
|
26
|
+
setIsDark(checkDark());
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'class'] });
|
|
30
|
+
return () => observer.disconnect();
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
33
|
+
return isDark;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Telegram-style Shared Singleton Tiling Engine
|
|
37
|
+
class SpoilerEngine {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.subscribers = new Map();
|
|
40
|
+
this.tileCanvas = null;
|
|
41
|
+
this.tileCtx = null;
|
|
42
|
+
this.tileSize = 200;
|
|
43
|
+
this.particles = [];
|
|
44
|
+
this.animId = null;
|
|
45
|
+
this.speedMultiplier = 1.8;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
initTile() {
|
|
49
|
+
if (this.tileCanvas) return;
|
|
50
|
+
if (typeof document === 'undefined') return;
|
|
51
|
+
|
|
52
|
+
this.tileCanvas = document.createElement('canvas');
|
|
53
|
+
this.tileCanvas.width = this.tileSize;
|
|
54
|
+
this.tileCanvas.height = this.tileSize;
|
|
55
|
+
this.tileCtx = this.tileCanvas.getContext('2d');
|
|
56
|
+
|
|
57
|
+
// 220 dense sparkling micro-particles inside a 200x200 seamless tile
|
|
58
|
+
const count = 220;
|
|
59
|
+
this.particles = [];
|
|
60
|
+
for (let i = 0; i < count; i++) {
|
|
61
|
+
const isMicro = Math.random() < 0.7;
|
|
62
|
+
this.particles.push({
|
|
63
|
+
x: Math.random() * this.tileSize,
|
|
64
|
+
y: Math.random() * this.tileSize,
|
|
65
|
+
size: isMicro ? (Math.random() * 0.4 + 0.6) : (Math.random() * 0.5 + 1.0),
|
|
66
|
+
phase: Math.random() * Math.PI * 2,
|
|
67
|
+
speed: Math.random() * 0.05 + 0.02,
|
|
68
|
+
baseAlpha: Math.random() * 0.55 + 0.35,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
updateSpeed() {
|
|
74
|
+
if (this.subscribers.size === 0) return;
|
|
75
|
+
let maxSpeed = 1.8;
|
|
76
|
+
for (const s of this.subscribers.values()) {
|
|
77
|
+
if (typeof s === 'number' && s > 0) {
|
|
78
|
+
maxSpeed = Math.max(maxSpeed, s);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
this.speedMultiplier = maxSpeed;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
subscribe(callback, speed = 1.8) {
|
|
85
|
+
this.subscribers.set(callback, speed);
|
|
86
|
+
this.updateSpeed();
|
|
87
|
+
if (this.subscribers.size === 1) {
|
|
88
|
+
this.start();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
unsubscribe(callback) {
|
|
93
|
+
this.subscribers.delete(callback);
|
|
94
|
+
this.updateSpeed();
|
|
95
|
+
if (this.subscribers.size === 0) {
|
|
96
|
+
this.stop();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
start() {
|
|
101
|
+
this.initTile();
|
|
102
|
+
if (this.animId) return;
|
|
103
|
+
|
|
104
|
+
const loop = () => {
|
|
105
|
+
this.renderTile();
|
|
106
|
+
for (const cb of this.subscribers.keys()) {
|
|
107
|
+
cb(this.tileCanvas);
|
|
108
|
+
}
|
|
109
|
+
this.animId = requestAnimationFrame(loop);
|
|
110
|
+
};
|
|
111
|
+
this.animId = requestAnimationFrame(loop);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
stop() {
|
|
115
|
+
if (this.animId) {
|
|
116
|
+
cancelAnimationFrame(this.animId);
|
|
117
|
+
this.animId = null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
renderTile() {
|
|
122
|
+
const ctx = this.tileCtx;
|
|
123
|
+
if (!ctx) return;
|
|
124
|
+
ctx.clearRect(0, 0, this.tileSize, this.tileSize);
|
|
125
|
+
|
|
126
|
+
const mult = this.speedMultiplier;
|
|
127
|
+
// Fast batch drawing of sparkling white particles with speed multiplier
|
|
128
|
+
for (let i = 0; i < this.particles.length; i++) {
|
|
129
|
+
const p = this.particles[i];
|
|
130
|
+
p.phase += p.speed * mult;
|
|
131
|
+
|
|
132
|
+
p.x += Math.sin(p.phase) * (0.05 * mult);
|
|
133
|
+
p.y += Math.cos(p.phase) * (0.05 * mult);
|
|
134
|
+
if (p.x < 0) p.x = this.tileSize;
|
|
135
|
+
if (p.x > this.tileSize) p.x = 0;
|
|
136
|
+
if (p.y < 0) p.y = this.tileSize;
|
|
137
|
+
if (p.y > this.tileSize) p.y = 0;
|
|
138
|
+
|
|
139
|
+
const shimmer = Math.sin(p.phase) * 0.35;
|
|
140
|
+
const alpha = Math.max(0.12, Math.min(1, p.baseAlpha + shimmer));
|
|
141
|
+
|
|
142
|
+
ctx.beginPath();
|
|
143
|
+
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
|
144
|
+
ctx.fillStyle = `rgba(255, 255, 255, ${alpha})`;
|
|
145
|
+
ctx.fill();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const spoilerEngine = new SpoilerEngine();
|
|
151
|
+
|
|
152
|
+
function SpoilerCanvas({
|
|
153
|
+
active,
|
|
154
|
+
isBursting,
|
|
155
|
+
burstOrigin,
|
|
156
|
+
onBurstComplete,
|
|
157
|
+
isDark,
|
|
158
|
+
shimmerSpeed,
|
|
159
|
+
}) {
|
|
160
|
+
const canvasRef = useRef(null);
|
|
161
|
+
const sizeRef = useRef({ width: 0, height: 0, dpr: 1 });
|
|
162
|
+
const animBurstRef = useRef(null);
|
|
163
|
+
|
|
164
|
+
// Resize handling with devicePixelRatio for crisp Retina rendering
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
const canvas = canvasRef.current;
|
|
167
|
+
if (!canvas) return;
|
|
168
|
+
const parent = canvas.parentElement;
|
|
169
|
+
if (!parent) return;
|
|
170
|
+
|
|
171
|
+
const ro = new ResizeObserver((entries) => {
|
|
172
|
+
for (const entry of entries) {
|
|
173
|
+
const rect = entry.contentRect;
|
|
174
|
+
if (rect.width > 0 && rect.height > 0) {
|
|
175
|
+
const dpr = window.devicePixelRatio || 1;
|
|
176
|
+
canvas.width = Math.floor(rect.width * dpr);
|
|
177
|
+
canvas.height = Math.floor(rect.height * dpr);
|
|
178
|
+
canvas.style.width = `${rect.width}px`;
|
|
179
|
+
canvas.style.height = `${rect.height}px`;
|
|
180
|
+
sizeRef.current = { width: rect.width, height: rect.height, dpr };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
ro.observe(parent);
|
|
186
|
+
return () => ro.disconnect();
|
|
187
|
+
}, []);
|
|
188
|
+
|
|
189
|
+
// Shared Tiling Loop (Hardware accelerated repeat - 0.01ms draw call)
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (!active || isBursting) return;
|
|
192
|
+
|
|
193
|
+
const draw = (tileCanvas) => {
|
|
194
|
+
const canvas = canvasRef.current;
|
|
195
|
+
if (!canvas) return;
|
|
196
|
+
const ctx = canvas.getContext('2d');
|
|
197
|
+
if (!ctx) return;
|
|
198
|
+
const { width, height, dpr } = sizeRef.current;
|
|
199
|
+
if (!width || !height) return;
|
|
200
|
+
|
|
201
|
+
ctx.save();
|
|
202
|
+
ctx.scale(dpr, dpr);
|
|
203
|
+
ctx.clearRect(0, 0, width, height);
|
|
204
|
+
|
|
205
|
+
// Frosted veil: slate-silver in light mode, obsidian in dark mode
|
|
206
|
+
ctx.fillStyle = isDark
|
|
207
|
+
? 'rgba(12, 16, 22, 0.78)'
|
|
208
|
+
: 'rgba(92, 100, 114, 0.46)';
|
|
209
|
+
ctx.fillRect(0, 0, width, height);
|
|
210
|
+
|
|
211
|
+
// Instant hardware texture fill from single shared tile
|
|
212
|
+
const pattern = ctx.createPattern(tileCanvas, 'repeat');
|
|
213
|
+
if (pattern) {
|
|
214
|
+
ctx.fillStyle = pattern;
|
|
215
|
+
ctx.fillRect(0, 0, width, height);
|
|
216
|
+
}
|
|
217
|
+
ctx.restore();
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
spoilerEngine.subscribe(draw, shimmerSpeed);
|
|
221
|
+
return () => spoilerEngine.unsubscribe(draw);
|
|
222
|
+
}, [active, isBursting, isDark, shimmerSpeed]);
|
|
223
|
+
|
|
224
|
+
// Burst Dispersal on Click (lasts only ~300ms, then shuts down)
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (!isBursting) return;
|
|
227
|
+
const canvas = canvasRef.current;
|
|
228
|
+
if (!canvas) return;
|
|
229
|
+
const ctx = canvas.getContext('2d');
|
|
230
|
+
if (!ctx) return;
|
|
231
|
+
const { width, height, dpr } = sizeRef.current;
|
|
232
|
+
|
|
233
|
+
const startTime = performance.now();
|
|
234
|
+
const duration = 280;
|
|
235
|
+
const originX = burstOrigin?.x ?? (width / 2);
|
|
236
|
+
const originY = burstOrigin?.y ?? (height / 2);
|
|
237
|
+
|
|
238
|
+
const burstParticles = [];
|
|
239
|
+
for (let i = 0; i < 70; i++) {
|
|
240
|
+
const angle = Math.random() * Math.PI * 2;
|
|
241
|
+
const speed = Math.random() * 8 + 3;
|
|
242
|
+
burstParticles.push({
|
|
243
|
+
x: originX + (Math.random() - 0.5) * 30,
|
|
244
|
+
y: originY + (Math.random() - 0.5) * 30,
|
|
245
|
+
vx: Math.cos(angle) * speed,
|
|
246
|
+
vy: Math.sin(angle) * speed,
|
|
247
|
+
size: Math.random() * 1.2 + 0.8,
|
|
248
|
+
alpha: 1,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const animateBurst = (now) => {
|
|
253
|
+
const progress = Math.min(1, (now - startTime) / duration);
|
|
254
|
+
const fade = 1 - progress;
|
|
255
|
+
|
|
256
|
+
ctx.save();
|
|
257
|
+
ctx.scale(dpr, dpr);
|
|
258
|
+
ctx.clearRect(0, 0, width, height);
|
|
259
|
+
|
|
260
|
+
// Fading veil
|
|
261
|
+
ctx.fillStyle = isDark
|
|
262
|
+
? `rgba(12, 16, 22, ${0.78 * fade})`
|
|
263
|
+
: `rgba(92, 100, 114, ${0.46 * fade})`;
|
|
264
|
+
ctx.fillRect(0, 0, width, height);
|
|
265
|
+
|
|
266
|
+
// Outward radiating sparkles
|
|
267
|
+
for (const p of burstParticles) {
|
|
268
|
+
p.x += p.vx;
|
|
269
|
+
p.y += p.vy;
|
|
270
|
+
p.vx *= 0.94;
|
|
271
|
+
p.vy *= 0.94;
|
|
272
|
+
p.alpha = Math.max(0, p.alpha * 0.93);
|
|
273
|
+
|
|
274
|
+
ctx.beginPath();
|
|
275
|
+
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
|
276
|
+
ctx.fillStyle = `rgba(255, 255, 255, ${p.alpha * fade})`;
|
|
277
|
+
ctx.fill();
|
|
278
|
+
}
|
|
279
|
+
ctx.restore();
|
|
280
|
+
|
|
281
|
+
if (progress < 1) {
|
|
282
|
+
animBurstRef.current = requestAnimationFrame(animateBurst);
|
|
283
|
+
} else {
|
|
284
|
+
if (onBurstComplete) onBurstComplete();
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
animBurstRef.current = requestAnimationFrame(animateBurst);
|
|
289
|
+
return () => {
|
|
290
|
+
if (animBurstRef.current) cancelAnimationFrame(animBurstRef.current);
|
|
291
|
+
};
|
|
292
|
+
}, [isBursting, burstOrigin, isDark]);
|
|
293
|
+
|
|
294
|
+
return (
|
|
295
|
+
<canvas
|
|
296
|
+
ref={canvasRef}
|
|
297
|
+
style={{
|
|
298
|
+
position: 'absolute',
|
|
299
|
+
inset: 0,
|
|
300
|
+
width: '100%',
|
|
301
|
+
height: '100%',
|
|
302
|
+
pointerEvents: 'none',
|
|
303
|
+
borderRadius: 'inherit',
|
|
304
|
+
zIndex: 2,
|
|
305
|
+
transition: 'opacity 0.25s ease',
|
|
306
|
+
}}
|
|
307
|
+
/>
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function getPlacementStyles(position) {
|
|
312
|
+
switch (position) {
|
|
313
|
+
case 'top':
|
|
314
|
+
return { alignItems: 'center', justifyContent: 'flex-start', paddingTop: 24 };
|
|
315
|
+
case 'top-left':
|
|
316
|
+
return { alignItems: 'flex-start', justifyContent: 'flex-start', padding: 20 };
|
|
317
|
+
case 'top-right':
|
|
318
|
+
return { alignItems: 'flex-end', justifyContent: 'flex-start', padding: 20 };
|
|
319
|
+
case 'bottom':
|
|
320
|
+
return { alignItems: 'center', justifyContent: 'flex-end', paddingBottom: 24 };
|
|
321
|
+
case 'bottom-left':
|
|
322
|
+
return { alignItems: 'flex-start', justifyContent: 'flex-end', padding: 20 };
|
|
323
|
+
case 'bottom-right':
|
|
324
|
+
return { alignItems: 'flex-end', justifyContent: 'flex-end', padding: 20 };
|
|
325
|
+
case 'center':
|
|
326
|
+
default:
|
|
327
|
+
return { alignItems: 'center', justifyContent: 'center' };
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export default function PrivacyBlur({
|
|
332
|
+
active = false,
|
|
333
|
+
blur = 6,
|
|
334
|
+
spoiler = false,
|
|
335
|
+
shimmerSpeed,
|
|
336
|
+
showBadge = true,
|
|
337
|
+
showCountdown = false,
|
|
338
|
+
showRevealButton = false,
|
|
339
|
+
position = 'center',
|
|
340
|
+
icon,
|
|
341
|
+
badgeIcon,
|
|
342
|
+
countdownIcon,
|
|
343
|
+
text,
|
|
344
|
+
subtext,
|
|
345
|
+
revealable = false,
|
|
346
|
+
interactive,
|
|
347
|
+
revealDuration,
|
|
348
|
+
revealText = 'Показать',
|
|
349
|
+
hideText = 'Скрыть',
|
|
350
|
+
onReveal,
|
|
351
|
+
onHide,
|
|
352
|
+
style,
|
|
353
|
+
contentStyle,
|
|
354
|
+
className,
|
|
355
|
+
children,
|
|
356
|
+
}) {
|
|
357
|
+
const isDark = useIsDarkMode();
|
|
358
|
+
const isRevealable = Boolean(revealable || interactive);
|
|
359
|
+
const [tempRevealed, setTempRevealed] = useState(false);
|
|
360
|
+
const [timeLeft, setTimeLeft] = useState(0);
|
|
361
|
+
const [isBursting, setIsBursting] = useState(false);
|
|
362
|
+
const [burstOrigin, setBurstOrigin] = useState(null);
|
|
363
|
+
|
|
364
|
+
const containerRef = useRef(null);
|
|
365
|
+
const timerRef = useRef(null);
|
|
366
|
+
|
|
367
|
+
const clearTimer = () => {
|
|
368
|
+
if (timerRef.current) {
|
|
369
|
+
clearInterval(timerRef.current);
|
|
370
|
+
timerRef.current = null;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
useEffect(() => {
|
|
375
|
+
if (!active) {
|
|
376
|
+
clearTimer();
|
|
377
|
+
setTempRevealed(false);
|
|
378
|
+
setIsBursting(false);
|
|
379
|
+
setTimeLeft(0);
|
|
380
|
+
}
|
|
381
|
+
}, [active]);
|
|
382
|
+
|
|
383
|
+
useEffect(() => {
|
|
384
|
+
return () => clearTimer();
|
|
385
|
+
}, []);
|
|
386
|
+
|
|
387
|
+
const finishReveal = () => {
|
|
388
|
+
const hasDuration = revealDuration !== undefined && revealDuration !== null && revealDuration !== false;
|
|
389
|
+
if (hasDuration) {
|
|
390
|
+
const duration = typeof revealDuration === 'number' && revealDuration > 0 ? revealDuration : 5;
|
|
391
|
+
clearTimer();
|
|
392
|
+
setTempRevealed(true);
|
|
393
|
+
setTimeLeft(duration);
|
|
394
|
+
|
|
395
|
+
timerRef.current = setInterval(() => {
|
|
396
|
+
setTimeLeft((prev) => {
|
|
397
|
+
if (prev <= 1) {
|
|
398
|
+
clearTimer();
|
|
399
|
+
setTempRevealed(false);
|
|
400
|
+
if (onHide) onHide();
|
|
401
|
+
return 0;
|
|
402
|
+
}
|
|
403
|
+
return prev - 1;
|
|
404
|
+
});
|
|
405
|
+
}, 1000);
|
|
406
|
+
} else {
|
|
407
|
+
if (onReveal) onReveal();
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const handleReveal = (e) => {
|
|
412
|
+
if (e) e.stopPropagation();
|
|
413
|
+
if (!isRevealable || isBursting) return;
|
|
414
|
+
|
|
415
|
+
if (spoiler) {
|
|
416
|
+
let origin = null;
|
|
417
|
+
if (e && typeof e.clientX === 'number' && typeof e.clientY === 'number' && containerRef.current) {
|
|
418
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
419
|
+
origin = {
|
|
420
|
+
x: Math.max(0, Math.min(rect.width, e.clientX - rect.left)),
|
|
421
|
+
y: Math.max(0, Math.min(rect.height, e.clientY - rect.top)),
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
setBurstOrigin(origin);
|
|
425
|
+
setIsBursting(true);
|
|
426
|
+
} else {
|
|
427
|
+
finishReveal();
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const handleBurstComplete = () => {
|
|
432
|
+
setIsBursting(false);
|
|
433
|
+
finishReveal();
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
const handleHideNow = (e) => {
|
|
437
|
+
if (e) e.stopPropagation();
|
|
438
|
+
clearTimer();
|
|
439
|
+
setTempRevealed(false);
|
|
440
|
+
setIsBursting(false);
|
|
441
|
+
setTimeLeft(0);
|
|
442
|
+
if (onHide) onHide();
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
const effectiveBadgeIcon = badgeIcon || icon;
|
|
446
|
+
const blurValue = typeof blur === 'number' ? `${blur}px` : blur;
|
|
447
|
+
const isBlurred = active && !tempRevealed;
|
|
448
|
+
const hasOverlay = showBadge && Boolean(text || effectiveBadgeIcon || (isRevealable && showRevealButton));
|
|
449
|
+
const placementStyles = getPlacementStyles(position);
|
|
450
|
+
|
|
451
|
+
return (
|
|
452
|
+
<div
|
|
453
|
+
ref={containerRef}
|
|
454
|
+
className={className}
|
|
455
|
+
onClick={isBlurred && isRevealable ? handleReveal : undefined}
|
|
456
|
+
style={{
|
|
457
|
+
position: 'relative',
|
|
458
|
+
width: '100%',
|
|
459
|
+
height: '100%',
|
|
460
|
+
minHeight: '100%',
|
|
461
|
+
display: 'flex',
|
|
462
|
+
flexDirection: 'column',
|
|
463
|
+
flex: 1,
|
|
464
|
+
overflow: 'hidden',
|
|
465
|
+
cursor: isBlurred && isRevealable ? 'pointer' : 'default',
|
|
466
|
+
...style,
|
|
467
|
+
}}
|
|
468
|
+
>
|
|
469
|
+
<div
|
|
470
|
+
style={{
|
|
471
|
+
width: '100%',
|
|
472
|
+
height: '100%',
|
|
473
|
+
display: 'flex',
|
|
474
|
+
flexDirection: 'column',
|
|
475
|
+
flex: 1,
|
|
476
|
+
filter: isBlurred && !isBursting ? `blur(${blurValue})` : 'none',
|
|
477
|
+
userSelect: isBlurred ? 'none' : 'auto',
|
|
478
|
+
pointerEvents: isBlurred ? 'none' : 'auto',
|
|
479
|
+
transition: 'filter 0.3s ease, opacity 0.25s ease',
|
|
480
|
+
opacity: isBlurred ? (isBursting ? 0.9 : 0.6) : 1,
|
|
481
|
+
...contentStyle,
|
|
482
|
+
}}
|
|
483
|
+
>
|
|
484
|
+
{children}
|
|
485
|
+
</div>
|
|
486
|
+
|
|
487
|
+
{spoiler && isBlurred && (
|
|
488
|
+
<SpoilerCanvas
|
|
489
|
+
active={isBlurred}
|
|
490
|
+
isBursting={isBursting}
|
|
491
|
+
burstOrigin={burstOrigin}
|
|
492
|
+
onBurstComplete={handleBurstComplete}
|
|
493
|
+
isDark={isDark}
|
|
494
|
+
shimmerSpeed={shimmerSpeed}
|
|
495
|
+
/>
|
|
496
|
+
)}
|
|
497
|
+
|
|
498
|
+
{isBlurred && hasOverlay && (
|
|
499
|
+
<div
|
|
500
|
+
style={{
|
|
501
|
+
position: 'absolute',
|
|
502
|
+
inset: 0,
|
|
503
|
+
width: '100%',
|
|
504
|
+
height: '100%',
|
|
505
|
+
display: 'flex',
|
|
506
|
+
flexDirection: 'column',
|
|
507
|
+
gap: 6,
|
|
508
|
+
padding: 12,
|
|
509
|
+
boxSizing: 'border-box',
|
|
510
|
+
zIndex: 3,
|
|
511
|
+
pointerEvents: isRevealable ? 'auto' : 'none',
|
|
512
|
+
opacity: isBursting ? 0 : 1,
|
|
513
|
+
transition: 'opacity 0.2s ease',
|
|
514
|
+
...placementStyles,
|
|
515
|
+
}}
|
|
516
|
+
>
|
|
517
|
+
<div
|
|
518
|
+
onClick={isRevealable ? handleReveal : undefined}
|
|
519
|
+
style={{
|
|
520
|
+
display: 'inline-flex',
|
|
521
|
+
alignItems: 'center',
|
|
522
|
+
gap: 8,
|
|
523
|
+
padding: '6px 14px',
|
|
524
|
+
borderRadius: 'var(--rads)',
|
|
525
|
+
background: 'var(--surface)',
|
|
526
|
+
border: '1px solid var(--border-light)',
|
|
527
|
+
boxShadow: 'var(--shadow)',
|
|
528
|
+
color: 'var(--primary-text)',
|
|
529
|
+
fontSize: '.76rem',
|
|
530
|
+
fontWeight: 600,
|
|
531
|
+
cursor: isRevealable ? 'pointer' : 'default',
|
|
532
|
+
backdropFilter: 'blur(8px)',
|
|
533
|
+
WebkitBackdropFilter: 'blur(8px)',
|
|
534
|
+
transition: 'all 0.2s ease',
|
|
535
|
+
maxWidth: '90%',
|
|
536
|
+
userSelect: 'none',
|
|
537
|
+
}}
|
|
538
|
+
>
|
|
539
|
+
<span style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0, alignSelf: 'center' }}>
|
|
540
|
+
{effectiveBadgeIcon || <EyeOff size={14} style={{ color: 'var(--muted)' }} />}
|
|
541
|
+
</span>
|
|
542
|
+
{text && <span style={{ whiteSpace: 'normal', wordBreak: 'break-word', lineHeight: 1.35 }}>{text}</span>}
|
|
543
|
+
{isRevealable && showRevealButton && (
|
|
544
|
+
<span style={{ fontSize: '.7rem', color: 'var(--accent)', textDecoration: 'underline', marginLeft: 4, flexShrink: 0, whiteSpace: 'nowrap', alignSelf: 'center' }}>
|
|
545
|
+
{revealText}
|
|
546
|
+
</span>
|
|
547
|
+
)}
|
|
548
|
+
</div>
|
|
549
|
+
{subtext && (
|
|
550
|
+
<span style={{ fontSize: '.68rem', color: 'var(--muted)', textAlign: 'center' }}>
|
|
551
|
+
{subtext}
|
|
552
|
+
</span>
|
|
553
|
+
)}
|
|
554
|
+
</div>
|
|
555
|
+
)}
|
|
556
|
+
|
|
557
|
+
{active && tempRevealed && showCountdown && (
|
|
558
|
+
<div
|
|
559
|
+
style={{
|
|
560
|
+
position: 'absolute',
|
|
561
|
+
top: 8,
|
|
562
|
+
right: 8,
|
|
563
|
+
display: 'inline-flex',
|
|
564
|
+
alignItems: 'center',
|
|
565
|
+
gap: 6,
|
|
566
|
+
padding: '3px 8px',
|
|
567
|
+
borderRadius: 'var(--rads)',
|
|
568
|
+
background: 'var(--surface)',
|
|
569
|
+
border: '1px solid var(--border-light)',
|
|
570
|
+
boxShadow: 'var(--shadow)',
|
|
571
|
+
fontSize: '.7rem',
|
|
572
|
+
fontWeight: 600,
|
|
573
|
+
color: 'var(--muted)',
|
|
574
|
+
zIndex: 4,
|
|
575
|
+
userSelect: 'none',
|
|
576
|
+
backdropFilter: 'blur(8px)',
|
|
577
|
+
WebkitBackdropFilter: 'blur(8px)',
|
|
578
|
+
}}
|
|
579
|
+
>
|
|
580
|
+
<span style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}>
|
|
581
|
+
{countdownIcon || <Eye size={12} style={{ color: 'var(--accent)' }} />}
|
|
582
|
+
</span>
|
|
583
|
+
<span style={{ whiteSpace: 'nowrap' }}>Скроется через {timeLeft}с</span>
|
|
584
|
+
<span
|
|
585
|
+
onClick={handleHideNow}
|
|
586
|
+
style={{
|
|
587
|
+
color: 'var(--accent)',
|
|
588
|
+
textDecoration: 'underline',
|
|
589
|
+
marginLeft: 4,
|
|
590
|
+
cursor: 'pointer',
|
|
591
|
+
flexShrink: 0,
|
|
592
|
+
whiteSpace: 'nowrap',
|
|
593
|
+
}}
|
|
594
|
+
>
|
|
595
|
+
{hideText}
|
|
596
|
+
</span>
|
|
597
|
+
</div>
|
|
598
|
+
)}
|
|
599
|
+
</div>
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export { PrivacyBlur };
|