@twick/visualizer 0.14.2 → 0.14.4
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/README.md +104 -4
- package/package.json +8 -8
- package/package.json.bak +8 -8
- package/src/animations/blur.tsx +47 -11
- package/src/animations/breathe.tsx +44 -9
- package/src/animations/fade.tsx +126 -13
- package/src/animations/index.ts +12 -0
- package/src/animations/photo-rise.tsx +48 -11
- package/src/animations/photo-zoom.tsx +45 -9
- package/src/animations/rise.tsx +52 -13
- package/src/animations/succession.tsx +45 -10
- package/src/elements/audio.element.tsx +63 -1
- package/src/elements/caption.element.tsx +82 -0
- package/src/elements/circle.element.tsx +70 -2
- package/src/elements/icon.element.tsx +70 -2
- package/src/elements/image.element.tsx +81 -0
- package/src/elements/index.ts +14 -0
- package/src/elements/rect.element.tsx +72 -2
- package/src/elements/scene.element.tsx +87 -19
- package/src/elements/text.element.tsx +74 -0
- package/src/elements/video.element.tsx +220 -1
- package/src/frame-effects/circle.frame.tsx +77 -12
- package/src/frame-effects/index.ts +7 -0
- package/src/frame-effects/rect.frame.tsx +108 -13
- package/src/helpers/element.utils.ts +100 -8
- package/src/helpers/event.utils.ts +15 -0
- package/src/helpers/log.utils.ts +37 -11
- package/src/helpers/types.ts +119 -0
- package/src/helpers/utils.ts +17 -0
- package/src/index.ts +190 -0
- package/src/text-effects/elastic.tsx +39 -8
- package/src/text-effects/erase.tsx +42 -9
- package/src/text-effects/index.ts +9 -0
- package/src/text-effects/stream-word.tsx +43 -9
- package/src/text-effects/typewriter.tsx +43 -9
- package/src/visualizer-grouped.ts +83 -0
- package/src/visualizer.tsx +89 -5
- package/typedoc.json +8 -3
|
@@ -6,24 +6,92 @@ import { ImageElement } from "./image.element";
|
|
|
6
6
|
import { VideoElement } from "./video.element";
|
|
7
7
|
import { logger } from "../helpers/log.utils";
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @group SceneElement
|
|
11
|
+
* SceneElement creates and manages scene container elements in the visualizer.
|
|
12
|
+
* Handles scene setup, background configuration, and container management
|
|
13
|
+
* for organizing visual content and elements.
|
|
14
|
+
*
|
|
15
|
+
* Features:
|
|
16
|
+
* - Scene container creation and management
|
|
17
|
+
* - Background and environment setup
|
|
18
|
+
* - Element organization and grouping
|
|
19
|
+
* - Scene-level animations and effects
|
|
20
|
+
*
|
|
21
|
+
* @param containerRef - Reference to the container element
|
|
22
|
+
* @param element - Scene element configuration and properties
|
|
23
|
+
* @param view - The main scene view for rendering
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* // Basic scene element
|
|
28
|
+
* {
|
|
29
|
+
* id: "main-scene",
|
|
30
|
+
* type: "scene",
|
|
31
|
+
* s: 0,
|
|
32
|
+
* e: 30,
|
|
33
|
+
* props: {
|
|
34
|
+
* backgroundColor: "#000000",
|
|
35
|
+
* width: 1920,
|
|
36
|
+
* height: 1080
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* // Scene with background and effects
|
|
41
|
+
* {
|
|
42
|
+
* id: "animated-scene",
|
|
43
|
+
* type: "scene",
|
|
44
|
+
* s: 0,
|
|
45
|
+
* e: 60,
|
|
46
|
+
* props: {
|
|
47
|
+
* backgroundColor: "linear-gradient(45deg, #ff0000, #00ff00)",
|
|
48
|
+
* width: 1920,
|
|
49
|
+
* height: 1080,
|
|
50
|
+
* opacity: 0.9
|
|
51
|
+
* },
|
|
52
|
+
* animation: {
|
|
53
|
+
* name: "fade",
|
|
54
|
+
* animate: "enter",
|
|
55
|
+
* duration: 3
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
9
60
|
export const SceneElement = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
61
|
+
name: "scene",
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Generator function that creates and manages scene elements.
|
|
65
|
+
* Handles scene creation, setup, and cleanup.
|
|
66
|
+
*
|
|
67
|
+
* @param params - Element parameters including container reference, element config, and view
|
|
68
|
+
* @returns Generator that controls the scene element lifecycle
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```js
|
|
72
|
+
* yield* SceneElement.create({
|
|
73
|
+
* containerRef: mainContainer,
|
|
74
|
+
* element: sceneConfig,
|
|
75
|
+
* view: sceneView
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
*create({ containerRef, element, view }: ElementParams) {
|
|
80
|
+
yield* waitFor(element?.s);
|
|
81
|
+
const mediaContainerRef = createRef<any>();
|
|
82
|
+
logger(`SceneElement: ${JSON.stringify(element)}`);
|
|
83
|
+
yield containerRef().add(
|
|
84
|
+
<Rect
|
|
85
|
+
ref={mediaContainerRef}
|
|
86
|
+
fill={element.backgroundColor ?? DEFAULT_BACKGROUND_COLOR}
|
|
87
|
+
size={"100%"}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
if (element.type === ELEMENT_TYPES.IMAGE) {
|
|
91
|
+
yield* ImageElement.create({ containerRef, element, view });
|
|
92
|
+
} else if (element.type === ELEMENT_TYPES.VIDEO) {
|
|
93
|
+
yield* VideoElement.create({ containerRef, element, view });
|
|
94
|
+
}
|
|
95
|
+
yield mediaContainerRef().remove();
|
|
96
|
+
},
|
|
29
97
|
};
|
|
@@ -2,9 +2,83 @@ import { ElementParams } from "../helpers/types";
|
|
|
2
2
|
import { all, createRef, waitFor } from "@twick/core";
|
|
3
3
|
import { Txt } from "@twick/2d";
|
|
4
4
|
import { addAnimation, addTextEffect } from "../helpers/element.utils";
|
|
5
|
+
import { logger } from "../helpers/log.utils";
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @group TextElement
|
|
9
|
+
* TextElement creates and manages text content in the visualizer scene.
|
|
10
|
+
* Handles text rendering, animations, and text effects for dynamic
|
|
11
|
+
* text presentations and content creation.
|
|
12
|
+
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - Text rendering with custom styling and fonts
|
|
15
|
+
* - Text animations and effects
|
|
16
|
+
* - Timing control and synchronization
|
|
17
|
+
* - Automatic cleanup and resource management
|
|
18
|
+
*
|
|
19
|
+
* @param containerRef - Reference to the container element
|
|
20
|
+
* @param element - Text element configuration and properties
|
|
21
|
+
* @param view - The main scene view for rendering
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```js
|
|
25
|
+
* // Basic text element
|
|
26
|
+
* {
|
|
27
|
+
* id: "welcome-text",
|
|
28
|
+
* type: "text",
|
|
29
|
+
* s: 0,
|
|
30
|
+
* e: 10,
|
|
31
|
+
* t: "Welcome to our presentation!",
|
|
32
|
+
* props: {
|
|
33
|
+
* fill: "#ffffff",
|
|
34
|
+
* fontSize: 48,
|
|
35
|
+
* fontFamily: "Arial"
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* // Text with animation and effects
|
|
40
|
+
* {
|
|
41
|
+
* id: "animated-text",
|
|
42
|
+
* type: "text",
|
|
43
|
+
* s: 2,
|
|
44
|
+
* e: 15,
|
|
45
|
+
* t: "Animated text content",
|
|
46
|
+
* props: {
|
|
47
|
+
* fill: "#ff0000",
|
|
48
|
+
* fontSize: 36,
|
|
49
|
+
* fontFamily: "Helvetica"
|
|
50
|
+
* },
|
|
51
|
+
* animation: {
|
|
52
|
+
* name: "fade",
|
|
53
|
+
* animate: "enter",
|
|
54
|
+
* duration: 2
|
|
55
|
+
* },
|
|
56
|
+
* textEffect: {
|
|
57
|
+
* name: "typewriter",
|
|
58
|
+
* duration: 3
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
6
63
|
export const TextElement = {
|
|
7
64
|
name: "text",
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Generator function that creates and manages text elements in the scene.
|
|
68
|
+
* Handles text creation, animations, effects, and cleanup.
|
|
69
|
+
*
|
|
70
|
+
* @param params - Element parameters including container reference, element config, and view
|
|
71
|
+
* @returns Generator that controls the text element lifecycle
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```js
|
|
75
|
+
* yield* TextElement.create({
|
|
76
|
+
* containerRef: mainContainer,
|
|
77
|
+
* element: textConfig,
|
|
78
|
+
* view: sceneView
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
8
82
|
*create({ containerRef, element, view }: ElementParams) {
|
|
9
83
|
const elementRef = createRef<any>();
|
|
10
84
|
|
|
@@ -1,11 +1,230 @@
|
|
|
1
1
|
import { ElementParams } from "../helpers/types";
|
|
2
2
|
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
-
import {
|
|
3
|
+
import { Video, Rect } from "@twick/2d";
|
|
4
4
|
import { addAnimation, addFrameEffect, fitElement } from "../helpers/element.utils";
|
|
5
5
|
import { applyColorFilter } from "../helpers/filters";
|
|
6
|
+
import { logger } from "../helpers/log.utils";
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @group VideoElement
|
|
10
|
+
* @description Professional video content management with effects and animations
|
|
11
|
+
*
|
|
12
|
+
* VideoElement creates and manages video content in the visualizer scene.
|
|
13
|
+
* Handles video playback, frame effects, animations, and content fitting
|
|
14
|
+
* for professional video presentations and content creation.
|
|
15
|
+
*
|
|
16
|
+
* ## Key Features
|
|
17
|
+
*
|
|
18
|
+
* - **Video playback** with start/end timing control
|
|
19
|
+
* - **Frame effects** and animations for visual enhancement
|
|
20
|
+
* - **Object fit options** for content scaling (contain, cover, fill, none)
|
|
21
|
+
* - **Color filters** and media effects for artistic styling
|
|
22
|
+
* - **Automatic cleanup** and resource management
|
|
23
|
+
* - **Synchronization** with other scene elements
|
|
24
|
+
*
|
|
25
|
+
* ## Use Cases
|
|
26
|
+
*
|
|
27
|
+
* - **Main content videos**: Primary video content with effects
|
|
28
|
+
* - **Background videos**: Ambient video backgrounds
|
|
29
|
+
* - **Video overlays**: Picture-in-picture style content
|
|
30
|
+
* - **Video transitions**: Smooth scene-to-scene transitions
|
|
31
|
+
* - **Video effects**: Artistic and creative video manipulation
|
|
32
|
+
*
|
|
33
|
+
* ## Best Practices
|
|
34
|
+
*
|
|
35
|
+
* - **Format**: Use MP4 with H.264 encoding for best compatibility
|
|
36
|
+
* - **Resolution**: Match scene dimensions or use appropriate object-fit
|
|
37
|
+
* - **Performance**: Optimize video files for web delivery
|
|
38
|
+
* - **Timing**: Set precise start/end times for synchronization
|
|
39
|
+
* - **Effects**: Combine with animations and frame effects for impact
|
|
40
|
+
*
|
|
41
|
+
* ## Integration Examples
|
|
42
|
+
*
|
|
43
|
+
* ### Basic Video Element
|
|
44
|
+
* ```js
|
|
45
|
+
* {
|
|
46
|
+
* id: "main-video",
|
|
47
|
+
* type: "video",
|
|
48
|
+
* s: 0, e: 15,
|
|
49
|
+
* props: {
|
|
50
|
+
* src: "video.mp4",
|
|
51
|
+
* width: 1920,
|
|
52
|
+
* height: 1080
|
|
53
|
+
* },
|
|
54
|
+
* objectFit: "cover"
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* ### Video with Animation
|
|
59
|
+
* ```js
|
|
60
|
+
* {
|
|
61
|
+
* id: "intro-video",
|
|
62
|
+
* type: "video",
|
|
63
|
+
* s: 0, e: 10,
|
|
64
|
+
* props: { src: "intro.mp4" },
|
|
65
|
+
* animation: {
|
|
66
|
+
* name: "fade",
|
|
67
|
+
* animate: "enter",
|
|
68
|
+
* duration: 2
|
|
69
|
+
* },
|
|
70
|
+
* objectFit: "contain"
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* ### Video with Frame Effect
|
|
75
|
+
* ```js
|
|
76
|
+
* {
|
|
77
|
+
* id: "framed-video",
|
|
78
|
+
* type: "video",
|
|
79
|
+
* s: 2, e: 20,
|
|
80
|
+
* props: { src: "content.mp4" },
|
|
81
|
+
* frameEffects: [{
|
|
82
|
+
* name: "circle",
|
|
83
|
+
* s: 2, e: 20,
|
|
84
|
+
* props: {
|
|
85
|
+
* frameSize: [500, 500],
|
|
86
|
+
* frameShape: "circle",
|
|
87
|
+
* framePosition: { x: 960, y: 540 },
|
|
88
|
+
* radius: 250,
|
|
89
|
+
* objectFit: "cover",
|
|
90
|
+
* transitionDuration: 1.5
|
|
91
|
+
* }
|
|
92
|
+
* }]
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* ### Complex Video Scene
|
|
97
|
+
* ```js
|
|
98
|
+
* // Multi-track video scene with overlays
|
|
99
|
+
* const videoScene = {
|
|
100
|
+
* backgroundColor: "#000000",
|
|
101
|
+
* playerId: "video-player",
|
|
102
|
+
* properties: { width: 1920, height: 1080 },
|
|
103
|
+
* tracks: [
|
|
104
|
+
* {
|
|
105
|
+
* id: "background",
|
|
106
|
+
* type: "video",
|
|
107
|
+
* elements: [{
|
|
108
|
+
* id: "bg-video",
|
|
109
|
+
* type: "video",
|
|
110
|
+
* s: 0, e: 30,
|
|
111
|
+
* props: { src: "background.mp4", opacity: 0.3 },
|
|
112
|
+
* objectFit: "cover"
|
|
113
|
+
* }]
|
|
114
|
+
* },
|
|
115
|
+
* {
|
|
116
|
+
* id: "main-content",
|
|
117
|
+
* type: "video",
|
|
118
|
+
* elements: [
|
|
119
|
+
* {
|
|
120
|
+
* id: "main-video",
|
|
121
|
+
* type: "video",
|
|
122
|
+
* s: 2, e: 25,
|
|
123
|
+
* props: { src: "main-content.mp4" },
|
|
124
|
+
* animation: {
|
|
125
|
+
* name: "fade",
|
|
126
|
+
* animate: "enter",
|
|
127
|
+
* duration: 2
|
|
128
|
+
* },
|
|
129
|
+
* frameEffects: [{
|
|
130
|
+
* name: "rect",
|
|
131
|
+
* s: 2, e: 25,
|
|
132
|
+
* props: {
|
|
133
|
+
* frameSize: [800, 600],
|
|
134
|
+
* frameShape: "rect",
|
|
135
|
+
* framePosition: { x: 960, y: 540 },
|
|
136
|
+
* radius: 20,
|
|
137
|
+
* objectFit: "cover"
|
|
138
|
+
* }
|
|
139
|
+
* }]
|
|
140
|
+
* },
|
|
141
|
+
* {
|
|
142
|
+
* id: "video-caption",
|
|
143
|
+
* type: "caption",
|
|
144
|
+
* s: 5, e: 20,
|
|
145
|
+
* t: "Video Caption",
|
|
146
|
+
* props: {
|
|
147
|
+
* colors: { text: "#ffffff", background: "rgba(0,0,0,0.7)" },
|
|
148
|
+
* font: { family: "Arial", size: 36, weight: 600 }
|
|
149
|
+
* }
|
|
150
|
+
* }
|
|
151
|
+
* ]
|
|
152
|
+
* }
|
|
153
|
+
* ]
|
|
154
|
+
* };
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* ## 🚀 Performance Tips
|
|
158
|
+
*
|
|
159
|
+
* - **Preload videos** for smooth playback
|
|
160
|
+
* - **Use appropriate object-fit** to avoid unnecessary scaling
|
|
161
|
+
* - **Optimize video files** for web delivery (compression, format)
|
|
162
|
+
* - **Batch frame effects** for better performance
|
|
163
|
+
* - **Monitor memory usage** with multiple video elements
|
|
164
|
+
*
|
|
165
|
+
* @param containerRef - Reference to the container element
|
|
166
|
+
* @param element - Video element configuration and properties
|
|
167
|
+
* @param view - The main scene view for rendering
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```js
|
|
171
|
+
* // Basic video element
|
|
172
|
+
* {
|
|
173
|
+
* id: "main-video",
|
|
174
|
+
* type: "video",
|
|
175
|
+
* s: 0, e: 15,
|
|
176
|
+
* props: {
|
|
177
|
+
* src: "video.mp4",
|
|
178
|
+
* width: 1920,
|
|
179
|
+
* height: 1080
|
|
180
|
+
* },
|
|
181
|
+
* objectFit: "cover"
|
|
182
|
+
* }
|
|
183
|
+
*
|
|
184
|
+
* // Video with frame effect and animation
|
|
185
|
+
* {
|
|
186
|
+
* id: "framed-video",
|
|
187
|
+
* type: "video",
|
|
188
|
+
* s: 2, e: 20,
|
|
189
|
+
* props: { src: "content.mp4" },
|
|
190
|
+
* animation: {
|
|
191
|
+
* name: "fade",
|
|
192
|
+
* animate: "enter",
|
|
193
|
+
* duration: 2
|
|
194
|
+
* },
|
|
195
|
+
* frameEffects: [{
|
|
196
|
+
* name: "circle",
|
|
197
|
+
* s: 2, e: 20,
|
|
198
|
+
* props: {
|
|
199
|
+
* frameSize: [500, 500],
|
|
200
|
+
* frameShape: "circle",
|
|
201
|
+
* framePosition: { x: 960, y: 540 },
|
|
202
|
+
* radius: 250,
|
|
203
|
+
* objectFit: "cover"
|
|
204
|
+
* }
|
|
205
|
+
* }]
|
|
206
|
+
* }
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
7
209
|
export const VideoElement = {
|
|
8
210
|
name: "video",
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Generator function that creates and manages video elements in the scene.
|
|
214
|
+
* Handles video creation, frame setup, animations, effects, and cleanup.
|
|
215
|
+
*
|
|
216
|
+
* @param params - Element parameters including container reference, element config, and view
|
|
217
|
+
* @returns Generator that controls the video element lifecycle
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```js
|
|
221
|
+
* yield* VideoElement.create({
|
|
222
|
+
* containerRef: mainContainer,
|
|
223
|
+
* element: videoConfig,
|
|
224
|
+
* view: sceneView
|
|
225
|
+
* });
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
9
228
|
*create({ containerRef, element, view }: ElementParams) {
|
|
10
229
|
yield* waitFor(element?.s);
|
|
11
230
|
const frameContainerRef = createRef<any>();
|
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* @group CircleFrameEffect
|
|
3
|
+
* CircleFrameEffect animates a frame transitioning into a circular shape,
|
|
4
|
+
* resizing, repositioning, and optionally fitting its content. Creates a
|
|
5
|
+
* circular mask around content perfect for profile pictures and artistic presentations.
|
|
6
|
+
*
|
|
7
|
+
* Behavior:
|
|
8
|
+
* - Waits for the specified start time
|
|
9
|
+
* - Resizes and repositions the frame container smoothly
|
|
10
|
+
* - Animates the corner radius to create a perfect circle
|
|
11
|
+
* - Repositions the content element if needed
|
|
12
|
+
* - Optionally fits the element inside the container based on object-fit
|
|
13
|
+
*
|
|
14
|
+
* @param containerRef - Reference to the frame container element
|
|
15
|
+
* @param elementRef - Reference to the content element inside the frame
|
|
16
|
+
* @param initFrameState - Initial size and position state of the element
|
|
17
|
+
* @param frameEffect - Frame transformation configuration and timing
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```js
|
|
21
|
+
* // Basic circular frame
|
|
22
|
+
* frameEffects: [{
|
|
23
|
+
* name: "circle",
|
|
24
|
+
* s: 0,
|
|
25
|
+
* e: 10,
|
|
26
|
+
* props: {
|
|
27
|
+
* frameSize: [400, 400],
|
|
28
|
+
* frameShape: "circle",
|
|
29
|
+
* framePosition: { x: 960, y: 540 },
|
|
30
|
+
* radius: 200,
|
|
31
|
+
* objectFit: "cover",
|
|
32
|
+
* transitionDuration: 1.5
|
|
33
|
+
* }
|
|
34
|
+
* }]
|
|
35
|
+
* ```
|
|
4
36
|
*/
|
|
5
37
|
|
|
6
38
|
import { all, waitFor } from "@twick/core";
|
|
@@ -14,25 +46,58 @@ import { FrameEffectParams } from "../helpers/types";
|
|
|
14
46
|
|
|
15
47
|
/**
|
|
16
48
|
* CircleFrameEffect animates a frame transitioning into a circular shape,
|
|
17
|
-
* resizing, repositioning, and optionally fitting its content.
|
|
49
|
+
* resizing, repositioning, and optionally fitting its content. Creates a
|
|
50
|
+
* circular mask around content perfect for profile pictures and artistic presentations.
|
|
18
51
|
*
|
|
19
52
|
* Behavior:
|
|
20
|
-
* - Waits for the specified start time
|
|
21
|
-
* - Resizes and repositions the frame container smoothly
|
|
22
|
-
* - Animates the corner radius to create a perfect circle
|
|
23
|
-
* - Repositions the content element if needed
|
|
24
|
-
* - Optionally fits the element inside the container based on object-fit
|
|
53
|
+
* - Waits for the specified start time
|
|
54
|
+
* - Resizes and repositions the frame container smoothly
|
|
55
|
+
* - Animates the corner radius to create a perfect circle
|
|
56
|
+
* - Repositions the content element if needed
|
|
57
|
+
* - Optionally fits the element inside the container based on object-fit
|
|
25
58
|
*
|
|
26
|
-
* @param containerRef - Reference to the frame container element
|
|
27
|
-
* @param elementRef - Reference to the content element inside the frame
|
|
28
|
-
* @param initFrameState - Initial size and position state of the element
|
|
29
|
-
* @param frameEffect - Frame transformation configuration and timing
|
|
59
|
+
* @param containerRef - Reference to the frame container element
|
|
60
|
+
* @param elementRef - Reference to the content element inside the frame
|
|
61
|
+
* @param initFrameState - Initial size and position state of the element
|
|
62
|
+
* @param frameEffect - Frame transformation configuration and timing
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```js
|
|
66
|
+
* // Basic circular frame
|
|
67
|
+
* frameEffects: [{
|
|
68
|
+
* name: "circle",
|
|
69
|
+
* s: 0,
|
|
70
|
+
* e: 10,
|
|
71
|
+
* props: {
|
|
72
|
+
* frameSize: [400, 400],
|
|
73
|
+
* frameShape: "circle",
|
|
74
|
+
* framePosition: { x: 960, y: 540 },
|
|
75
|
+
* radius: 200,
|
|
76
|
+
* objectFit: "cover",
|
|
77
|
+
* transitionDuration: 1.5
|
|
78
|
+
* }
|
|
79
|
+
* }]
|
|
80
|
+
* ```
|
|
30
81
|
*/
|
|
31
82
|
export const CircleFrameEffect = {
|
|
32
83
|
name: "circle",
|
|
33
84
|
|
|
34
85
|
/**
|
|
35
86
|
* Generator function controlling the circle frame animation.
|
|
87
|
+
* Handles frame resizing, positioning, corner radius animation, and content fitting.
|
|
88
|
+
*
|
|
89
|
+
* @param params - Frame effect parameters including element references and configuration
|
|
90
|
+
* @returns Generator that controls the circle frame animation timeline
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```js
|
|
94
|
+
* yield* CircleFrameEffect.run({
|
|
95
|
+
* containerRef: frameContainer,
|
|
96
|
+
* elementRef: contentElement,
|
|
97
|
+
* initFrameState: initialState,
|
|
98
|
+
* frameEffect: circleConfig
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
36
101
|
*/
|
|
37
102
|
*run({
|
|
38
103
|
containerRef,
|
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* @group RectFrameEffect
|
|
3
|
+
* RectFrameEffect applies frame transformations such as resizing, repositioning,
|
|
4
|
+
* rounding corners, and optionally fitting the element within the frame according
|
|
5
|
+
* to an object-fit mode. Creates rectangular masks and containers for content
|
|
6
|
+
* presentation with smooth transitions.
|
|
7
|
+
*
|
|
8
|
+
* Behavior:
|
|
9
|
+
* - Waits for the specified start time
|
|
10
|
+
* - Resizes and repositions the container and element smoothly
|
|
11
|
+
* - Adjusts corner radius if provided
|
|
12
|
+
* - Optionally fits the element inside the container
|
|
13
|
+
*
|
|
14
|
+
* @param containerRef - Reference to the frame container element
|
|
15
|
+
* @param elementRef - Reference to the content element inside the frame
|
|
16
|
+
* @param initFrameState - Initial size and position state of the element
|
|
17
|
+
* @param frameEffect - Frame transformation configuration and timing
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```js
|
|
21
|
+
* // Basic rectangular frame
|
|
22
|
+
* frameEffects: [{
|
|
23
|
+
* name: "rect",
|
|
24
|
+
* s: 0,
|
|
25
|
+
* e: 10,
|
|
26
|
+
* props: {
|
|
27
|
+
* frameSize: [600, 400],
|
|
28
|
+
* frameShape: "rect",
|
|
29
|
+
* framePosition: { x: 960, y: 540 },
|
|
30
|
+
* radius: 20,
|
|
31
|
+
* objectFit: "cover",
|
|
32
|
+
* transitionDuration: 1.5
|
|
33
|
+
* }
|
|
34
|
+
* }]
|
|
35
|
+
*
|
|
36
|
+
* // Rounded rectangle frame
|
|
37
|
+
* frameEffects: [{
|
|
38
|
+
* name: "rect",
|
|
39
|
+
* s: 2,
|
|
40
|
+
* e: 15,
|
|
41
|
+
* props: {
|
|
42
|
+
* frameSize: [800, 600],
|
|
43
|
+
* frameShape: "rect",
|
|
44
|
+
* framePosition: { x: 960, y: 540 },
|
|
45
|
+
* radius: 50,
|
|
46
|
+
* objectFit: "contain",
|
|
47
|
+
* transitionDuration: 2
|
|
48
|
+
* }
|
|
49
|
+
* }]
|
|
50
|
+
* ```
|
|
4
51
|
*/
|
|
5
52
|
|
|
6
53
|
import { all, waitFor } from "@twick/core";
|
|
@@ -13,26 +60,74 @@ import {
|
|
|
13
60
|
import { FrameEffectParams } from "../helpers/types";
|
|
14
61
|
|
|
15
62
|
/**
|
|
16
|
-
* RectFrameEffect applies frame transformations such as resizing,
|
|
17
|
-
*
|
|
18
|
-
*
|
|
63
|
+
* RectFrameEffect applies frame transformations such as resizing, repositioning,
|
|
64
|
+
* rounding corners, and optionally fitting the element within the frame according
|
|
65
|
+
* to an object-fit mode. Creates rectangular masks and containers for content
|
|
66
|
+
* presentation with smooth transitions.
|
|
19
67
|
*
|
|
20
68
|
* Behavior:
|
|
21
|
-
* - Waits for the specified start time
|
|
22
|
-
* - Resizes and repositions the container and element smoothly
|
|
23
|
-
* - Adjusts corner radius if provided
|
|
24
|
-
* - Optionally fits the element inside the container
|
|
69
|
+
* - Waits for the specified start time
|
|
70
|
+
* - Resizes and repositions the container and element smoothly
|
|
71
|
+
* - Adjusts corner radius if provided
|
|
72
|
+
* - Optionally fits the element inside the container
|
|
25
73
|
*
|
|
26
|
-
* @param containerRef - Reference to the frame container element
|
|
27
|
-
* @param elementRef - Reference to the content element inside the frame
|
|
28
|
-
* @param initFrameState - Initial size and position state of the element
|
|
29
|
-
* @param frameEffect - Frame transformation configuration and timing
|
|
74
|
+
* @param containerRef - Reference to the frame container element
|
|
75
|
+
* @param elementRef - Reference to the content element inside the frame
|
|
76
|
+
* @param initFrameState - Initial size and position state of the element
|
|
77
|
+
* @param frameEffect - Frame transformation configuration and timing
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```js
|
|
81
|
+
* // Basic rectangular frame
|
|
82
|
+
* frameEffects: [{
|
|
83
|
+
* name: "rect",
|
|
84
|
+
* s: 0,
|
|
85
|
+
* e: 10,
|
|
86
|
+
* props: {
|
|
87
|
+
* frameSize: [600, 400],
|
|
88
|
+
* frameShape: "rect",
|
|
89
|
+
* framePosition: { x: 960, y: 540 },
|
|
90
|
+
* radius: 20,
|
|
91
|
+
* objectFit: "cover",
|
|
92
|
+
* transitionDuration: 1.5
|
|
93
|
+
* }
|
|
94
|
+
* }]
|
|
95
|
+
*
|
|
96
|
+
* // Rounded rectangle frame
|
|
97
|
+
* frameEffects: [{
|
|
98
|
+
* name: "rect",
|
|
99
|
+
* s: 2,
|
|
100
|
+
* e: 15,
|
|
101
|
+
* props: {
|
|
102
|
+
* frameSize: [800, 600],
|
|
103
|
+
* frameShape: "rect",
|
|
104
|
+
* framePosition: { x: 960, y: 540 },
|
|
105
|
+
* radius: 50,
|
|
106
|
+
* objectFit: "contain",
|
|
107
|
+
* transitionDuration: 2
|
|
108
|
+
* }
|
|
109
|
+
* }]
|
|
110
|
+
* ```
|
|
30
111
|
*/
|
|
31
112
|
export const RectFrameEffect = {
|
|
32
113
|
name: "rect",
|
|
33
114
|
|
|
34
115
|
/**
|
|
35
116
|
* Generator function controlling the frame resizing and positioning animation.
|
|
117
|
+
* Handles rectangular frame transformations with smooth transitions and content fitting.
|
|
118
|
+
*
|
|
119
|
+
* @param params - Frame effect parameters including element references and configuration
|
|
120
|
+
* @returns Generator that controls the rectangular frame animation timeline
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```js
|
|
124
|
+
* yield* RectFrameEffect.run({
|
|
125
|
+
* containerRef: frameContainer,
|
|
126
|
+
* elementRef: contentElement,
|
|
127
|
+
* initFrameState: initialState,
|
|
128
|
+
* frameEffect: rectConfig
|
|
129
|
+
* });
|
|
130
|
+
* ```
|
|
36
131
|
*/
|
|
37
132
|
*run({
|
|
38
133
|
containerRef,
|