@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,46 @@
|
|
|
1
|
+
import './style.css'
|
|
2
|
+
import { splitTextIntoChars } from '../../../shared/text-split.js'
|
|
3
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
4
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
5
|
+
|
|
6
|
+
export const ANIMATION_ID = buildAnimId('fly-in-chars')
|
|
7
|
+
|
|
8
|
+
const CSS_CLASS = buildAnimClass('fly-in-chars')
|
|
9
|
+
const CHAR_CLASS = buildAnimClass('fly-in-char')
|
|
10
|
+
|
|
11
|
+
function randomBetween(min, max) {
|
|
12
|
+
return Math.round(min + Math.random() * (max - min))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function init(el, options = {}) {
|
|
16
|
+
if (el.classList.contains(CSS_CLASS)) {
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
el.classList.add(CSS_CLASS)
|
|
21
|
+
|
|
22
|
+
if (prefersReducedMotion()) {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
splitTextIntoChars(el, {
|
|
27
|
+
stagger: options.stagger ?? 36,
|
|
28
|
+
charClass: CHAR_CLASS,
|
|
29
|
+
maxChars: options.maxChars ?? 160,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const chars = el.querySelectorAll(`.${CHAR_CLASS}`)
|
|
33
|
+
for (const char of chars) {
|
|
34
|
+
char.style.setProperty('--readdy-anim-fly-in-x', `${randomBetween(-120, 120)}px`)
|
|
35
|
+
char.style.setProperty('--readdy-anim-fly-in-y', `${randomBetween(-80, 80)}px`)
|
|
36
|
+
char.style.setProperty('--readdy-anim-fly-in-rotate', `${randomBetween(-25, 25)}deg`)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function destroy(el) {
|
|
41
|
+
el.classList.remove(CSS_CLASS)
|
|
42
|
+
if (el.dataset.originalText) {
|
|
43
|
+
el.innerHTML = el.dataset.originalText
|
|
44
|
+
delete el.dataset.originalText
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -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 AnimFlyInCharsProps = {
|
|
6
|
+
children: React.ReactElement
|
|
7
|
+
stagger?: number
|
|
8
|
+
maxChars?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function AnimFlyInChars({
|
|
12
|
+
children,
|
|
13
|
+
stagger,
|
|
14
|
+
maxChars,
|
|
15
|
+
}: AnimFlyInCharsProps) {
|
|
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, maxChars })
|
|
24
|
+
return () => {
|
|
25
|
+
destroy(el)
|
|
26
|
+
}
|
|
27
|
+
}, [maxChars, stagger])
|
|
28
|
+
|
|
29
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@keyframes readdy-anim-fly-in-char {
|
|
2
|
+
from {
|
|
3
|
+
opacity: 0;
|
|
4
|
+
transform: translate(var(--readdy-anim-fly-in-x, 0), var(--readdy-anim-fly-in-y, 8px))
|
|
5
|
+
rotate(var(--readdy-anim-fly-in-rotate, 0deg));
|
|
6
|
+
}
|
|
7
|
+
to {
|
|
8
|
+
opacity: 1;
|
|
9
|
+
transform: translate(0, 0) rotate(0deg);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.readdy-anim-fly-in-chars {
|
|
14
|
+
white-space: normal;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.readdy-anim-fly-in-chars .readdy-anim-fly-in-char {
|
|
18
|
+
display: inline-block;
|
|
19
|
+
opacity: 0;
|
|
20
|
+
animation: readdy-anim-fly-in-char 0.85s cubic-bezier(0.22, 1, 0.36, 1) forwards;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@media (prefers-reduced-motion: reduce) {
|
|
24
|
+
.readdy-anim-fly-in-chars .readdy-anim-fly-in-char {
|
|
25
|
+
opacity: 1;
|
|
26
|
+
transform: none;
|
|
27
|
+
animation: none;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
2
|
+
export const ANIMATION_ID = buildAnimId('gradient-text')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gradient Text — 渐变文字
|
|
6
|
+
* 实现:CSS-only,init 给元素加 .readdy-anim-gradient-text class,destroy 移除
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import './style.css'
|
|
10
|
+
|
|
11
|
+
const CSS_CLASS = buildAnimClass('gradient-text')
|
|
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
|
+
* Gradient Text — 渐变文字
|
|
6
|
+
*
|
|
7
|
+
* 用法:
|
|
8
|
+
* <AnimGradientText><p>标题文字</p></AnimGradientText>
|
|
9
|
+
*
|
|
10
|
+
* 不加 wrapper div — 通过 cloneElement 给子元素注入 ref,加/删 .readdy-anim-gradient-text class
|
|
11
|
+
* 必须恰好包裹一个子元素
|
|
12
|
+
*/
|
|
13
|
+
export function AnimGradientText({ 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
|
+
/* Gradient Text — 渐变文字 */
|
|
2
|
+
|
|
3
|
+
@keyframes readdy-anim-gradient-flow {
|
|
4
|
+
from {
|
|
5
|
+
background-position: 0% center;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
to {
|
|
9
|
+
background-position: 100% center;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.readdy-anim-gradient-text {
|
|
14
|
+
background: linear-gradient(90deg, #22d3ee 0%, #a78bfa 35%, #f472b6 50%, #a78bfa 65%, #22d3ee 100%);
|
|
15
|
+
background-size: 200% 100%;
|
|
16
|
+
-webkit-background-clip: text;
|
|
17
|
+
background-clip: text;
|
|
18
|
+
-webkit-text-fill-color: transparent;
|
|
19
|
+
color: transparent;
|
|
20
|
+
animation: readdy-anim-gradient-flow 3s ease-in-out infinite alternate;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@media (prefers-reduced-motion: reduce) {
|
|
24
|
+
.readdy-anim-gradient-text {
|
|
25
|
+
animation: none;
|
|
26
|
+
background-position: 0 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import './style.css'
|
|
2
|
+
import { splitTextIntoChars } from '../../../shared/text-split.js'
|
|
3
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
4
|
+
|
|
5
|
+
export const ANIMATION_ID = buildAnimId('letter-bounce')
|
|
6
|
+
|
|
7
|
+
const CSS_CLASS = buildAnimClass('letter-bounce')
|
|
8
|
+
const CHAR_CLASS = buildAnimClass('letter-bounce-char')
|
|
9
|
+
|
|
10
|
+
export function init(el, options = {}) {
|
|
11
|
+
if (!el.classList.contains(CSS_CLASS)) {
|
|
12
|
+
el.classList.add(CSS_CLASS)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
el.style.setProperty('--readdy-anim-letter-bounce-duration', `${options.duration ?? 850}ms`)
|
|
16
|
+
el.style.setProperty('--readdy-anim-letter-bounce-amplitude', `${options.amplitude ?? 6}px`)
|
|
17
|
+
|
|
18
|
+
splitTextIntoChars(el, {
|
|
19
|
+
stagger: options.stagger ?? 60,
|
|
20
|
+
charClass: CHAR_CLASS,
|
|
21
|
+
maxChars: options.maxChars ?? 160,
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function destroy(el) {
|
|
26
|
+
el.classList.remove(CSS_CLASS)
|
|
27
|
+
el.style.removeProperty('--readdy-anim-letter-bounce-duration')
|
|
28
|
+
el.style.removeProperty('--readdy-anim-letter-bounce-amplitude')
|
|
29
|
+
if (el.dataset.originalText) {
|
|
30
|
+
el.innerHTML = el.dataset.originalText
|
|
31
|
+
delete el.dataset.originalText
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 AnimLetterBounceProps = {
|
|
6
|
+
children: React.ReactElement
|
|
7
|
+
stagger?: number
|
|
8
|
+
maxChars?: number
|
|
9
|
+
duration?: number
|
|
10
|
+
amplitude?: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function AnimLetterBounce({
|
|
14
|
+
children,
|
|
15
|
+
stagger,
|
|
16
|
+
maxChars,
|
|
17
|
+
duration,
|
|
18
|
+
amplitude,
|
|
19
|
+
}: AnimLetterBounceProps) {
|
|
20
|
+
const ref = useRef<HTMLElement>(null)
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const el = ref.current
|
|
24
|
+
if (!el) return
|
|
25
|
+
if (prefersReducedMotion()) return
|
|
26
|
+
|
|
27
|
+
init(el, { stagger, maxChars, duration, amplitude })
|
|
28
|
+
return () => {
|
|
29
|
+
destroy(el)
|
|
30
|
+
}
|
|
31
|
+
}, [amplitude, duration, maxChars, stagger])
|
|
32
|
+
|
|
33
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
@keyframes readdy-anim-letter-wave {
|
|
2
|
+
0%,
|
|
3
|
+
100% {
|
|
4
|
+
transform: translateY(0);
|
|
5
|
+
}
|
|
6
|
+
50% {
|
|
7
|
+
transform: translateY(calc(var(--readdy-anim-letter-bounce-amplitude, 6px) * -1));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.readdy-anim-letter-bounce {
|
|
12
|
+
white-space: normal;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.readdy-anim-letter-bounce .readdy-anim-letter-bounce-char {
|
|
16
|
+
display: inline-block;
|
|
17
|
+
animation: readdy-anim-letter-wave var(--readdy-anim-letter-bounce-duration, 850ms) ease-in-out infinite;
|
|
18
|
+
will-change: transform;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@media (prefers-reduced-motion: reduce) {
|
|
22
|
+
.readdy-anim-letter-bounce .readdy-anim-letter-bounce-char {
|
|
23
|
+
animation: none;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
2
|
+
export const ANIMATION_ID = buildAnimId('roll-in')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Roll In — 文字滚入
|
|
6
|
+
* 实现:按字符拆分并错峰 rollIn
|
|
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('roll-in')
|
|
14
|
+
const CHAR_CLASS = buildAnimClass('roll-in-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 ?? 45,
|
|
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
|
+
* Roll In — 文字滚入
|
|
7
|
+
*
|
|
8
|
+
* 用法:
|
|
9
|
+
* <AnimRollIn><p>标题文字</p></AnimRollIn>
|
|
10
|
+
*
|
|
11
|
+
* 不加 wrapper div — 通过 cloneElement 给子元素注入 ref,加/删 .readdy-anim-roll-in class
|
|
12
|
+
* 必须恰好包裹一个子元素
|
|
13
|
+
*/
|
|
14
|
+
export function AnimRollIn({ 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,31 @@
|
|
|
1
|
+
/* Roll In — 文字滚入 */
|
|
2
|
+
|
|
3
|
+
@keyframes readdy-anim-roll-in-char {
|
|
4
|
+
from {
|
|
5
|
+
opacity: 0;
|
|
6
|
+
transform: translateX(-1.1em) rotate(-110deg);
|
|
7
|
+
}
|
|
8
|
+
to {
|
|
9
|
+
opacity: 1;
|
|
10
|
+
transform: translateX(0) rotate(0deg);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.readdy-anim-roll-in {
|
|
15
|
+
white-space: normal;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.readdy-anim-roll-in .readdy-anim-roll-in-char {
|
|
19
|
+
display: inline-block;
|
|
20
|
+
opacity: 0;
|
|
21
|
+
transform-origin: 50% 60%;
|
|
22
|
+
animation: readdy-anim-roll-in-char 0.72s cubic-bezier(0.22, 1, 0.36, 1) forwards;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@media (prefers-reduced-motion: reduce) {
|
|
26
|
+
.readdy-anim-roll-in .readdy-anim-roll-in-char {
|
|
27
|
+
opacity: 1;
|
|
28
|
+
transform: none;
|
|
29
|
+
animation: none;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import './style.css'
|
|
2
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
3
|
+
|
|
4
|
+
export const ANIMATION_ID = buildAnimId('shimmer-text')
|
|
5
|
+
|
|
6
|
+
const CSS_CLASS = buildAnimClass('shimmer-text')
|
|
7
|
+
|
|
8
|
+
export function init(el) {
|
|
9
|
+
if (!el.classList.contains(CSS_CLASS)) {
|
|
10
|
+
el.classList.add(CSS_CLASS)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function destroy(el) {
|
|
15
|
+
el.classList.remove(CSS_CLASS)
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { useRef, useEffect } from 'react'
|
|
2
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
3
|
+
import { init, destroy } from './index.js'
|
|
4
|
+
import { buildAnimClass } from '../../../shared/constants.js'
|
|
5
|
+
|
|
6
|
+
const CSS_CLASS = buildAnimClass('shimmer-text')
|
|
7
|
+
|
|
8
|
+
export function AnimShimmerText({ children }: { children: React.ReactElement }) {
|
|
9
|
+
const ref = useRef<HTMLElement>(null)
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const el = ref.current
|
|
13
|
+
if (!el) return
|
|
14
|
+
if (prefersReducedMotion()) {
|
|
15
|
+
el.classList.add(CSS_CLASS)
|
|
16
|
+
return () => {
|
|
17
|
+
el.classList.remove(CSS_CLASS)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
init(el)
|
|
22
|
+
return () => {
|
|
23
|
+
destroy(el)
|
|
24
|
+
}
|
|
25
|
+
}, [])
|
|
26
|
+
|
|
27
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
28
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@keyframes readdy-anim-shimmer-text {
|
|
2
|
+
to {
|
|
3
|
+
background-position: 200% center;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.readdy-anim-shimmer-text {
|
|
8
|
+
background: linear-gradient(
|
|
9
|
+
90deg,
|
|
10
|
+
#334155 0%,
|
|
11
|
+
#64748b 34%,
|
|
12
|
+
#ffffff 50%,
|
|
13
|
+
#64748b 66%,
|
|
14
|
+
#334155 100%
|
|
15
|
+
);
|
|
16
|
+
background-size: 200% 100%;
|
|
17
|
+
background-position: 0% center;
|
|
18
|
+
-webkit-background-clip: text;
|
|
19
|
+
background-clip: text;
|
|
20
|
+
color: transparent;
|
|
21
|
+
-webkit-text-fill-color: transparent;
|
|
22
|
+
animation: readdy-anim-shimmer-text 2.2s linear infinite;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@media (prefers-reduced-motion: reduce) {
|
|
26
|
+
.readdy-anim-shimmer-text {
|
|
27
|
+
animation: none;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import './style.css'
|
|
2
|
+
import { splitTextIntoChars } from '../../../shared/text-split.js'
|
|
3
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
4
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
5
|
+
|
|
6
|
+
export const ANIMATION_ID = buildAnimId('shuffle')
|
|
7
|
+
|
|
8
|
+
const CSS_CLASS = buildAnimClass('shuffle')
|
|
9
|
+
const CHAR_CLASS = buildAnimClass('shuffle-char')
|
|
10
|
+
const GLYPHS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*+-?'
|
|
11
|
+
const stateMap = new WeakMap()
|
|
12
|
+
|
|
13
|
+
function randomGlyph() {
|
|
14
|
+
return GLYPHS[Math.floor(Math.random() * GLYPHS.length)]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function clearState(state) {
|
|
18
|
+
for (const intervalId of state.intervals) {
|
|
19
|
+
window.clearInterval(intervalId)
|
|
20
|
+
}
|
|
21
|
+
for (const timeoutId of state.timeouts) {
|
|
22
|
+
window.clearTimeout(timeoutId)
|
|
23
|
+
}
|
|
24
|
+
state.intervals = []
|
|
25
|
+
state.timeouts = []
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function runShuffle(el, options = {}) {
|
|
29
|
+
const state = stateMap.get(el)
|
|
30
|
+
if (!state) return
|
|
31
|
+
|
|
32
|
+
clearState(state)
|
|
33
|
+
|
|
34
|
+
const chars = [...el.querySelectorAll(`.${CHAR_CLASS}`)]
|
|
35
|
+
chars.forEach((char, index) => {
|
|
36
|
+
const finalChar = char.dataset.finalChar ?? char.textContent ?? ''
|
|
37
|
+
const startDelay = index * (options.stagger ?? 35)
|
|
38
|
+
const frames = options.shuffleFrames ?? 7
|
|
39
|
+
const frameDelay = options.frameDelay ?? 40
|
|
40
|
+
|
|
41
|
+
char.textContent = randomGlyph()
|
|
42
|
+
char.classList.remove('is-settled')
|
|
43
|
+
|
|
44
|
+
const timeoutId = window.setTimeout(() => {
|
|
45
|
+
let frame = 0
|
|
46
|
+
const intervalId = window.setInterval(() => {
|
|
47
|
+
frame += 1
|
|
48
|
+
char.textContent = frame >= frames ? finalChar : randomGlyph()
|
|
49
|
+
char.classList.toggle('is-settled', frame >= frames)
|
|
50
|
+
|
|
51
|
+
if (frame >= frames) {
|
|
52
|
+
window.clearInterval(intervalId)
|
|
53
|
+
}
|
|
54
|
+
}, frameDelay)
|
|
55
|
+
|
|
56
|
+
state.intervals.push(intervalId)
|
|
57
|
+
}, startDelay)
|
|
58
|
+
|
|
59
|
+
state.timeouts.push(timeoutId)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function init(el, options = {}) {
|
|
64
|
+
if (el.classList.contains(CSS_CLASS)) {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
el.classList.add(CSS_CLASS)
|
|
69
|
+
|
|
70
|
+
el.style.setProperty('--readdy-anim-shuffle-opacity', `${options.idleOpacity ?? 0.45}`)
|
|
71
|
+
el.style.setProperty('--readdy-anim-shuffle-translate-y', options.idleOffset ?? '0.08em')
|
|
72
|
+
el.style.setProperty('--readdy-anim-shuffle-scale', `${options.idleScale ?? 0.98}`)
|
|
73
|
+
el.style.setProperty('--readdy-anim-shuffle-settle-duration', `${options.settleDuration ?? 180}ms`)
|
|
74
|
+
|
|
75
|
+
splitTextIntoChars(el, {
|
|
76
|
+
stagger: options.stagger ?? 35,
|
|
77
|
+
charClass: CHAR_CLASS,
|
|
78
|
+
maxChars: options.maxChars ?? 120,
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const chars = el.querySelectorAll(`.${CHAR_CLASS}`)
|
|
82
|
+
chars.forEach((char) => {
|
|
83
|
+
char.dataset.finalChar = char.textContent ?? ''
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
if (prefersReducedMotion()) {
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const state = {
|
|
91
|
+
intervals: [],
|
|
92
|
+
timeouts: [],
|
|
93
|
+
onMouseEnter: () => runShuffle(el, options),
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
stateMap.set(el, state)
|
|
97
|
+
el.addEventListener('mouseenter', state.onMouseEnter)
|
|
98
|
+
runShuffle(el, options)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function destroy(el) {
|
|
102
|
+
const state = stateMap.get(el)
|
|
103
|
+
if (state) {
|
|
104
|
+
clearState(state)
|
|
105
|
+
el.removeEventListener('mouseenter', state.onMouseEnter)
|
|
106
|
+
stateMap.delete(el)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
el.classList.remove(CSS_CLASS)
|
|
110
|
+
el.style.removeProperty('--readdy-anim-shuffle-opacity')
|
|
111
|
+
el.style.removeProperty('--readdy-anim-shuffle-translate-y')
|
|
112
|
+
el.style.removeProperty('--readdy-anim-shuffle-scale')
|
|
113
|
+
el.style.removeProperty('--readdy-anim-shuffle-settle-duration')
|
|
114
|
+
if (el.dataset.originalText) {
|
|
115
|
+
el.innerHTML = el.dataset.originalText
|
|
116
|
+
delete el.dataset.originalText
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { useRef, useEffect } from 'react'
|
|
2
|
+
import { init, destroy } from './index.js'
|
|
3
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
4
|
+
|
|
5
|
+
type AnimShuffleProps = {
|
|
6
|
+
children: React.ReactElement
|
|
7
|
+
stagger?: number
|
|
8
|
+
shuffleFrames?: number
|
|
9
|
+
frameDelay?: number
|
|
10
|
+
maxChars?: number
|
|
11
|
+
idleOpacity?: number
|
|
12
|
+
idleOffset?: string
|
|
13
|
+
idleScale?: number
|
|
14
|
+
settleDuration?: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function AnimShuffle({
|
|
18
|
+
children,
|
|
19
|
+
stagger,
|
|
20
|
+
shuffleFrames,
|
|
21
|
+
frameDelay,
|
|
22
|
+
maxChars,
|
|
23
|
+
idleOpacity,
|
|
24
|
+
idleOffset,
|
|
25
|
+
idleScale,
|
|
26
|
+
settleDuration,
|
|
27
|
+
}: AnimShuffleProps) {
|
|
28
|
+
const ref = useRef<HTMLElement>(null)
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const el = ref.current
|
|
32
|
+
if (!el || prefersReducedMotion()) return
|
|
33
|
+
|
|
34
|
+
init(el, {
|
|
35
|
+
stagger,
|
|
36
|
+
shuffleFrames,
|
|
37
|
+
frameDelay,
|
|
38
|
+
maxChars,
|
|
39
|
+
idleOpacity,
|
|
40
|
+
idleOffset,
|
|
41
|
+
idleScale,
|
|
42
|
+
settleDuration,
|
|
43
|
+
})
|
|
44
|
+
return () => {
|
|
45
|
+
destroy(el)
|
|
46
|
+
}
|
|
47
|
+
}, [frameDelay, idleOffset, idleOpacity, idleScale, maxChars, settleDuration, shuffleFrames, stagger])
|
|
48
|
+
|
|
49
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
50
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.readdy-anim-shuffle {
|
|
2
|
+
white-space: normal;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.readdy-anim-shuffle .readdy-anim-shuffle-char {
|
|
6
|
+
display: inline-block;
|
|
7
|
+
min-width: 0.7ch;
|
|
8
|
+
opacity: var(--readdy-anim-shuffle-opacity, 0.45);
|
|
9
|
+
transform: translateY(var(--readdy-anim-shuffle-translate-y, 0.08em)) scale(var(--readdy-anim-shuffle-scale, 0.98));
|
|
10
|
+
transition:
|
|
11
|
+
opacity var(--readdy-anim-shuffle-settle-duration, 180ms) ease,
|
|
12
|
+
transform var(--readdy-anim-shuffle-settle-duration, 180ms) ease;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.readdy-anim-shuffle .readdy-anim-shuffle-char.is-settled {
|
|
16
|
+
opacity: 1;
|
|
17
|
+
transform: translateY(0) scale(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@media (prefers-reduced-motion: reduce) {
|
|
21
|
+
.readdy-anim-shuffle .readdy-anim-shuffle-char {
|
|
22
|
+
opacity: 1;
|
|
23
|
+
transform: none;
|
|
24
|
+
}
|
|
25
|
+
}
|