@readdy/anim 0.0.21
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/animations/button/3d-flip/index.js +60 -0
- package/animations/button/3d-flip/react.tsx +29 -0
- package/animations/button/3d-flip/style.css +17 -0
- package/animations/button/blur-fade-in/index.js +21 -0
- package/animations/button/blur-fade-in/react.tsx +26 -0
- package/animations/button/blur-fade-in/style.css +27 -0
- package/animations/button/border-beam/index.js +172 -0
- package/animations/button/border-beam/react.tsx +55 -0
- package/animations/button/border-beam/style.css +59 -0
- package/animations/button/bounce-elastic/index.js +21 -0
- package/animations/button/bounce-elastic/react.tsx +26 -0
- package/animations/button/bounce-elastic/style.css +31 -0
- package/animations/button/bubble-button/index.js +317 -0
- package/animations/button/bubble-button/react.tsx +19 -0
- package/animations/button/bubble-button/style.css +245 -0
- package/animations/button/confetti-button/index.js +66 -0
- package/animations/button/confetti-button/react.tsx +30 -0
- package/animations/button/confetti-button/style.css +48 -0
- package/animations/button/glow-cta/index.js +69 -0
- package/animations/button/glow-cta/react.tsx +45 -0
- package/animations/button/glow-cta/style.css +78 -0
- package/animations/button/magnetic-hover/index.js +61 -0
- package/animations/button/magnetic-hover/react.tsx +29 -0
- package/animations/button/magnetic-hover/style.css +18 -0
- package/animations/button/pulse/index.js +21 -0
- package/animations/button/pulse/react.tsx +26 -0
- package/animations/button/pulse/style.css +24 -0
- package/animations/button/rainbow-button/index.js +21 -0
- package/animations/button/rainbow-button/react.tsx +26 -0
- package/animations/button/rainbow-button/style.css +54 -0
- package/animations/button/shimmer-border/index.js +28 -0
- package/animations/button/shimmer-border/react.tsx +41 -0
- package/animations/button/shimmer-border/style.css +53 -0
- package/animations/button/sketch-button/index.js +16 -0
- package/animations/button/sketch-button/react.tsx +19 -0
- package/animations/button/sketch-button/style.css +25 -0
- package/animations/card/blur-rise/index.js +21 -0
- package/animations/card/blur-rise/react.tsx +26 -0
- package/animations/card/blur-rise/style.css +27 -0
- package/animations/card/bounce-in-bottom/index.js +21 -0
- package/animations/card/bounce-in-bottom/react.tsx +26 -0
- package/animations/card/bounce-in-bottom/style.css +31 -0
- package/animations/card/card-fan-spread/index.js +146 -0
- package/animations/card/card-fan-spread/react.tsx +35 -0
- package/animations/card/card-fan-spread/style.css +90 -0
- package/animations/card/card-flip/index.js +203 -0
- package/animations/card/card-flip/react.tsx +35 -0
- package/animations/card/card-flip/style.css +71 -0
- package/animations/card/float-idle/index.js +21 -0
- package/animations/card/float-idle/react.tsx +26 -0
- package/animations/card/float-idle/style.css +21 -0
- package/animations/card/image-magnifier/index.js +333 -0
- package/animations/card/image-magnifier/react.tsx +31 -0
- package/animations/card/image-magnifier/style.css +42 -0
- package/animations/card/image-zoom-rotate/index.js +48 -0
- package/animations/card/image-zoom-rotate/react.tsx +31 -0
- package/animations/card/image-zoom-rotate/style.css +20 -0
- package/animations/card/pop-in-stack/index.js +25 -0
- package/animations/card/pop-in-stack/react.tsx +33 -0
- package/animations/card/pop-in-stack/style.css +25 -0
- package/animations/card/reveal-from-top/index.js +21 -0
- package/animations/card/reveal-from-top/react.tsx +26 -0
- package/animations/card/reveal-from-top/style.css +28 -0
- package/animations/card/rgb-split-glitch/index.js +28 -0
- package/animations/card/rgb-split-glitch/react.tsx +41 -0
- package/animations/card/rgb-split-glitch/style.css +33 -0
- package/animations/card/tilted-card/index.js +64 -0
- package/animations/card/tilted-card/react.tsx +33 -0
- package/animations/card/tilted-card/style.css +27 -0
- package/animations/header/anime-splittext/index.js +108 -0
- package/animations/header/anime-splittext/react.tsx +30 -0
- package/animations/header/anime-splittext/style.css +71 -0
- package/animations/header/bounce-in-down/index.js +40 -0
- package/animations/header/bounce-in-down/react.tsx +29 -0
- package/animations/header/bounce-in-down/style.css +40 -0
- package/animations/header/fly-in-chars/index.js +46 -0
- package/animations/header/fly-in-chars/react.tsx +30 -0
- package/animations/header/fly-in-chars/style.css +29 -0
- package/animations/header/gradient-text/index.js +21 -0
- package/animations/header/gradient-text/react.tsx +26 -0
- package/animations/header/gradient-text/style.css +28 -0
- package/animations/header/letter-bounce/index.js +33 -0
- package/animations/header/letter-bounce/react.tsx +34 -0
- package/animations/header/letter-bounce/style.css +25 -0
- package/animations/header/roll-in/index.js +40 -0
- package/animations/header/roll-in/react.tsx +29 -0
- package/animations/header/roll-in/style.css +31 -0
- package/animations/header/shimmer-text/index.js +16 -0
- package/animations/header/shimmer-text/react.tsx +28 -0
- package/animations/header/shimmer-text/style.css +29 -0
- package/animations/header/shuffle/index.js +118 -0
- package/animations/header/shuffle/react.tsx +50 -0
- package/animations/header/shuffle/style.css +25 -0
- package/animations/header/split-text/index.js +72 -0
- package/animations/header/split-text/react.tsx +38 -0
- package/animations/header/split-text/style.css +31 -0
- package/animations/header/text-type/index.js +267 -0
- package/animations/header/text-type/react.tsx +63 -0
- package/animations/header/text-type/style.css +37 -0
- package/animations/header/word-curtain-reveal/index.js +97 -0
- package/animations/header/word-curtain-reveal/react.tsx +30 -0
- package/animations/header/word-curtain-reveal/style.css +39 -0
- package/dist/button/3d-flip/react.js +21 -0
- package/dist/button/3d-flip.js +61 -0
- package/dist/button/blur-fade-in/react.js +28 -0
- package/dist/button/blur-fade-in.js +17 -0
- package/dist/button/border-beam/react.js +22 -0
- package/dist/button/border-beam.js +168 -0
- package/dist/button/bounce-elastic/react.js +28 -0
- package/dist/button/bounce-elastic.js +17 -0
- package/dist/button/bubble-button/react.js +20 -0
- package/dist/button/bubble-button.js +318 -0
- package/dist/button/confetti-button/react.js +21 -0
- package/dist/button/confetti-button.js +67 -0
- package/dist/button/glow-cta/react.js +23 -0
- package/dist/button/glow-cta.js +65 -0
- package/dist/button/magnetic-hover/react.js +21 -0
- package/dist/button/magnetic-hover.js +62 -0
- package/dist/button/pulse/react.js +28 -0
- package/dist/button/pulse.js +17 -0
- package/dist/button/rainbow-button/react.js +28 -0
- package/dist/button/rainbow-button.js +17 -0
- package/dist/button/shimmer-border/react.js +22 -0
- package/dist/button/shimmer-border.js +24 -0
- package/dist/button/sketch-button/react.js +20 -0
- package/dist/button/sketch-button.js +17 -0
- package/dist/card/blur-rise/react.js +28 -0
- package/dist/card/blur-rise.js +17 -0
- package/dist/card/bounce-in-bottom/react.js +28 -0
- package/dist/card/bounce-in-bottom.js +17 -0
- package/dist/card/card-fan-spread/react.js +20 -0
- package/dist/card/card-fan-spread.js +147 -0
- package/dist/card/float-idle/react.js +28 -0
- package/dist/card/float-idle.js +17 -0
- package/dist/card/image-magnifier/react.js +22 -0
- package/dist/card/image-magnifier.js +334 -0
- package/dist/card/image-zoom-rotate/react.js +21 -0
- package/dist/card/image-zoom-rotate.js +49 -0
- package/dist/card/pop-in-stack/react.js +20 -0
- package/dist/card/pop-in-stack.js +26 -0
- package/dist/card/reveal-from-top/react.js +28 -0
- package/dist/card/reveal-from-top.js +17 -0
- package/dist/card/rgb-split-glitch/react.js +22 -0
- package/dist/card/rgb-split-glitch.js +24 -0
- package/dist/card/tilted-card/react.js +21 -0
- package/dist/card/tilted-card.js +65 -0
- package/dist/chunks/constants-EnH6-Pz4.js +66 -0
- package/dist/chunks/constants-ZTHic1pf.js +66 -0
- package/dist/chunks/pointer-follow-B3RFnn_q.js +93 -0
- package/dist/chunks/pointer-follow-BETANySn.js +93 -0
- package/dist/chunks/reduced-motion-BpQYuEzK.js +17 -0
- package/dist/chunks/reduced-motion-HX79Ac8G.js +17 -0
- package/dist/chunks/resolve-card-media-Cj3V_oms.js +43 -0
- package/dist/chunks/resolve-card-media-DBIU-duL.js +43 -0
- package/dist/chunks/text-split-D02jltVh.js +191 -0
- package/dist/chunks/text-split-frOR4UpH.js +191 -0
- package/dist/full.css +1 -0
- package/dist/full.js +3192 -0
- package/dist/header/anime-splittext/react.js +22 -0
- package/dist/header/anime-splittext.js +109 -0
- package/dist/header/bounce-in-down/react.js +32 -0
- package/dist/header/bounce-in-down.js +36 -0
- package/dist/header/fly-in-chars/react.js +23 -0
- package/dist/header/fly-in-chars.js +47 -0
- package/dist/header/gradient-text/react.js +28 -0
- package/dist/header/gradient-text.js +17 -0
- package/dist/header/letter-bounce/react.js +23 -0
- package/dist/header/letter-bounce.js +34 -0
- package/dist/header/roll-in/react.js +32 -0
- package/dist/header/roll-in.js +36 -0
- package/dist/header/shimmer-text/react.js +27 -0
- package/dist/header/shimmer-text.js +17 -0
- package/dist/header/shuffle/react.js +30 -0
- package/dist/header/shuffle.js +119 -0
- package/dist/header/split-text/react.js +26 -0
- package/dist/header/split-text.js +73 -0
- package/dist/header/text-type/react.js +43 -0
- package/dist/header/text-type.js +268 -0
- package/dist/header/word-curtain-reveal/react.js +22 -0
- package/dist/header/word-curtain-reveal.js +98 -0
- package/dist/meta.json +6 -0
- package/dist/metadata.json +1051 -0
- package/dist/react.css +1 -0
- package/dist/types/animations/button/3d-flip/index.d.ts +3 -0
- package/dist/types/animations/button/3d-flip/react.d.ts +8 -0
- package/dist/types/animations/button/blur-fade-in/index.d.ts +3 -0
- package/dist/types/animations/button/blur-fade-in/react.d.ts +13 -0
- package/dist/types/animations/button/border-beam/index.d.ts +3 -0
- package/dist/types/animations/button/border-beam/react.d.ts +25 -0
- package/dist/types/animations/button/bounce-elastic/index.d.ts +3 -0
- package/dist/types/animations/button/bounce-elastic/react.d.ts +13 -0
- package/dist/types/animations/button/bubble-button/index.d.ts +3 -0
- package/dist/types/animations/button/bubble-button/react.d.ts +4 -0
- package/dist/types/animations/button/confetti-button/index.d.ts +3 -0
- package/dist/types/animations/button/confetti-button/react.d.ts +8 -0
- package/dist/types/animations/button/glow-cta/index.d.ts +3 -0
- package/dist/types/animations/button/glow-cta/react.d.ts +20 -0
- package/dist/types/animations/button/magnetic-hover/index.d.ts +3 -0
- package/dist/types/animations/button/magnetic-hover/react.d.ts +8 -0
- package/dist/types/animations/button/pulse/index.d.ts +3 -0
- package/dist/types/animations/button/pulse/react.d.ts +13 -0
- package/dist/types/animations/button/rainbow-button/index.d.ts +3 -0
- package/dist/types/animations/button/rainbow-button/react.d.ts +13 -0
- package/dist/types/animations/button/shimmer-border/index.d.ts +3 -0
- package/dist/types/animations/button/shimmer-border/react.d.ts +18 -0
- package/dist/types/animations/button/sketch-button/index.d.ts +3 -0
- package/dist/types/animations/button/sketch-button/react.d.ts +4 -0
- package/dist/types/animations/card/blur-rise/index.d.ts +3 -0
- package/dist/types/animations/card/blur-rise/react.d.ts +13 -0
- package/dist/types/animations/card/bounce-in-bottom/index.d.ts +3 -0
- package/dist/types/animations/card/bounce-in-bottom/react.d.ts +13 -0
- package/dist/types/animations/card/card-fan-spread/index.d.ts +3 -0
- package/dist/types/animations/card/card-fan-spread/react.d.ts +11 -0
- package/dist/types/animations/card/card-flip/index.d.ts +3 -0
- package/dist/types/animations/card/card-flip/react.d.ts +11 -0
- package/dist/types/animations/card/float-idle/index.d.ts +3 -0
- package/dist/types/animations/card/float-idle/react.d.ts +13 -0
- package/dist/types/animations/card/image-magnifier/index.d.ts +3 -0
- package/dist/types/animations/card/image-magnifier/react.d.ts +9 -0
- package/dist/types/animations/card/image-zoom-rotate/index.d.ts +3 -0
- package/dist/types/animations/card/image-zoom-rotate/react.d.ts +9 -0
- package/dist/types/animations/card/pop-in-stack/index.d.ts +3 -0
- package/dist/types/animations/card/pop-in-stack/react.d.ts +10 -0
- package/dist/types/animations/card/reveal-from-top/index.d.ts +3 -0
- package/dist/types/animations/card/reveal-from-top/react.d.ts +13 -0
- package/dist/types/animations/card/rgb-split-glitch/index.d.ts +3 -0
- package/dist/types/animations/card/rgb-split-glitch/react.d.ts +18 -0
- package/dist/types/animations/card/tilted-card/index.d.ts +3 -0
- package/dist/types/animations/card/tilted-card/react.d.ts +10 -0
- package/dist/types/animations/header/anime-splittext/index.d.ts +3 -0
- package/dist/types/animations/header/anime-splittext/react.d.ts +8 -0
- package/dist/types/animations/header/bounce-in-down/index.d.ts +3 -0
- package/dist/types/animations/header/bounce-in-down/react.d.ts +13 -0
- package/dist/types/animations/header/fly-in-chars/index.d.ts +3 -0
- package/dist/types/animations/header/fly-in-chars/react.d.ts +8 -0
- package/dist/types/animations/header/gradient-text/index.d.ts +3 -0
- package/dist/types/animations/header/gradient-text/react.d.ts +13 -0
- package/dist/types/animations/header/letter-bounce/index.d.ts +3 -0
- package/dist/types/animations/header/letter-bounce/react.d.ts +10 -0
- package/dist/types/animations/header/roll-in/index.d.ts +3 -0
- package/dist/types/animations/header/roll-in/react.d.ts +13 -0
- package/dist/types/animations/header/shimmer-text/index.d.ts +3 -0
- package/dist/types/animations/header/shimmer-text/react.d.ts +4 -0
- package/dist/types/animations/header/shuffle/index.d.ts +3 -0
- package/dist/types/animations/header/shuffle/react.d.ts +14 -0
- package/dist/types/animations/header/split-text/index.d.ts +3 -0
- package/dist/types/animations/header/split-text/react.d.ts +10 -0
- package/dist/types/animations/header/text-type/index.d.ts +3 -0
- package/dist/types/animations/header/text-type/react.d.ts +13 -0
- package/dist/types/animations/header/word-curtain-reveal/index.d.ts +3 -0
- package/dist/types/animations/header/word-curtain-reveal/react.d.ts +8 -0
- package/dist/types/react-barrel.d.ts +34 -0
- package/dist/types/scripts/bundle-all.d.ts +173 -0
- package/dist/types/scripts/check-metadata.d.ts +1 -0
- package/dist/types/scripts/copy-metadata.d.ts +1 -0
- package/dist/types/scripts/generate-animation-id-map.d.ts +1 -0
- package/dist/types/scripts/generate-dist-meta.d.ts +1 -0
- package/dist/types/scripts/generate-preview-manifest.d.ts +1 -0
- package/dist/types/scripts/update-metadata.d.ts +1 -0
- package/dist/types/shared/constants.d.ts +34 -0
- package/dist/types/shared/meta.d.ts +18 -0
- package/dist/types/shared/pointer-follow.d.ts +8 -0
- package/dist/types/shared/reduced-motion.d.ts +11 -0
- package/dist/types/shared/resolve-card-media.d.ts +1 -0
- package/dist/types/shared/text-split.d.ts +19 -0
- package/dist/types/stories/3d-flip.stories.d.ts +7 -0
- package/dist/types/stories/_helpers.d.ts +24 -0
- package/dist/types/stories/anime-splittext.stories.d.ts +8 -0
- package/dist/types/stories/blur-fade-in.stories.d.ts +8 -0
- package/dist/types/stories/blur-rise.stories.d.ts +8 -0
- package/dist/types/stories/blur-to-sharp-rise-header.stories.d.ts +8 -0
- package/dist/types/stories/border-beam.stories.d.ts +8 -0
- package/dist/types/stories/bounce-elastic.stories.d.ts +8 -0
- package/dist/types/stories/bounce-in-bottom.stories.d.ts +8 -0
- package/dist/types/stories/bounce-in-down.stories.d.ts +9 -0
- package/dist/types/stories/bubble-button.stories.d.ts +8 -0
- package/dist/types/stories/card-fan-spread.stories.d.ts +7 -0
- package/dist/types/stories/card-flip.stories.d.ts +7 -0
- package/dist/types/stories/confetti-button.stories.d.ts +7 -0
- package/dist/types/stories/float-idle.stories.d.ts +8 -0
- package/dist/types/stories/fly-in-chars.stories.d.ts +8 -0
- package/dist/types/stories/glow-cta.stories.d.ts +9 -0
- package/dist/types/stories/gradient-text.stories.d.ts +9 -0
- package/dist/types/stories/image-magnifier.stories.d.ts +10 -0
- package/dist/types/stories/image-zoom-rotate.stories.d.ts +7 -0
- package/dist/types/stories/letter-bounce.stories.d.ts +8 -0
- package/dist/types/stories/magic-ui-border-beam-card.stories.d.ts +8 -0
- package/dist/types/stories/magnetic-hover.stories.d.ts +7 -0
- package/dist/types/stories/pop-in-stack.stories.d.ts +7 -0
- package/dist/types/stories/pulse.stories.d.ts +8 -0
- package/dist/types/stories/rainbow-button.stories.d.ts +8 -0
- package/dist/types/stories/reveal-from-top.stories.d.ts +8 -0
- package/dist/types/stories/rgb-split-glitch.stories.d.ts +8 -0
- package/dist/types/stories/roll-in.stories.d.ts +9 -0
- package/dist/types/stories/shimmer-border.stories.d.ts +9 -0
- package/dist/types/stories/shimmer-text.stories.d.ts +8 -0
- package/dist/types/stories/shuffle.stories.d.ts +8 -0
- package/dist/types/stories/sketch-button.stories.d.ts +7 -0
- package/dist/types/stories/split-text.stories.d.ts +8 -0
- package/dist/types/stories/text-type.stories.d.ts +8 -0
- package/dist/types/stories/tilted-card.stories.d.ts +7 -0
- package/dist/types/stories/word-curtain-reveal.stories.d.ts +8 -0
- package/package.json +166 -0
- package/react-barrel.js +44 -0
- package/shared/constants.js +64 -0
- package/shared/meta.js +21 -0
- package/shared/pointer-follow.js +91 -0
- package/shared/reduced-motion.js +15 -0
- package/shared/resolve-card-media.js +41 -0
- package/shared/text-split.js +188 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react'
|
|
2
|
+
import { init, destroy } from './index.js'
|
|
3
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
4
|
+
|
|
5
|
+
type AnimPopInStackProps = {
|
|
6
|
+
children: React.ReactElement
|
|
7
|
+
delay?: number
|
|
8
|
+
duration?: number
|
|
9
|
+
offset?: number
|
|
10
|
+
scaleStart?: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function AnimPopInStack({
|
|
14
|
+
children,
|
|
15
|
+
delay,
|
|
16
|
+
duration,
|
|
17
|
+
offset,
|
|
18
|
+
scaleStart,
|
|
19
|
+
}: AnimPopInStackProps) {
|
|
20
|
+
const ref = useRef<HTMLElement>(null)
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const el = ref.current
|
|
24
|
+
if (!el || prefersReducedMotion()) return
|
|
25
|
+
|
|
26
|
+
init(el, { delay, duration, offset, scaleStart })
|
|
27
|
+
return () => {
|
|
28
|
+
destroy(el)
|
|
29
|
+
}
|
|
30
|
+
}, [delay, duration, offset, scaleStart])
|
|
31
|
+
|
|
32
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
@keyframes readdy-anim-stack-pop {
|
|
2
|
+
0% {
|
|
3
|
+
opacity: 0;
|
|
4
|
+
transform: translateY(var(--readdy-anim-pop-offset, 18px)) scale(var(--readdy-anim-pop-scale-start, 0.88));
|
|
5
|
+
}
|
|
6
|
+
100% {
|
|
7
|
+
opacity: 1;
|
|
8
|
+
transform: translateY(0) scale(1);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.readdy-anim-pop-in-stack {
|
|
13
|
+
position: relative;
|
|
14
|
+
animation: readdy-anim-stack-pop var(--readdy-anim-pop-duration, 600ms) cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
15
|
+
animation-delay: var(--readdy-anim-pop-delay, 0ms);
|
|
16
|
+
will-change: transform, opacity;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@media (prefers-reduced-motion: reduce) {
|
|
20
|
+
.readdy-anim-pop-in-stack {
|
|
21
|
+
animation: none;
|
|
22
|
+
opacity: 1;
|
|
23
|
+
transform: none;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
2
|
+
export const ANIMATION_ID = buildAnimId('reveal-from-top')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reveal From Top — 卡片从顶部揭示
|
|
6
|
+
* 实现:CSS-only,init 给元素加 .readdy-anim-reveal-from-top class,destroy 移除
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import './style.css'
|
|
10
|
+
|
|
11
|
+
const CSS_CLASS = buildAnimClass('reveal-from-top')
|
|
12
|
+
|
|
13
|
+
export function init(el, options = {}) {
|
|
14
|
+
if (!el.classList.contains(CSS_CLASS)) {
|
|
15
|
+
el.classList.add(CSS_CLASS)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function destroy(el) {
|
|
20
|
+
el.classList.remove(CSS_CLASS)
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { useRef, useEffect } from 'react'
|
|
2
|
+
import { init, destroy } from './index.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reveal From Top — 卡片从顶部揭示
|
|
6
|
+
*
|
|
7
|
+
* 用法:
|
|
8
|
+
* <AnimRevealFromTop><div className="card">内容</div></AnimRevealFromTop>
|
|
9
|
+
*
|
|
10
|
+
* 不加 wrapper div — 通过 cloneElement 给子元素注入 ref,加/删 .readdy-anim-reveal-from-top class
|
|
11
|
+
* 必须恰好包裹一个子元素
|
|
12
|
+
*/
|
|
13
|
+
export function AnimRevealFromTop({ children }: { children: React.ReactElement }) {
|
|
14
|
+
const ref = useRef<HTMLElement>(null)
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const el = ref.current
|
|
18
|
+
if (!el) return
|
|
19
|
+
init(el)
|
|
20
|
+
return () => {
|
|
21
|
+
destroy(el)
|
|
22
|
+
}
|
|
23
|
+
}, [])
|
|
24
|
+
|
|
25
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* Reveal From Top — 卡片从顶部揭示 */
|
|
2
|
+
|
|
3
|
+
@keyframes readdy-anim-reveal-from-top {
|
|
4
|
+
from {
|
|
5
|
+
opacity: 0;
|
|
6
|
+
transform: translateY(-28px);
|
|
7
|
+
clip-path: inset(0 0 100% 0 round 20px);
|
|
8
|
+
}
|
|
9
|
+
to {
|
|
10
|
+
opacity: 1;
|
|
11
|
+
transform: translateY(0);
|
|
12
|
+
clip-path: inset(0 0 0 0 round 20px);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.readdy-anim-reveal-from-top {
|
|
17
|
+
animation: readdy-anim-reveal-from-top 0.75s cubic-bezier(0.22, 1, 0.36, 1) forwards;
|
|
18
|
+
will-change: opacity, transform, clip-path;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@media (prefers-reduced-motion: reduce) {
|
|
22
|
+
.readdy-anim-reveal-from-top {
|
|
23
|
+
animation: none;
|
|
24
|
+
opacity: 1;
|
|
25
|
+
transform: none;
|
|
26
|
+
clip-path: inset(0 0 0 0 round 20px);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
2
|
+
export const ANIMATION_ID = buildAnimId('rgb-split-glitch')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* RGB Split Glitch — 卡片 RGB 色散故障效果
|
|
6
|
+
* 实现:CSS-only,init 给元素加 .readdy-anim-rgb-split-glitch class,destroy 移除
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import './style.css'
|
|
10
|
+
|
|
11
|
+
const CSS_CLASS = buildAnimClass('rgb-split-glitch')
|
|
12
|
+
|
|
13
|
+
export function init(el, options = {}) {
|
|
14
|
+
if (!el.classList.contains(CSS_CLASS)) {
|
|
15
|
+
el.classList.add(CSS_CLASS)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
el.style.setProperty('--readdy-anim-rgb-glitch-duration', `${options.duration ?? 1100}ms`)
|
|
19
|
+
el.style.setProperty('--readdy-anim-rgb-glitch-shift', `${options.shift ?? 3}px`)
|
|
20
|
+
el.style.setProperty('--readdy-anim-rgb-glitch-shadow', `${options.shadowOffset ?? 2}px`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function destroy(el) {
|
|
24
|
+
el.classList.remove(CSS_CLASS)
|
|
25
|
+
el.style.removeProperty('--readdy-anim-rgb-glitch-duration')
|
|
26
|
+
el.style.removeProperty('--readdy-anim-rgb-glitch-shift')
|
|
27
|
+
el.style.removeProperty('--readdy-anim-rgb-glitch-shadow')
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { useRef, useEffect } from 'react'
|
|
2
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
3
|
+
import { init, destroy } from './index.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* RGB Split Glitch — 卡片 RGB 色散故障效果
|
|
7
|
+
*
|
|
8
|
+
* 用法:
|
|
9
|
+
* <AnimRgbSplitGlitch><div className="card">内容</div></AnimRgbSplitGlitch>
|
|
10
|
+
*
|
|
11
|
+
* 不加 wrapper div — 通过 cloneElement 给子元素注入 ref,加/删 .readdy-anim-rgb-split-glitch class
|
|
12
|
+
* 必须恰好包裹一个子元素
|
|
13
|
+
*/
|
|
14
|
+
type AnimRgbSplitGlitchProps = {
|
|
15
|
+
children: React.ReactElement
|
|
16
|
+
duration?: number
|
|
17
|
+
shift?: number
|
|
18
|
+
shadowOffset?: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function AnimRgbSplitGlitch({
|
|
22
|
+
children,
|
|
23
|
+
duration,
|
|
24
|
+
shift,
|
|
25
|
+
shadowOffset,
|
|
26
|
+
}: AnimRgbSplitGlitchProps) {
|
|
27
|
+
const ref = useRef<HTMLElement>(null)
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const el = ref.current
|
|
31
|
+
if (!el) return
|
|
32
|
+
if (prefersReducedMotion()) return
|
|
33
|
+
|
|
34
|
+
init(el, { duration, shift, shadowOffset })
|
|
35
|
+
return () => {
|
|
36
|
+
destroy(el)
|
|
37
|
+
}
|
|
38
|
+
}, [duration, shift, shadowOffset])
|
|
39
|
+
|
|
40
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
41
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* RGB Split Glitch — 卡片 RGB 色散故障效果 */
|
|
2
|
+
|
|
3
|
+
@keyframes readdy-anim-rgb-glitch {
|
|
4
|
+
0%, 100% { transform: translate(0); filter: none; }
|
|
5
|
+
20% {
|
|
6
|
+
transform: translate(calc(var(--readdy-anim-rgb-glitch-shift, 3px) * -1), calc(var(--readdy-anim-rgb-glitch-shift, 3px) * 0.3333));
|
|
7
|
+
filter:
|
|
8
|
+
drop-shadow(var(--readdy-anim-rgb-glitch-shadow, 2px) 0 red)
|
|
9
|
+
drop-shadow(calc(var(--readdy-anim-rgb-glitch-shadow, 2px) * -1) 0 cyan);
|
|
10
|
+
}
|
|
11
|
+
40% {
|
|
12
|
+
transform: translate(var(--readdy-anim-rgb-glitch-shift, 3px), calc(var(--readdy-anim-rgb-glitch-shift, 3px) * -0.3333));
|
|
13
|
+
filter:
|
|
14
|
+
drop-shadow(calc(var(--readdy-anim-rgb-glitch-shadow, 2px) * -1) 0 blue)
|
|
15
|
+
drop-shadow(var(--readdy-anim-rgb-glitch-shadow, 2px) 0 lime);
|
|
16
|
+
}
|
|
17
|
+
60% {
|
|
18
|
+
transform: translate(calc(var(--readdy-anim-rgb-glitch-shift, 3px) * -0.6667), calc(var(--readdy-anim-rgb-glitch-shift, 3px) * 0.6667));
|
|
19
|
+
filter:
|
|
20
|
+
drop-shadow(var(--readdy-anim-rgb-glitch-shadow, 2px) 0 red)
|
|
21
|
+
drop-shadow(calc(var(--readdy-anim-rgb-glitch-shadow, 2px) * -1) 0 cyan);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.readdy-anim-rgb-split-glitch {
|
|
26
|
+
animation: readdy-anim-rgb-glitch var(--readdy-anim-rgb-glitch-duration, 1100ms) steps(2) infinite;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@media (prefers-reduced-motion: reduce) {
|
|
30
|
+
.readdy-anim-rgb-split-glitch {
|
|
31
|
+
animation: none;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import './style.css'
|
|
2
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
3
|
+
import { attachPointerFollow, getPointerMetrics } from '../../../shared/pointer-follow.js'
|
|
4
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
5
|
+
|
|
6
|
+
export const ANIMATION_ID = buildAnimId('tilted-card')
|
|
7
|
+
|
|
8
|
+
const CSS_CLASS = buildAnimClass('tilted-card')
|
|
9
|
+
const stateMap = new WeakMap()
|
|
10
|
+
|
|
11
|
+
function reset(el) {
|
|
12
|
+
el.style.setProperty('--readdy-anim-card-tilt-x', '0deg')
|
|
13
|
+
el.style.setProperty('--readdy-anim-card-tilt-y', '0deg')
|
|
14
|
+
el.style.setProperty('--readdy-anim-card-scale', '1')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function init(el, options = {}) {
|
|
18
|
+
destroy(el)
|
|
19
|
+
|
|
20
|
+
el.classList.add(CSS_CLASS)
|
|
21
|
+
reset(el)
|
|
22
|
+
|
|
23
|
+
const perspective = options.perspective ?? 900
|
|
24
|
+
const duration = options.duration ?? 550
|
|
25
|
+
el.style.setProperty('--readdy-anim-card-tilt-perspective', `${perspective}px`)
|
|
26
|
+
el.style.setProperty('--readdy-anim-card-tilt-duration', `${duration}ms`)
|
|
27
|
+
|
|
28
|
+
if (prefersReducedMotion()) {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const maxTilt = options.maxTilt ?? 10
|
|
33
|
+
const scale = options.scale ?? 1.02
|
|
34
|
+
|
|
35
|
+
const onMove = (event, context) => {
|
|
36
|
+
const { relativeX, relativeY } = getPointerMetrics(context.rect, event)
|
|
37
|
+
|
|
38
|
+
el.style.setProperty('--readdy-anim-card-tilt-x', `${relativeY * -maxTilt * 2}deg`)
|
|
39
|
+
el.style.setProperty('--readdy-anim-card-tilt-y', `${relativeX * maxTilt * 2}deg`)
|
|
40
|
+
el.style.setProperty('--readdy-anim-card-scale', `${scale}`)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const onLeave = () => {
|
|
44
|
+
reset(el)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const cleanup = attachPointerFollow(el, { onMove, onLeave })
|
|
48
|
+
stateMap.set(el, { cleanup })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function destroy(el) {
|
|
52
|
+
const state = stateMap.get(el)
|
|
53
|
+
if (state) {
|
|
54
|
+
state.cleanup()
|
|
55
|
+
stateMap.delete(el)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
el.classList.remove(CSS_CLASS)
|
|
59
|
+
el.style.removeProperty('--readdy-anim-card-tilt-x')
|
|
60
|
+
el.style.removeProperty('--readdy-anim-card-tilt-y')
|
|
61
|
+
el.style.removeProperty('--readdy-anim-card-scale')
|
|
62
|
+
el.style.removeProperty('--readdy-anim-card-tilt-perspective')
|
|
63
|
+
el.style.removeProperty('--readdy-anim-card-tilt-duration')
|
|
64
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react'
|
|
2
|
+
import { init, destroy } from './index.js'
|
|
3
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
4
|
+
|
|
5
|
+
type AnimTiltedCardProps = {
|
|
6
|
+
children: React.ReactElement
|
|
7
|
+
maxTilt?: number
|
|
8
|
+
scale?: number
|
|
9
|
+
perspective?: number
|
|
10
|
+
duration?: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function AnimTiltedCard({
|
|
14
|
+
children,
|
|
15
|
+
maxTilt,
|
|
16
|
+
scale,
|
|
17
|
+
perspective,
|
|
18
|
+
duration,
|
|
19
|
+
}: AnimTiltedCardProps) {
|
|
20
|
+
const ref = useRef<HTMLElement>(null)
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const el = ref.current
|
|
24
|
+
if (!el || prefersReducedMotion()) return
|
|
25
|
+
|
|
26
|
+
init(el, { maxTilt, scale, perspective, duration })
|
|
27
|
+
return () => {
|
|
28
|
+
destroy(el)
|
|
29
|
+
}
|
|
30
|
+
}, [maxTilt, scale, perspective, duration])
|
|
31
|
+
|
|
32
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
.readdy-anim-tilted-card {
|
|
2
|
+
transform:
|
|
3
|
+
perspective(var(--readdy-anim-card-tilt-perspective, 900px))
|
|
4
|
+
rotateX(var(--readdy-anim-card-tilt-x, 0deg))
|
|
5
|
+
rotateY(var(--readdy-anim-card-tilt-y, 0deg))
|
|
6
|
+
scale(var(--readdy-anim-card-scale, 1));
|
|
7
|
+
transform-style: preserve-3d;
|
|
8
|
+
transition:
|
|
9
|
+
transform var(--readdy-anim-card-tilt-duration, 550ms) cubic-bezier(0.22, 1, 0.36, 1),
|
|
10
|
+
box-shadow var(--readdy-anim-card-tilt-duration, 550ms) ease;
|
|
11
|
+
will-change: transform;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.readdy-anim-tilted-card:hover {
|
|
15
|
+
box-shadow: 0 20px 40px rgba(15, 23, 42, 0.18);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@media (prefers-reduced-motion: reduce) {
|
|
19
|
+
.readdy-anim-tilted-card {
|
|
20
|
+
transform: none;
|
|
21
|
+
transition: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.readdy-anim-tilted-card:hover {
|
|
25
|
+
box-shadow: none;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import './style.css'
|
|
2
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
3
|
+
|
|
4
|
+
export const ANIMATION_ID = buildAnimId('anime-splittext')
|
|
5
|
+
|
|
6
|
+
const CSS_CLASS = buildAnimClass('anime-splittext')
|
|
7
|
+
const WORD_CLASS = buildAnimClass('anime-word')
|
|
8
|
+
const WORD_INNER_CLASS = buildAnimClass('anime-word-inner')
|
|
9
|
+
const CHAR_CLASS = buildAnimClass('anime-char')
|
|
10
|
+
|
|
11
|
+
function splitAnimatedUnits(text) {
|
|
12
|
+
if (/\s/.test(text)) {
|
|
13
|
+
return text.split(/(\s+)/).filter(Boolean)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return Array.from(text)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function buildWordFragment(word, wordIndex, stagger, duration) {
|
|
20
|
+
const outer = document.createElement('span')
|
|
21
|
+
outer.className = WORD_CLASS
|
|
22
|
+
outer.style.setProperty('--readdy-anim-word-offset', wordIndex % 2 === 0 ? '110%' : '-110%')
|
|
23
|
+
|
|
24
|
+
const inner = document.createElement('span')
|
|
25
|
+
inner.className = WORD_INNER_CLASS
|
|
26
|
+
inner.style.setProperty('--readdy-anim-word-delay', `${wordIndex * stagger}ms`)
|
|
27
|
+
inner.style.setProperty('--readdy-anim-word-loop-delay', `${duration + 20 + wordIndex * stagger}ms`)
|
|
28
|
+
|
|
29
|
+
;[...word].forEach((char, charIndex) => {
|
|
30
|
+
const charSpan = document.createElement('span')
|
|
31
|
+
charSpan.className = CHAR_CLASS
|
|
32
|
+
charSpan.textContent = char
|
|
33
|
+
charSpan.style.setProperty(
|
|
34
|
+
'--readdy-anim-char-delay',
|
|
35
|
+
`${Math.round(duration * 0.6) + wordIndex * stagger + charIndex * 36}ms`
|
|
36
|
+
)
|
|
37
|
+
inner.appendChild(charSpan)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
outer.appendChild(inner)
|
|
41
|
+
return outer
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function wrapWordsInTextNode(textNode, getWordIndex, stagger, duration) {
|
|
45
|
+
const text = textNode.textContent ?? ''
|
|
46
|
+
if (!text.trim()) {
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const parts = splitAnimatedUnits(text)
|
|
51
|
+
const fragment = document.createDocumentFragment()
|
|
52
|
+
|
|
53
|
+
for (const part of parts) {
|
|
54
|
+
if (!part) continue
|
|
55
|
+
|
|
56
|
+
if (/^\s+$/.test(part)) {
|
|
57
|
+
fragment.appendChild(document.createTextNode(part))
|
|
58
|
+
continue
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
fragment.appendChild(buildWordFragment(part, getWordIndex(), stagger, duration))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
textNode.parentNode?.replaceChild(fragment, textNode)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function splitWords(el, options = {}) {
|
|
68
|
+
if (!el.dataset.originalText) {
|
|
69
|
+
el.dataset.originalText = el.innerHTML
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const stagger = options.stagger ?? 120
|
|
73
|
+
const duration = options.duration ?? 700
|
|
74
|
+
|
|
75
|
+
let wordIndex = 0
|
|
76
|
+
const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT)
|
|
77
|
+
const textNodes = []
|
|
78
|
+
let node = walker.nextNode()
|
|
79
|
+
|
|
80
|
+
while (node) {
|
|
81
|
+
textNodes.push(node)
|
|
82
|
+
node = walker.nextNode()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (const textNode of textNodes) {
|
|
86
|
+
wrapWordsInTextNode(textNode, () => wordIndex++, stagger, duration)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function init(el, options = {}) {
|
|
91
|
+
destroy(el)
|
|
92
|
+
|
|
93
|
+
if (!el.classList.contains(CSS_CLASS)) {
|
|
94
|
+
el.classList.add(CSS_CLASS)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
el.style.setProperty('--readdy-anim-anime-word-duration', `${options.duration ?? 700}ms`)
|
|
98
|
+
splitWords(el, options)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function destroy(el) {
|
|
102
|
+
el.classList.remove(CSS_CLASS)
|
|
103
|
+
el.style.removeProperty('--readdy-anim-anime-word-duration')
|
|
104
|
+
if (el.dataset.originalText) {
|
|
105
|
+
el.innerHTML = el.dataset.originalText
|
|
106
|
+
delete el.dataset.originalText
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { useRef, useEffect } from 'react'
|
|
2
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
3
|
+
import { init, destroy } from './index.js'
|
|
4
|
+
|
|
5
|
+
type AnimAnimeSplittextProps = {
|
|
6
|
+
children: React.ReactElement
|
|
7
|
+
stagger?: number
|
|
8
|
+
duration?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function AnimAnimeSplittext({
|
|
12
|
+
children,
|
|
13
|
+
stagger,
|
|
14
|
+
duration,
|
|
15
|
+
}: AnimAnimeSplittextProps) {
|
|
16
|
+
const ref = useRef<HTMLElement>(null)
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const el = ref.current
|
|
20
|
+
if (!el) return
|
|
21
|
+
if (prefersReducedMotion()) return
|
|
22
|
+
|
|
23
|
+
init(el, { stagger, duration })
|
|
24
|
+
return () => {
|
|
25
|
+
destroy(el)
|
|
26
|
+
}
|
|
27
|
+
}, [duration, stagger])
|
|
28
|
+
|
|
29
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
30
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
@keyframes readdy-anim-anime-word-in {
|
|
2
|
+
from {
|
|
3
|
+
opacity: 0;
|
|
4
|
+
transform: translateY(var(--readdy-anim-word-offset, 110%));
|
|
5
|
+
}
|
|
6
|
+
to {
|
|
7
|
+
opacity: 1;
|
|
8
|
+
transform: translateY(0);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@keyframes readdy-anim-anime-word-loop {
|
|
13
|
+
0%,
|
|
14
|
+
100% {
|
|
15
|
+
transform: translateY(0);
|
|
16
|
+
}
|
|
17
|
+
25% {
|
|
18
|
+
transform: translateY(calc(var(--readdy-anim-word-offset, 110%) * 0.12));
|
|
19
|
+
}
|
|
20
|
+
50% {
|
|
21
|
+
transform: translateY(calc(var(--readdy-anim-word-offset, 110%) * -0.08));
|
|
22
|
+
}
|
|
23
|
+
75% {
|
|
24
|
+
transform: translateY(calc(var(--readdy-anim-word-offset, 110%) * 0.06));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@keyframes readdy-anim-anime-char-wiggle {
|
|
29
|
+
0%,
|
|
30
|
+
100% {
|
|
31
|
+
transform: translateY(0);
|
|
32
|
+
}
|
|
33
|
+
35% {
|
|
34
|
+
transform: translateY(-0.12em);
|
|
35
|
+
}
|
|
36
|
+
65% {
|
|
37
|
+
transform: translateY(0.05em);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.readdy-anim-anime-splittext {
|
|
42
|
+
white-space: normal;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.readdy-anim-anime-splittext .readdy-anim-anime-word {
|
|
46
|
+
display: inline-block;
|
|
47
|
+
overflow: hidden;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.readdy-anim-anime-splittext .readdy-anim-anime-word-inner {
|
|
51
|
+
display: inline-block;
|
|
52
|
+
opacity: 0;
|
|
53
|
+
animation:
|
|
54
|
+
readdy-anim-anime-word-in var(--readdy-anim-anime-word-duration, 700ms) cubic-bezier(0.16, 1, 0.3, 1) forwards,
|
|
55
|
+
readdy-anim-anime-word-loop 3.6s ease-in-out infinite;
|
|
56
|
+
animation-delay: var(--readdy-anim-word-delay, 0ms), var(--readdy-anim-word-loop-delay, 720ms);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.readdy-anim-anime-splittext .readdy-anim-anime-char {
|
|
60
|
+
display: inline-block;
|
|
61
|
+
animation: readdy-anim-anime-char-wiggle 1.25s ease-in-out infinite;
|
|
62
|
+
animation-delay: var(--readdy-anim-char-delay, 420ms);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@media (prefers-reduced-motion: reduce) {
|
|
66
|
+
.readdy-anim-anime-splittext .readdy-anim-anime-word-inner,
|
|
67
|
+
.readdy-anim-anime-splittext .readdy-anim-anime-char {
|
|
68
|
+
animation: none;
|
|
69
|
+
opacity: 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
2
|
+
export const ANIMATION_ID = buildAnimId('bounce-in-down')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Bounce In Down — 从上方弹入
|
|
6
|
+
* 实现:按字符拆分并错峰 bounceInDown
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import './style.css'
|
|
10
|
+
import { splitTextIntoChars } from '../../../shared/text-split.js'
|
|
11
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
12
|
+
|
|
13
|
+
const CSS_CLASS = buildAnimClass('bounce-in-down')
|
|
14
|
+
const CHAR_CLASS = buildAnimClass('bounce-in-down-char')
|
|
15
|
+
|
|
16
|
+
export function init(el, options = {}) {
|
|
17
|
+
if (el.classList.contains(CSS_CLASS)) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
el.classList.add(CSS_CLASS)
|
|
22
|
+
|
|
23
|
+
if (prefersReducedMotion()) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
splitTextIntoChars(el, {
|
|
28
|
+
stagger: options.stagger ?? 40,
|
|
29
|
+
charClass: CHAR_CLASS,
|
|
30
|
+
maxChars: options.maxChars ?? 160,
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function destroy(el) {
|
|
35
|
+
el.classList.remove(CSS_CLASS)
|
|
36
|
+
if (el.dataset.originalText) {
|
|
37
|
+
el.innerHTML = el.dataset.originalText
|
|
38
|
+
delete el.dataset.originalText
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { useRef, useEffect } from 'react'
|
|
2
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
3
|
+
import { init, destroy } from './index.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Bounce In Down — 从上方弹入
|
|
7
|
+
*
|
|
8
|
+
* 用法:
|
|
9
|
+
* <AnimBounceInDown><p>标题文字</p></AnimBounceInDown>
|
|
10
|
+
*
|
|
11
|
+
* 不加 wrapper div — 通过 cloneElement 给子元素注入 ref,加/删 .readdy-anim-bounce-in-down class
|
|
12
|
+
* 必须恰好包裹一个子元素
|
|
13
|
+
*/
|
|
14
|
+
export function AnimBounceInDown({ children }: { children: React.ReactElement }) {
|
|
15
|
+
const ref = useRef<HTMLElement>(null)
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const el = ref.current
|
|
19
|
+
if (!el) return
|
|
20
|
+
if (prefersReducedMotion()) return
|
|
21
|
+
|
|
22
|
+
init(el)
|
|
23
|
+
return () => {
|
|
24
|
+
destroy(el)
|
|
25
|
+
}
|
|
26
|
+
}, [])
|
|
27
|
+
|
|
28
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
29
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* Bounce In Down — 从上方弹入 */
|
|
2
|
+
|
|
3
|
+
@keyframes readdy-anim-bounce-in-down-char {
|
|
4
|
+
0% {
|
|
5
|
+
opacity: 0;
|
|
6
|
+
transform: translateY(-1.4em);
|
|
7
|
+
}
|
|
8
|
+
60% {
|
|
9
|
+
opacity: 1;
|
|
10
|
+
transform: translateY(0.16em);
|
|
11
|
+
}
|
|
12
|
+
75% {
|
|
13
|
+
transform: translateY(-0.08em);
|
|
14
|
+
}
|
|
15
|
+
90% {
|
|
16
|
+
transform: translateY(0.04em);
|
|
17
|
+
}
|
|
18
|
+
100% {
|
|
19
|
+
opacity: 1;
|
|
20
|
+
transform: translateY(0);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.readdy-anim-bounce-in-down {
|
|
25
|
+
white-space: normal;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.readdy-anim-bounce-in-down .readdy-anim-bounce-in-down-char {
|
|
29
|
+
display: inline-block;
|
|
30
|
+
opacity: 0;
|
|
31
|
+
animation: readdy-anim-bounce-in-down-char 0.9s cubic-bezier(0.215, 0.61, 0.355, 1) forwards;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@media (prefers-reduced-motion: reduce) {
|
|
35
|
+
.readdy-anim-bounce-in-down .readdy-anim-bounce-in-down-char {
|
|
36
|
+
opacity: 1;
|
|
37
|
+
transform: none;
|
|
38
|
+
animation: none;
|
|
39
|
+
}
|
|
40
|
+
}
|