@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
package/dist/HoloFx.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Flex, useInViewport, useReducedMotion } from "@once-ui-system/core";
|
|
4
|
+
import classNames from "clsx";
|
|
5
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
6
|
+
import styles from "./HoloFx.module.css";
|
|
7
|
+
const formatMask = (maskPosition = "100 200") => {
|
|
8
|
+
const [x, y] = maskPosition.split(" ");
|
|
9
|
+
const formattedX = `${x}%`;
|
|
10
|
+
const formattedY = `${y ? y : x}%`;
|
|
11
|
+
return `radial-gradient(ellipse ${formattedX} ${formattedY} at var(--gradient-pos-x, 50%) var(--gradient-pos-y, 50%), black 50%, transparent 100%)`;
|
|
12
|
+
};
|
|
13
|
+
const getMaskStyle = (mask) => {
|
|
14
|
+
return mask?.maskPosition ? formatMask(mask.maskPosition) : formatMask();
|
|
15
|
+
};
|
|
16
|
+
const HoloFx = ({ ref, children, reducedMotion = "auto", shine, burn, texture, ...rest }) => {
|
|
17
|
+
const internalRef = useRef(null);
|
|
18
|
+
const lastCallRef = useRef(0);
|
|
19
|
+
const mergedRef = useCallback((node) => {
|
|
20
|
+
internalRef.current = node;
|
|
21
|
+
if (typeof ref === "function") {
|
|
22
|
+
ref(node);
|
|
23
|
+
}
|
|
24
|
+
else if (ref) {
|
|
25
|
+
ref.current = node;
|
|
26
|
+
}
|
|
27
|
+
}, [ref]);
|
|
28
|
+
const isInViewport = useInViewport(internalRef);
|
|
29
|
+
const { shouldAnimate } = useReducedMotion(reducedMotion);
|
|
30
|
+
const isActive = isInViewport && shouldAnimate;
|
|
31
|
+
const shineDefaults = {
|
|
32
|
+
opacity: 30,
|
|
33
|
+
blending: "color-dodge",
|
|
34
|
+
...shine,
|
|
35
|
+
// After the spread: `shine.mask` is the options object, not the CSS mask.
|
|
36
|
+
mask: getMaskStyle(shine?.mask),
|
|
37
|
+
};
|
|
38
|
+
const burnDefaults = {
|
|
39
|
+
opacity: 30,
|
|
40
|
+
filter: "brightness(0.2) contrast(2)",
|
|
41
|
+
blending: "color-dodge",
|
|
42
|
+
...burn,
|
|
43
|
+
// After the spread: `burn.mask` is the options object, not the CSS mask.
|
|
44
|
+
mask: getMaskStyle(burn?.mask),
|
|
45
|
+
};
|
|
46
|
+
const textureDefaults = {
|
|
47
|
+
opacity: 10,
|
|
48
|
+
blending: "color-dodge",
|
|
49
|
+
image: "repeating-linear-gradient(-45deg, var(--static-white) 0, var(--static-white) 1px, transparent 3px, transparent 2px)",
|
|
50
|
+
...texture,
|
|
51
|
+
// After the spread: `texture.mask` is the options object, not the CSS mask.
|
|
52
|
+
mask: getMaskStyle(texture?.mask),
|
|
53
|
+
};
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!isActive)
|
|
56
|
+
return;
|
|
57
|
+
const handleMouseMove = (event) => {
|
|
58
|
+
const now = Date.now();
|
|
59
|
+
if (now - lastCallRef.current < 16)
|
|
60
|
+
return;
|
|
61
|
+
lastCallRef.current = now;
|
|
62
|
+
const element = internalRef.current;
|
|
63
|
+
if (!element)
|
|
64
|
+
return;
|
|
65
|
+
const rect = element.getBoundingClientRect();
|
|
66
|
+
const offsetX = event.clientX - rect.left;
|
|
67
|
+
const offsetY = event.clientY - rect.top;
|
|
68
|
+
const centerX = rect.width / 2;
|
|
69
|
+
const centerY = rect.height / 2;
|
|
70
|
+
const deltaX = ((offsetX - centerX) / centerX) * 100;
|
|
71
|
+
const deltaY = ((offsetY - centerY) / centerY) * 100;
|
|
72
|
+
element.style.setProperty("--gradient-pos-x", `${deltaX}%`);
|
|
73
|
+
element.style.setProperty("--gradient-pos-y", `${deltaY}%`);
|
|
74
|
+
};
|
|
75
|
+
document.addEventListener("mousemove", handleMouseMove, { passive: true });
|
|
76
|
+
return () => {
|
|
77
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
78
|
+
};
|
|
79
|
+
}, [isActive]);
|
|
80
|
+
return (_jsxs(Flex, { overflow: "hidden", className: styles.holoFx, ref: mergedRef, ...rest, children: [_jsx(Flex, { fill: true, className: styles.base, children: children }), _jsx(Flex, { m: { hide: true }, position: "absolute", fill: true, pointerEvents: "none", className: classNames(styles.overlay, styles.burn), "aria-hidden": "true", inert: true, style: {
|
|
81
|
+
["--burn-opacity"]: burnDefaults.opacity + "%",
|
|
82
|
+
filter: burnDefaults.filter,
|
|
83
|
+
mixBlendMode: burnDefaults.blending,
|
|
84
|
+
maskImage: burnDefaults.mask,
|
|
85
|
+
}, children: children }), _jsx(Flex, { m: { hide: true }, position: "absolute", fill: true, pointerEvents: "none", className: classNames(styles.overlay, styles.shine), "aria-hidden": "true", inert: true, style: {
|
|
86
|
+
["--shine-opacity"]: shineDefaults.opacity + "%",
|
|
87
|
+
filter: shineDefaults.filter,
|
|
88
|
+
mixBlendMode: shineDefaults.blending,
|
|
89
|
+
maskImage: shineDefaults.mask,
|
|
90
|
+
}, children: children }), _jsx(Flex, { m: { hide: true }, position: "absolute", fill: true, pointerEvents: "none", className: classNames(styles.overlay, styles.texture), "aria-hidden": "true", style: {
|
|
91
|
+
["--texture-opacity"]: textureDefaults.opacity + "%",
|
|
92
|
+
backgroundImage: textureDefaults.image,
|
|
93
|
+
filter: textureDefaults.filter,
|
|
94
|
+
mixBlendMode: textureDefaults.blending,
|
|
95
|
+
maskImage: textureDefaults.mask,
|
|
96
|
+
} })] }));
|
|
97
|
+
};
|
|
98
|
+
HoloFx.displayName = "HoloFx";
|
|
99
|
+
export { HoloFx };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
.overlay {
|
|
2
|
+
opacity: 0;
|
|
3
|
+
transition: opacity 0.3s ease-in-out;
|
|
4
|
+
pointer-events: none;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.holoFx {
|
|
8
|
+
isolation: isolate;
|
|
9
|
+
z-index: 0;
|
|
10
|
+
}
|
|
11
|
+
@media (hover: hover) {
|
|
12
|
+
.holoFx:hover .burn {
|
|
13
|
+
transform: translateX(1px) translateY(1px);
|
|
14
|
+
opacity: var(--burn-opacity);
|
|
15
|
+
z-index: 1;
|
|
16
|
+
}
|
|
17
|
+
.holoFx:hover .shine {
|
|
18
|
+
transform: translateX(-1px) translateY(-1px);
|
|
19
|
+
opacity: var(--light-opacity);
|
|
20
|
+
z-index: 2;
|
|
21
|
+
}
|
|
22
|
+
.holoFx:hover .texture {
|
|
23
|
+
opacity: var(--texture-opacity);
|
|
24
|
+
transform: translateX(calc(var(--gradient-pos-x) / 50)) scale(1.1);
|
|
25
|
+
background-size: 150% 150%;
|
|
26
|
+
background-position: center;
|
|
27
|
+
z-index: 3;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Speed } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
type LetterFxProps = {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
trigger?: "hover" | "instant" | "custom";
|
|
7
|
+
/**
|
|
8
|
+
* A multiplier on the scramble's pace (`2` is twice as fast), or
|
|
9
|
+
* `"slow"`/`"medium"`/`"fast"` (0.5, 1, 2).
|
|
10
|
+
*/
|
|
11
|
+
speed?: Speed;
|
|
12
|
+
/** The characters to cycle through: an array, or a string read one character at a time. */
|
|
13
|
+
charset?: string | string[];
|
|
14
|
+
onTrigger?: (triggerFn: () => void) => void;
|
|
15
|
+
className?: string;
|
|
16
|
+
style?: React.CSSProperties;
|
|
17
|
+
};
|
|
18
|
+
declare const LetterFx: {
|
|
19
|
+
({ ref, children, trigger, speed, charset, onTrigger, className, style, }: LetterFxProps & {
|
|
20
|
+
ref?: React.Ref<HTMLSpanElement>;
|
|
21
|
+
}): React.JSX.Element;
|
|
22
|
+
displayName: string;
|
|
23
|
+
};
|
|
24
|
+
export { LetterFx };
|
package/dist/LetterFx.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useReducedMotion, VisuallyHidden } from "@once-ui-system/core";
|
|
4
|
+
import classNames from "clsx";
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
|
+
import { prefersReducedMotionNow } from "./internal/reducedMotion.js";
|
|
7
|
+
import { speedFactor } from "./internal/speed.js";
|
|
8
|
+
const defaultCharset = ["X", "$", "@", "a", "H", "z", "o", "0", "y", "#", "?", "*", "0", "1", "+"];
|
|
9
|
+
function getRandomCharacter(charset) {
|
|
10
|
+
const randomIndex = Math.floor(Math.random() * charset.length);
|
|
11
|
+
return charset[randomIndex];
|
|
12
|
+
}
|
|
13
|
+
function createEventHandler(originalText, setText, inProgress, setInProgress, speed, charset, setHasAnimated) {
|
|
14
|
+
// The designed pace (speed 1): a 30ms step and 300ms of scrambling first.
|
|
15
|
+
const factor = speedFactor(speed);
|
|
16
|
+
const BASE_DELAY = 30 / factor;
|
|
17
|
+
const REVEAL_DELAY = 30 / factor;
|
|
18
|
+
const INITIAL_RANDOM_DURATION = 300 / factor;
|
|
19
|
+
const generateRandomText = () => originalText
|
|
20
|
+
.split("")
|
|
21
|
+
.map((char) => (char === " " ? " " : getRandomCharacter(charset)))
|
|
22
|
+
.join("");
|
|
23
|
+
return async () => {
|
|
24
|
+
if (inProgress)
|
|
25
|
+
return;
|
|
26
|
+
setInProgress(true);
|
|
27
|
+
let randomizedText = generateRandomText();
|
|
28
|
+
const endTime = Date.now() + INITIAL_RANDOM_DURATION;
|
|
29
|
+
while (Date.now() < endTime) {
|
|
30
|
+
setText(randomizedText);
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve, BASE_DELAY));
|
|
32
|
+
randomizedText = generateRandomText();
|
|
33
|
+
}
|
|
34
|
+
for (let i = 0; i < originalText.length; i++) {
|
|
35
|
+
await new Promise((resolve) => setTimeout(resolve, REVEAL_DELAY));
|
|
36
|
+
setText(`${originalText.substring(0, i + 1)}${randomizedText.substring(i + 1)}`);
|
|
37
|
+
}
|
|
38
|
+
setInProgress(false);
|
|
39
|
+
if (setHasAnimated) {
|
|
40
|
+
setHasAnimated(true);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const LetterFx = ({ ref, children, trigger = "hover", speed = "medium", charset = defaultCharset, onTrigger, className, style, }) => {
|
|
45
|
+
const [text, setText] = useState(typeof children === "string" ? children : "");
|
|
46
|
+
const [inProgress, setInProgress] = useState(false);
|
|
47
|
+
const [hasAnimated, setHasAnimated] = useState(false);
|
|
48
|
+
const originalText = useRef(typeof children === "string" ? children : "");
|
|
49
|
+
const { prefersReducedMotion } = useReducedMotion();
|
|
50
|
+
const eventHandler = useCallback(() => {
|
|
51
|
+
// Under reduced motion there is no scramble: the text stays as it is.
|
|
52
|
+
if (prefersReducedMotion || prefersReducedMotionNow()) {
|
|
53
|
+
if (!inProgress)
|
|
54
|
+
setText(originalText.current);
|
|
55
|
+
if (trigger === "instant")
|
|
56
|
+
setHasAnimated(true);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
createEventHandler(originalText.current, setText, inProgress, setInProgress, speed, charset, trigger === "instant" ? setHasAnimated : undefined)();
|
|
60
|
+
}, [inProgress, speed, charset, trigger, setHasAnimated, prefersReducedMotion]);
|
|
61
|
+
// Only new text resets the display. This used to share an effect with the
|
|
62
|
+
// instant trigger, so every new `eventHandler` (each render, with an inline
|
|
63
|
+
// `charset` array) put the original text back over the scramble.
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (typeof children === "string") {
|
|
66
|
+
setText(children);
|
|
67
|
+
originalText.current = children;
|
|
68
|
+
}
|
|
69
|
+
}, [children]);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (typeof children === "string" && trigger === "instant" && !hasAnimated) {
|
|
72
|
+
eventHandler();
|
|
73
|
+
}
|
|
74
|
+
}, [children, trigger, eventHandler, hasAnimated]);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (trigger === "custom" && onTrigger) {
|
|
77
|
+
onTrigger(eventHandler);
|
|
78
|
+
}
|
|
79
|
+
}, [trigger, onTrigger, eventHandler]);
|
|
80
|
+
return (_jsx("span", { ref: ref, className: classNames(className), style: style, onMouseOver: trigger === "hover" ? eventHandler : undefined, children: typeof children !== "string" ? (children) : inProgress ? (_jsxs(_Fragment, { children: [_jsx(VisuallyHidden, { children: originalText.current }), _jsx("span", { "aria-hidden": "true", children: text })] })) : (text) }));
|
|
81
|
+
};
|
|
82
|
+
LetterFx.displayName = "LetterFx";
|
|
83
|
+
export { LetterFx };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Flex, type Speed } from "@once-ui-system/core";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
interface BulgeConfig {
|
|
4
|
+
type?: "ripple" | "wave";
|
|
5
|
+
/** Milliseconds one bulge wave takes (seconds until 3.0). Default 3000. */
|
|
6
|
+
duration?: number;
|
|
7
|
+
intensity?: number;
|
|
8
|
+
repeat?: boolean;
|
|
9
|
+
/** Milliseconds between waves. */
|
|
10
|
+
delay?: number;
|
|
11
|
+
}
|
|
12
|
+
interface MatrixFxProps extends React.ComponentProps<typeof Flex> {
|
|
13
|
+
/** A multiplier on the designed pace (`1`), or `"slow"`/`"medium"`/`"fast"` (0.5, 1, 2). */
|
|
14
|
+
speed?: Speed;
|
|
15
|
+
colors?: string[];
|
|
16
|
+
size?: number;
|
|
17
|
+
spacing?: number;
|
|
18
|
+
revealFrom?: "center" | "top" | "bottom" | "left" | "right";
|
|
19
|
+
trigger?: "hover" | "instant" | "mount" | "click" | "manual";
|
|
20
|
+
active?: boolean;
|
|
21
|
+
flicker?: boolean;
|
|
22
|
+
bulge?: BulgeConfig;
|
|
23
|
+
fps?: number;
|
|
24
|
+
reducedMotion?: boolean | "auto";
|
|
25
|
+
children?: React.ReactNode;
|
|
26
|
+
}
|
|
27
|
+
declare const MatrixFx: {
|
|
28
|
+
({ ref: forwardedRef, speed: speedProp, colors, size, spacing, revealFrom, trigger, active, flicker, bulge, fps, reducedMotion, children, ...rest }: MatrixFxProps): React.JSX.Element;
|
|
29
|
+
displayName: string;
|
|
30
|
+
};
|
|
31
|
+
export type { BulgeConfig };
|
|
32
|
+
export { MatrixFx };
|