@once-ui-system/fx 0.0.0-stage → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +78 -0
- package/dist/HoloFx.d.ts +34 -0
- package/dist/HoloFx.js +99 -0
- package/dist/HoloFx.module.css +29 -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 +25 -0
- package/dist/ShineFx.d.ts +17 -0
- package/dist/ShineFx.js +17 -0
- package/dist/ShineFx.module.css +37 -0
- package/dist/TiltFx.d.ts +12 -0
- package/dist/TiltFx.js +79 -0
- package/dist/TiltFx.module.css +11 -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 +224 -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 +78 -4
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ColorValue, type DisplayProps, Flex, type SpacingToken, type Speed } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
interface ParticleFxProps extends React.ComponentProps<typeof Flex> {
|
|
4
|
+
density?: number;
|
|
5
|
+
color?: ColorValue;
|
|
6
|
+
size?: SpacingToken;
|
|
7
|
+
/**
|
|
8
|
+
* A multiplier on the designed drift (`1`), or `"slow"`/`"medium"`/`"fast"`
|
|
9
|
+
* (0.5, 1, 2). The default was `0.3` until 3.0, on a scale where `1` was
|
|
10
|
+
* over three times the designed pace; `speed={n}` from 2.x is `n / 0.3` now.
|
|
11
|
+
*/
|
|
12
|
+
speed?: Speed;
|
|
13
|
+
interactive?: boolean;
|
|
14
|
+
mode?: "repel" | "attract";
|
|
15
|
+
intensity?: number;
|
|
16
|
+
opacity?: DisplayProps["opacity"];
|
|
17
|
+
reducedMotion?: boolean | "auto";
|
|
18
|
+
className?: string;
|
|
19
|
+
style?: React.CSSProperties;
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
declare const ParticleFx: {
|
|
23
|
+
({ ref: forwardedRef, density, color, size, speed: speedProp, interactive, mode, intensity, opacity, reducedMotion, children, className, style, ...rest }: ParticleFxProps): React.JSX.Element;
|
|
24
|
+
displayName: string;
|
|
25
|
+
};
|
|
26
|
+
export { ParticleFx };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Flex, useInViewport, useReducedMotion, } from "@once-ui-system/core";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
import { cssColor } from "./internal/cssColor.js";
|
|
6
|
+
import { speedFactor } from "./internal/speed.js";
|
|
7
|
+
const ParticleFx = ({ ref: forwardedRef, density = 100, color = "brand-on-background-weak", size = "2", speed: speedProp, interactive = false, mode = "repel", intensity = 20, opacity = 100, reducedMotion = "auto", children, className, style, ...rest }) => {
|
|
8
|
+
// 0.3 is the drift ParticleFx was designed at; `speed` scales it.
|
|
9
|
+
const speed = speedFactor(speedProp) * 0.3;
|
|
10
|
+
const containerRef = useRef(null);
|
|
11
|
+
const isInViewport = useInViewport(containerRef);
|
|
12
|
+
const { shouldAnimate } = useReducedMotion(reducedMotion);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (forwardedRef && "current" in forwardedRef) {
|
|
15
|
+
forwardedRef.current = containerRef.current;
|
|
16
|
+
}
|
|
17
|
+
else if (typeof forwardedRef === "function") {
|
|
18
|
+
forwardedRef(containerRef.current);
|
|
19
|
+
}
|
|
20
|
+
}, [forwardedRef]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const container = containerRef.current;
|
|
23
|
+
if (!container)
|
|
24
|
+
return;
|
|
25
|
+
// If reduced motion, render static particles with no animation loop
|
|
26
|
+
const effectiveDensity = shouldAnimate ? density : Math.min(density, 30);
|
|
27
|
+
const particleEls = [];
|
|
28
|
+
// Flat arrays for fast iteration — no Map lookups or style parsing per frame
|
|
29
|
+
const currentX = new Float32Array(effectiveDensity);
|
|
30
|
+
const currentY = new Float32Array(effectiveDensity);
|
|
31
|
+
const initialX = new Float32Array(effectiveDensity);
|
|
32
|
+
const initialY = new Float32Array(effectiveDensity);
|
|
33
|
+
const targetX = new Float32Array(effectiveDensity);
|
|
34
|
+
const targetY = new Float32Array(effectiveDensity);
|
|
35
|
+
let mousePosition = { x: -1000, y: -1000 };
|
|
36
|
+
let animationFrameId = null;
|
|
37
|
+
const parsedSize = `var(--static-space-${size})`;
|
|
38
|
+
const parsedOpacity = `${opacity}%`;
|
|
39
|
+
const movementSpeed = speed * 0.08;
|
|
40
|
+
const repulsionStrength = 0.15 * (speed || 1);
|
|
41
|
+
const handleMouseMove = (e) => {
|
|
42
|
+
const rect = container.getBoundingClientRect();
|
|
43
|
+
mousePosition = {
|
|
44
|
+
x: ((e.clientX - rect.left) / rect.width) * 100,
|
|
45
|
+
y: ((e.clientY - rect.top) / rect.height) * 100,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
// Create particles using translate3d instead of left/top
|
|
49
|
+
for (let i = 0; i < effectiveDensity; i++) {
|
|
50
|
+
const el = document.createElement("div");
|
|
51
|
+
// Lets a test or a screenshot tool find (and hide) the particles.
|
|
52
|
+
el.setAttribute("data-fx-particle", "");
|
|
53
|
+
el.style.cssText = `
|
|
54
|
+
position:absolute;left:0;top:0;
|
|
55
|
+
width:${parsedSize};height:${parsedSize};
|
|
56
|
+
background:${cssColor(color)};
|
|
57
|
+
border-radius:50%;
|
|
58
|
+
pointer-events:none;
|
|
59
|
+
opacity:${parsedOpacity};
|
|
60
|
+
will-change:transform;
|
|
61
|
+
`;
|
|
62
|
+
const ix = 10 + Math.random() * 80;
|
|
63
|
+
const iy = 10 + Math.random() * 80;
|
|
64
|
+
initialX[i] = ix;
|
|
65
|
+
initialY[i] = iy;
|
|
66
|
+
currentX[i] = ix;
|
|
67
|
+
currentY[i] = iy;
|
|
68
|
+
targetX[i] = ix;
|
|
69
|
+
targetY[i] = iy;
|
|
70
|
+
el.style.transform = `translate3d(${ix}cqw, ${iy}cqh, 0)`;
|
|
71
|
+
container.appendChild(el);
|
|
72
|
+
particleEls.push(el);
|
|
73
|
+
}
|
|
74
|
+
// If reduced motion or not in viewport initially, just place them statically
|
|
75
|
+
if (!shouldAnimate)
|
|
76
|
+
return () => cleanup();
|
|
77
|
+
const updateParticles = () => {
|
|
78
|
+
const time = Date.now() * 0.001 * speed;
|
|
79
|
+
for (let i = 0; i < effectiveDensity; i++) {
|
|
80
|
+
const cx = currentX[i];
|
|
81
|
+
const cy = currentY[i];
|
|
82
|
+
const baseNoiseX = Math.sin(time + i) * 0.5;
|
|
83
|
+
const baseNoiseY = Math.cos(time + i * 1.2) * 0.5;
|
|
84
|
+
let tx = initialX[i] + baseNoiseX;
|
|
85
|
+
let ty = initialY[i] + baseNoiseY;
|
|
86
|
+
if (interactive) {
|
|
87
|
+
const dx = mousePosition.x - cx;
|
|
88
|
+
const dy = mousePosition.y - cy;
|
|
89
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
90
|
+
if (distance < intensity) {
|
|
91
|
+
const angle = Math.atan2(dy, dx);
|
|
92
|
+
if (mode === "attract") {
|
|
93
|
+
const minDistance = 8;
|
|
94
|
+
if (distance <= minDistance) {
|
|
95
|
+
tx = mousePosition.x;
|
|
96
|
+
ty = mousePosition.y;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const normalizedDistance = Math.min(distance / intensity, 1);
|
|
100
|
+
const force = distance * repulsionStrength * normalizedDistance * 0.3;
|
|
101
|
+
tx = cx + Math.cos(angle) * force;
|
|
102
|
+
ty = cy + Math.sin(angle) * force;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const force = (intensity - distance) * repulsionStrength;
|
|
107
|
+
tx -= Math.cos(angle) * force;
|
|
108
|
+
ty -= Math.sin(angle) * force;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
tx = Math.max(5, Math.min(95, tx));
|
|
113
|
+
ty = Math.max(5, Math.min(95, ty));
|
|
114
|
+
targetX[i] = tx;
|
|
115
|
+
targetY[i] = ty;
|
|
116
|
+
const nx = cx + (tx - cx) * movementSpeed;
|
|
117
|
+
const ny = cy + (ty - cy) * movementSpeed;
|
|
118
|
+
currentX[i] = nx;
|
|
119
|
+
currentY[i] = ny;
|
|
120
|
+
particleEls[i].style.transform = `translate3d(${nx}cqw, ${ny}cqh, 0)`;
|
|
121
|
+
}
|
|
122
|
+
animationFrameId = requestAnimationFrame(updateParticles);
|
|
123
|
+
};
|
|
124
|
+
if (interactive) {
|
|
125
|
+
container.addEventListener("mousemove", handleMouseMove, { passive: true });
|
|
126
|
+
}
|
|
127
|
+
// Start animation only if in viewport
|
|
128
|
+
if (isInViewport) {
|
|
129
|
+
animationFrameId = requestAnimationFrame(updateParticles);
|
|
130
|
+
}
|
|
131
|
+
function cleanup() {
|
|
132
|
+
container.removeEventListener("mousemove", handleMouseMove);
|
|
133
|
+
if (animationFrameId != null) {
|
|
134
|
+
cancelAnimationFrame(animationFrameId);
|
|
135
|
+
}
|
|
136
|
+
particleEls.forEach((el) => el.remove());
|
|
137
|
+
}
|
|
138
|
+
return () => cleanup();
|
|
139
|
+
}, [
|
|
140
|
+
color,
|
|
141
|
+
size,
|
|
142
|
+
speed,
|
|
143
|
+
interactive,
|
|
144
|
+
intensity,
|
|
145
|
+
opacity,
|
|
146
|
+
density,
|
|
147
|
+
mode,
|
|
148
|
+
shouldAnimate,
|
|
149
|
+
isInViewport,
|
|
150
|
+
]);
|
|
151
|
+
return (_jsx(Flex, { ref: containerRef, fill: true, position: "relative", pointerEvents: interactive ? "auto" : "none", className: className, style: { containerType: "size", ...style }, ...rest, children: children }));
|
|
152
|
+
};
|
|
153
|
+
ParticleFx.displayName = "ParticleFx";
|
|
154
|
+
export { ParticleFx };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type CSSUnit, Flex, type SpacingToken } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
interface RevealFxProps extends React.ComponentProps<typeof Flex> {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
/**
|
|
6
|
+
* Milliseconds the reveal takes. Was `speed` until 3.0 (`"fast"` 1000,
|
|
7
|
+
* `"medium"` 2000, `"slow"` 3000).
|
|
8
|
+
*/
|
|
9
|
+
duration?: number;
|
|
10
|
+
/** Milliseconds before the reveal starts. Was seconds until 2.0. */
|
|
11
|
+
delay?: number;
|
|
12
|
+
defaultRevealed?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* How far the content travels up as it reveals: a number is on the token
|
|
15
|
+
* scale (`16` is `"16"`, 1rem), a string a spacing token (`"16"`) or a CSS
|
|
16
|
+
* length (`"1rem"`).
|
|
17
|
+
*/
|
|
18
|
+
translateY?: number | SpacingToken | CSSUnit;
|
|
19
|
+
revealed?: boolean;
|
|
20
|
+
style?: React.CSSProperties;
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
declare const RevealFx: {
|
|
24
|
+
({ ref, children, duration, delay, defaultRevealed, translateY, revealed, style, className, ...rest }: RevealFxProps): React.JSX.Element;
|
|
25
|
+
displayName: string;
|
|
26
|
+
};
|
|
27
|
+
export { RevealFx };
|
package/dist/RevealFx.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Flex } from "@once-ui-system/core";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { translateValue as resolveTranslate } from "./internal/translate.js";
|
|
6
|
+
import styles from "./RevealFx.module.css";
|
|
7
|
+
const RevealFx = ({ ref, children, duration = 2000, delay = 0, defaultRevealed = false, translateY, revealed, style, className, ...rest }) => {
|
|
8
|
+
const [isRevealed, setIsRevealed] = useState(defaultRevealed);
|
|
9
|
+
const [maskRemoved, setMaskRemoved] = useState(false);
|
|
10
|
+
const transitionTimeoutRef = useRef(null);
|
|
11
|
+
const controlled = revealed !== undefined;
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
// Controlled: `revealed` alone decides, so the delay timer must not
|
|
14
|
+
// reveal content the caller is still holding back.
|
|
15
|
+
if (controlled)
|
|
16
|
+
return;
|
|
17
|
+
const timer = setTimeout(() => {
|
|
18
|
+
setIsRevealed(true);
|
|
19
|
+
// Always set a timeout to remove the mask after transition completes
|
|
20
|
+
transitionTimeoutRef.current = setTimeout(() => {
|
|
21
|
+
setMaskRemoved(true);
|
|
22
|
+
}, duration);
|
|
23
|
+
}, delay);
|
|
24
|
+
return () => {
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
if (transitionTimeoutRef.current) {
|
|
27
|
+
clearTimeout(transitionTimeoutRef.current);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}, [delay, controlled]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (revealed !== undefined) {
|
|
33
|
+
setIsRevealed(revealed);
|
|
34
|
+
// Reset mask removal state when revealed changes
|
|
35
|
+
setMaskRemoved(false);
|
|
36
|
+
// If revealed is true, set timeout to remove mask after transition
|
|
37
|
+
if (revealed) {
|
|
38
|
+
if (transitionTimeoutRef.current) {
|
|
39
|
+
clearTimeout(transitionTimeoutRef.current);
|
|
40
|
+
}
|
|
41
|
+
transitionTimeoutRef.current = setTimeout(() => {
|
|
42
|
+
setMaskRemoved(true);
|
|
43
|
+
}, duration);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// An unmount mid-transition left this timer to set state afterwards.
|
|
47
|
+
return () => {
|
|
48
|
+
if (transitionTimeoutRef.current)
|
|
49
|
+
clearTimeout(transitionTimeoutRef.current);
|
|
50
|
+
};
|
|
51
|
+
}, [revealed]);
|
|
52
|
+
const translateValue = resolveTranslate(translateY);
|
|
53
|
+
const revealStyle = {
|
|
54
|
+
transitionDuration: `${duration}ms`,
|
|
55
|
+
transform: isRevealed ? "translateY(0)" : `translateY(${translateValue})`,
|
|
56
|
+
...style,
|
|
57
|
+
};
|
|
58
|
+
// If mask is removed after transition, use the no-mask classes
|
|
59
|
+
if (maskRemoved) {
|
|
60
|
+
return (_jsx(Flex, { fillWidth: true, ref: ref, style: revealStyle, className: `${styles.revealedNoMask} ${className || ""}`, ...rest, children: children }));
|
|
61
|
+
}
|
|
62
|
+
return (_jsx(Flex, { fillWidth: true, ref: ref, style: revealStyle, className: `${styles.revealFx} ${isRevealed ? styles.revealed : styles.hidden} ${className || ""}`, ...rest, children: children }));
|
|
63
|
+
};
|
|
64
|
+
RevealFx.displayName = "RevealFx";
|
|
65
|
+
export { RevealFx };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.revealFx {
|
|
2
|
+
mask-size: 400% 100%;
|
|
3
|
+
transition: all ease-in-out;
|
|
4
|
+
mask-image: linear-gradient(to right, black 0%, black 25%, transparent 50%);
|
|
5
|
+
}
|
|
6
|
+
.revealFx.hidden {
|
|
7
|
+
mask-position: 100% 0;
|
|
8
|
+
filter: blur(1rem);
|
|
9
|
+
}
|
|
10
|
+
.revealFx.revealed {
|
|
11
|
+
mask-position: 0 0;
|
|
12
|
+
filter: blur(0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.hiddenNoMask {
|
|
16
|
+
transition: all ease-in-out;
|
|
17
|
+
filter: blur(0.5rem);
|
|
18
|
+
opacity: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.revealedNoMask {
|
|
22
|
+
transition: all ease-in-out;
|
|
23
|
+
filter: blur(0);
|
|
24
|
+
opacity: 1;
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Text } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
export interface ShineFxProps extends Omit<React.ComponentProps<typeof Text>, "ref"> {
|
|
4
|
+
ref?: React.Ref<HTMLSpanElement>;
|
|
5
|
+
/** Milliseconds one sweep takes. Was `speed` until 3.0 (and seconds until 2.0). */
|
|
6
|
+
duration?: number;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
inverse?: boolean;
|
|
9
|
+
baseOpacity?: number;
|
|
10
|
+
reducedMotion?: boolean | "auto";
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
declare const ShineFx: {
|
|
14
|
+
({ ref, duration, disabled, inverse, baseOpacity, reducedMotion, children, className, style, ...text }: ShineFxProps): React.JSX.Element;
|
|
15
|
+
displayName: string;
|
|
16
|
+
};
|
|
17
|
+
export { ShineFx };
|
package/dist/ShineFx.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Text, useReducedMotion } from "@once-ui-system/core";
|
|
4
|
+
import classNames from "clsx";
|
|
5
|
+
import styles from "./ShineFx.module.css";
|
|
6
|
+
const ShineFx = ({ ref, duration = 1000, disabled = false, inverse = false, baseOpacity = 0.3, reducedMotion = "auto", children, className, style, ...text }) => {
|
|
7
|
+
const { shouldAnimate } = useReducedMotion(reducedMotion);
|
|
8
|
+
const isDisabled = disabled || !shouldAnimate;
|
|
9
|
+
const animationDuration = `${duration}ms`;
|
|
10
|
+
return (_jsx(Text, { ...text, ref: ref, className: classNames(styles.shineFx, isDisabled ? styles.disabled : "", inverse ? styles.inverse : styles.default, className), style: {
|
|
11
|
+
...style,
|
|
12
|
+
animationDuration,
|
|
13
|
+
["--shine-base-opacity"]: baseOpacity,
|
|
14
|
+
}, children: children }));
|
|
15
|
+
};
|
|
16
|
+
ShineFx.displayName = "ShineFx";
|
|
17
|
+
export { ShineFx };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.shineFx {
|
|
2
|
+
--shine-base-opacity: 0.3;
|
|
3
|
+
display: inline-block;
|
|
4
|
+
-webkit-text-fill-color: transparent;
|
|
5
|
+
background: linear-gradient(120deg, color-mix(in srgb, currentColor, transparent calc((1 - var(--shine-base-opacity)) * 100%)) 40%, currentColor 50%, color-mix(in srgb, currentColor, transparent calc((1 - var(--shine-base-opacity)) * 100%)) 60%);
|
|
6
|
+
background-size: 200% 100%;
|
|
7
|
+
-webkit-background-clip: text;
|
|
8
|
+
background-clip: text;
|
|
9
|
+
animation: shine 5s linear infinite;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.inverse {
|
|
13
|
+
--shine-base-opacity: 0.3;
|
|
14
|
+
display: inline-block;
|
|
15
|
+
-webkit-text-fill-color: transparent;
|
|
16
|
+
background: linear-gradient(120deg, currentColor 40%, color-mix(in srgb, currentColor, transparent calc((1 - var(--shine-base-opacity)) * 100%)) 50%, currentColor 60%);
|
|
17
|
+
background-size: 200% 100%;
|
|
18
|
+
-webkit-background-clip: text;
|
|
19
|
+
background-clip: text;
|
|
20
|
+
animation: shine 5s linear infinite;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@keyframes shine {
|
|
24
|
+
0% {
|
|
25
|
+
background-position: 100%;
|
|
26
|
+
}
|
|
27
|
+
100% {
|
|
28
|
+
background-position: -100%;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
.shineFx.disabled {
|
|
32
|
+
animation: none;
|
|
33
|
+
-webkit-text-fill-color: inherit;
|
|
34
|
+
background: none;
|
|
35
|
+
-webkit-background-clip: unset;
|
|
36
|
+
background-clip: unset;
|
|
37
|
+
}
|
package/dist/TiltFx.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Flex } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
interface TiltFxProps extends React.ComponentProps<typeof Flex> {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
intensity?: number;
|
|
6
|
+
reducedMotion?: boolean | "auto";
|
|
7
|
+
}
|
|
8
|
+
declare const TiltFx: {
|
|
9
|
+
({ ref, children, intensity, reducedMotion, ...rest }: TiltFxProps): React.JSX.Element;
|
|
10
|
+
displayName: string;
|
|
11
|
+
};
|
|
12
|
+
export { TiltFx };
|
package/dist/TiltFx.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Flex, useReducedMotion } from "@once-ui-system/core";
|
|
4
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
5
|
+
import { cannotHover } from "./internal/pointer.js";
|
|
6
|
+
import { composeTransform, translateTransform } from "./internal/translate.js";
|
|
7
|
+
import styles from "./TiltFx.module.css";
|
|
8
|
+
const TiltFx = ({ ref, children, intensity = 1, reducedMotion = "auto", ...rest }) => {
|
|
9
|
+
const internalRef = useRef(null);
|
|
10
|
+
const lastCallRef = useRef(0);
|
|
11
|
+
const mergedRef = useCallback((node) => {
|
|
12
|
+
internalRef.current = node;
|
|
13
|
+
if (typeof ref === "function") {
|
|
14
|
+
ref(node);
|
|
15
|
+
}
|
|
16
|
+
else if (ref) {
|
|
17
|
+
ref.current = node;
|
|
18
|
+
}
|
|
19
|
+
}, [ref]);
|
|
20
|
+
const resetTimeoutRef = useRef(null);
|
|
21
|
+
const isTouchDeviceRef = useRef(false);
|
|
22
|
+
const { shouldAnimate } = useReducedMotion(reducedMotion);
|
|
23
|
+
// The tilt is written over the element's transform, which Flex resolves
|
|
24
|
+
// from `translateX`/`translateY`: keep the translate in front of it, or a
|
|
25
|
+
// hover moves the element back to where the props had not put it.
|
|
26
|
+
const tiltTransform = (tilt) => composeTransform(translateTransform(rest.translateX, rest.translateY), tilt) ?? "";
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
isTouchDeviceRef.current = cannotHover();
|
|
29
|
+
}, []);
|
|
30
|
+
const handleMouseMove = (e) => {
|
|
31
|
+
if (isTouchDeviceRef.current || !shouldAnimate)
|
|
32
|
+
return;
|
|
33
|
+
if (resetTimeoutRef.current) {
|
|
34
|
+
clearTimeout(resetTimeoutRef.current);
|
|
35
|
+
resetTimeoutRef.current = null;
|
|
36
|
+
}
|
|
37
|
+
const now = Date.now();
|
|
38
|
+
if (now - lastCallRef.current < 16)
|
|
39
|
+
return;
|
|
40
|
+
lastCallRef.current = now;
|
|
41
|
+
const element = internalRef.current;
|
|
42
|
+
if (!element)
|
|
43
|
+
return;
|
|
44
|
+
const rect = element.getBoundingClientRect();
|
|
45
|
+
const offsetX = e.clientX - rect.left;
|
|
46
|
+
const offsetY = e.clientY - rect.top;
|
|
47
|
+
const centerX = rect.width / 2;
|
|
48
|
+
const centerY = rect.height / 2;
|
|
49
|
+
const deltaX = (offsetX - centerX) / centerX;
|
|
50
|
+
const deltaY = (offsetY - centerY) / centerY;
|
|
51
|
+
const rotateX = -deltaY * 2 * intensity;
|
|
52
|
+
const rotateY = -deltaX * 2 * intensity;
|
|
53
|
+
const translateZ = 30 * intensity;
|
|
54
|
+
window.requestAnimationFrame(() => {
|
|
55
|
+
element.style.transform = tiltTransform(`perspective(1000px) translate3d(0, 0, ${translateZ}px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`);
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
const handleMouseLeave = () => {
|
|
59
|
+
if (isTouchDeviceRef.current || !shouldAnimate)
|
|
60
|
+
return;
|
|
61
|
+
const element = internalRef.current;
|
|
62
|
+
if (element) {
|
|
63
|
+
resetTimeoutRef.current = setTimeout(() => {
|
|
64
|
+
element.style.transform = tiltTransform("perspective(1000px) translate3d(0, 0, 0) rotateX(0deg) rotateY(0deg)");
|
|
65
|
+
resetTimeoutRef.current = null;
|
|
66
|
+
}, 100);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
return () => {
|
|
71
|
+
if (resetTimeoutRef.current) {
|
|
72
|
+
clearTimeout(resetTimeoutRef.current);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}, []);
|
|
76
|
+
return (_jsx(Flex, { ref: mergedRef, overflow: "hidden", className: styles.tiltFx, onMouseMove: handleMouseMove, onMouseLeave: handleMouseLeave, ...rest, children: children }));
|
|
77
|
+
};
|
|
78
|
+
export { TiltFx };
|
|
79
|
+
TiltFx.displayName = "TiltFx";
|
package/dist/TypeFx.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Text } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import { type FadeState } from "./internal/FadingLetters.js";
|
|
4
|
+
export interface TypeFxProps extends Omit<React.ComponentProps<typeof Text>, "children" | "ref"> {
|
|
5
|
+
ref?: React.Ref<HTMLSpanElement>;
|
|
6
|
+
words: string | string[];
|
|
7
|
+
/**
|
|
8
|
+
* `"type"` (the default) types each word out and erases it. `"fade"` (2.x's
|
|
9
|
+
* FadingLettersFx) fades the letters of `words` in one after another, as
|
|
10
|
+
* `state` says, and holds them.
|
|
11
|
+
*/
|
|
12
|
+
mode?: "type" | "fade";
|
|
13
|
+
/**
|
|
14
|
+
* Fade mode: `"entering"` (the default) fades the letters in, `"visible"`
|
|
15
|
+
* shows them still, `"exiting"` fades them out. Was FadingLettersFx's
|
|
16
|
+
* `animationState`.
|
|
17
|
+
*/
|
|
18
|
+
state?: FadeState;
|
|
19
|
+
/**
|
|
20
|
+
* Milliseconds each character takes to type (higher is slower); erasing
|
|
21
|
+
* runs at half of it. Was `speed` until 3.0. In fade mode, the gap between
|
|
22
|
+
* two letters' entries, default 40.
|
|
23
|
+
*/
|
|
24
|
+
charDuration?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Milliseconds before typing starts; in fade mode, before the first letter
|
|
27
|
+
* enters (FadingLettersFx's `messageIdx` was `delay={messageIdx * 2500}`).
|
|
28
|
+
*/
|
|
29
|
+
delay?: number;
|
|
30
|
+
/** Milliseconds a finished word stays before it is erased. */
|
|
31
|
+
hold?: number;
|
|
32
|
+
trigger?: "instant" | "custom";
|
|
33
|
+
onTrigger?: (triggerFn: () => void) => void;
|
|
34
|
+
loop?: boolean;
|
|
35
|
+
children?: React.ReactNode;
|
|
36
|
+
}
|
|
37
|
+
declare const TypeFx: {
|
|
38
|
+
({ ref, ...props }: TypeFxProps): React.JSX.Element;
|
|
39
|
+
displayName: string;
|
|
40
|
+
};
|
|
41
|
+
export { TypeFx };
|
package/dist/TypeFx.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Text, useReducedMotion, VisuallyHidden } from "@once-ui-system/core";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { fadingLetters } from "./internal/FadingLetters.js";
|
|
6
|
+
import { prefersReducedMotionNow } from "./internal/reducedMotion.js";
|
|
7
|
+
const TypeFx = ({ ref, ...props }) => props.mode === "fade" ? _jsx(FadeFx, { ...props, ref: ref }) : _jsx(TypingFx, { ...props, ref: ref });
|
|
8
|
+
const FadeFx = ({ ref, words, mode: _mode, state = "entering", charDuration = 40, delay = 0, hold: _hold, trigger: _trigger, onTrigger: _onTrigger, loop: _loop, children, ...text }) => (_jsxs(Text, { ...text, ref: ref, style: { display: "contents", ...text.style }, children: [children, fadingLetters(Array.isArray(words) ? words.join(" ") : words, state, delay, charDuration)] }));
|
|
9
|
+
FadeFx.displayName = "FadeFx";
|
|
10
|
+
const TypingFx = ({ ref, words, mode: _mode, state: _state, charDuration = 100, delay = 0, hold = 2000, trigger = "instant", onTrigger, loop = true, children, ...text }) => {
|
|
11
|
+
const [displayText, setDisplayText] = useState("");
|
|
12
|
+
const [isComplete, setIsComplete] = useState(false);
|
|
13
|
+
const [triggered, setTriggered] = useState(trigger === "instant");
|
|
14
|
+
const timeoutRef = useRef(null);
|
|
15
|
+
const { prefersReducedMotion } = useReducedMotion();
|
|
16
|
+
const wordsHash = JSON.stringify(Array.isArray(words) ? words : [words]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (trigger === "instant")
|
|
19
|
+
setTriggered(true);
|
|
20
|
+
}, [trigger]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (trigger === "custom" && onTrigger) {
|
|
23
|
+
onTrigger(() => setTriggered(true));
|
|
24
|
+
}
|
|
25
|
+
}, [trigger, onTrigger]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!triggered)
|
|
28
|
+
return;
|
|
29
|
+
let active = true;
|
|
30
|
+
let pendingResolve = null;
|
|
31
|
+
setDisplayText("");
|
|
32
|
+
setIsComplete(false);
|
|
33
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
34
|
+
pendingResolve = resolve;
|
|
35
|
+
timeoutRef.current = window.setTimeout(resolve, ms);
|
|
36
|
+
});
|
|
37
|
+
const run = async () => {
|
|
38
|
+
// An empty list (data not loaded yet) types nothing instead of crashing on `undefined.length`.
|
|
39
|
+
const wordsArray = JSON.parse(wordsHash).filter((word) => typeof word === "string");
|
|
40
|
+
if (wordsArray.length === 0)
|
|
41
|
+
return;
|
|
42
|
+
const isSingleWord = wordsArray.length === 1;
|
|
43
|
+
// Under reduced motion nothing is typed out: the word it would settle
|
|
44
|
+
// on shows at once, the last one without `loop`, else the first.
|
|
45
|
+
if (prefersReducedMotion || prefersReducedMotionNow()) {
|
|
46
|
+
setDisplayText(loop ? wordsArray[0] : wordsArray[wordsArray.length - 1]);
|
|
47
|
+
setIsComplete(true);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (delay > 0) {
|
|
51
|
+
await sleep(delay);
|
|
52
|
+
if (!active)
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let currentIndex = 0;
|
|
56
|
+
while (active) {
|
|
57
|
+
const currentWord = wordsArray[currentIndex];
|
|
58
|
+
for (let i = 0; i <= currentWord.length; i++) {
|
|
59
|
+
if (!active)
|
|
60
|
+
return;
|
|
61
|
+
setDisplayText(currentWord.substring(0, i));
|
|
62
|
+
await sleep(charDuration);
|
|
63
|
+
}
|
|
64
|
+
// Without `loop` the last word stays: it used to be deleted too,
|
|
65
|
+
// leaving the text empty.
|
|
66
|
+
if (isSingleWord || (!loop && currentIndex === wordsArray.length - 1)) {
|
|
67
|
+
if (active)
|
|
68
|
+
setIsComplete(true);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!active)
|
|
72
|
+
return;
|
|
73
|
+
await sleep(hold);
|
|
74
|
+
for (let i = currentWord.length; i >= 0; i--) {
|
|
75
|
+
if (!active)
|
|
76
|
+
return;
|
|
77
|
+
setDisplayText(currentWord.substring(0, i));
|
|
78
|
+
await sleep(charDuration / 2);
|
|
79
|
+
}
|
|
80
|
+
currentIndex = (currentIndex + 1) % wordsArray.length;
|
|
81
|
+
if (!loop && currentIndex === 0)
|
|
82
|
+
return;
|
|
83
|
+
if (!active)
|
|
84
|
+
return;
|
|
85
|
+
await sleep(charDuration);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
run();
|
|
89
|
+
return () => {
|
|
90
|
+
active = false;
|
|
91
|
+
if (timeoutRef.current !== null) {
|
|
92
|
+
clearTimeout(timeoutRef.current);
|
|
93
|
+
}
|
|
94
|
+
if (pendingResolve)
|
|
95
|
+
pendingResolve();
|
|
96
|
+
};
|
|
97
|
+
}, [triggered, wordsHash, charDuration, delay, hold, loop, prefersReducedMotion]);
|
|
98
|
+
return (_jsxs(Text, { ...text, ref: ref, children: [children, _jsx(VisuallyHidden, { children: (Array.isArray(words) ? words : [words]).join(", ") }), _jsxs("span", { "aria-hidden": "true", children: [displayText, !isComplete && _jsx("span", { style: { opacity: 0.5 }, children: "|" })] })] }));
|
|
99
|
+
};
|
|
100
|
+
TypingFx.displayName = "TypingFx";
|
|
101
|
+
TypeFx.displayName = "TypeFx";
|
|
102
|
+
export { TypeFx };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Flex, type Speed } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
type WeatherType = "rain" | "snow" | "leaves" | "lightning";
|
|
4
|
+
interface WeatherFxProps extends React.ComponentProps<typeof Flex> {
|
|
5
|
+
type?: WeatherType;
|
|
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
|
+
angle?: number;
|
|
11
|
+
/** Milliseconds to keep emitting before the weather stops (seconds until 3.0). Unset runs forever. */
|
|
12
|
+
duration?: number;
|
|
13
|
+
trigger?: "mount" | "hover" | "click" | "manual";
|
|
14
|
+
active?: boolean;
|
|
15
|
+
reducedMotion?: boolean | "auto";
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
declare const WeatherFx: {
|
|
19
|
+
({ ref: forwardedRef, type, speed: speedProp, colors, intensity, angle, duration, trigger, active, reducedMotion, children, ...rest }: WeatherFxProps): React.JSX.Element;
|
|
20
|
+
displayName: string;
|
|
21
|
+
};
|
|
22
|
+
export { WeatherFx };
|