@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/dist/CountFx.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Row, Text, useReducedMotion, VisuallyHidden } from "@once-ui-system/core";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { prefersReducedMotionNow } from "./internal/reducedMotion.js";
|
|
6
|
+
const CountFx = ({ ref, value, duration = 1000, easing = "ease-out", format, separator, decimals, effect = "simple", children, ...text }) => {
|
|
7
|
+
const [displayValue, setDisplayValue] = useState(value);
|
|
8
|
+
const [animationProgress, setAnimationProgress] = useState(1);
|
|
9
|
+
const animationRef = useRef(undefined);
|
|
10
|
+
// What the display currently reads, mirrored on every frame. A run starts
|
|
11
|
+
// from here rather than from the last *completed* value: when `value` is
|
|
12
|
+
// changed back mid-flight, the old code saw `value === previousValueRef`
|
|
13
|
+
// and returned early, having already cancelled the frame, stranding the
|
|
14
|
+
// number at whatever it happened to be showing.
|
|
15
|
+
const displayValueRef = useRef(value);
|
|
16
|
+
// Where the run in flight started. `smooth` renders its digit wheels from
|
|
17
|
+
// this origin, so it has to track the current run, not the last finished one.
|
|
18
|
+
const previousValueRef = useRef(value);
|
|
19
|
+
const { prefersReducedMotion } = useReducedMotion();
|
|
20
|
+
// Default format function with separator and decimals support
|
|
21
|
+
const defaultFormat = (val) => {
|
|
22
|
+
let formattedValue = decimals !== undefined ? val.toFixed(decimals) : val.toString();
|
|
23
|
+
if (separator) {
|
|
24
|
+
const parts = formattedValue.split(".");
|
|
25
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
26
|
+
formattedValue = parts.join(".");
|
|
27
|
+
}
|
|
28
|
+
return formattedValue;
|
|
29
|
+
};
|
|
30
|
+
const formatValue = format || defaultFormat;
|
|
31
|
+
// Easing functions
|
|
32
|
+
const getEasing = (progress) => {
|
|
33
|
+
switch (easing) {
|
|
34
|
+
case "linear":
|
|
35
|
+
return progress;
|
|
36
|
+
case "ease-out":
|
|
37
|
+
return 1 - (1 - progress) ** 3;
|
|
38
|
+
case "ease-in-out":
|
|
39
|
+
return progress < 0.5 ? 2 * progress * progress : 1 - (-2 * progress + 2) ** 2 / 2;
|
|
40
|
+
default:
|
|
41
|
+
return 1 - (1 - progress) ** 3;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
// Wheel animation: create digit wheels
|
|
45
|
+
const renderWheelDigits = (currentValue, targetValue) => {
|
|
46
|
+
const currentStr = currentValue.toString().padStart(targetValue.toString().length, "0");
|
|
47
|
+
const targetStr = targetValue.toString();
|
|
48
|
+
const maxLength = Math.max(currentStr.length, targetStr.length);
|
|
49
|
+
return Array.from({ length: maxLength }, (_, index) => {
|
|
50
|
+
const currentDigit = parseInt(currentStr[maxLength - 1 - index] || "0");
|
|
51
|
+
const targetDigit = parseInt(targetStr[maxLength - 1 - index] || "0");
|
|
52
|
+
// Calculate progress for this specific digit
|
|
53
|
+
const digitDifference = targetDigit - currentDigit;
|
|
54
|
+
const digitProgress = Math.abs(digitDifference) > 0 ? Math.min(Math.abs(digitDifference) / 10, 1) : 1; // Progress based on how close to target
|
|
55
|
+
// Create wheel effect for this digit
|
|
56
|
+
const wheelDigits = [];
|
|
57
|
+
for (let i = 0; i <= 9; i++) {
|
|
58
|
+
const isActive = i === currentDigit;
|
|
59
|
+
// Calculate transition speed based on progress (slower as it approaches target)
|
|
60
|
+
const transitionDuration = 0.1 + digitProgress * 0.2; // 0.1s to 0.3s
|
|
61
|
+
// Calculate position for wheel effect
|
|
62
|
+
let position = 0;
|
|
63
|
+
if (isActive) {
|
|
64
|
+
position = 0; // Current digit is centered
|
|
65
|
+
}
|
|
66
|
+
else if (i < currentDigit) {
|
|
67
|
+
position = -100; // Digits below current are above
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
position = 100; // Digits above current are below
|
|
71
|
+
}
|
|
72
|
+
wheelDigits.push(_jsx(Row, { center: true, position: "absolute", top: "0", left: "0", right: "0", bottom: "0", style: {
|
|
73
|
+
height: "1em",
|
|
74
|
+
width: "100%",
|
|
75
|
+
transform: `translateY(${position * 2}%)`,
|
|
76
|
+
transition: `all ${transitionDuration}s ease-out`,
|
|
77
|
+
pointerEvents: "none",
|
|
78
|
+
}, children: i }, i));
|
|
79
|
+
}
|
|
80
|
+
return (_jsx(Row, { align: "center", overflow: "hidden", inline: true, style: {
|
|
81
|
+
height: "1em",
|
|
82
|
+
width: "0.8em",
|
|
83
|
+
marginLeft: "-0.125em",
|
|
84
|
+
marginRight: "-0.125em",
|
|
85
|
+
position: "relative",
|
|
86
|
+
isolation: "isolate",
|
|
87
|
+
}, children: wheelDigits }, index));
|
|
88
|
+
}).reverse();
|
|
89
|
+
};
|
|
90
|
+
// Smooth animation: animate each digit independently from start to target
|
|
91
|
+
const renderSmoothDigits = (startValue, targetValue, progress) => {
|
|
92
|
+
const startStr = startValue.toString().padStart(targetValue.toString().length, "0");
|
|
93
|
+
const targetStr = targetValue.toString();
|
|
94
|
+
const maxLength = Math.max(startStr.length, targetStr.length);
|
|
95
|
+
return Array.from({ length: maxLength }, (_, index) => {
|
|
96
|
+
const startDigit = parseInt(startStr[maxLength - 1 - index] || "0");
|
|
97
|
+
const targetDigit = parseInt(targetStr[maxLength - 1 - index] || "0");
|
|
98
|
+
// Calculate the shortest path between digits (handles wrapping around 0-9)
|
|
99
|
+
let digitDifference = targetDigit - startDigit;
|
|
100
|
+
if (Math.abs(digitDifference) > 5) {
|
|
101
|
+
// Take the shorter path around the wheel
|
|
102
|
+
digitDifference = digitDifference > 0 ? digitDifference - 10 : digitDifference + 10;
|
|
103
|
+
}
|
|
104
|
+
// Calculate the current digit position based on progress
|
|
105
|
+
const currentDigitPosition = startDigit + digitDifference * progress;
|
|
106
|
+
// Create wheel effect for this digit
|
|
107
|
+
const wheelDigits = [];
|
|
108
|
+
for (let i = 0; i <= 9; i++) {
|
|
109
|
+
// Calculate the position of each digit in the wheel
|
|
110
|
+
let position = 0;
|
|
111
|
+
// Calculate the relative position of this digit to the current position
|
|
112
|
+
let relativePosition = i - currentDigitPosition;
|
|
113
|
+
// Handle wrapping around the wheel
|
|
114
|
+
if (relativePosition > 5)
|
|
115
|
+
relativePosition -= 10;
|
|
116
|
+
if (relativePosition < -5)
|
|
117
|
+
relativePosition += 10;
|
|
118
|
+
// Convert to percentage position
|
|
119
|
+
position = relativePosition * 200; // 200% for full wheel height
|
|
120
|
+
const opacity = Math.max(0, 1 - Math.abs(relativePosition) * 2);
|
|
121
|
+
wheelDigits.push(_jsx(Row, { center: true, position: "absolute", top: "0", left: "0", right: "0", bottom: "0", pointerEvents: "none", fillWidth: true, style: {
|
|
122
|
+
height: "1em",
|
|
123
|
+
transform: `translateY(${position}%)`,
|
|
124
|
+
transition: "none",
|
|
125
|
+
opacity: opacity,
|
|
126
|
+
}, children: i }, i));
|
|
127
|
+
}
|
|
128
|
+
return (_jsx(Row, { style: {
|
|
129
|
+
height: "1em",
|
|
130
|
+
marginLeft: "-0.125em",
|
|
131
|
+
marginRight: "-0.125em",
|
|
132
|
+
}, children: _jsx(Row, { align: "center", inline: true, overflow: "hidden", style: {
|
|
133
|
+
opacity: 1,
|
|
134
|
+
height: "2em",
|
|
135
|
+
width: "0.8em",
|
|
136
|
+
isolation: "isolate",
|
|
137
|
+
}, children: wheelDigits }) }, index));
|
|
138
|
+
}).reverse();
|
|
139
|
+
};
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (value === displayValueRef.current)
|
|
142
|
+
return;
|
|
143
|
+
const startValue = displayValueRef.current;
|
|
144
|
+
previousValueRef.current = startValue;
|
|
145
|
+
const endValue = value;
|
|
146
|
+
const difference = endValue - startValue;
|
|
147
|
+
let startTime;
|
|
148
|
+
const commit = (next) => {
|
|
149
|
+
displayValueRef.current = next;
|
|
150
|
+
setDisplayValue(next);
|
|
151
|
+
};
|
|
152
|
+
// Under reduced motion the number changes without counting through.
|
|
153
|
+
if (prefersReducedMotion || prefersReducedMotionNow()) {
|
|
154
|
+
if (animationRef.current)
|
|
155
|
+
cancelAnimationFrame(animationRef.current);
|
|
156
|
+
animationRef.current = undefined;
|
|
157
|
+
previousValueRef.current = endValue;
|
|
158
|
+
commit(endValue);
|
|
159
|
+
setAnimationProgress(1);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const animate = (timestamp) => {
|
|
163
|
+
if (!startTime)
|
|
164
|
+
startTime = timestamp;
|
|
165
|
+
const elapsed = timestamp - startTime;
|
|
166
|
+
const progress = Math.min(elapsed / duration, 1);
|
|
167
|
+
const easedProgress = getEasing(progress);
|
|
168
|
+
if (effect === "wheel") {
|
|
169
|
+
// For wheel animation, we animate each digit independently
|
|
170
|
+
const currentValue = decimals !== undefined
|
|
171
|
+
? parseFloat((startValue + difference * easedProgress).toFixed(decimals))
|
|
172
|
+
: Math.floor(startValue + difference * easedProgress);
|
|
173
|
+
commit(currentValue);
|
|
174
|
+
}
|
|
175
|
+
else if (effect === "smooth") {
|
|
176
|
+
// For smooth animation, we track progress and animate digits independently
|
|
177
|
+
setAnimationProgress(easedProgress);
|
|
178
|
+
const currentValue = decimals !== undefined
|
|
179
|
+
? parseFloat((startValue + difference * easedProgress).toFixed(decimals))
|
|
180
|
+
: Math.floor(startValue + difference * easedProgress);
|
|
181
|
+
commit(currentValue);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
// Simple animation
|
|
185
|
+
const currentValue = startValue + difference * easedProgress;
|
|
186
|
+
const currentStepValue = decimals !== undefined
|
|
187
|
+
? parseFloat(currentValue.toFixed(decimals))
|
|
188
|
+
: Math.floor(currentValue);
|
|
189
|
+
commit(currentStepValue);
|
|
190
|
+
}
|
|
191
|
+
if (progress < 1) {
|
|
192
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
commit(endValue);
|
|
196
|
+
setAnimationProgress(1);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
if (animationRef.current) {
|
|
200
|
+
cancelAnimationFrame(animationRef.current);
|
|
201
|
+
}
|
|
202
|
+
animationRef.current = requestAnimationFrame(animate);
|
|
203
|
+
return () => {
|
|
204
|
+
if (animationRef.current) {
|
|
205
|
+
cancelAnimationFrame(animationRef.current);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}, [value, duration, easing, effect, prefersReducedMotion]);
|
|
209
|
+
// Cleanup on unmount
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
return () => {
|
|
212
|
+
if (animationRef.current) {
|
|
213
|
+
cancelAnimationFrame(animationRef.current);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}, []);
|
|
217
|
+
if (effect === "wheel") {
|
|
218
|
+
return (_jsx("span", { ref: ref, children: _jsxs(Text, { ...text, style: { display: "flex", alignItems: "center", gap: "0.1em", ...text.style }, children: [_jsx("span", { "aria-hidden": "true", style: { display: "contents" }, children: renderWheelDigits(displayValue, value) }), _jsx(VisuallyHidden, { children: formatValue(value) }), children] }) }));
|
|
219
|
+
}
|
|
220
|
+
if (effect === "smooth") {
|
|
221
|
+
return (_jsx("span", { ref: ref, children: _jsxs(Text, { ...text, style: { display: "flex", alignItems: "center", gap: "0.1em", ...text.style }, children: [_jsx("span", { "aria-hidden": "true", style: { display: "contents" }, children: renderSmoothDigits(previousValueRef.current, value, animationProgress) }), _jsx(VisuallyHidden, { children: formatValue(value) }), children] }) }));
|
|
222
|
+
}
|
|
223
|
+
return (_jsx("span", { ref: ref, children: _jsxs(Text, { ...text, children: [formatValue(displayValue), children] }) }));
|
|
224
|
+
};
|
|
225
|
+
CountFx.displayName = "CountFx";
|
|
226
|
+
export { CountFx };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type CountFxProps } from "./CountFx.js";
|
|
3
|
+
export interface CountdownFxProps extends Omit<CountFxProps, "value" | "format" | "separator" | "effect"> {
|
|
4
|
+
targetDate: Date | string;
|
|
5
|
+
format?: "HH:MM:SS" | "DD:HH:MM:SS" | "MM:SS";
|
|
6
|
+
effect?: CountFxProps["effect"];
|
|
7
|
+
onComplete?: () => void;
|
|
8
|
+
}
|
|
9
|
+
declare const CountdownFx: {
|
|
10
|
+
({ ref, targetDate, format, effect, onComplete, ...countFxProps }: CountdownFxProps): React.JSX.Element;
|
|
11
|
+
displayName: string;
|
|
12
|
+
};
|
|
13
|
+
export { CountdownFx };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Row, Text } from "@once-ui-system/core";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { CountFx } from "./CountFx.js";
|
|
6
|
+
const CountdownFx = ({ ref, targetDate, format = "HH:MM:SS", effect = "wheel", onComplete, ...countFxProps }) => {
|
|
7
|
+
const [timeRemaining, setTimeRemaining] = useState({
|
|
8
|
+
days: 0,
|
|
9
|
+
hours: 0,
|
|
10
|
+
minutes: 0,
|
|
11
|
+
seconds: 0,
|
|
12
|
+
total: 0,
|
|
13
|
+
});
|
|
14
|
+
// The target as a number, so a fresh Date for the same moment (a parent
|
|
15
|
+
// re-rendering `new Date(...)`) does not restart the countdown.
|
|
16
|
+
const target = typeof targetDate === "string" ? new Date(targetDate).getTime() : targetDate.getTime();
|
|
17
|
+
// Read through a ref: an inline callback is a new function on every render,
|
|
18
|
+
// and must not restart the countdown or fire again.
|
|
19
|
+
const onCompleteRef = useRef(onComplete);
|
|
20
|
+
onCompleteRef.current = onComplete;
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
let interval;
|
|
23
|
+
const calculateTimeRemaining = () => {
|
|
24
|
+
const now = new Date().getTime();
|
|
25
|
+
const difference = target - now;
|
|
26
|
+
if (difference <= 0) {
|
|
27
|
+
setTimeRemaining({ days: 0, hours: 0, minutes: 0, seconds: 0, total: 0 });
|
|
28
|
+
// Done: stop ticking, so onComplete fires once rather than every second.
|
|
29
|
+
if (interval !== undefined)
|
|
30
|
+
clearInterval(interval);
|
|
31
|
+
interval = undefined;
|
|
32
|
+
onCompleteRef.current?.();
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const days = Math.floor(difference / (1000 * 60 * 60 * 24));
|
|
36
|
+
const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
|
37
|
+
const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60));
|
|
38
|
+
const seconds = Math.floor((difference % (1000 * 60)) / 1000);
|
|
39
|
+
setTimeRemaining({ days, hours, minutes, seconds, total: difference });
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
if (calculateTimeRemaining()) {
|
|
43
|
+
interval = setInterval(calculateTimeRemaining, 1000);
|
|
44
|
+
}
|
|
45
|
+
return () => {
|
|
46
|
+
if (interval !== undefined)
|
|
47
|
+
clearInterval(interval);
|
|
48
|
+
};
|
|
49
|
+
}, [target]);
|
|
50
|
+
const padZero = (num) => num.toString().padStart(2, "0");
|
|
51
|
+
const renderTimeUnit = (value, key) => {
|
|
52
|
+
const paddedValue = padZero(value);
|
|
53
|
+
const digits = paddedValue.split("");
|
|
54
|
+
return (_jsx(Row, { gap: "0", inline: true, children: digits.map((digit, index) => (_jsx(CountFx, { value: parseInt(digit), effect: effect, duration: 400, ...countFxProps }, `${key}-${index}`))) }, key));
|
|
55
|
+
};
|
|
56
|
+
const renderSeparator = () => (_jsx(Text, { ...countFxProps, style: { width: "0.5em", textAlign: "center" }, children: ":" }, "separator"));
|
|
57
|
+
if (timeRemaining.total === 0) {
|
|
58
|
+
return (_jsxs(Row, { ref: ref, gap: "0", align: "center", textVariant: countFxProps.textVariant, style: { fontVariantNumeric: "tabular-nums" }, children: [format === "DD:HH:MM:SS" && (_jsxs(_Fragment, { children: [renderTimeUnit(0, "days"), renderSeparator()] })), renderTimeUnit(0, "hours"), renderSeparator(), renderTimeUnit(0, "minutes"), format !== "MM:SS" && (_jsxs(_Fragment, { children: [renderSeparator(), renderTimeUnit(0, "seconds")] }))] }));
|
|
59
|
+
}
|
|
60
|
+
return (_jsxs(Row, { ref: ref, gap: "0", align: "center", style: { fontVariantNumeric: "tabular-nums" }, children: [format === "DD:HH:MM:SS" && timeRemaining.days > 0 && (_jsxs(_Fragment, { children: [renderTimeUnit(timeRemaining.days, "days"), renderSeparator()] })), format !== "MM:SS" && (_jsxs(_Fragment, { children: [renderTimeUnit(format === "DD:HH:MM:SS"
|
|
61
|
+
? timeRemaining.hours
|
|
62
|
+
: timeRemaining.days * 24 + timeRemaining.hours, "hours"), renderSeparator()] })), renderTimeUnit(timeRemaining.minutes, "minutes"), renderSeparator(), renderTimeUnit(timeRemaining.seconds, "seconds")] }));
|
|
63
|
+
};
|
|
64
|
+
CountdownFx.displayName = "CountdownFx";
|
|
65
|
+
export { CountdownFx };
|
package/dist/Effect.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Flex, type Speed } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import { BlobFx } from "./BlobFx.js";
|
|
4
|
+
import { CelebrationFx } from "./CelebrationFx.js";
|
|
5
|
+
import { MatrixFx } from "./MatrixFx.js";
|
|
6
|
+
import { ParticleFx } from "./ParticleFx.js";
|
|
7
|
+
import { WeatherFx } from "./WeatherFx.js";
|
|
8
|
+
/**
|
|
9
|
+
* The ambient effects that are interchangeable with one another: each paints a
|
|
10
|
+
* full-bleed decorative layer behind its content and none of them owns any
|
|
11
|
+
* layout. `"none"` renders the content with no layer at all, which is what
|
|
12
|
+
* makes the whole set switchable from a single setting.
|
|
13
|
+
*/
|
|
14
|
+
type EffectType = "none" | "blob" | "matrix" | "weather" | "particle" | "celebration";
|
|
15
|
+
interface EffectProps extends React.ComponentProps<typeof Flex> {
|
|
16
|
+
/**
|
|
17
|
+
* Which ambient layer to paint. This is the whole point of the component: a
|
|
18
|
+
* template can expose one setting and swap its aesthetic without any of its
|
|
19
|
+
* pages knowing which effect they ended up with.
|
|
20
|
+
*/
|
|
21
|
+
type?: EffectType;
|
|
22
|
+
/**
|
|
23
|
+
* Palette for the layer, shared across every effect that paints in colour.
|
|
24
|
+
* `particle` takes a single colour, so it uses the first entry. `blob` paints
|
|
25
|
+
* from the accent scheme and ignores this.
|
|
26
|
+
*/
|
|
27
|
+
colors?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Shared speed multiplier (`1` is each effect's designed pace), or
|
|
30
|
+
* `"slow"`/`"medium"`/`"fast"` (0.5, 1, 2). Ignored by `blob`, which is
|
|
31
|
+
* seeded, not timed.
|
|
32
|
+
*/
|
|
33
|
+
speed?: Speed;
|
|
34
|
+
reducedMotion?: boolean | "auto";
|
|
35
|
+
/**
|
|
36
|
+
* Per-effect settings. Only the block matching `type` is read, so a template
|
|
37
|
+
* can configure all of them up front and still switch with one prop. Anything
|
|
38
|
+
* set here wins over the shared `colors`/`speed`/`reducedMotion` above.
|
|
39
|
+
*/
|
|
40
|
+
blob?: Omit<React.ComponentProps<typeof BlobFx>, "children">;
|
|
41
|
+
matrix?: Omit<React.ComponentProps<typeof MatrixFx>, "children">;
|
|
42
|
+
weather?: Omit<React.ComponentProps<typeof WeatherFx>, "children">;
|
|
43
|
+
particle?: Omit<React.ComponentProps<typeof ParticleFx>, "children">;
|
|
44
|
+
celebration?: Omit<React.ComponentProps<typeof CelebrationFx>, "children">;
|
|
45
|
+
children?: React.ReactNode;
|
|
46
|
+
}
|
|
47
|
+
declare const Effect: {
|
|
48
|
+
({ ref, type, colors, speed, reducedMotion, blob, matrix, weather, particle, celebration, children, ...flex }: EffectProps): React.JSX.Element;
|
|
49
|
+
displayName: string;
|
|
50
|
+
};
|
|
51
|
+
export type { EffectProps, EffectType };
|
|
52
|
+
export { Effect };
|
package/dist/Effect.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Flex } from "@once-ui-system/core";
|
|
4
|
+
import { BlobFx } from "./BlobFx.js";
|
|
5
|
+
import { CelebrationFx } from "./CelebrationFx.js";
|
|
6
|
+
import { MatrixFx } from "./MatrixFx.js";
|
|
7
|
+
import { ParticleFx } from "./ParticleFx.js";
|
|
8
|
+
import { WeatherFx } from "./WeatherFx.js";
|
|
9
|
+
const Effect = ({ ref, type = "none", colors, speed, reducedMotion, blob, matrix, weather, particle, celebration, children, ...flex }) => {
|
|
10
|
+
// Every layer is positioned identically and sits under the children, so
|
|
11
|
+
// switching `type` changes the look and nothing else.
|
|
12
|
+
const layer = { position: "absolute", fill: true, top: "0", left: "0" };
|
|
13
|
+
const shared = { speed, reducedMotion };
|
|
14
|
+
const effect = (() => {
|
|
15
|
+
switch (type) {
|
|
16
|
+
case "blob":
|
|
17
|
+
return _jsx(BlobFx, { ...layer, ...blob });
|
|
18
|
+
case "matrix":
|
|
19
|
+
return _jsx(MatrixFx, { ...layer, ...shared, colors: colors, ...matrix });
|
|
20
|
+
case "weather":
|
|
21
|
+
return _jsx(WeatherFx, { ...layer, ...shared, colors: colors, ...weather });
|
|
22
|
+
case "celebration":
|
|
23
|
+
return _jsx(CelebrationFx, { ...layer, ...shared, colors: colors, ...celebration });
|
|
24
|
+
case "particle":
|
|
25
|
+
return _jsx(ParticleFx, { ...layer, ...shared, color: colors?.[0], ...particle });
|
|
26
|
+
default:
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
30
|
+
return (_jsxs(Flex, { ref: ref, fill: true, position: "relative", overflow: "hidden", ...flex, children: [effect, children] }));
|
|
31
|
+
};
|
|
32
|
+
Effect.displayName = "Effect";
|
|
33
|
+
export { Effect };
|
package/dist/FlipFx.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Flex } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
export interface FlipFxProps extends React.ComponentProps<typeof Flex> {
|
|
4
|
+
flipDirection?: "horizontal" | "vertical";
|
|
5
|
+
timing?: number;
|
|
6
|
+
flipped?: boolean;
|
|
7
|
+
onFlip?: (flipped: boolean) => void;
|
|
8
|
+
disableClickFlip?: boolean;
|
|
9
|
+
/** Milliseconds between automatic flips (seconds until 3.0). Unset never flips on its own. */
|
|
10
|
+
autoFlipInterval?: number;
|
|
11
|
+
front: React.ReactNode;
|
|
12
|
+
back: React.ReactNode;
|
|
13
|
+
className?: string;
|
|
14
|
+
style?: React.CSSProperties;
|
|
15
|
+
}
|
|
16
|
+
declare const FlipFx: {
|
|
17
|
+
({ ref, ...props }: FlipFxProps): React.JSX.Element;
|
|
18
|
+
displayName: string;
|
|
19
|
+
};
|
|
20
|
+
export { FlipFx };
|
package/dist/FlipFx.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Flex } from "@once-ui-system/core";
|
|
4
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import { composeTransform, translateTransform } from "./internal/translate.js";
|
|
6
|
+
const FlipFx = ({ ref, ...props }) => {
|
|
7
|
+
const { flipDirection = "horizontal", timing = 2000, flipped, onFlip, disableClickFlip = false, autoFlipInterval, front, back, className, style, translateX, translateY, ...flex } = props;
|
|
8
|
+
const [internalFlipped, setInternalFlipped] = useState(false);
|
|
9
|
+
const flippedState = flipped ?? internalFlipped;
|
|
10
|
+
const cardRef = useRef(null);
|
|
11
|
+
const frontRef = useRef(null);
|
|
12
|
+
const backRef = useRef(null);
|
|
13
|
+
useLayoutEffect(() => {
|
|
14
|
+
const updateHeight = () => {
|
|
15
|
+
if (cardRef.current && frontRef.current && backRef.current) {
|
|
16
|
+
const frontH = frontRef.current.scrollHeight;
|
|
17
|
+
const backH = backRef.current.scrollHeight;
|
|
18
|
+
cardRef.current.style.height = `${Math.max(frontH, backH)}px`;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
updateHeight();
|
|
22
|
+
const observer = new ResizeObserver(updateHeight);
|
|
23
|
+
if (frontRef.current)
|
|
24
|
+
observer.observe(frontRef.current);
|
|
25
|
+
if (backRef.current)
|
|
26
|
+
observer.observe(backRef.current);
|
|
27
|
+
return () => observer.disconnect();
|
|
28
|
+
}, [flippedState, front, back]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (autoFlipInterval) {
|
|
31
|
+
const interval = setInterval(() => {
|
|
32
|
+
setInternalFlipped((prev) => !prev);
|
|
33
|
+
onFlip?.(!flippedState);
|
|
34
|
+
}, autoFlipInterval);
|
|
35
|
+
return () => clearInterval(interval);
|
|
36
|
+
}
|
|
37
|
+
}, [autoFlipInterval, flippedState, onFlip]);
|
|
38
|
+
const handleFlip = useCallback(() => {
|
|
39
|
+
if (disableClickFlip || autoFlipInterval)
|
|
40
|
+
return;
|
|
41
|
+
setInternalFlipped((v) => !v);
|
|
42
|
+
onFlip?.(!flippedState);
|
|
43
|
+
}, [disableClickFlip, autoFlipInterval, flippedState, onFlip]);
|
|
44
|
+
const handleKeyDown = useCallback((event) => {
|
|
45
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
handleFlip();
|
|
48
|
+
}
|
|
49
|
+
}, [handleFlip]);
|
|
50
|
+
return (_jsxs(Flex, { ref: (node) => {
|
|
51
|
+
cardRef.current = node;
|
|
52
|
+
if (typeof ref === "function")
|
|
53
|
+
ref(node);
|
|
54
|
+
else if (ref)
|
|
55
|
+
ref.current = node;
|
|
56
|
+
}, className: className, style: {
|
|
57
|
+
transformStyle: "preserve-3d",
|
|
58
|
+
transition: `transform ${timing}ms cubic-bezier(0.22, 1, 0.36, 1)`,
|
|
59
|
+
// The flip composes with a translate prop instead of replacing it.
|
|
60
|
+
transform: composeTransform(translateTransform(translateX, translateY), flippedState && (flipDirection === "vertical" ? "rotateX(180deg)" : "rotateY(180deg)")) ?? "none",
|
|
61
|
+
perspective: "1000px",
|
|
62
|
+
...style,
|
|
63
|
+
}, onClick: handleFlip, onKeyDown: handleKeyDown, role: "button", "aria-pressed": flippedState, tabIndex: 0, ...flex, children: [_jsx(Flex, { ref: frontRef, fill: true, position: "absolute", overflow: "hidden", "aria-hidden": flippedState, style: {
|
|
64
|
+
backfaceVisibility: "hidden",
|
|
65
|
+
}, children: front }), _jsx(Flex, { ref: backRef, fill: true, position: "absolute", overflow: "hidden", "aria-hidden": !flippedState, style: {
|
|
66
|
+
backfaceVisibility: "hidden",
|
|
67
|
+
transform: flipDirection === "vertical" ? "rotateX(180deg)" : "rotateY(180deg)",
|
|
68
|
+
}, children: back })] }));
|
|
69
|
+
};
|
|
70
|
+
FlipFx.displayName = "FlipFx";
|
|
71
|
+
export { FlipFx };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Flex, type Speed } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
interface GlitchFxProps extends React.ComponentProps<typeof Flex> {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
/**
|
|
6
|
+
* A multiplier on the 2.5s glitch cycle (`2` is twice as fast), or
|
|
7
|
+
* `"slow"`/`"medium"`/`"fast"` (0.5, 1, 2).
|
|
8
|
+
*/
|
|
9
|
+
speed?: Speed;
|
|
10
|
+
/** Milliseconds between glitches when `trigger="custom"`. */
|
|
11
|
+
interval?: number;
|
|
12
|
+
trigger?: "instant" | "hover" | "custom";
|
|
13
|
+
continuous?: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare const GlitchFx: {
|
|
16
|
+
({ ref, children, speed, interval, trigger, continuous, style, ...rest }: GlitchFxProps): React.JSX.Element;
|
|
17
|
+
displayName: string;
|
|
18
|
+
};
|
|
19
|
+
export { GlitchFx };
|
package/dist/GlitchFx.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Flex } from "@once-ui-system/core";
|
|
4
|
+
import classNames from "clsx";
|
|
5
|
+
import { useCallback, useEffect, useState } from "react";
|
|
6
|
+
import styles from "./GlitchFx.module.css";
|
|
7
|
+
import { speedFactor } from "./internal/speed.js";
|
|
8
|
+
const GlitchFx = ({ ref, children, speed = "medium", interval = 2500, trigger = "instant", continuous = true, style, ...rest }) => {
|
|
9
|
+
const [isGlitching, setIsGlitching] = useState(continuous || trigger === "instant");
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (continuous || trigger === "instant") {
|
|
12
|
+
setIsGlitching(true);
|
|
13
|
+
}
|
|
14
|
+
}, [continuous, trigger]);
|
|
15
|
+
const handleMouseEnter = () => {
|
|
16
|
+
if (trigger === "hover") {
|
|
17
|
+
setIsGlitching(true);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const handleMouseLeave = () => {
|
|
21
|
+
if (trigger === "hover") {
|
|
22
|
+
setIsGlitching(false);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const triggerGlitch = useCallback(() => {
|
|
26
|
+
if (trigger === "custom") {
|
|
27
|
+
setIsGlitching(true);
|
|
28
|
+
setTimeout(() => setIsGlitching(false), 500);
|
|
29
|
+
}
|
|
30
|
+
}, [trigger]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (trigger === "custom") {
|
|
33
|
+
const glitchInterval = setInterval(triggerGlitch, interval);
|
|
34
|
+
return () => clearInterval(glitchInterval);
|
|
35
|
+
}
|
|
36
|
+
}, [trigger, interval, triggerGlitch]);
|
|
37
|
+
const cycle = `${2500 / speedFactor(speed)}ms`;
|
|
38
|
+
return (_jsxs(Flex, { ref: ref, inline: true, zIndex: 0, className: classNames(isGlitching && styles.active), onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, style: { ["--glitch-duration"]: cycle, ...style }, ...rest, children: [_jsx(Flex, { fillWidth: true, inline: true, zIndex: 1, children: children }), _jsx(Flex, { inline: true, position: "absolute", top: "0", left: "0", fill: true, zIndex: 0, opacity: 50, className: classNames(styles.glitchLayer, styles.blueShift), "aria-hidden": "true", inert: true, children: children }), _jsx(Flex, { inline: true, position: "absolute", top: "0", left: "0", fill: true, zIndex: 0, opacity: 50, className: classNames(styles.glitchLayer, styles.redShift), "aria-hidden": "true", inert: true, children: children })] }));
|
|
39
|
+
};
|
|
40
|
+
GlitchFx.displayName = "GlitchFx";
|
|
41
|
+
export { GlitchFx };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
@layer once-ui {
|
|
2
|
+
.glitchLayer {
|
|
3
|
+
pointer-events: none;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.blueShift {
|
|
7
|
+
filter: hue-rotate(260deg);
|
|
8
|
+
animation: glitch-blue var(--glitch-duration, 2.5s) infinite;
|
|
9
|
+
z-index: 1;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.redShift {
|
|
13
|
+
filter: hue-rotate(120deg);
|
|
14
|
+
animation: glitch-red var(--glitch-duration, 2.5s) infinite;
|
|
15
|
+
z-index: 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@keyframes glitch-blue {
|
|
19
|
+
6%, 14%, 70%, 78% {
|
|
20
|
+
transform: none;
|
|
21
|
+
opacity: 0.25;
|
|
22
|
+
clip-path: inset(0 0 0 0);
|
|
23
|
+
}
|
|
24
|
+
10%, 12% {
|
|
25
|
+
transform: translate(-5px, -3px) skew(1deg, -2deg);
|
|
26
|
+
opacity: 0.5;
|
|
27
|
+
clip-path: inset(50% 0 25% 0);
|
|
28
|
+
}
|
|
29
|
+
11%, 13% {
|
|
30
|
+
transform: translate(4px, -7px) skew(-1deg) scaleX(1.5) scaleY(1.25);
|
|
31
|
+
opacity: 0.7;
|
|
32
|
+
clip-path: inset(0 35% 40% 0);
|
|
33
|
+
}
|
|
34
|
+
14%, 82% {
|
|
35
|
+
transform: translate(-5px, -3px) skew(1deg, -1deg);
|
|
36
|
+
opacity: 0.3;
|
|
37
|
+
clip-path: inset(30% 5% 25% 40%);
|
|
38
|
+
}
|
|
39
|
+
75%, 83% {
|
|
40
|
+
transform: translate(-9px, 2px) skew(-1deg, 0);
|
|
41
|
+
opacity: 0.2;
|
|
42
|
+
clip-path: inset(0 35% 45% 10%);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
@keyframes glitch-red {
|
|
46
|
+
6%, 14%, 70%, 78% {
|
|
47
|
+
transform: none;
|
|
48
|
+
opacity: 0;
|
|
49
|
+
clip-path: inset(0 0 0 0);
|
|
50
|
+
}
|
|
51
|
+
10%, 12% {
|
|
52
|
+
transform: translate(6px, 4px) skew(1deg);
|
|
53
|
+
opacity: 0.5;
|
|
54
|
+
clip-path: inset(5% 0 10% 0);
|
|
55
|
+
}
|
|
56
|
+
11%, 13% {
|
|
57
|
+
transform: translate(-4px, 5px) skew(0, -1deg);
|
|
58
|
+
opacity: 0.7;
|
|
59
|
+
clip-path: inset(5% 0 10% 0);
|
|
60
|
+
}
|
|
61
|
+
14%, 82% {
|
|
62
|
+
transform: translate(-7px, -4px) skew(1deg, -1deg);
|
|
63
|
+
opacity: 0.2;
|
|
64
|
+
clip-path: inset(50% 25% 25% 0);
|
|
65
|
+
}
|
|
66
|
+
75%, 80% {
|
|
67
|
+
transform: translate(4px, -6px) skew(-1deg) scaleX(2) scaleY(1.25);
|
|
68
|
+
opacity: 0.3;
|
|
69
|
+
clip-path: inset(0 0 20% 50%);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
.active .blueShift, .active .redShift {
|
|
73
|
+
animation-play-state: running;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.glitchFx:not(.active) .blueShift,
|
|
77
|
+
.glitchFx:not(.active) .redShift {
|
|
78
|
+
animation-play-state: paused;
|
|
79
|
+
}
|
|
80
|
+
}
|
package/dist/HoloFx.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Flex } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import { type CSSProperties } from "react";
|
|
4
|
+
interface MaskOptions {
|
|
5
|
+
maskPosition?: string;
|
|
6
|
+
}
|
|
7
|
+
interface HoloFxProps extends React.ComponentProps<typeof Flex> {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
reducedMotion?: boolean | "auto";
|
|
10
|
+
shine?: {
|
|
11
|
+
opacity?: number;
|
|
12
|
+
filter?: string;
|
|
13
|
+
blending?: CSSProperties["mixBlendMode"];
|
|
14
|
+
mask?: MaskOptions;
|
|
15
|
+
};
|
|
16
|
+
burn?: {
|
|
17
|
+
opacity?: number;
|
|
18
|
+
filter?: string;
|
|
19
|
+
blending?: CSSProperties["mixBlendMode"];
|
|
20
|
+
mask?: MaskOptions;
|
|
21
|
+
};
|
|
22
|
+
texture?: {
|
|
23
|
+
opacity?: number;
|
|
24
|
+
filter?: string;
|
|
25
|
+
blending?: CSSProperties["mixBlendMode"];
|
|
26
|
+
image?: string;
|
|
27
|
+
mask?: MaskOptions;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
declare const HoloFx: {
|
|
31
|
+
({ ref, children, reducedMotion, shine, burn, texture, ...rest }: HoloFxProps): React.JSX.Element;
|
|
32
|
+
displayName: string;
|
|
33
|
+
};
|
|
34
|
+
export { HoloFx };
|