@twick/visualizer 0.14.0 → 0.14.3
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/.eslintrc.json +20 -20
- package/README.md +113 -13
- package/package.json +14 -14
- package/package.json.bak +34 -0
- package/src/animations/blur.tsx +96 -60
- package/src/animations/breathe.tsx +95 -60
- package/src/animations/fade.tsx +173 -60
- package/src/animations/index.ts +12 -0
- package/src/animations/photo-rise.tsx +103 -66
- package/src/animations/photo-zoom.tsx +109 -73
- package/src/animations/rise.tsx +157 -118
- package/src/animations/succession.tsx +112 -77
- package/src/components/frame-effects.tsx +188 -188
- package/src/components/track.tsx +237 -232
- package/src/controllers/animation.controller.ts +38 -38
- package/src/controllers/element.controller.ts +42 -42
- package/src/controllers/frame-effect.controller.tsx +29 -29
- package/src/controllers/text-effect.controller.ts +32 -32
- package/src/elements/audio.element.tsx +79 -17
- package/src/elements/caption.element.tsx +169 -87
- package/src/elements/circle.element.tsx +88 -20
- package/src/elements/icon.element.tsx +88 -20
- package/src/elements/image.element.tsx +134 -55
- package/src/elements/index.ts +14 -0
- package/src/elements/rect.element.tsx +92 -22
- package/src/elements/scene.element.tsx +97 -29
- package/src/elements/text.element.tsx +101 -27
- package/src/elements/video.element.tsx +274 -56
- package/src/frame-effects/circle.frame.tsx +168 -103
- package/src/frame-effects/index.ts +7 -0
- package/src/frame-effects/rect.frame.tsx +198 -103
- package/src/global.css +11 -11
- package/src/helpers/caption.utils.ts +29 -29
- package/src/helpers/constants.ts +162 -158
- package/src/helpers/element.utils.ts +331 -239
- package/src/helpers/event.utils.ts +21 -0
- package/src/helpers/filters.ts +127 -127
- package/src/helpers/log.utils.ts +55 -29
- package/src/helpers/timing.utils.ts +109 -109
- package/src/helpers/types.ts +361 -241
- package/src/helpers/utils.ts +36 -19
- package/src/index.ts +196 -6
- package/src/live.tsx +16 -16
- package/src/project.ts +6 -6
- package/src/sample.ts +247 -247
- package/src/text-effects/elastic.tsx +70 -39
- package/src/text-effects/erase.tsx +91 -58
- package/src/text-effects/index.ts +9 -0
- package/src/text-effects/stream-word.tsx +94 -60
- package/src/text-effects/typewriter.tsx +93 -59
- package/src/visualizer-grouped.ts +83 -0
- package/src/visualizer.tsx +182 -78
- package/tsconfig.json +11 -11
- package/typedoc.json +19 -14
- package/vite.config.ts +15 -15
- package/.turbo/turbo-build.log +0 -19
- package/.turbo/turbo-docs.log +0 -7
- package/LICENSE +0 -197
- package/dist/mp4.wasm +0 -0
- package/dist/project.css +0 -1
- package/dist/project.js +0 -145
- package/docs/.nojekyll +0 -1
- package/docs/README.md +0 -13
- package/docs/interfaces/Animation.md +0 -47
- package/docs/interfaces/Element.md +0 -47
- package/docs/interfaces/FrameEffectPlugin.md +0 -47
- package/docs/interfaces/TextEffect.md +0 -47
- package/docs/modules.md +0 -535
package/src/animations/fade.tsx
CHANGED
|
@@ -1,60 +1,173 @@
|
|
|
1
|
-
import { waitFor } from "@twick/core";
|
|
2
|
-
import { AnimationParams } from "../helpers/types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* FadeAnimation
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
import { waitFor } from "@twick/core";
|
|
2
|
+
import { AnimationParams } from "../helpers/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @group FadeAnimation
|
|
6
|
+
* @description Simple fade-in and fade-out effects for smooth element transitions
|
|
7
|
+
*
|
|
8
|
+
* FadeAnimation applies a simple fade-in and fade-out effect by adjusting opacity.
|
|
9
|
+
* Creates smooth opacity transitions for elements entering or exiting the scene.
|
|
10
|
+
* Perfect for subtle, professional animations that don't distract from content.
|
|
11
|
+
*
|
|
12
|
+
* ## Animation Modes
|
|
13
|
+
*
|
|
14
|
+
* - **"enter"**: Starts transparent and fades in to fully opaque
|
|
15
|
+
* - **"exit"**: Waits, then fades out to transparent
|
|
16
|
+
* - **"both"**: Fades in, waits, then fades out
|
|
17
|
+
*
|
|
18
|
+
* ## Use Cases
|
|
19
|
+
*
|
|
20
|
+
* - **Text overlays**: Smooth introduction of captions and titles
|
|
21
|
+
* - **Background elements**: Subtle scene transitions
|
|
22
|
+
* - **UI components**: Professional interface animations
|
|
23
|
+
* - **Content reveals**: Gentle disclosure of information
|
|
24
|
+
*
|
|
25
|
+
* ## Best Practices
|
|
26
|
+
*
|
|
27
|
+
* - **Duration**: 1-3 seconds for most use cases
|
|
28
|
+
* - **Timing**: Use "enter" for introductions, "exit" for conclusions
|
|
29
|
+
* - **Combination**: Pair with other animations for complex effects
|
|
30
|
+
* - **Performance**: Lightweight and efficient for multiple elements
|
|
31
|
+
*
|
|
32
|
+
* ## Integration Examples
|
|
33
|
+
*
|
|
34
|
+
* ### Basic Text Fade
|
|
35
|
+
* ```js
|
|
36
|
+
* {
|
|
37
|
+
* id: "welcome-text",
|
|
38
|
+
* type: "text",
|
|
39
|
+
* s: 0, e: 5,
|
|
40
|
+
* t: "Welcome!",
|
|
41
|
+
* animation: {
|
|
42
|
+
* name: "fade",
|
|
43
|
+
* animate: "enter",
|
|
44
|
+
* duration: 2
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* ### Video with Fade Transition
|
|
50
|
+
* ```js
|
|
51
|
+
* {
|
|
52
|
+
* id: "intro-video",
|
|
53
|
+
* type: "video",
|
|
54
|
+
* s: 0, e: 10,
|
|
55
|
+
* props: { src: "intro.mp4" },
|
|
56
|
+
* animation: {
|
|
57
|
+
* name: "fade",
|
|
58
|
+
* animate: "both",
|
|
59
|
+
* duration: 3,
|
|
60
|
+
* interval: 1
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* ### Multi-Element Fade Sequence
|
|
66
|
+
* ```js
|
|
67
|
+
* // Fade in multiple elements with staggered timing
|
|
68
|
+
* const elements = [
|
|
69
|
+
* {
|
|
70
|
+
* id: "title",
|
|
71
|
+
* type: "text",
|
|
72
|
+
* s: 0, e: 8,
|
|
73
|
+
* t: "Main Title",
|
|
74
|
+
* animation: { name: "fade", animate: "enter", duration: 2 }
|
|
75
|
+
* },
|
|
76
|
+
* {
|
|
77
|
+
* id: "subtitle",
|
|
78
|
+
* type: "text",
|
|
79
|
+
* s: 1, e: 8,
|
|
80
|
+
* t: "Subtitle",
|
|
81
|
+
* animation: { name: "fade", animate: "enter", duration: 2 }
|
|
82
|
+
* },
|
|
83
|
+
* {
|
|
84
|
+
* id: "background",
|
|
85
|
+
* type: "rect",
|
|
86
|
+
* s: 0, e: 10,
|
|
87
|
+
* props: { fill: "#000000", opacity: 0.5 },
|
|
88
|
+
* animation: { name: "fade", animate: "enter", duration: 1.5 }
|
|
89
|
+
* }
|
|
90
|
+
* ];
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @param elementRef - Reference to the main element to animate
|
|
94
|
+
* @param containerRef - Optional reference to a container element
|
|
95
|
+
* @param duration - Duration of the fade transition in seconds
|
|
96
|
+
* @param totalDuration - Total duration of the animation in seconds
|
|
97
|
+
* @param animate - Animation phase ("enter" | "exit" | "both")
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```js
|
|
101
|
+
* // Basic fade-in animation
|
|
102
|
+
* animation: {
|
|
103
|
+
* name: "fade",
|
|
104
|
+
* animate: "enter",
|
|
105
|
+
* duration: 2,
|
|
106
|
+
* direction: "center"
|
|
107
|
+
* }
|
|
108
|
+
*
|
|
109
|
+
* // Fade in and out
|
|
110
|
+
* animation: {
|
|
111
|
+
* name: "fade",
|
|
112
|
+
* animate: "both",
|
|
113
|
+
* duration: 3,
|
|
114
|
+
* interval: 1
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export const FadeAnimation = {
|
|
119
|
+
name: "fade",
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Generator function controlling the fade animation.
|
|
123
|
+
* Handles opacity transitions based on the specified animation mode.
|
|
124
|
+
*
|
|
125
|
+
* @param params - Animation parameters including element references and timing
|
|
126
|
+
* @returns Generator that controls the fade animation timeline
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```js
|
|
130
|
+
* yield* FadeAnimation.run({
|
|
131
|
+
* elementRef: myElement,
|
|
132
|
+
* interval: 1,
|
|
133
|
+
* duration: 3,
|
|
134
|
+
* animate: "enter"
|
|
135
|
+
* });
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
*run({
|
|
139
|
+
elementRef,
|
|
140
|
+
containerRef,
|
|
141
|
+
interval,
|
|
142
|
+
duration,
|
|
143
|
+
animate,
|
|
144
|
+
}: AnimationParams) {
|
|
145
|
+
// Use containerRef if provided, otherwise fallback to elementRef
|
|
146
|
+
const ref = containerRef ?? elementRef;
|
|
147
|
+
|
|
148
|
+
let animationInterval = Math.min(interval, duration);
|
|
149
|
+
if (animate === "enter") {
|
|
150
|
+
// Start fully transparent
|
|
151
|
+
ref().opacity(0);
|
|
152
|
+
// Fade in to full opacity over 'interval'
|
|
153
|
+
yield* ref().opacity(1, animationInterval);
|
|
154
|
+
|
|
155
|
+
} else if (animate === "exit") {
|
|
156
|
+
// Wait until it's time to start fading out
|
|
157
|
+
yield* waitFor(duration - animationInterval);
|
|
158
|
+
// Fade out to transparent over 'interval'
|
|
159
|
+
yield* ref().opacity(0, animationInterval);
|
|
160
|
+
|
|
161
|
+
} else if (animate === "both") {
|
|
162
|
+
animationInterval = Math.min(interval, duration/2);
|
|
163
|
+
// Start fully transparent
|
|
164
|
+
ref().opacity(0);
|
|
165
|
+
// Fade in to full opacity
|
|
166
|
+
yield* ref().opacity(1, animationInterval);
|
|
167
|
+
// Wait for the remaining duration before fade-out
|
|
168
|
+
yield* waitFor(duration - animationInterval);
|
|
169
|
+
// Fade out to transparent
|
|
170
|
+
yield* ref().opacity(0, animationInterval);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @group Animations
|
|
3
|
+
* @description Motion effects and transitions for elements
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { FadeAnimation } from './fade';
|
|
7
|
+
export { RiseAnimation } from './rise';
|
|
8
|
+
export { BlurAnimation } from './blur';
|
|
9
|
+
export { BreatheAnimation } from './breathe';
|
|
10
|
+
export { SuccessionAnimation } from './succession';
|
|
11
|
+
export { PhotoRiseAnimation } from './photo-rise';
|
|
12
|
+
export { PhotoZoomAnimation } from './photo-zoom';
|
|
@@ -1,66 +1,103 @@
|
|
|
1
|
-
import { AnimationParams } from "../helpers/types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* PhotoRiseAnimation
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* - "
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
import { AnimationParams } from "../helpers/types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @group PhotoRiseAnimation
|
|
5
|
+
* PhotoRiseAnimation applies a smooth directional movement to a photo element.
|
|
6
|
+
* Creates elegant slide-in animations that bring photos into view from any direction.
|
|
7
|
+
* Perfect for photo galleries, presentations, and content reveals.
|
|
8
|
+
*
|
|
9
|
+
* Behavior:
|
|
10
|
+
* - Starts offset in a given direction (up, down, left, or right)
|
|
11
|
+
* - Animates back to the original position over the specified duration
|
|
12
|
+
*
|
|
13
|
+
* Available directions:
|
|
14
|
+
* - "up": Starts below and moves upward
|
|
15
|
+
* - "down": Starts above and moves downward
|
|
16
|
+
* - "left": Starts to the right and moves leftward
|
|
17
|
+
* - "right": Starts to the left and moves rightward
|
|
18
|
+
*
|
|
19
|
+
* @param elementRef - Reference to the photo element to animate
|
|
20
|
+
* @param containerRef - Optional reference to a container element (required for this animation)
|
|
21
|
+
* @param direction - Direction of the movement ("up" | "down" | "left" | "right")
|
|
22
|
+
* @param duration - Duration of the movement animation in seconds
|
|
23
|
+
* @param intensity - Offset distance in pixels (default: 200)
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* // Slide in from bottom
|
|
28
|
+
* animation: {
|
|
29
|
+
* name: "photo-rise",
|
|
30
|
+
* direction: "up",
|
|
31
|
+
* duration: 1.5,
|
|
32
|
+
* intensity: 300
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* // Slide in from left
|
|
36
|
+
* animation: {
|
|
37
|
+
* name: "photo-rise",
|
|
38
|
+
* direction: "left",
|
|
39
|
+
* duration: 2,
|
|
40
|
+
* intensity: 400
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export const PhotoRiseAnimation = {
|
|
45
|
+
name: "photo-rise",
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Generator function controlling the photo rise animation.
|
|
49
|
+
* Handles directional movement animations for photo elements.
|
|
50
|
+
*
|
|
51
|
+
* @param params - Animation parameters including element references and direction
|
|
52
|
+
* @returns Generator that controls the photo rise animation timeline
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```js
|
|
56
|
+
* yield* PhotoRiseAnimation.run({
|
|
57
|
+
* elementRef: photoElement,
|
|
58
|
+
* containerRef: container,
|
|
59
|
+
* direction: "up",
|
|
60
|
+
* duration: 1.5,
|
|
61
|
+
* intensity: 200
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
*run({
|
|
66
|
+
elementRef,
|
|
67
|
+
containerRef,
|
|
68
|
+
direction,
|
|
69
|
+
duration,
|
|
70
|
+
intensity = 200,
|
|
71
|
+
}: AnimationParams) {
|
|
72
|
+
// Only run if a containerRef is provided
|
|
73
|
+
if (containerRef) {
|
|
74
|
+
// Get the element's current position
|
|
75
|
+
const pos = elementRef().position();
|
|
76
|
+
|
|
77
|
+
if (direction === "up") {
|
|
78
|
+
// Start offset below
|
|
79
|
+
elementRef().y(pos.y + intensity);
|
|
80
|
+
// Animate moving upward to the original position
|
|
81
|
+
yield* elementRef().y(pos.y, duration);
|
|
82
|
+
|
|
83
|
+
} else if (direction === "down") {
|
|
84
|
+
// Start offset above
|
|
85
|
+
elementRef().y(pos.y - intensity);
|
|
86
|
+
// Animate moving downward to the original position
|
|
87
|
+
yield* elementRef().y(pos.y, duration);
|
|
88
|
+
|
|
89
|
+
} else if (direction === "left") {
|
|
90
|
+
// Start offset to the right
|
|
91
|
+
elementRef().x(pos.x + intensity);
|
|
92
|
+
// Animate moving left to the original position
|
|
93
|
+
yield* elementRef().x(pos.x, duration);
|
|
94
|
+
|
|
95
|
+
} else if (direction === "right") {
|
|
96
|
+
// Start offset to the left
|
|
97
|
+
elementRef().x(pos.x - intensity);
|
|
98
|
+
// Animate moving right to the original position
|
|
99
|
+
yield* elementRef().x(pos.x, duration);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
};
|
|
@@ -1,73 +1,109 @@
|
|
|
1
|
-
import { Vector2 } from "@twick/core";
|
|
2
|
-
import { AnimationParams } from "../helpers/types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* PhotoZoomAnimation
|
|
6
|
-
* on a photo element.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
1
|
+
import { Vector2 } from "@twick/core";
|
|
2
|
+
import { AnimationParams } from "../helpers/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @group PhotoZoomAnimation
|
|
6
|
+
* PhotoZoomAnimation applies a smooth zoom-in or zoom-out effect on a photo element.
|
|
7
|
+
* Creates dynamic zoom effects that add depth and focus to photo content.
|
|
8
|
+
* Perfect for highlighting details or creating cinematic photo presentations.
|
|
9
|
+
*
|
|
10
|
+
* Available animation modes:
|
|
11
|
+
* - "in": Starts zoomed in and smoothly scales back to the original size
|
|
12
|
+
* - "out": Starts at normal size and smoothly scales up to the target zoom level
|
|
13
|
+
*
|
|
14
|
+
* @param elementRef - Reference to the photo element to animate
|
|
15
|
+
* @param containerRef - Optional reference to a container element (required for this animation)
|
|
16
|
+
* @param mode - Animation phase ("in" | "out")
|
|
17
|
+
* @param duration - Duration of the zoom animation in seconds
|
|
18
|
+
* @param intensity - Zoom scale multiplier (default: 1.5)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```js
|
|
22
|
+
* // Zoom in effect
|
|
23
|
+
* animation: {
|
|
24
|
+
* name: "photo-zoom",
|
|
25
|
+
* mode: "in",
|
|
26
|
+
* duration: 2,
|
|
27
|
+
* intensity: 1.8
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* // Zoom out effect
|
|
31
|
+
* animation: {
|
|
32
|
+
* name: "photo-zoom",
|
|
33
|
+
* mode: "out",
|
|
34
|
+
* duration: 1.5,
|
|
35
|
+
* intensity: 2.0
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export const PhotoZoomAnimation = {
|
|
40
|
+
name: "photo-zoom",
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Generator function controlling the photo zoom animation.
|
|
44
|
+
* Handles smooth scaling transitions for zoom effects on photo elements.
|
|
45
|
+
*
|
|
46
|
+
* @param params - Animation parameters including element references and zoom settings
|
|
47
|
+
* @returns Generator that controls the photo zoom animation timeline
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```js
|
|
51
|
+
* yield* PhotoZoomAnimation.run({
|
|
52
|
+
* elementRef: photoElement,
|
|
53
|
+
* containerRef: container,
|
|
54
|
+
* mode: "in",
|
|
55
|
+
* duration: 2,
|
|
56
|
+
* intensity: 1.5
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
*run({
|
|
61
|
+
elementRef,
|
|
62
|
+
containerRef,
|
|
63
|
+
mode,
|
|
64
|
+
duration,
|
|
65
|
+
intensity = 1.5,
|
|
66
|
+
}: AnimationParams) {
|
|
67
|
+
// Only run if a containerRef is provided
|
|
68
|
+
if (containerRef) {
|
|
69
|
+
// Get the element's current scale
|
|
70
|
+
const elementScale = elementRef().scale();
|
|
71
|
+
|
|
72
|
+
if (mode === "in") {
|
|
73
|
+
// Instantly set to zoomed-in scale
|
|
74
|
+
yield elementRef().scale(
|
|
75
|
+
new Vector2(
|
|
76
|
+
elementScale.x * intensity,
|
|
77
|
+
elementScale.y * intensity
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
// Smoothly scale back to original size over 'duration'
|
|
81
|
+
yield* elementRef().scale(
|
|
82
|
+
new Vector2(
|
|
83
|
+
elementScale.x,
|
|
84
|
+
elementScale.y
|
|
85
|
+
),
|
|
86
|
+
duration
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (mode === "out") {
|
|
91
|
+
// Start at original scale
|
|
92
|
+
elementRef().scale(
|
|
93
|
+
new Vector2(
|
|
94
|
+
elementScale.x,
|
|
95
|
+
elementScale.y
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
// Smoothly scale up to zoomed-in scale over 'duration'
|
|
99
|
+
yield* elementRef().scale(
|
|
100
|
+
new Vector2(
|
|
101
|
+
elementScale.x * intensity,
|
|
102
|
+
elementScale.y * intensity
|
|
103
|
+
),
|
|
104
|
+
duration
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
};
|