@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,71 @@
|
|
|
1
|
+
.readdy-anim-card-flip {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: block;
|
|
4
|
+
perspective: var(--readdy-anim-card-flip-perspective, 2000px);
|
|
5
|
+
transform-style: preserve-3d;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.readdy-anim-card-flip .readdy-anim-card-flip-scene {
|
|
9
|
+
position: relative;
|
|
10
|
+
width: 100%;
|
|
11
|
+
min-height: inherit;
|
|
12
|
+
height: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.readdy-anim-card-flip .readdy-anim-card-flip-inner {
|
|
16
|
+
position: relative;
|
|
17
|
+
width: 100%;
|
|
18
|
+
min-height: inherit;
|
|
19
|
+
height: 100%;
|
|
20
|
+
transform-style: preserve-3d;
|
|
21
|
+
transition: transform var(--readdy-anim-card-flip-duration, 500ms) cubic-bezier(0.77, 0, 0.175, 1);
|
|
22
|
+
will-change: transform;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.readdy-anim-card-flip:hover .readdy-anim-card-flip-inner,
|
|
26
|
+
.readdy-anim-card-flip:focus-within .readdy-anim-card-flip-inner {
|
|
27
|
+
transform: rotateY(180deg);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.readdy-anim-card-flip .readdy-anim-card-flip-face {
|
|
31
|
+
position: absolute;
|
|
32
|
+
inset: 0;
|
|
33
|
+
display: block;
|
|
34
|
+
box-sizing: border-box;
|
|
35
|
+
width: 100%;
|
|
36
|
+
height: 100%;
|
|
37
|
+
border-radius: inherit;
|
|
38
|
+
backface-visibility: hidden;
|
|
39
|
+
transform-style: preserve-3d;
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.readdy-anim-card-flip .readdy-anim-card-flip-front {
|
|
44
|
+
z-index: 2;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.readdy-anim-card-flip .readdy-anim-card-flip-back {
|
|
48
|
+
transform: rotateY(180deg);
|
|
49
|
+
filter: saturate(0.92) brightness(0.95);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.readdy-anim-card-flip .readdy-anim-card-flip-back::after {
|
|
53
|
+
content: '';
|
|
54
|
+
position: absolute;
|
|
55
|
+
inset: 0;
|
|
56
|
+
pointer-events: none;
|
|
57
|
+
background:
|
|
58
|
+
linear-gradient(180deg, rgba(15, 23, 42, 0.04) 0%, rgba(15, 23, 42, 0.1) 100%),
|
|
59
|
+
radial-gradient(circle at top right, rgba(255, 255, 255, 0.22), transparent 42%);
|
|
60
|
+
mix-blend-mode: multiply;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.readdy-anim-card-flip .readdy-anim-card-flip-back > * {
|
|
64
|
+
pointer-events: none !important;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@media (prefers-reduced-motion: reduce) {
|
|
68
|
+
.readdy-anim-card-flip .readdy-anim-card-flip-inner {
|
|
69
|
+
transition: none;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
2
|
+
export const ANIMATION_ID = buildAnimId('float-idle')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Float Idle — 卡片悬浮idle
|
|
6
|
+
* 实现:CSS-only,init 给元素加 .readdy-anim-float-idle class,destroy 移除
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import './style.css'
|
|
10
|
+
|
|
11
|
+
const CSS_CLASS = buildAnimClass('float-idle')
|
|
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
|
+
* Float Idle — 卡片悬浮idle
|
|
6
|
+
*
|
|
7
|
+
* 用法:
|
|
8
|
+
* <AnimFloatIdle><div className="card">内容</div></AnimFloatIdle>
|
|
9
|
+
*
|
|
10
|
+
* 不加 wrapper div — 通过 cloneElement 给子元素注入 ref,加/删 .readdy-anim-float-idle class
|
|
11
|
+
* 必须恰好包裹一个子元素
|
|
12
|
+
*/
|
|
13
|
+
export function AnimFloatIdle({ 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,21 @@
|
|
|
1
|
+
/* Float Idle — 卡片悬浮idle */
|
|
2
|
+
|
|
3
|
+
@keyframes readdy-anim-float-idle {
|
|
4
|
+
0%, 100% {
|
|
5
|
+
transform: translateY(0);
|
|
6
|
+
}
|
|
7
|
+
50% {
|
|
8
|
+
transform: translateY(-8px);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.readdy-anim-float-idle {
|
|
13
|
+
animation: readdy-anim-float-idle 3s ease-in-out infinite;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@media (prefers-reduced-motion: reduce) {
|
|
17
|
+
.readdy-anim-float-idle {
|
|
18
|
+
animation: none;
|
|
19
|
+
transform: none;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import './style.css'
|
|
2
|
+
import { prefersReducedMotion } from '../../../shared/reduced-motion.js'
|
|
3
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
4
|
+
import { attachPointerFollow } from '../../../shared/pointer-follow.js'
|
|
5
|
+
import { resolveCardMediaElement } from '../../../shared/resolve-card-media.js'
|
|
6
|
+
|
|
7
|
+
export const ANIMATION_ID = buildAnimId('image-magnifier')
|
|
8
|
+
|
|
9
|
+
const CSS_CLASS = buildAnimClass('image-magnifier')
|
|
10
|
+
const MEDIA_CLASS = buildAnimClass('card-media')
|
|
11
|
+
const ENHANCED_MEDIA_CLASS = buildAnimClass('image-magnifier-media')
|
|
12
|
+
const LENS_CLASS = buildAnimClass('image-magnifier-lens')
|
|
13
|
+
const stateMap = new WeakMap()
|
|
14
|
+
|
|
15
|
+
function resolveImageUrl(image) {
|
|
16
|
+
try {
|
|
17
|
+
return new URL(image.currentSrc || image.src, document.baseURI).href
|
|
18
|
+
} catch {
|
|
19
|
+
return image.currentSrc || image.src
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function parsePositionToken(token, axis) {
|
|
24
|
+
const value = token.trim().toLowerCase()
|
|
25
|
+
if (!value) {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (value === 'center') {
|
|
30
|
+
return { type: 'factor', value: 0.5 }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (axis === 'x') {
|
|
34
|
+
if (value === 'left') return { type: 'factor', value: 0 }
|
|
35
|
+
if (value === 'right') return { type: 'factor', value: 1 }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (axis === 'y') {
|
|
39
|
+
if (value === 'top') return { type: 'factor', value: 0 }
|
|
40
|
+
if (value === 'bottom') return { type: 'factor', value: 1 }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (value.endsWith('%')) {
|
|
44
|
+
const percentage = Number.parseFloat(value)
|
|
45
|
+
if (Number.isFinite(percentage)) {
|
|
46
|
+
return { type: 'factor', value: percentage / 100 }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (value.endsWith('px')) {
|
|
51
|
+
const pixels = Number.parseFloat(value)
|
|
52
|
+
if (Number.isFinite(pixels)) {
|
|
53
|
+
return { type: 'px', value: pixels }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function resolveObjectPosition(image) {
|
|
61
|
+
const raw = window.getComputedStyle(image).objectPosition || '50% 50%'
|
|
62
|
+
const tokens = raw.split(/\s+/).filter(Boolean)
|
|
63
|
+
|
|
64
|
+
if (tokens.length === 0) {
|
|
65
|
+
return {
|
|
66
|
+
x: { type: 'factor', value: 0.5 },
|
|
67
|
+
y: { type: 'factor', value: 0.5 },
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (tokens.length === 1) {
|
|
72
|
+
const token = tokens[0]
|
|
73
|
+
const x = parsePositionToken(token, 'x')
|
|
74
|
+
const y = parsePositionToken(token, 'y')
|
|
75
|
+
|
|
76
|
+
if (y && !x) {
|
|
77
|
+
return { x: { type: 'factor', value: 0.5 }, y }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
x: x ?? { type: 'factor', value: 0.5 },
|
|
82
|
+
y: { type: 'factor', value: 0.5 },
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let xToken = tokens[0]
|
|
87
|
+
let yToken = tokens[1]
|
|
88
|
+
const firstIsVertical = ['top', 'bottom'].includes(tokens[0].toLowerCase())
|
|
89
|
+
const secondIsHorizontal = ['left', 'right'].includes(tokens[1].toLowerCase())
|
|
90
|
+
|
|
91
|
+
if (firstIsVertical && secondIsHorizontal) {
|
|
92
|
+
xToken = tokens[1]
|
|
93
|
+
yToken = tokens[0]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
x: parsePositionToken(xToken, 'x') ?? { type: 'factor', value: 0.5 },
|
|
98
|
+
y: parsePositionToken(yToken, 'y') ?? { type: 'factor', value: 0.5 },
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function resolveObjectOffset(availableSpace, position) {
|
|
103
|
+
if (position.type === 'px') {
|
|
104
|
+
return position.value
|
|
105
|
+
}
|
|
106
|
+
return availableSpace * position.value
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function ensureLens(el) {
|
|
110
|
+
const media = resolveCardMediaElement(el, MEDIA_CLASS)
|
|
111
|
+
media.classList.add(ENHANCED_MEDIA_CLASS)
|
|
112
|
+
|
|
113
|
+
let lens = media.querySelector(`.${LENS_CLASS}`)
|
|
114
|
+
if (!lens) {
|
|
115
|
+
lens = document.createElement('span')
|
|
116
|
+
lens.className = LENS_CLASS
|
|
117
|
+
media.appendChild(lens)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return { media, lens }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function syncLensSurface(media, lens, zoomFactor) {
|
|
124
|
+
const image = media.querySelector('img')
|
|
125
|
+
const computed = window.getComputedStyle(media)
|
|
126
|
+
|
|
127
|
+
if (image?.currentSrc || image?.src) {
|
|
128
|
+
lens.style.backgroundImage = `url("${resolveImageUrl(image)}")`
|
|
129
|
+
lens.style.backgroundColor = 'transparent'
|
|
130
|
+
lens.style.backgroundRepeat = 'no-repeat'
|
|
131
|
+
lens.style.removeProperty('background-size')
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
lens.style.backgroundImage = computed.backgroundImage
|
|
136
|
+
lens.style.backgroundColor = computed.backgroundColor
|
|
137
|
+
lens.style.backgroundRepeat = computed.backgroundRepeat
|
|
138
|
+
lens.style.removeProperty('background-size')
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function primeLensSurface(el, state, zoomFactor) {
|
|
142
|
+
const { media, lens, image } = state
|
|
143
|
+
const markReady = () => {
|
|
144
|
+
if (stateMap.get(el) !== state) {
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
state.surfaceReady = true
|
|
148
|
+
syncLensSurface(media, lens, zoomFactor)
|
|
149
|
+
if (state.lastPointer) {
|
|
150
|
+
syncLensPosition({
|
|
151
|
+
mediaRect: media.getBoundingClientRect(),
|
|
152
|
+
lens,
|
|
153
|
+
image,
|
|
154
|
+
pointerX: state.lastPointer.x,
|
|
155
|
+
pointerY: state.lastPointer.y,
|
|
156
|
+
lensSize: state.lensSize,
|
|
157
|
+
zoomFactor,
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (!(image?.currentSrc || image?.src)) {
|
|
163
|
+
markReady()
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
syncLensSurface(media, lens, zoomFactor)
|
|
168
|
+
|
|
169
|
+
// If the image is already visible enough to be used as a magnifier source,
|
|
170
|
+
// don't block pointer interaction on decode/load timing.
|
|
171
|
+
state.surfaceReady = true
|
|
172
|
+
|
|
173
|
+
if (image.complete && image.naturalWidth) {
|
|
174
|
+
if (typeof image.decode === 'function') {
|
|
175
|
+
image.decode().then(markReady).catch(markReady)
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
markReady()
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
state.onLoad = () => {
|
|
184
|
+
markReady()
|
|
185
|
+
}
|
|
186
|
+
image.addEventListener('load', state.onLoad, { once: true })
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function syncLensPosition({
|
|
190
|
+
mediaRect,
|
|
191
|
+
lens,
|
|
192
|
+
image,
|
|
193
|
+
pointerX,
|
|
194
|
+
pointerY,
|
|
195
|
+
lensSize,
|
|
196
|
+
zoomFactor,
|
|
197
|
+
}) {
|
|
198
|
+
const lensX = pointerX - mediaRect.left
|
|
199
|
+
const lensY = pointerY - mediaRect.top
|
|
200
|
+
|
|
201
|
+
lens.style.setProperty('--readdy-anim-image-magnifier-lens-x', `${lensX}px`)
|
|
202
|
+
lens.style.setProperty('--readdy-anim-image-magnifier-lens-y', `${lensY}px`)
|
|
203
|
+
lens.style.opacity = '1'
|
|
204
|
+
|
|
205
|
+
if (image?.currentSrc || image?.src) {
|
|
206
|
+
const imageRect = image.getBoundingClientRect()
|
|
207
|
+
const naturalWidth = image.naturalWidth
|
|
208
|
+
const naturalHeight = image.naturalHeight
|
|
209
|
+
|
|
210
|
+
if (naturalWidth && naturalHeight && imageRect.width && imageRect.height) {
|
|
211
|
+
const localX = Math.min(Math.max(pointerX - imageRect.left, 0), imageRect.width)
|
|
212
|
+
const localY = Math.min(Math.max(pointerY - imageRect.top, 0), imageRect.height)
|
|
213
|
+
const scale = Math.max(imageRect.width / naturalWidth, imageRect.height / naturalHeight)
|
|
214
|
+
const renderedWidth = naturalWidth * scale
|
|
215
|
+
const renderedHeight = naturalHeight * scale
|
|
216
|
+
const objectPosition = resolveObjectPosition(image)
|
|
217
|
+
const offsetX = resolveObjectOffset(imageRect.width - renderedWidth, objectPosition.x)
|
|
218
|
+
const offsetY = resolveObjectOffset(imageRect.height - renderedHeight, objectPosition.y)
|
|
219
|
+
|
|
220
|
+
lens.style.backgroundSize = `${renderedWidth * zoomFactor}px ${renderedHeight * zoomFactor}px`
|
|
221
|
+
lens.style.backgroundPosition = `${
|
|
222
|
+
-(localX - offsetX) * zoomFactor + lensSize / 2
|
|
223
|
+
}px ${-(localY - offsetY) * zoomFactor + lensSize / 2}px`
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const localX = (lensX / mediaRect.width) * 100
|
|
229
|
+
const localY = (lensY / mediaRect.height) * 100
|
|
230
|
+
lens.style.setProperty('--readdy-anim-magnifier-x', `${localX}%`)
|
|
231
|
+
lens.style.setProperty('--readdy-anim-magnifier-y', `${localY}%`)
|
|
232
|
+
lens.style.backgroundPosition = `${localX}% ${localY}%`
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function init(el, options = {}) {
|
|
236
|
+
destroy(el)
|
|
237
|
+
|
|
238
|
+
el.classList.add(CSS_CLASS)
|
|
239
|
+
|
|
240
|
+
if (prefersReducedMotion()) {
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const lensSize = options.lensSize ?? 104
|
|
245
|
+
const zoom = options.zoom ?? 320
|
|
246
|
+
const zoomFactor = zoom / 100
|
|
247
|
+
const fadeDuration = options.fadeDuration ?? 160
|
|
248
|
+
|
|
249
|
+
el.style.setProperty('--readdy-anim-image-magnifier-lens-size', `${lensSize}px`)
|
|
250
|
+
el.style.setProperty('--readdy-anim-image-magnifier-zoom', `${zoom}%`)
|
|
251
|
+
el.style.setProperty('--readdy-anim-image-magnifier-fade-duration', `${fadeDuration}ms`)
|
|
252
|
+
|
|
253
|
+
const { media, lens } = ensureLens(el)
|
|
254
|
+
const image = media.querySelector('img')
|
|
255
|
+
const state = {
|
|
256
|
+
media,
|
|
257
|
+
lens,
|
|
258
|
+
cleanupPointerFollow: () => {},
|
|
259
|
+
image,
|
|
260
|
+
onLoad: null,
|
|
261
|
+
surfaceReady: false,
|
|
262
|
+
lastPointer: null,
|
|
263
|
+
lensSize,
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const onMove = (event, context) => {
|
|
267
|
+
state.lastPointer = {
|
|
268
|
+
x: event.clientX,
|
|
269
|
+
y: event.clientY,
|
|
270
|
+
}
|
|
271
|
+
if (!state.surfaceReady) {
|
|
272
|
+
return
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
syncLensPosition({
|
|
276
|
+
mediaRect: context.rect,
|
|
277
|
+
lens,
|
|
278
|
+
image,
|
|
279
|
+
pointerX: event.clientX,
|
|
280
|
+
pointerY: event.clientY,
|
|
281
|
+
lensSize,
|
|
282
|
+
zoomFactor,
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const onLeave = () => {
|
|
287
|
+
lens.style.opacity = '0'
|
|
288
|
+
state.lastPointer = null
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const onEnter = (event, context) => {
|
|
292
|
+
state.lastPointer = {
|
|
293
|
+
x: event.clientX,
|
|
294
|
+
y: event.clientY,
|
|
295
|
+
}
|
|
296
|
+
if (!state.surfaceReady) {
|
|
297
|
+
return
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
syncLensPosition({
|
|
301
|
+
mediaRect: context.rect,
|
|
302
|
+
lens,
|
|
303
|
+
image,
|
|
304
|
+
pointerX: event.clientX,
|
|
305
|
+
pointerY: event.clientY,
|
|
306
|
+
lensSize,
|
|
307
|
+
zoomFactor,
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const cleanupPointerFollow = attachPointerFollow(media, { onEnter, onMove, onLeave })
|
|
312
|
+
state.cleanupPointerFollow = cleanupPointerFollow
|
|
313
|
+
stateMap.set(el, state)
|
|
314
|
+
primeLensSurface(el, state, zoomFactor)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export function destroy(el) {
|
|
318
|
+
const state = stateMap.get(el)
|
|
319
|
+
if (state) {
|
|
320
|
+
state.cleanupPointerFollow()
|
|
321
|
+
if (state.image && state.onLoad) {
|
|
322
|
+
state.image.removeEventListener('load', state.onLoad)
|
|
323
|
+
}
|
|
324
|
+
state.media.classList.remove(ENHANCED_MEDIA_CLASS)
|
|
325
|
+
stateMap.delete(el)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
el.classList.remove(CSS_CLASS)
|
|
329
|
+
el.style.removeProperty('--readdy-anim-image-magnifier-lens-size')
|
|
330
|
+
el.style.removeProperty('--readdy-anim-image-magnifier-zoom')
|
|
331
|
+
el.style.removeProperty('--readdy-anim-image-magnifier-fade-duration')
|
|
332
|
+
el.querySelector(`.${LENS_CLASS}`)?.remove()
|
|
333
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 AnimImageMagnifierProps = {
|
|
6
|
+
children: React.ReactElement
|
|
7
|
+
lensSize?: number
|
|
8
|
+
zoom?: number
|
|
9
|
+
fadeDuration?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function AnimImageMagnifier({
|
|
13
|
+
children,
|
|
14
|
+
lensSize,
|
|
15
|
+
zoom,
|
|
16
|
+
fadeDuration,
|
|
17
|
+
}: AnimImageMagnifierProps) {
|
|
18
|
+
const ref = useRef<HTMLElement>(null)
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const el = ref.current
|
|
22
|
+
if (!el || prefersReducedMotion()) return
|
|
23
|
+
|
|
24
|
+
init(el, { lensSize, zoom, fadeDuration })
|
|
25
|
+
return () => {
|
|
26
|
+
destroy(el)
|
|
27
|
+
}
|
|
28
|
+
}, [lensSize, zoom, fadeDuration])
|
|
29
|
+
|
|
30
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
31
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
.readdy-anim-image-magnifier .readdy-anim-card-media,
|
|
2
|
+
.readdy-anim-image-magnifier .readdy-anim-image-magnifier-media {
|
|
3
|
+
position: relative;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
background:
|
|
6
|
+
radial-gradient(circle at 25% 25%, rgba(255, 255, 255, 0.85), transparent 38%),
|
|
7
|
+
linear-gradient(135deg, rgba(34, 211, 238, 0.95), rgba(167, 139, 250, 0.84));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.readdy-anim-image-magnifier .readdy-anim-image-magnifier-lens {
|
|
11
|
+
position: absolute;
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
width: var(--readdy-anim-image-magnifier-lens-size, 104px);
|
|
14
|
+
height: var(--readdy-anim-image-magnifier-lens-size, 104px);
|
|
15
|
+
border-radius: 999px;
|
|
16
|
+
border: 2px solid rgba(255, 255, 255, 0.86);
|
|
17
|
+
box-shadow:
|
|
18
|
+
0 16px 34px rgba(15, 23, 42, 0.22),
|
|
19
|
+
inset 0 0 0 1px rgba(255, 255, 255, 0.28);
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
left: 0;
|
|
22
|
+
top: 0;
|
|
23
|
+
will-change: transform, opacity, background-position, background-size;
|
|
24
|
+
transform:
|
|
25
|
+
translate3d(
|
|
26
|
+
var(--readdy-anim-image-magnifier-lens-x, 50%),
|
|
27
|
+
var(--readdy-anim-image-magnifier-lens-y, 50%),
|
|
28
|
+
0
|
|
29
|
+
)
|
|
30
|
+
translate(-50%, -50%);
|
|
31
|
+
opacity: 0;
|
|
32
|
+
background-size: var(--readdy-anim-image-magnifier-zoom, 320%) var(--readdy-anim-image-magnifier-zoom, 320%);
|
|
33
|
+
background-position: var(--readdy-anim-magnifier-x, 50%) var(--readdy-anim-magnifier-y, 50%);
|
|
34
|
+
transition: opacity var(--readdy-anim-image-magnifier-fade-duration, 160ms) ease;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@media (prefers-reduced-motion: reduce) {
|
|
38
|
+
.readdy-anim-image-magnifier .readdy-anim-image-magnifier-lens {
|
|
39
|
+
opacity: 0;
|
|
40
|
+
transition: none;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import './style.css'
|
|
2
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
3
|
+
import { resolveCardMediaElement } from '../../../shared/resolve-card-media.js'
|
|
4
|
+
|
|
5
|
+
export const ANIMATION_ID = buildAnimId('image-zoom-rotate')
|
|
6
|
+
|
|
7
|
+
const CSS_CLASS = buildAnimClass('image-zoom-rotate')
|
|
8
|
+
const MEDIA_CLASS = buildAnimClass('card-media')
|
|
9
|
+
|
|
10
|
+
const autoMediaState = new WeakMap()
|
|
11
|
+
|
|
12
|
+
export function init(el, options = {}) {
|
|
13
|
+
if (!el.classList.contains(CSS_CLASS)) {
|
|
14
|
+
el.classList.add(CSS_CLASS)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
el.style.setProperty('--readdy-anim-image-zoom-scale', `${options.scale ?? 1.08}`)
|
|
18
|
+
el.style.setProperty('--readdy-anim-image-zoom-rotate', `${options.rotate ?? 2}deg`)
|
|
19
|
+
el.style.setProperty('--readdy-anim-image-zoom-duration', `${options.duration ?? 500}ms`)
|
|
20
|
+
|
|
21
|
+
const media = resolveCardMediaElement(el, MEDIA_CLASS)
|
|
22
|
+
if (!media) return
|
|
23
|
+
|
|
24
|
+
const state = {
|
|
25
|
+
media,
|
|
26
|
+
addedMediaClass: false,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!media.classList.contains(MEDIA_CLASS)) {
|
|
30
|
+
media.classList.add(MEDIA_CLASS)
|
|
31
|
+
state.addedMediaClass = true
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
autoMediaState.set(el, state)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function destroy(el) {
|
|
38
|
+
el.classList.remove(CSS_CLASS)
|
|
39
|
+
el.style.removeProperty('--readdy-anim-image-zoom-scale')
|
|
40
|
+
el.style.removeProperty('--readdy-anim-image-zoom-rotate')
|
|
41
|
+
el.style.removeProperty('--readdy-anim-image-zoom-duration')
|
|
42
|
+
|
|
43
|
+
const state = autoMediaState.get(el)
|
|
44
|
+
if (state?.addedMediaClass) {
|
|
45
|
+
state.media?.classList.remove(MEDIA_CLASS)
|
|
46
|
+
}
|
|
47
|
+
autoMediaState.delete(el)
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 AnimImageZoomRotateProps = {
|
|
6
|
+
children: React.ReactElement
|
|
7
|
+
scale?: number
|
|
8
|
+
rotate?: number
|
|
9
|
+
duration?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function AnimImageZoomRotate({
|
|
13
|
+
children,
|
|
14
|
+
scale,
|
|
15
|
+
rotate,
|
|
16
|
+
duration,
|
|
17
|
+
}: AnimImageZoomRotateProps) {
|
|
18
|
+
const ref = useRef<HTMLElement>(null)
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const el = ref.current
|
|
22
|
+
if (!el || prefersReducedMotion()) return
|
|
23
|
+
|
|
24
|
+
init(el, { scale, rotate, duration })
|
|
25
|
+
return () => {
|
|
26
|
+
destroy(el)
|
|
27
|
+
}
|
|
28
|
+
}, [scale, rotate, duration])
|
|
29
|
+
|
|
30
|
+
return React.cloneElement(React.Children.only(children), { ref })
|
|
31
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.readdy-anim-image-zoom-rotate {
|
|
2
|
+
overflow: hidden;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.readdy-anim-image-zoom-rotate .readdy-anim-card-media {
|
|
6
|
+
transform-origin: center;
|
|
7
|
+
transition: transform var(--readdy-anim-image-zoom-duration, 500ms) ease;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.readdy-anim-image-zoom-rotate:hover .readdy-anim-card-media {
|
|
11
|
+
transform:
|
|
12
|
+
scale(var(--readdy-anim-image-zoom-scale, 1.08))
|
|
13
|
+
rotate(var(--readdy-anim-image-zoom-rotate, 2deg));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@media (prefers-reduced-motion: reduce) {
|
|
17
|
+
.readdy-anim-image-zoom-rotate:hover .readdy-anim-card-media {
|
|
18
|
+
transform: none;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import './style.css'
|
|
2
|
+
import { buildAnimClass, buildAnimId } from '../../../shared/constants.js'
|
|
3
|
+
|
|
4
|
+
export const ANIMATION_ID = buildAnimId('pop-in-stack')
|
|
5
|
+
|
|
6
|
+
const CSS_CLASS = buildAnimClass('pop-in-stack')
|
|
7
|
+
|
|
8
|
+
export function init(el, options = {}) {
|
|
9
|
+
if (!el.classList.contains(CSS_CLASS)) {
|
|
10
|
+
el.classList.add(CSS_CLASS)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
el.style.setProperty('--readdy-anim-pop-delay', `${options.delay ?? 0}ms`)
|
|
14
|
+
el.style.setProperty('--readdy-anim-pop-duration', `${options.duration ?? 600}ms`)
|
|
15
|
+
el.style.setProperty('--readdy-anim-pop-offset', `${options.offset ?? 18}px`)
|
|
16
|
+
el.style.setProperty('--readdy-anim-pop-scale-start', `${options.scaleStart ?? 0.88}`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function destroy(el) {
|
|
20
|
+
el.classList.remove(CSS_CLASS)
|
|
21
|
+
el.style.removeProperty('--readdy-anim-pop-delay')
|
|
22
|
+
el.style.removeProperty('--readdy-anim-pop-duration')
|
|
23
|
+
el.style.removeProperty('--readdy-anim-pop-offset')
|
|
24
|
+
el.style.removeProperty('--readdy-anim-pop-scale-start')
|
|
25
|
+
}
|