Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/r/DecryptedText-JS-CSS.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/r/DecryptedText-JS-TW.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/r/DecryptedText-TS-CSS.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/r/DecryptedText-TS-TW.json

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions src/content/TextAnimations/DecryptedText/DecryptedText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default function DecryptedText({
const containerRef = useRef(null);
const orderRef = useRef([]);
const pointerRef = useRef(0);
const intervalRef = useRef(null);

const availableChars = useMemo(() => {
return useOriginalCharsOnly
Expand Down Expand Up @@ -147,7 +148,6 @@ export default function DecryptedText({
useEffect(() => {
if (!isAnimating) return;

let interval;
let currentIteration = 0;

const getNextIndex = revealedSet => {
Expand Down Expand Up @@ -176,7 +176,7 @@ export default function DecryptedText({
}
};

interval = setInterval(() => {
intervalRef.current = setInterval(() => {
setRevealedIndices(prevRevealed => {
if (sequential) {
// Forward
Expand All @@ -188,7 +188,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, newRevealed));
return newRevealed;
} else {
clearInterval(interval);
clearInterval(intervalRef.current);
setIsAnimating(false);
setIsDecrypted(true);
return prevRevealed;
Expand All @@ -202,13 +202,13 @@ export default function DecryptedText({
newRevealed.delete(idxToRemove);
setDisplayText(shuffleText(text, newRevealed));
if (newRevealed.size === 0) {
clearInterval(interval);
clearInterval(intervalRef.current);
setIsAnimating(false);
setIsDecrypted(false);
}
return newRevealed;
} else {
clearInterval(interval);
clearInterval(intervalRef.current);
setIsAnimating(false);
setIsDecrypted(false);
return prevRevealed;
Expand All @@ -220,7 +220,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, prevRevealed));
currentIteration++;
if (currentIteration >= maxIterations) {
clearInterval(interval);
clearInterval(intervalRef.current);
setIsAnimating(false);
setDisplayText(text);
setIsDecrypted(true);
Expand All @@ -239,7 +239,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, nextSet));
currentIteration++;
if (nextSet.size === 0 || currentIteration >= maxIterations) {
clearInterval(interval);
clearInterval(intervalRef.current);
setIsAnimating(false);
setIsDecrypted(false);
// ensure final scrambled state
Expand All @@ -253,7 +253,7 @@ export default function DecryptedText({
});
}, speed);

return () => clearInterval(interval);
return () => clearInterval(intervalRef.current);
}, [
isAnimating,
text,
Expand Down Expand Up @@ -293,16 +293,15 @@ export default function DecryptedText({
const triggerHoverDecrypt = useCallback(() => {
if (isAnimating) return;

// Reset animation state cleanly
setRevealedIndices(new Set());
setIsDecrypted(false);
setDisplayText(text);

setDirection('forward');
setIsAnimating(true);
}, [isAnimating, text]);

const resetToPlainText = useCallback(() => {
clearInterval(intervalRef.current);
setIsAnimating(false);
setRevealedIndices(new Set());
setDisplayText(text);
Expand Down
19 changes: 9 additions & 10 deletions src/tailwind/TextAnimations/DecryptedText/DecryptedText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function DecryptedText({
const containerRef = useRef(null);
const orderRef = useRef([]);
const pointerRef = useRef(0);
const intervalRef = useRef(null);

const availableChars = useMemo(() => {
return useOriginalCharsOnly
Expand Down Expand Up @@ -130,7 +131,6 @@ export default function DecryptedText({
useEffect(() => {
if (!isAnimating) return;

let interval;
let currentIteration = 0;

const getNextIndex = revealedSet => {
Expand Down Expand Up @@ -158,7 +158,7 @@ export default function DecryptedText({
}
};

interval = setInterval(() => {
intervalRef.current = setInterval(() => {
setRevealedIndices(prevRevealed => {
if (sequential) {
// Forward
Expand All @@ -170,7 +170,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, newRevealed));
return newRevealed;
} else {
clearInterval(interval);
clearInterval(intervalRef.current);
setIsAnimating(false);
setIsDecrypted(true);
return prevRevealed;
Expand All @@ -185,13 +185,13 @@ export default function DecryptedText({
newRevealed.delete(idxToRemove);
setDisplayText(shuffleText(text, newRevealed));
if (newRevealed.size === 0) {
clearInterval(interval);
clearInterval(intervalRef.current);
setIsAnimating(false);
setIsDecrypted(false);
}
return newRevealed;
} else {
clearInterval(interval);
clearInterval(intervalRef.current);
setIsAnimating(false);
setIsDecrypted(false);
return prevRevealed;
Expand All @@ -203,7 +203,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, prevRevealed));
currentIteration++;
if (currentIteration >= maxIterations) {
clearInterval(interval);
clearInterval(intervalRef.current);
setIsAnimating(false);
setDisplayText(text);
setIsDecrypted(true);
Expand All @@ -222,7 +222,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, nextSet));
currentIteration++;
if (nextSet.size === 0 || currentIteration >= maxIterations) {
clearInterval(interval);
clearInterval(intervalRef.current);
setIsAnimating(false);
setIsDecrypted(false);
// ensure final scrambled state
Expand All @@ -236,7 +236,7 @@ export default function DecryptedText({
});
}, speed);

return () => clearInterval(interval);
return () => clearInterval(intervalRef.current);
}, [
isAnimating,
text,
Expand Down Expand Up @@ -276,16 +276,15 @@ export default function DecryptedText({
const triggerHoverDecrypt = useCallback(() => {
if (isAnimating) return;

// Reset animation state cleanly
setRevealedIndices(new Set());
setIsDecrypted(false);
setDisplayText(text);

setDirection('forward');
setIsAnimating(true);
}, [isAnimating, text]);

const resetToPlainText = useCallback(() => {
clearInterval(intervalRef.current);
setIsAnimating(false);
setRevealedIndices(new Set());
setDisplayText(text);
Expand Down
19 changes: 9 additions & 10 deletions src/ts-default/TextAnimations/DecryptedText/DecryptedText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function DecryptedText({
const containerRef = useRef<HTMLSpanElement>(null);
const orderRef = useRef<number[]>([]);
const pointerRef = useRef<number>(0);
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);

const availableChars = useMemo<string[]>(() => {
return useOriginalCharsOnly
Expand Down Expand Up @@ -165,7 +166,6 @@ export default function DecryptedText({
useEffect(() => {
if (!isAnimating) return;

let interval: ReturnType<typeof setInterval>;
let currentIteration = 0;

const getNextIndex = (revealedSet: Set<number>): number => {
Expand Down Expand Up @@ -194,7 +194,7 @@ export default function DecryptedText({
}
};

interval = setInterval(() => {
intervalRef.current = setInterval(() => {
setRevealedIndices(prevRevealed => {
if (sequential) {
// Forward
Expand All @@ -206,7 +206,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, newRevealed));
return newRevealed;
} else {
clearInterval(interval);
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setIsDecrypted(true);
return prevRevealed;
Expand All @@ -220,13 +220,13 @@ export default function DecryptedText({
newRevealed.delete(idxToRemove);
setDisplayText(shuffleText(text, newRevealed));
if (newRevealed.size === 0) {
clearInterval(interval);
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setIsDecrypted(false);
}
return newRevealed;
} else {
clearInterval(interval);
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setIsDecrypted(false);
return prevRevealed;
Expand All @@ -238,7 +238,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, prevRevealed));
currentIteration++;
if (currentIteration >= maxIterations) {
clearInterval(interval);
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setDisplayText(text);
setIsDecrypted(true);
Expand All @@ -257,7 +257,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, nextSet));
currentIteration++;
if (nextSet.size === 0 || currentIteration >= maxIterations) {
clearInterval(interval);
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setIsDecrypted(false);
// ensure final scrambled state
Expand All @@ -271,7 +271,7 @@ export default function DecryptedText({
});
}, speed);

return () => clearInterval(interval);
return () => clearInterval(intervalRef.current ?? undefined);
}, [
isAnimating,
text,
Expand Down Expand Up @@ -311,16 +311,15 @@ export default function DecryptedText({
const triggerHoverDecrypt = useCallback(() => {
if (isAnimating) return;

// Reset animation state cleanly
setRevealedIndices(new Set());
setIsDecrypted(false);
setDisplayText(text);

setDirection('forward');
setIsAnimating(true);
}, [isAnimating, text]);

const resetToPlainText = useCallback(() => {
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setRevealedIndices(new Set());
setDisplayText(text);
Expand Down
19 changes: 9 additions & 10 deletions src/ts-tailwind/TextAnimations/DecryptedText/DecryptedText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function DecryptedText({
const containerRef = useRef<HTMLSpanElement>(null);
const orderRef = useRef<number[]>([]);
const pointerRef = useRef<number>(0);
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);

const availableChars = useMemo<string[]>(() => {
return useOriginalCharsOnly
Expand Down Expand Up @@ -148,7 +149,6 @@ export default function DecryptedText({
useEffect(() => {
if (!isAnimating) return;

let interval: ReturnType<typeof setInterval>;
let currentIteration = 0;

const getNextIndex = (revealedSet: Set<number>): number => {
Expand Down Expand Up @@ -176,7 +176,7 @@ export default function DecryptedText({
}
};

interval = setInterval(() => {
intervalRef.current = setInterval(() => {
setRevealedIndices(prevRevealed => {
if (sequential) {
// Forward
Expand All @@ -188,7 +188,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, newRevealed));
return newRevealed;
} else {
clearInterval(interval);
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setIsDecrypted(true);
return prevRevealed;
Expand All @@ -202,13 +202,13 @@ export default function DecryptedText({
newRevealed.delete(idxToRemove);
setDisplayText(shuffleText(text, newRevealed));
if (newRevealed.size === 0) {
clearInterval(interval);
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setIsDecrypted(false);
}
return newRevealed;
} else {
clearInterval(interval);
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setIsDecrypted(false);
return prevRevealed;
Expand All @@ -220,7 +220,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, prevRevealed));
currentIteration++;
if (currentIteration >= maxIterations) {
clearInterval(interval);
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setDisplayText(text);
setIsDecrypted(true);
Expand All @@ -239,7 +239,7 @@ export default function DecryptedText({
setDisplayText(shuffleText(text, nextSet));
currentIteration++;
if (nextSet.size === 0 || currentIteration >= maxIterations) {
clearInterval(interval);
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setIsDecrypted(false);
// ensure final scrambled state
Expand All @@ -252,7 +252,7 @@ export default function DecryptedText({
return prevRevealed;
});
}, speed);
return () => clearInterval(interval);
return () => clearInterval(intervalRef.current ?? undefined);
}, [
isAnimating,
text,
Expand Down Expand Up @@ -292,16 +292,15 @@ export default function DecryptedText({
const triggerHoverDecrypt = useCallback(() => {
if (isAnimating) return;

// Reset animation state cleanly
setRevealedIndices(new Set());
setIsDecrypted(false);
setDisplayText(text);

setDirection('forward');
setIsAnimating(true);
}, [isAnimating, text]);

const resetToPlainText = useCallback(() => {
clearInterval(intervalRef.current ?? undefined);
setIsAnimating(false);
setRevealedIndices(new Set());
setDisplayText(text);
Expand Down