@twick/visualizer 0.14.0 → 0.14.2
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 +12 -12
- package/package.json +13 -13
- package/package.json.bak +34 -0
- package/src/animations/blur.tsx +60 -60
- package/src/animations/breathe.tsx +60 -60
- package/src/animations/fade.tsx +60 -60
- package/src/animations/photo-rise.tsx +66 -66
- package/src/animations/photo-zoom.tsx +73 -73
- package/src/animations/rise.tsx +118 -118
- package/src/animations/succession.tsx +77 -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 +17 -17
- package/src/elements/caption.element.tsx +87 -87
- package/src/elements/circle.element.tsx +20 -20
- package/src/elements/icon.element.tsx +20 -20
- package/src/elements/image.element.tsx +53 -55
- package/src/elements/rect.element.tsx +22 -22
- package/src/elements/scene.element.tsx +29 -29
- package/src/elements/text.element.tsx +27 -27
- package/src/elements/video.element.tsx +55 -56
- package/src/frame-effects/circle.frame.tsx +103 -103
- package/src/frame-effects/rect.frame.tsx +103 -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 +239 -239
- package/src/helpers/event.utils.ts +6 -0
- package/src/helpers/filters.ts +127 -127
- package/src/helpers/log.utils.ts +29 -29
- package/src/helpers/timing.utils.ts +109 -109
- package/src/helpers/types.ts +242 -241
- package/src/helpers/utils.ts +19 -19
- package/src/index.ts +6 -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 +39 -39
- package/src/text-effects/erase.tsx +58 -58
- package/src/text-effects/stream-word.tsx +60 -60
- package/src/text-effects/typewriter.tsx +59 -59
- package/src/visualizer.tsx +98 -78
- package/tsconfig.json +11 -11
- package/typedoc.json +14 -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
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { Vector2 } from "@twick/core";
|
|
2
|
-
import { AnimationParams } from "../helpers/types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* PhotoZoomAnimation applies a smooth zoom-in or zoom-out effect
|
|
6
|
-
* on a photo element.
|
|
7
|
-
*
|
|
8
|
-
* Available animation modes:
|
|
9
|
-
* - "in": Starts zoomed in and smoothly scales back to the original size.
|
|
10
|
-
* - "out": Starts at normal size and smoothly scales up to the target zoom level.
|
|
11
|
-
*
|
|
12
|
-
* @param elementRef - Reference to the photo element to animate.
|
|
13
|
-
* @param containerRef - Optional reference to a container element (required for this animation).
|
|
14
|
-
* @param mode - Animation phase ("in" | "out").
|
|
15
|
-
* @param duration - Duration of the zoom animation.
|
|
16
|
-
* @param intensity - Zoom scale multiplier (default: 1.5).
|
|
17
|
-
*/
|
|
18
|
-
export const PhotoZoomAnimation = {
|
|
19
|
-
name: "photo-zoom",
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Generator function controlling the photo zoom animation.
|
|
23
|
-
*/
|
|
24
|
-
*run({
|
|
25
|
-
elementRef,
|
|
26
|
-
containerRef,
|
|
27
|
-
mode,
|
|
28
|
-
duration,
|
|
29
|
-
intensity = 1.5,
|
|
30
|
-
}: AnimationParams) {
|
|
31
|
-
// Only run if a containerRef is provided
|
|
32
|
-
if (containerRef) {
|
|
33
|
-
// Get the element's current scale
|
|
34
|
-
const elementScale = elementRef().scale();
|
|
35
|
-
|
|
36
|
-
if (mode === "in") {
|
|
37
|
-
// Instantly set to zoomed-in scale
|
|
38
|
-
yield elementRef().scale(
|
|
39
|
-
new Vector2(
|
|
40
|
-
elementScale.x * intensity,
|
|
41
|
-
elementScale.y * intensity
|
|
42
|
-
)
|
|
43
|
-
);
|
|
44
|
-
// Smoothly scale back to original size over 'duration'
|
|
45
|
-
yield* elementRef().scale(
|
|
46
|
-
new Vector2(
|
|
47
|
-
elementScale.x,
|
|
48
|
-
elementScale.y
|
|
49
|
-
),
|
|
50
|
-
duration
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (mode === "out") {
|
|
55
|
-
// Start at original scale
|
|
56
|
-
elementRef().scale(
|
|
57
|
-
new Vector2(
|
|
58
|
-
elementScale.x,
|
|
59
|
-
elementScale.y
|
|
60
|
-
)
|
|
61
|
-
);
|
|
62
|
-
// Smoothly scale up to zoomed-in scale over 'duration'
|
|
63
|
-
yield* elementRef().scale(
|
|
64
|
-
new Vector2(
|
|
65
|
-
elementScale.x * intensity,
|
|
66
|
-
elementScale.y * intensity
|
|
67
|
-
),
|
|
68
|
-
duration
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
};
|
|
1
|
+
import { Vector2 } from "@twick/core";
|
|
2
|
+
import { AnimationParams } from "../helpers/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* PhotoZoomAnimation applies a smooth zoom-in or zoom-out effect
|
|
6
|
+
* on a photo element.
|
|
7
|
+
*
|
|
8
|
+
* Available animation modes:
|
|
9
|
+
* - "in": Starts zoomed in and smoothly scales back to the original size.
|
|
10
|
+
* - "out": Starts at normal size and smoothly scales up to the target zoom level.
|
|
11
|
+
*
|
|
12
|
+
* @param elementRef - Reference to the photo element to animate.
|
|
13
|
+
* @param containerRef - Optional reference to a container element (required for this animation).
|
|
14
|
+
* @param mode - Animation phase ("in" | "out").
|
|
15
|
+
* @param duration - Duration of the zoom animation.
|
|
16
|
+
* @param intensity - Zoom scale multiplier (default: 1.5).
|
|
17
|
+
*/
|
|
18
|
+
export const PhotoZoomAnimation = {
|
|
19
|
+
name: "photo-zoom",
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Generator function controlling the photo zoom animation.
|
|
23
|
+
*/
|
|
24
|
+
*run({
|
|
25
|
+
elementRef,
|
|
26
|
+
containerRef,
|
|
27
|
+
mode,
|
|
28
|
+
duration,
|
|
29
|
+
intensity = 1.5,
|
|
30
|
+
}: AnimationParams) {
|
|
31
|
+
// Only run if a containerRef is provided
|
|
32
|
+
if (containerRef) {
|
|
33
|
+
// Get the element's current scale
|
|
34
|
+
const elementScale = elementRef().scale();
|
|
35
|
+
|
|
36
|
+
if (mode === "in") {
|
|
37
|
+
// Instantly set to zoomed-in scale
|
|
38
|
+
yield elementRef().scale(
|
|
39
|
+
new Vector2(
|
|
40
|
+
elementScale.x * intensity,
|
|
41
|
+
elementScale.y * intensity
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
// Smoothly scale back to original size over 'duration'
|
|
45
|
+
yield* elementRef().scale(
|
|
46
|
+
new Vector2(
|
|
47
|
+
elementScale.x,
|
|
48
|
+
elementScale.y
|
|
49
|
+
),
|
|
50
|
+
duration
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (mode === "out") {
|
|
55
|
+
// Start at original scale
|
|
56
|
+
elementRef().scale(
|
|
57
|
+
new Vector2(
|
|
58
|
+
elementScale.x,
|
|
59
|
+
elementScale.y
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
// Smoothly scale up to zoomed-in scale over 'duration'
|
|
63
|
+
yield* elementRef().scale(
|
|
64
|
+
new Vector2(
|
|
65
|
+
elementScale.x * intensity,
|
|
66
|
+
elementScale.y * intensity
|
|
67
|
+
),
|
|
68
|
+
duration
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
package/src/animations/rise.tsx
CHANGED
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
import { all, waitFor, delay } from "@twick/core";
|
|
2
|
-
import { AnimationParams } from "../helpers/types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* RiseAnimation combines vertical motion and opacity transitions
|
|
6
|
-
* to create a "rising" (or "falling") appearance/disappearance effect.
|
|
7
|
-
*
|
|
8
|
-
* Available animation modes:
|
|
9
|
-
* - "enter": Starts offset and transparent, moves into position while fading in.
|
|
10
|
-
* - "exit": Waits, then moves out of position while fading out.
|
|
11
|
-
* - "both": Enters, waits, and exits in a continuous sequence.
|
|
12
|
-
*
|
|
13
|
-
* @param elementRef - Reference to the main element to animate.
|
|
14
|
-
* @param containerRef - Optional reference to a container element.
|
|
15
|
-
* @param interval - Duration of movement and opacity transitions (default: 0.25).
|
|
16
|
-
* @param duration - Total duration of the animation.
|
|
17
|
-
* @param animate - Animation phase ("enter" | "exit" | "both").
|
|
18
|
-
* @param direction - Direction to animate ("up" or "down").
|
|
19
|
-
* @param intensity - Number of units to offset position vertically (default: 200).
|
|
20
|
-
*/
|
|
21
|
-
export const RiseAnimation = {
|
|
22
|
-
name: "rise",
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Generator function controlling the rise/fall animation.
|
|
26
|
-
*/
|
|
27
|
-
*run({
|
|
28
|
-
elementRef,
|
|
29
|
-
containerRef,
|
|
30
|
-
interval = 0.25,
|
|
31
|
-
duration,
|
|
32
|
-
animate,
|
|
33
|
-
direction,
|
|
34
|
-
intensity = 200,
|
|
35
|
-
}: AnimationParams) {
|
|
36
|
-
// Use containerRef if provided, otherwise fallback to elementRef
|
|
37
|
-
const ref = containerRef ?? elementRef;
|
|
38
|
-
|
|
39
|
-
// Get the element's current position
|
|
40
|
-
const pos = ref().position();
|
|
41
|
-
|
|
42
|
-
let animationInterval = Math.min(interval, duration);
|
|
43
|
-
|
|
44
|
-
if (animate === "enter") {
|
|
45
|
-
// Start fully transparent
|
|
46
|
-
ref().opacity(0);
|
|
47
|
-
|
|
48
|
-
if (direction === "up") {
|
|
49
|
-
// Offset element below final position
|
|
50
|
-
ref().y(pos.y + intensity);
|
|
51
|
-
// Animate moving up while fading in
|
|
52
|
-
yield* all(
|
|
53
|
-
ref().opacity(1, animationInterval / 4),
|
|
54
|
-
ref().y(pos.y, animationInterval)
|
|
55
|
-
);
|
|
56
|
-
} else if (direction === "down") {
|
|
57
|
-
// Offset element above final position
|
|
58
|
-
ref().y(pos.y - intensity);
|
|
59
|
-
// Animate moving down while fading in
|
|
60
|
-
yield* all(
|
|
61
|
-
ref().opacity(1, animationInterval / 4),
|
|
62
|
-
ref().y(pos.y, animationInterval)
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
} else if (animate === "exit") {
|
|
66
|
-
// Wait until exit animation starts
|
|
67
|
-
yield* waitFor(duration - animationInterval);
|
|
68
|
-
|
|
69
|
-
if (direction === "up") {
|
|
70
|
-
// Animate moving up while fading out (opacity fades slightly after motion starts)
|
|
71
|
-
yield* all(
|
|
72
|
-
delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
|
|
73
|
-
ref().y(pos.y - intensity, animationInterval)
|
|
74
|
-
);
|
|
75
|
-
} else if (direction === "down") {
|
|
76
|
-
// Animate moving down while fading out
|
|
77
|
-
yield* all(
|
|
78
|
-
delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
|
|
79
|
-
ref().y(pos.y + intensity, animationInterval)
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
} else if (animate === "both") {
|
|
83
|
-
animationInterval = Math.min(interval, duration/2);
|
|
84
|
-
// Start fully transparent
|
|
85
|
-
ref().opacity(0);
|
|
86
|
-
|
|
87
|
-
if (direction === "up") {
|
|
88
|
-
// Enter animation: move up while fading in
|
|
89
|
-
ref().y(pos.y + intensity);
|
|
90
|
-
yield* all(
|
|
91
|
-
ref().opacity(1, animationInterval / 4),
|
|
92
|
-
ref().y(pos.y, animationInterval)
|
|
93
|
-
);
|
|
94
|
-
// Wait for the remaining duration
|
|
95
|
-
yield* waitFor(duration - animationInterval);
|
|
96
|
-
// Exit animation: move up further while fading out
|
|
97
|
-
yield* all(
|
|
98
|
-
delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
|
|
99
|
-
ref().y(pos.y - intensity, animationInterval)
|
|
100
|
-
);
|
|
101
|
-
} else if (direction === "down") {
|
|
102
|
-
// Enter animation: move down while fading in
|
|
103
|
-
ref().y(pos.y - intensity);
|
|
104
|
-
yield* all(
|
|
105
|
-
ref().opacity(1, animationInterval / 4),
|
|
106
|
-
ref().y(pos.y, animationInterval)
|
|
107
|
-
);
|
|
108
|
-
// Wait for the remaining duration
|
|
109
|
-
yield* waitFor(duration - animationInterval);
|
|
110
|
-
// Exit animation: move down further while fading out
|
|
111
|
-
yield* all(
|
|
112
|
-
delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
|
|
113
|
-
ref().y(pos.y + intensity, animationInterval)
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
};
|
|
1
|
+
import { all, waitFor, delay } from "@twick/core";
|
|
2
|
+
import { AnimationParams } from "../helpers/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* RiseAnimation combines vertical motion and opacity transitions
|
|
6
|
+
* to create a "rising" (or "falling") appearance/disappearance effect.
|
|
7
|
+
*
|
|
8
|
+
* Available animation modes:
|
|
9
|
+
* - "enter": Starts offset and transparent, moves into position while fading in.
|
|
10
|
+
* - "exit": Waits, then moves out of position while fading out.
|
|
11
|
+
* - "both": Enters, waits, and exits in a continuous sequence.
|
|
12
|
+
*
|
|
13
|
+
* @param elementRef - Reference to the main element to animate.
|
|
14
|
+
* @param containerRef - Optional reference to a container element.
|
|
15
|
+
* @param interval - Duration of movement and opacity transitions (default: 0.25).
|
|
16
|
+
* @param duration - Total duration of the animation.
|
|
17
|
+
* @param animate - Animation phase ("enter" | "exit" | "both").
|
|
18
|
+
* @param direction - Direction to animate ("up" or "down").
|
|
19
|
+
* @param intensity - Number of units to offset position vertically (default: 200).
|
|
20
|
+
*/
|
|
21
|
+
export const RiseAnimation = {
|
|
22
|
+
name: "rise",
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Generator function controlling the rise/fall animation.
|
|
26
|
+
*/
|
|
27
|
+
*run({
|
|
28
|
+
elementRef,
|
|
29
|
+
containerRef,
|
|
30
|
+
interval = 0.25,
|
|
31
|
+
duration,
|
|
32
|
+
animate,
|
|
33
|
+
direction,
|
|
34
|
+
intensity = 200,
|
|
35
|
+
}: AnimationParams) {
|
|
36
|
+
// Use containerRef if provided, otherwise fallback to elementRef
|
|
37
|
+
const ref = containerRef ?? elementRef;
|
|
38
|
+
|
|
39
|
+
// Get the element's current position
|
|
40
|
+
const pos = ref().position();
|
|
41
|
+
|
|
42
|
+
let animationInterval = Math.min(interval, duration);
|
|
43
|
+
|
|
44
|
+
if (animate === "enter") {
|
|
45
|
+
// Start fully transparent
|
|
46
|
+
ref().opacity(0);
|
|
47
|
+
|
|
48
|
+
if (direction === "up") {
|
|
49
|
+
// Offset element below final position
|
|
50
|
+
ref().y(pos.y + intensity);
|
|
51
|
+
// Animate moving up while fading in
|
|
52
|
+
yield* all(
|
|
53
|
+
ref().opacity(1, animationInterval / 4),
|
|
54
|
+
ref().y(pos.y, animationInterval)
|
|
55
|
+
);
|
|
56
|
+
} else if (direction === "down") {
|
|
57
|
+
// Offset element above final position
|
|
58
|
+
ref().y(pos.y - intensity);
|
|
59
|
+
// Animate moving down while fading in
|
|
60
|
+
yield* all(
|
|
61
|
+
ref().opacity(1, animationInterval / 4),
|
|
62
|
+
ref().y(pos.y, animationInterval)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
} else if (animate === "exit") {
|
|
66
|
+
// Wait until exit animation starts
|
|
67
|
+
yield* waitFor(duration - animationInterval);
|
|
68
|
+
|
|
69
|
+
if (direction === "up") {
|
|
70
|
+
// Animate moving up while fading out (opacity fades slightly after motion starts)
|
|
71
|
+
yield* all(
|
|
72
|
+
delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
|
|
73
|
+
ref().y(pos.y - intensity, animationInterval)
|
|
74
|
+
);
|
|
75
|
+
} else if (direction === "down") {
|
|
76
|
+
// Animate moving down while fading out
|
|
77
|
+
yield* all(
|
|
78
|
+
delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
|
|
79
|
+
ref().y(pos.y + intensity, animationInterval)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
} else if (animate === "both") {
|
|
83
|
+
animationInterval = Math.min(interval, duration/2);
|
|
84
|
+
// Start fully transparent
|
|
85
|
+
ref().opacity(0);
|
|
86
|
+
|
|
87
|
+
if (direction === "up") {
|
|
88
|
+
// Enter animation: move up while fading in
|
|
89
|
+
ref().y(pos.y + intensity);
|
|
90
|
+
yield* all(
|
|
91
|
+
ref().opacity(1, animationInterval / 4),
|
|
92
|
+
ref().y(pos.y, animationInterval)
|
|
93
|
+
);
|
|
94
|
+
// Wait for the remaining duration
|
|
95
|
+
yield* waitFor(duration - animationInterval);
|
|
96
|
+
// Exit animation: move up further while fading out
|
|
97
|
+
yield* all(
|
|
98
|
+
delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
|
|
99
|
+
ref().y(pos.y - intensity, animationInterval)
|
|
100
|
+
);
|
|
101
|
+
} else if (direction === "down") {
|
|
102
|
+
// Enter animation: move down while fading in
|
|
103
|
+
ref().y(pos.y - intensity);
|
|
104
|
+
yield* all(
|
|
105
|
+
ref().opacity(1, animationInterval / 4),
|
|
106
|
+
ref().y(pos.y, animationInterval)
|
|
107
|
+
);
|
|
108
|
+
// Wait for the remaining duration
|
|
109
|
+
yield* waitFor(duration - animationInterval);
|
|
110
|
+
// Exit animation: move down further while fading out
|
|
111
|
+
yield* all(
|
|
112
|
+
delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
|
|
113
|
+
ref().y(pos.y + intensity, animationInterval)
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
};
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { all, delay, Vector2, waitFor } from "@twick/core";
|
|
2
|
-
import { AnimationParams } from "../helpers/types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* SuccessionAnimation combines scaling and opacity transitions
|
|
6
|
-
* to create an appearing and disappearing zoom effect.
|
|
7
|
-
*
|
|
8
|
-
* Available animation modes:
|
|
9
|
-
* - "enter": Starts scaled down and transparent, then scales up while fading in.
|
|
10
|
-
* - "exit": Waits, then scales down while fading out.
|
|
11
|
-
* - "both": Scales up and fades in, waits, then scales down and fades out.
|
|
12
|
-
*
|
|
13
|
-
* @param elementRef - Reference to the main element to animate.
|
|
14
|
-
* @param containerRef - Optional reference to a container element.
|
|
15
|
-
* @param interval - Duration of scaling and opacity transitions.
|
|
16
|
-
* @param duration - Total duration of the animation.
|
|
17
|
-
* @param animate - Animation phase ("enter" | "exit" | "both").
|
|
18
|
-
*/
|
|
19
|
-
export const SuccessionAnimation = {
|
|
20
|
-
name: "succession",
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Generator function controlling the succession animation.
|
|
24
|
-
*/
|
|
25
|
-
*run({
|
|
26
|
-
elementRef,
|
|
27
|
-
containerRef,
|
|
28
|
-
interval,
|
|
29
|
-
duration,
|
|
30
|
-
animate,
|
|
31
|
-
}: AnimationParams) {
|
|
32
|
-
// Use containerRef if provided, otherwise fallback to elementRef
|
|
33
|
-
const ref = containerRef ?? elementRef;
|
|
34
|
-
|
|
35
|
-
// Capture the element's original scale
|
|
36
|
-
const scale = ref().scale();
|
|
37
|
-
|
|
38
|
-
let animationInterval = Math.min(interval, duration);
|
|
39
|
-
if (animate === "enter") {
|
|
40
|
-
// Start fully transparent and scaled down to 50%
|
|
41
|
-
ref().opacity(0);
|
|
42
|
-
ref().scale(new Vector2(scale.x / 2, scale.y / 2));
|
|
43
|
-
// Animate scaling up to original size and fading in
|
|
44
|
-
yield* all(
|
|
45
|
-
ref().scale(scale, animationInterval),
|
|
46
|
-
ref().opacity(1, animationInterval / 2)
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
} else if (animate === "exit") {
|
|
50
|
-
// Wait until exit animation should start
|
|
51
|
-
yield* waitFor(duration - animationInterval);
|
|
52
|
-
// Animate scaling down to 50% and fading out (opacity starts after half the interval)
|
|
53
|
-
yield* all(
|
|
54
|
-
ref().scale(new Vector2(scale.x / 2, scale.y / 2), animationInterval),
|
|
55
|
-
delay(animationInterval / 2, ref().opacity(0, animationInterval / 2))
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
} else if (animate === "both") {
|
|
59
|
-
animationInterval = Math.min(interval, duration/2);
|
|
60
|
-
// Start fully transparent and scaled down to 50%
|
|
61
|
-
ref().opacity(0);
|
|
62
|
-
ref().scale(new Vector2(scale.x / 2, scale.y / 2));
|
|
63
|
-
// Animate scaling up and fading in
|
|
64
|
-
yield* all(
|
|
65
|
-
ref().scale(scale, animationInterval),
|
|
66
|
-
ref().opacity(1, animationInterval / 2)
|
|
67
|
-
);
|
|
68
|
-
// Wait for the remaining duration
|
|
69
|
-
yield* waitFor(duration - animationInterval);
|
|
70
|
-
// Animate scaling down and fading out
|
|
71
|
-
yield* all(
|
|
72
|
-
ref().scale(new Vector2(scale.x / 2, scale.y / 2), animationInterval),
|
|
73
|
-
delay(animationInterval / 2, ref().opacity(0, animationInterval / 2))
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
};
|
|
1
|
+
import { all, delay, Vector2, waitFor } from "@twick/core";
|
|
2
|
+
import { AnimationParams } from "../helpers/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SuccessionAnimation combines scaling and opacity transitions
|
|
6
|
+
* to create an appearing and disappearing zoom effect.
|
|
7
|
+
*
|
|
8
|
+
* Available animation modes:
|
|
9
|
+
* - "enter": Starts scaled down and transparent, then scales up while fading in.
|
|
10
|
+
* - "exit": Waits, then scales down while fading out.
|
|
11
|
+
* - "both": Scales up and fades in, waits, then scales down and fades out.
|
|
12
|
+
*
|
|
13
|
+
* @param elementRef - Reference to the main element to animate.
|
|
14
|
+
* @param containerRef - Optional reference to a container element.
|
|
15
|
+
* @param interval - Duration of scaling and opacity transitions.
|
|
16
|
+
* @param duration - Total duration of the animation.
|
|
17
|
+
* @param animate - Animation phase ("enter" | "exit" | "both").
|
|
18
|
+
*/
|
|
19
|
+
export const SuccessionAnimation = {
|
|
20
|
+
name: "succession",
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Generator function controlling the succession animation.
|
|
24
|
+
*/
|
|
25
|
+
*run({
|
|
26
|
+
elementRef,
|
|
27
|
+
containerRef,
|
|
28
|
+
interval,
|
|
29
|
+
duration,
|
|
30
|
+
animate,
|
|
31
|
+
}: AnimationParams) {
|
|
32
|
+
// Use containerRef if provided, otherwise fallback to elementRef
|
|
33
|
+
const ref = containerRef ?? elementRef;
|
|
34
|
+
|
|
35
|
+
// Capture the element's original scale
|
|
36
|
+
const scale = ref().scale();
|
|
37
|
+
|
|
38
|
+
let animationInterval = Math.min(interval, duration);
|
|
39
|
+
if (animate === "enter") {
|
|
40
|
+
// Start fully transparent and scaled down to 50%
|
|
41
|
+
ref().opacity(0);
|
|
42
|
+
ref().scale(new Vector2(scale.x / 2, scale.y / 2));
|
|
43
|
+
// Animate scaling up to original size and fading in
|
|
44
|
+
yield* all(
|
|
45
|
+
ref().scale(scale, animationInterval),
|
|
46
|
+
ref().opacity(1, animationInterval / 2)
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
} else if (animate === "exit") {
|
|
50
|
+
// Wait until exit animation should start
|
|
51
|
+
yield* waitFor(duration - animationInterval);
|
|
52
|
+
// Animate scaling down to 50% and fading out (opacity starts after half the interval)
|
|
53
|
+
yield* all(
|
|
54
|
+
ref().scale(new Vector2(scale.x / 2, scale.y / 2), animationInterval),
|
|
55
|
+
delay(animationInterval / 2, ref().opacity(0, animationInterval / 2))
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
} else if (animate === "both") {
|
|
59
|
+
animationInterval = Math.min(interval, duration/2);
|
|
60
|
+
// Start fully transparent and scaled down to 50%
|
|
61
|
+
ref().opacity(0);
|
|
62
|
+
ref().scale(new Vector2(scale.x / 2, scale.y / 2));
|
|
63
|
+
// Animate scaling up and fading in
|
|
64
|
+
yield* all(
|
|
65
|
+
ref().scale(scale, animationInterval),
|
|
66
|
+
ref().opacity(1, animationInterval / 2)
|
|
67
|
+
);
|
|
68
|
+
// Wait for the remaining duration
|
|
69
|
+
yield* waitFor(duration - animationInterval);
|
|
70
|
+
// Animate scaling down and fading out
|
|
71
|
+
yield* all(
|
|
72
|
+
ref().scale(new Vector2(scale.x / 2, scale.y / 2), animationInterval),
|
|
73
|
+
delay(animationInterval / 2, ref().opacity(0, animationInterval / 2))
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
};
|