@once-ui-system/fx 0.0.0-stage → 3.0.0-beta.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.
- package/LICENSE.md +21 -0
- package/README.md +16 -2
- package/dist/BlobFx.d.ts +10 -0
- package/dist/BlobFx.js +86 -0
- package/dist/CelebrationFx.d.ts +21 -0
- package/dist/CelebrationFx.js +319 -0
- package/dist/CountFx.d.ts +19 -0
- package/dist/CountFx.js +226 -0
- package/dist/CountdownFx.d.ts +13 -0
- package/dist/CountdownFx.js +65 -0
- package/dist/Effect.d.ts +52 -0
- package/dist/Effect.js +33 -0
- package/dist/FlipFx.d.ts +20 -0
- package/dist/FlipFx.js +71 -0
- package/dist/GlitchFx.d.ts +19 -0
- package/dist/GlitchFx.js +41 -0
- package/dist/GlitchFx.module.css +80 -0
- package/dist/HoloFx.d.ts +34 -0
- package/dist/HoloFx.js +99 -0
- package/dist/HoloFx.module.css +31 -0
- package/dist/LetterFx.d.ts +24 -0
- package/dist/LetterFx.js +83 -0
- package/dist/MatrixFx.d.ts +32 -0
- package/dist/MatrixFx.js +886 -0
- package/dist/ParticleFx.d.ts +26 -0
- package/dist/ParticleFx.js +154 -0
- package/dist/RevealFx.d.ts +27 -0
- package/dist/RevealFx.js +65 -0
- package/dist/RevealFx.module.css +27 -0
- package/dist/ShineFx.d.ts +17 -0
- package/dist/ShineFx.js +17 -0
- package/dist/ShineFx.module.css +39 -0
- package/dist/TiltFx.d.ts +12 -0
- package/dist/TiltFx.js +79 -0
- package/dist/TiltFx.module.css +13 -0
- package/dist/TypeFx.d.ts +41 -0
- package/dist/TypeFx.js +102 -0
- package/dist/WeatherFx.d.ts +22 -0
- package/dist/WeatherFx.js +869 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +19 -0
- package/dist/internal/FadingLetters.d.ts +8 -0
- package/dist/internal/FadingLetters.js +21 -0
- package/dist/internal/FadingLetters.module.css +226 -0
- package/dist/internal/cssColor.d.ts +4 -0
- package/dist/internal/cssColor.js +70 -0
- package/dist/internal/pointer.d.ts +9 -0
- package/dist/internal/pointer.js +11 -0
- package/dist/internal/reducedMotion.d.ts +7 -0
- package/dist/internal/reducedMotion.js +11 -0
- package/dist/internal/speed.d.ts +13 -0
- package/dist/internal/speed.js +15 -0
- package/dist/internal/translate.d.ts +13 -0
- package/dist/internal/translate.js +81 -0
- package/package.json +79 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Dopler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @once-ui-system/fx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Once UI effects: `RevealFx`, `CountFx`, `CountdownFx`, `TypeFx`, `LetterFx`,
|
|
4
|
+
`ShineFx`, `GlitchFx`, `HoloFx`, `TiltFx`, `FlipFx`, `BlobFx`, `MatrixFx`,
|
|
5
|
+
`ParticleFx`, `WeatherFx`, `CelebrationFx` and `Effect`. Until 3.0 they were part
|
|
6
|
+
of `@once-ui-system/core`; they are built on it and take it as a peer.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @once-ui-system/core @once-ui-system/fx
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { RevealFx } from "@once-ui-system/fx";
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Documentation: [docs.once-ui.com](https://docs.once-ui.com). Migrating from 2.x:
|
|
17
|
+
[MIGRATING.md](https://github.com/once-ui-system/core/blob/main/MIGRATING.md).
|
package/dist/BlobFx.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Row } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
export interface BlobFxProps extends React.ComponentProps<typeof Row> {
|
|
4
|
+
seed?: number;
|
|
5
|
+
}
|
|
6
|
+
declare const BlobFx: {
|
|
7
|
+
({ ref, seed, ...flex }: BlobFxProps): React.JSX.Element;
|
|
8
|
+
displayName: string;
|
|
9
|
+
};
|
|
10
|
+
export { BlobFx };
|
package/dist/BlobFx.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Background, Row } from "@once-ui-system/core";
|
|
4
|
+
const BlobFx = ({ ref, seed = 0, ...flex }) => {
|
|
5
|
+
// Generate pseudo-random values based on seed for consistent variation
|
|
6
|
+
const random1 = ((seed * 9301 + 49297) % 233280) / 233280;
|
|
7
|
+
const random2 = ((seed * 4877 + 37991) % 233280) / 233280;
|
|
8
|
+
const random3 = ((seed * 7919 + 28411) % 233280) / 233280;
|
|
9
|
+
// Randomize animation durations (±20%)
|
|
10
|
+
const duration1 = 8 + (random1 - 0.5) * 3.2; // 6.4 - 9.6s
|
|
11
|
+
const duration2 = 12 + (random2 - 0.5) * 4.8; // 9.6 - 14.4s
|
|
12
|
+
const duration3 = 10 + (random3 - 0.5) * 4; // 8 - 12s
|
|
13
|
+
// Randomize movement offsets (±30%)
|
|
14
|
+
const offset1 = 1 + (random1 - 0.5) * 0.6; // 0.7 - 1.3
|
|
15
|
+
const offset2 = 1 + (random2 - 0.5) * 0.6;
|
|
16
|
+
const offset3 = 1 + (random3 - 0.5) * 0.6;
|
|
17
|
+
return (_jsxs(Row, { ref: ref, fill: true, pointerEvents: "none", overflow: "hidden", "aria-hidden": "true", style: { filter: "blur(2rem)" }, ...flex, children: [_jsx(Background, { position: "absolute", fill: true, bottom: "0", left: "0", gradient: {
|
|
18
|
+
display: true,
|
|
19
|
+
colorStart: "accent-solid-weak",
|
|
20
|
+
width: "38%",
|
|
21
|
+
height: "35%",
|
|
22
|
+
}, style: {
|
|
23
|
+
animation: `blob2-${seed} ${duration2}s ease-in-out infinite`,
|
|
24
|
+
} }), _jsx(Background, { position: "absolute", fill: true, bottom: "0", left: "-20%", gradient: {
|
|
25
|
+
display: true,
|
|
26
|
+
colorStart: "accent-solid-medium",
|
|
27
|
+
width: "42%",
|
|
28
|
+
height: "25%",
|
|
29
|
+
}, style: {
|
|
30
|
+
animation: `blob3-${seed} ${duration3}s ease-in-out infinite`,
|
|
31
|
+
mixBlendMode: "plus-lighter",
|
|
32
|
+
} }), _jsx(Background, { position: "absolute", fill: true, bottom: "0", left: "10%", gradient: {
|
|
33
|
+
display: true,
|
|
34
|
+
colorStart: "brand-solid-strong",
|
|
35
|
+
width: "50%",
|
|
36
|
+
height: "35%",
|
|
37
|
+
}, style: {
|
|
38
|
+
animation: `blob1-${seed} ${duration1}s ease-in-out infinite`,
|
|
39
|
+
mixBlendMode: "screen",
|
|
40
|
+
} }), _jsx("style", { dangerouslySetInnerHTML: {
|
|
41
|
+
// The keyframes exist only when motion is welcome: under
|
|
42
|
+
// prefers-reduced-motion the animation names resolve to nothing
|
|
43
|
+
// and the blobs hold still.
|
|
44
|
+
__html: `
|
|
45
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
46
|
+
@keyframes blob1-${seed} {
|
|
47
|
+
0%, 100% {
|
|
48
|
+
transform: translateX(0);
|
|
49
|
+
}
|
|
50
|
+
33% {
|
|
51
|
+
transform: translateX(${4 * offset1}rem);
|
|
52
|
+
}
|
|
53
|
+
66% {
|
|
54
|
+
transform: translateX(${-3 * offset1}rem);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@keyframes blob2-${seed} {
|
|
59
|
+
0%, 100% {
|
|
60
|
+
transform: translateX(0);
|
|
61
|
+
}
|
|
62
|
+
33% {
|
|
63
|
+
transform: translateX(${-7 * offset2}rem);
|
|
64
|
+
}
|
|
65
|
+
66% {
|
|
66
|
+
transform: translateX(${5 * offset2}rem);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@keyframes blob3-${seed} {
|
|
71
|
+
0%, 100% {
|
|
72
|
+
transform: translateX(0);
|
|
73
|
+
}
|
|
74
|
+
33% {
|
|
75
|
+
transform: translateX(${6 * offset3}rem);
|
|
76
|
+
}
|
|
77
|
+
66% {
|
|
78
|
+
transform: translateX(${-6 * offset3}rem);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
`,
|
|
83
|
+
} })] }));
|
|
84
|
+
};
|
|
85
|
+
BlobFx.displayName = "BlobFx";
|
|
86
|
+
export { BlobFx };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Flex, type Speed } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
type CelebrationType = "confetti" | "fireworks";
|
|
4
|
+
interface CelebrationFxProps extends React.ComponentProps<typeof Flex> {
|
|
5
|
+
type?: CelebrationType;
|
|
6
|
+
/** A multiplier on the designed pace (`1`), or `"slow"`/`"medium"`/`"fast"` (0.5, 1, 2). */
|
|
7
|
+
speed?: Speed;
|
|
8
|
+
colors?: string[];
|
|
9
|
+
intensity?: number;
|
|
10
|
+
/** Milliseconds to keep emitting (seconds until 3.0). */
|
|
11
|
+
duration?: number;
|
|
12
|
+
trigger?: "mount" | "hover" | "manual" | "click";
|
|
13
|
+
active?: boolean;
|
|
14
|
+
reducedMotion?: boolean | "auto";
|
|
15
|
+
children?: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
declare const CelebrationFx: {
|
|
18
|
+
({ ref: forwardedRef, type, speed: speedProp, colors, intensity, duration, trigger, active, reducedMotion, children, style, ...rest }: CelebrationFxProps): React.JSX.Element;
|
|
19
|
+
displayName: string;
|
|
20
|
+
};
|
|
21
|
+
export { CelebrationFx };
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Flex, useReducedMotion } from "@once-ui-system/core";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
import { speedFactor } from "./internal/speed.js";
|
|
6
|
+
const CelebrationFx = ({ ref: forwardedRef, type = "confetti", speed: speedProp, colors = ["brand-solid-medium", "accent-solid-medium"], intensity = 50, duration, trigger = "mount", active = true, reducedMotion = "auto", children, style, ...rest }) => {
|
|
7
|
+
const speed = speedFactor(speedProp);
|
|
8
|
+
const { shouldAnimate } = useReducedMotion(reducedMotion);
|
|
9
|
+
const containerRef = useRef(null);
|
|
10
|
+
const canvasRef = useRef(null);
|
|
11
|
+
const animationRef = useRef(undefined);
|
|
12
|
+
const particlesRef = useRef([]);
|
|
13
|
+
const isEmittingRef = useRef(trigger === "mount");
|
|
14
|
+
const emitStartTimeRef = useRef(Date.now());
|
|
15
|
+
const isHoveredRef = useRef(false);
|
|
16
|
+
const fireworkTimerRef = useRef(0);
|
|
17
|
+
const clickPositionRef = useRef(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (forwardedRef) {
|
|
20
|
+
if ("current" in forwardedRef) {
|
|
21
|
+
forwardedRef.current = containerRef.current;
|
|
22
|
+
}
|
|
23
|
+
else if (typeof forwardedRef === "function") {
|
|
24
|
+
forwardedRef(containerRef.current);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, [forwardedRef]);
|
|
28
|
+
// Handle manual trigger
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (trigger === "manual") {
|
|
31
|
+
if (active) {
|
|
32
|
+
isEmittingRef.current = true;
|
|
33
|
+
emitStartTimeRef.current = Date.now();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
isEmittingRef.current = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, [trigger, active]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const canvas = canvasRef.current;
|
|
42
|
+
const container = containerRef.current;
|
|
43
|
+
if (!canvas || !container)
|
|
44
|
+
return;
|
|
45
|
+
const ctx = canvas.getContext("2d");
|
|
46
|
+
if (!ctx)
|
|
47
|
+
return;
|
|
48
|
+
// Set canvas size
|
|
49
|
+
let canvasWidth = 0;
|
|
50
|
+
let canvasHeight = 0;
|
|
51
|
+
const updateSize = () => {
|
|
52
|
+
const rect = container.getBoundingClientRect();
|
|
53
|
+
canvasWidth = rect.width;
|
|
54
|
+
canvasHeight = rect.height;
|
|
55
|
+
canvas.width = rect.width * 2; // 2x for retina
|
|
56
|
+
canvas.height = rect.height * 2;
|
|
57
|
+
canvas.style.width = `${rect.width}px`;
|
|
58
|
+
canvas.style.height = `${rect.height}px`;
|
|
59
|
+
ctx.scale(2, 2); // Scale for retina
|
|
60
|
+
};
|
|
61
|
+
updateSize();
|
|
62
|
+
window.addEventListener("resize", updateSize);
|
|
63
|
+
// Parse colors - convert token names to CSS variables
|
|
64
|
+
const parsedColors = colors.map((color) => {
|
|
65
|
+
const computedColor = getComputedStyle(container).getPropertyValue(`--${color}`);
|
|
66
|
+
return computedColor || color;
|
|
67
|
+
});
|
|
68
|
+
// Initialize confetti
|
|
69
|
+
const initializeConfetti = () => {
|
|
70
|
+
const particles = [];
|
|
71
|
+
const shapes = ["rectangle", "circle", "triangle"];
|
|
72
|
+
for (let i = 0; i < intensity; i++) {
|
|
73
|
+
// Stagger particles more dramatically over a larger vertical range
|
|
74
|
+
const stagger = (i / intensity) * canvasHeight * 2;
|
|
75
|
+
particles.push({
|
|
76
|
+
x: Math.random() * canvasWidth,
|
|
77
|
+
y: -canvasHeight - Math.random() * canvasHeight - stagger,
|
|
78
|
+
width: 8 + Math.random() * 8,
|
|
79
|
+
height: 6 + Math.random() * 6,
|
|
80
|
+
color: parsedColors[Math.floor(Math.random() * parsedColors.length)],
|
|
81
|
+
rotation: Math.random() * Math.PI * 2,
|
|
82
|
+
rotationSpeed: (Math.random() - 0.5) * 0.2,
|
|
83
|
+
velocityX: (Math.random() - 0.5) * 3,
|
|
84
|
+
velocityY: (0.5 + Math.random() * 2.5) * speed,
|
|
85
|
+
gravity: (0.12 + Math.random() * 0.06) * speed,
|
|
86
|
+
opacity: 0.8 + Math.random() * 0.2,
|
|
87
|
+
shape: shapes[Math.floor(Math.random() * shapes.length)],
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return particles;
|
|
91
|
+
};
|
|
92
|
+
// Create a new firework (explodes immediately at random or click position)
|
|
93
|
+
const createFirework = (clickPos) => {
|
|
94
|
+
const firework = {
|
|
95
|
+
x: clickPos ? clickPos.x : Math.random() * canvasWidth,
|
|
96
|
+
y: clickPos ? clickPos.y : canvasHeight * (0.2 + Math.random() * 0.4),
|
|
97
|
+
targetY: 0, // Not used anymore
|
|
98
|
+
velocityY: 0,
|
|
99
|
+
color: parsedColors[Math.floor(Math.random() * parsedColors.length)],
|
|
100
|
+
exploded: true, // Start already exploded
|
|
101
|
+
particles: [],
|
|
102
|
+
};
|
|
103
|
+
// Explode immediately
|
|
104
|
+
explodeFirework(firework);
|
|
105
|
+
return firework;
|
|
106
|
+
};
|
|
107
|
+
// Explode firework into particles
|
|
108
|
+
const explodeFirework = (firework) => {
|
|
109
|
+
const particleCount = 30 + Math.floor(Math.random() * 20);
|
|
110
|
+
for (let i = 0; i < particleCount; i++) {
|
|
111
|
+
const angle = (Math.PI * 2 * i) / particleCount;
|
|
112
|
+
const velocity = 1 + Math.random() * 3;
|
|
113
|
+
firework.particles.push({
|
|
114
|
+
x: firework.x,
|
|
115
|
+
y: firework.y,
|
|
116
|
+
velocityX: Math.cos(angle) * velocity * speed,
|
|
117
|
+
velocityY: Math.sin(angle) * velocity * speed,
|
|
118
|
+
color: firework.color,
|
|
119
|
+
opacity: 1,
|
|
120
|
+
size: 1 + Math.random(),
|
|
121
|
+
life: 0,
|
|
122
|
+
maxLife: 60 + Math.random() * 40,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
firework.exploded = true;
|
|
126
|
+
};
|
|
127
|
+
// Initialize particles only if not already initialized
|
|
128
|
+
if (particlesRef.current.length === 0 && type === "confetti") {
|
|
129
|
+
particlesRef.current = initializeConfetti();
|
|
130
|
+
}
|
|
131
|
+
// Animation loop
|
|
132
|
+
const animate = () => {
|
|
133
|
+
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
134
|
+
// Check if we should still be emitting new particles
|
|
135
|
+
const shouldEmit = trigger === "hover"
|
|
136
|
+
? isHoveredRef.current
|
|
137
|
+
: trigger === "manual"
|
|
138
|
+
? // Read from the ref the manual-trigger effect keeps in step with
|
|
139
|
+
// `active`: this loop's closure holds the `active` it started with.
|
|
140
|
+
isEmittingRef.current
|
|
141
|
+
: trigger === "click"
|
|
142
|
+
? clickPositionRef.current !== null
|
|
143
|
+
: isEmittingRef.current;
|
|
144
|
+
// Check duration limit
|
|
145
|
+
if (duration && isEmittingRef.current && trigger !== "manual") {
|
|
146
|
+
const elapsed = Date.now() - emitStartTimeRef.current;
|
|
147
|
+
if (elapsed > duration) {
|
|
148
|
+
isEmittingRef.current = false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (type === "confetti") {
|
|
152
|
+
// Update and draw confetti
|
|
153
|
+
particlesRef.current.forEach((piece) => {
|
|
154
|
+
// Update physics
|
|
155
|
+
piece.velocityY += piece.gravity;
|
|
156
|
+
piece.x += piece.velocityX;
|
|
157
|
+
piece.y += piece.velocityY;
|
|
158
|
+
piece.rotation += piece.rotationSpeed;
|
|
159
|
+
// Add some air resistance
|
|
160
|
+
piece.velocityX *= 0.99;
|
|
161
|
+
// Only respawn if we're still emitting
|
|
162
|
+
if (piece.y > canvasHeight + 50 && shouldEmit) {
|
|
163
|
+
piece.y = -20 - Math.random() * canvasHeight * 0.5;
|
|
164
|
+
piece.x = Math.random() * canvasWidth;
|
|
165
|
+
piece.velocityX = (Math.random() - 0.5) * 3;
|
|
166
|
+
piece.velocityY = (0.5 + Math.random() * 2.5) * speed;
|
|
167
|
+
piece.gravity = (0.12 + Math.random() * 0.06) * speed;
|
|
168
|
+
}
|
|
169
|
+
// Only draw if still on screen
|
|
170
|
+
if (piece.y < canvasHeight + 100) {
|
|
171
|
+
// Draw confetti piece
|
|
172
|
+
ctx.save();
|
|
173
|
+
ctx.translate(piece.x, piece.y);
|
|
174
|
+
ctx.rotate(piece.rotation);
|
|
175
|
+
ctx.globalAlpha = piece.opacity;
|
|
176
|
+
ctx.fillStyle = piece.color;
|
|
177
|
+
if (piece.shape === "rectangle") {
|
|
178
|
+
ctx.fillRect(-piece.width / 2, -piece.height / 2, piece.width, piece.height);
|
|
179
|
+
}
|
|
180
|
+
else if (piece.shape === "circle") {
|
|
181
|
+
ctx.beginPath();
|
|
182
|
+
ctx.arc(0, 0, piece.width / 2, 0, Math.PI * 2);
|
|
183
|
+
ctx.fill();
|
|
184
|
+
}
|
|
185
|
+
else if (piece.shape === "triangle") {
|
|
186
|
+
ctx.beginPath();
|
|
187
|
+
ctx.moveTo(0, -piece.height / 2);
|
|
188
|
+
ctx.lineTo(piece.width / 2, piece.height / 2);
|
|
189
|
+
ctx.lineTo(-piece.width / 2, piece.height / 2);
|
|
190
|
+
ctx.closePath();
|
|
191
|
+
ctx.fill();
|
|
192
|
+
}
|
|
193
|
+
ctx.restore();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
else if (type === "fireworks") {
|
|
198
|
+
// Launch new fireworks
|
|
199
|
+
if (trigger === "click" && clickPositionRef.current) {
|
|
200
|
+
// Fire from click position
|
|
201
|
+
particlesRef.current.push(createFirework(clickPositionRef.current));
|
|
202
|
+
clickPositionRef.current = null;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
fireworkTimerRef.current++;
|
|
206
|
+
if (shouldEmit && fireworkTimerRef.current > 20 / speed) {
|
|
207
|
+
// Launch new firework every ~20 frames
|
|
208
|
+
fireworkTimerRef.current = 0;
|
|
209
|
+
particlesRef.current.push(createFirework());
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Update and draw fireworks (explosion particles only)
|
|
213
|
+
particlesRef.current.forEach((firework) => {
|
|
214
|
+
// Update and draw explosion particles
|
|
215
|
+
firework.particles.forEach((particle) => {
|
|
216
|
+
particle.life++;
|
|
217
|
+
if (particle.life < particle.maxLife) {
|
|
218
|
+
// Update position
|
|
219
|
+
particle.x += particle.velocityX;
|
|
220
|
+
particle.y += particle.velocityY;
|
|
221
|
+
particle.velocityY += 0.1; // Gravity
|
|
222
|
+
// Fade out
|
|
223
|
+
particle.opacity = 1 - particle.life / particle.maxLife;
|
|
224
|
+
// Draw particle
|
|
225
|
+
ctx.globalAlpha = particle.opacity;
|
|
226
|
+
ctx.fillStyle = particle.color;
|
|
227
|
+
ctx.beginPath();
|
|
228
|
+
ctx.arc(particle.x, particle.y, particle.size, 0, Math.PI * 2);
|
|
229
|
+
ctx.fill();
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
// Clean up dead fireworks (only when not emitting)
|
|
234
|
+
if (!shouldEmit) {
|
|
235
|
+
particlesRef.current = particlesRef.current.filter((firework) => {
|
|
236
|
+
// Keep if any particles are still alive
|
|
237
|
+
return firework.particles.some((p) => p.life < p.maxLife);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
ctx.globalAlpha = 1;
|
|
242
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
243
|
+
};
|
|
244
|
+
if (shouldAnimate) {
|
|
245
|
+
animate();
|
|
246
|
+
}
|
|
247
|
+
return () => {
|
|
248
|
+
window.removeEventListener("resize", updateSize);
|
|
249
|
+
if (animationRef.current) {
|
|
250
|
+
cancelAnimationFrame(animationRef.current);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}, [type, colors, speed, intensity, duration, trigger, shouldAnimate]);
|
|
254
|
+
const handleMouseEnter = () => {
|
|
255
|
+
if (trigger === "hover" && !isHoveredRef.current) {
|
|
256
|
+
isHoveredRef.current = true;
|
|
257
|
+
isEmittingRef.current = true;
|
|
258
|
+
emitStartTimeRef.current = Date.now();
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const handleMouseLeave = () => {
|
|
262
|
+
if (trigger === "hover" && isHoveredRef.current) {
|
|
263
|
+
isHoveredRef.current = false;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
const handleClick = (e) => {
|
|
267
|
+
if (trigger === "click" && containerRef.current) {
|
|
268
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
269
|
+
const x = e.clientX - rect.left;
|
|
270
|
+
const y = e.clientY - rect.top;
|
|
271
|
+
if (type === "confetti") {
|
|
272
|
+
// For confetti, add burst of particles from click position
|
|
273
|
+
const shapes = ["rectangle", "circle", "triangle"];
|
|
274
|
+
const canvas = canvasRef.current;
|
|
275
|
+
if (!canvas)
|
|
276
|
+
return;
|
|
277
|
+
const parsedColors = colors.map((color) => {
|
|
278
|
+
const computedColor = getComputedStyle(containerRef.current).getPropertyValue(`--${color}`);
|
|
279
|
+
return computedColor || color;
|
|
280
|
+
});
|
|
281
|
+
for (let i = 0; i < intensity; i++) {
|
|
282
|
+
const angle = (Math.PI * 2 * i) / intensity;
|
|
283
|
+
const velocity = 2 + Math.random() * 3;
|
|
284
|
+
particlesRef.current.push({
|
|
285
|
+
x,
|
|
286
|
+
y,
|
|
287
|
+
width: 8 + Math.random() * 8,
|
|
288
|
+
height: 6 + Math.random() * 6,
|
|
289
|
+
color: parsedColors[Math.floor(Math.random() * parsedColors.length)],
|
|
290
|
+
rotation: Math.random() * Math.PI * 2,
|
|
291
|
+
rotationSpeed: (Math.random() - 0.5) * 0.2,
|
|
292
|
+
velocityX: Math.cos(angle) * velocity,
|
|
293
|
+
velocityY: Math.sin(angle) * velocity - 2, // Slight upward bias
|
|
294
|
+
gravity: (0.12 + Math.random() * 0.06) * speed,
|
|
295
|
+
opacity: 0.8 + Math.random() * 0.2,
|
|
296
|
+
shape: shapes[Math.floor(Math.random() * shapes.length)],
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
// For fireworks, store click position
|
|
302
|
+
clickPositionRef.current = { x, y };
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
return (_jsxs(Flex, { ref: containerRef, fill: true, overflow: "hidden", onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onClick: handleClick, ...rest, style: {
|
|
307
|
+
cursor: trigger === "click" ? "pointer" : undefined,
|
|
308
|
+
...style,
|
|
309
|
+
}, children: [_jsx("canvas", { ref: canvasRef, "aria-hidden": "true", style: {
|
|
310
|
+
position: "absolute",
|
|
311
|
+
top: 0,
|
|
312
|
+
left: 0,
|
|
313
|
+
width: "100%",
|
|
314
|
+
height: "100%",
|
|
315
|
+
pointerEvents: "none",
|
|
316
|
+
} }), children] }));
|
|
317
|
+
};
|
|
318
|
+
CelebrationFx.displayName = "CelebrationFx";
|
|
319
|
+
export { CelebrationFx };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Text } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
export interface CountFxProps extends Omit<React.ComponentProps<typeof Text>, "ref"> {
|
|
4
|
+
value: number;
|
|
5
|
+
/** Milliseconds one count from the old value to the new one takes. Was `speed` until 3.0. */
|
|
6
|
+
duration?: number;
|
|
7
|
+
easing?: "linear" | "ease-out" | "ease-in-out";
|
|
8
|
+
format?: (value: number) => string;
|
|
9
|
+
separator?: string;
|
|
10
|
+
decimals?: number;
|
|
11
|
+
effect?: "simple" | "wheel" | "smooth";
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
14
|
+
}
|
|
15
|
+
declare const CountFx: {
|
|
16
|
+
({ ref, value, duration, easing, format, separator, decimals, effect, children, ...text }: CountFxProps): React.JSX.Element;
|
|
17
|
+
displayName: string;
|
|
18
|
+
};
|
|
19
|
+
export { CountFx };
|