@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
|
@@ -1,20 +1,88 @@
|
|
|
1
|
-
import { ElementParams } from "../helpers/types";
|
|
2
|
-
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
-
import { Icon } from "@twick/2d";
|
|
4
|
-
import { addAnimation } from "../helpers/element.utils";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import { ElementParams } from "../helpers/types";
|
|
2
|
+
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
+
import { Icon } from "@twick/2d";
|
|
4
|
+
import { addAnimation } from "../helpers/element.utils";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @group IconElement
|
|
8
|
+
* IconElement creates and manages icon elements in the visualizer scene.
|
|
9
|
+
* Handles icon rendering, styling, and animations for UI elements and
|
|
10
|
+
* visual design components.
|
|
11
|
+
*
|
|
12
|
+
* Features:
|
|
13
|
+
* - Icon rendering with custom styling
|
|
14
|
+
* - Size and position control
|
|
15
|
+
* - Color and opacity customization
|
|
16
|
+
* - Animation support
|
|
17
|
+
*
|
|
18
|
+
* @param containerRef - Reference to the container element
|
|
19
|
+
* @param element - Icon element configuration and properties
|
|
20
|
+
* @param view - The main scene view for rendering
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```js
|
|
24
|
+
* // Basic icon element
|
|
25
|
+
* {
|
|
26
|
+
* id: "play-icon",
|
|
27
|
+
* type: "icon",
|
|
28
|
+
* s: 0,
|
|
29
|
+
* e: 20,
|
|
30
|
+
* props: {
|
|
31
|
+
* icon: "play",
|
|
32
|
+
* size: 64,
|
|
33
|
+
* fill: "#ffffff"
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* // Icon with animation
|
|
38
|
+
* {
|
|
39
|
+
* id: "animated-icon",
|
|
40
|
+
* type: "icon",
|
|
41
|
+
* s: 2,
|
|
42
|
+
* e: 15,
|
|
43
|
+
* props: {
|
|
44
|
+
* icon: "pause",
|
|
45
|
+
* size: 48,
|
|
46
|
+
* fill: "#ff0000",
|
|
47
|
+
* opacity: 0.8
|
|
48
|
+
* },
|
|
49
|
+
* animation: {
|
|
50
|
+
* name: "fade",
|
|
51
|
+
* animate: "enter",
|
|
52
|
+
* duration: 2
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export const IconElement = {
|
|
58
|
+
name: "icon",
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Generator function that creates and manages icon elements in the scene.
|
|
62
|
+
* Handles icon creation, styling, and cleanup.
|
|
63
|
+
*
|
|
64
|
+
* @param params - Element parameters including container reference, element config, and view
|
|
65
|
+
* @returns Generator that controls the icon element lifecycle
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```js
|
|
69
|
+
* yield* IconElement.create({
|
|
70
|
+
* containerRef: mainContainer,
|
|
71
|
+
* element: iconConfig,
|
|
72
|
+
* view: sceneView
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
*create({ containerRef, element, view }: ElementParams) {
|
|
77
|
+
const elementRef = createRef<any>();
|
|
78
|
+
yield* waitFor(element?.s);
|
|
79
|
+
yield containerRef().add(
|
|
80
|
+
<Icon ref={elementRef} key={element.id} {...element.props} />
|
|
81
|
+
);
|
|
82
|
+
yield* all(
|
|
83
|
+
addAnimation({ elementRef: elementRef, element: element, view }),
|
|
84
|
+
waitFor(Math.max(0, element.e - element.s))
|
|
85
|
+
);
|
|
86
|
+
yield elementRef().remove();
|
|
87
|
+
},
|
|
88
|
+
};
|
|
@@ -1,55 +1,134 @@
|
|
|
1
|
-
import { ElementParams } from "../helpers/types";
|
|
2
|
-
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
-
import { Img, Rect } from "@twick/2d";
|
|
4
|
-
import { addAnimation, addFrameEffect, fitElement } from "../helpers/element.utils";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
-
}
|
|
1
|
+
import { ElementParams } from "../helpers/types";
|
|
2
|
+
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
+
import { Img, Rect } from "@twick/2d";
|
|
4
|
+
import { addAnimation, addFrameEffect, fitElement } from "../helpers/element.utils";
|
|
5
|
+
import { applyColorFilter } from "../helpers/filters";
|
|
6
|
+
import { logger } from "../helpers/log.utils";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @group ImageElement
|
|
10
|
+
* ImageElement creates and manages image content in the visualizer scene.
|
|
11
|
+
* Handles image rendering, frame effects, animations, and content fitting
|
|
12
|
+
* for professional image presentations and content creation.
|
|
13
|
+
*
|
|
14
|
+
* Features:
|
|
15
|
+
* - Image rendering with start/end timing control
|
|
16
|
+
* - Frame effects and animations
|
|
17
|
+
* - Object fit options for content scaling
|
|
18
|
+
* - Color filters and media effects
|
|
19
|
+
* - Automatic cleanup and resource management
|
|
20
|
+
*
|
|
21
|
+
* @param containerRef - Reference to the container element
|
|
22
|
+
* @param element - Image element configuration and properties
|
|
23
|
+
* @param view - The main scene view for rendering
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* // Basic image element
|
|
28
|
+
* {
|
|
29
|
+
* id: "main-image",
|
|
30
|
+
* type: "image",
|
|
31
|
+
* s: 0,
|
|
32
|
+
* e: 15,
|
|
33
|
+
* props: {
|
|
34
|
+
* src: "image.jpg",
|
|
35
|
+
* width: 1920,
|
|
36
|
+
* height: 1080
|
|
37
|
+
* },
|
|
38
|
+
* objectFit: "cover"
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* // Image with frame effect and animation
|
|
42
|
+
* {
|
|
43
|
+
* id: "framed-image",
|
|
44
|
+
* type: "image",
|
|
45
|
+
* s: 2,
|
|
46
|
+
* e: 20,
|
|
47
|
+
* props: {
|
|
48
|
+
* src: "content.jpg",
|
|
49
|
+
* mediaFilter: "sepia"
|
|
50
|
+
* },
|
|
51
|
+
* animation: {
|
|
52
|
+
* name: "fade",
|
|
53
|
+
* animate: "enter",
|
|
54
|
+
* duration: 2
|
|
55
|
+
* },
|
|
56
|
+
* frameEffects: [{
|
|
57
|
+
* name: "circle",
|
|
58
|
+
* s: 2,
|
|
59
|
+
* e: 20,
|
|
60
|
+
* props: {
|
|
61
|
+
* frameSize: [500, 500],
|
|
62
|
+
* frameShape: "circle",
|
|
63
|
+
* framePosition: { x: 960, y: 540 },
|
|
64
|
+
* radius: 250,
|
|
65
|
+
* objectFit: "cover"
|
|
66
|
+
* }
|
|
67
|
+
* }]
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export const ImageElement = {
|
|
72
|
+
name: "image",
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Generator function that creates and manages image elements in the scene.
|
|
76
|
+
* Handles image creation, frame setup, animations, effects, and cleanup.
|
|
77
|
+
*
|
|
78
|
+
* @param params - Element parameters including container reference, element config, and view
|
|
79
|
+
* @returns Generator that controls the image element lifecycle
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```js
|
|
83
|
+
* yield* ImageElement.create({
|
|
84
|
+
* containerRef: mainContainer,
|
|
85
|
+
* element: imageConfig,
|
|
86
|
+
* view: sceneView
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
*create({ containerRef, element, view }: ElementParams) {
|
|
91
|
+
yield* waitFor(element?.s);
|
|
92
|
+
const frameContainerRef = createRef<any>();
|
|
93
|
+
const frameElementRef = createRef<any>();
|
|
94
|
+
|
|
95
|
+
yield containerRef().add(
|
|
96
|
+
<Rect ref={frameContainerRef} key={element.id} {...element.frame}>
|
|
97
|
+
<Img
|
|
98
|
+
ref={frameElementRef}
|
|
99
|
+
key={`child-${element.id}`}
|
|
100
|
+
{...element.props}
|
|
101
|
+
/>
|
|
102
|
+
</Rect>
|
|
103
|
+
);
|
|
104
|
+
if (frameContainerRef()) {
|
|
105
|
+
yield fitElement({
|
|
106
|
+
elementRef: frameElementRef,
|
|
107
|
+
containerSize: frameContainerRef().size(),
|
|
108
|
+
elementSize: frameElementRef().size(),
|
|
109
|
+
objectFit: element.objectFit,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (element?.props?.mediaFilter) {
|
|
113
|
+
applyColorFilter(frameElementRef, element.props.mediaFilter);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
yield* all(
|
|
117
|
+
addAnimation({
|
|
118
|
+
elementRef: frameElementRef,
|
|
119
|
+
containerRef: frameContainerRef,
|
|
120
|
+
element: element,
|
|
121
|
+
view,
|
|
122
|
+
}),
|
|
123
|
+
addFrameEffect({
|
|
124
|
+
containerRef: frameContainerRef,
|
|
125
|
+
elementRef: frameElementRef,
|
|
126
|
+
element,
|
|
127
|
+
}),
|
|
128
|
+
waitFor(Math.max(0, element.e - element.s))
|
|
129
|
+
);
|
|
130
|
+
yield frameElementRef().remove();
|
|
131
|
+
yield frameContainerRef().remove();
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @group Elements
|
|
3
|
+
* @description Visual components for creating scenes and content
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { VideoElement } from './video.element';
|
|
7
|
+
export { ImageElement } from './image.element';
|
|
8
|
+
export { AudioElement } from './audio.element';
|
|
9
|
+
export { TextElement } from './text.element';
|
|
10
|
+
export { CaptionElement } from './caption.element';
|
|
11
|
+
export { RectElement } from './rect.element';
|
|
12
|
+
export { CircleElement } from './circle.element';
|
|
13
|
+
export { IconElement } from './icon.element';
|
|
14
|
+
export { SceneElement } from './scene.element';
|
|
@@ -1,22 +1,92 @@
|
|
|
1
|
-
import { ElementParams } from "../helpers/types";
|
|
2
|
-
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
-
import { Rect } from "@twick/2d";
|
|
4
|
-
import { addAnimation } from "../helpers/element.utils";
|
|
5
|
-
import { logger } from "../helpers/log.utils";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { ElementParams } from "../helpers/types";
|
|
2
|
+
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
+
import { Rect } from "@twick/2d";
|
|
4
|
+
import { addAnimation } from "../helpers/element.utils";
|
|
5
|
+
import { logger } from "../helpers/log.utils";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @group RectElement
|
|
9
|
+
* RectElement creates and manages rectangular shape elements in the visualizer scene.
|
|
10
|
+
* Handles rectangle rendering, styling, and animations for UI elements and
|
|
11
|
+
* visual design components.
|
|
12
|
+
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - Rectangle rendering with custom styling
|
|
15
|
+
* - Size and position control
|
|
16
|
+
* - Color and border customization
|
|
17
|
+
* - Animation support
|
|
18
|
+
*
|
|
19
|
+
* @param containerRef - Reference to the container element
|
|
20
|
+
* @param element - Rectangle element configuration and properties
|
|
21
|
+
* @param view - The main scene view for rendering
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```js
|
|
25
|
+
* // Basic rectangle element
|
|
26
|
+
* {
|
|
27
|
+
* id: "background-rect",
|
|
28
|
+
* type: "rect",
|
|
29
|
+
* s: 0,
|
|
30
|
+
* e: 20,
|
|
31
|
+
* props: {
|
|
32
|
+
* width: 800,
|
|
33
|
+
* height: 600,
|
|
34
|
+
* fill: "#000000",
|
|
35
|
+
* opacity: 0.5
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* // Rectangle with animation
|
|
40
|
+
* {
|
|
41
|
+
* id: "animated-rect",
|
|
42
|
+
* type: "rect",
|
|
43
|
+
* s: 2,
|
|
44
|
+
* e: 15,
|
|
45
|
+
* props: {
|
|
46
|
+
* width: 400,
|
|
47
|
+
* height: 300,
|
|
48
|
+
* fill: "#ff0000",
|
|
49
|
+
* stroke: "#ffffff",
|
|
50
|
+
* strokeWidth: 2
|
|
51
|
+
* },
|
|
52
|
+
* animation: {
|
|
53
|
+
* name: "fade",
|
|
54
|
+
* animate: "enter",
|
|
55
|
+
* duration: 2
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export const RectElement = {
|
|
61
|
+
name: "rect",
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Generator function that creates and manages rectangle elements in the scene.
|
|
65
|
+
* Handles rectangle creation, styling, and cleanup.
|
|
66
|
+
*
|
|
67
|
+
* @param params - Element parameters including container reference, element config, and view
|
|
68
|
+
* @returns Generator that controls the rectangle element lifecycle
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```js
|
|
72
|
+
* yield* RectElement.create({
|
|
73
|
+
* containerRef: mainContainer,
|
|
74
|
+
* element: rectConfig,
|
|
75
|
+
* view: sceneView
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
*create({ containerRef, element, view }: ElementParams) {
|
|
80
|
+
const elementRef = createRef<any>();
|
|
81
|
+
yield* waitFor(element?.s);
|
|
82
|
+
logger(`RectElement: ${JSON.stringify(element)}`);
|
|
83
|
+
yield containerRef().add(
|
|
84
|
+
<Rect ref={elementRef} key={element.id} {...element.props}/>
|
|
85
|
+
);
|
|
86
|
+
yield* all(
|
|
87
|
+
addAnimation({ elementRef: elementRef, element: element, view }),
|
|
88
|
+
waitFor(Math.max(0, element.e - element.s))
|
|
89
|
+
);
|
|
90
|
+
yield elementRef().remove();
|
|
91
|
+
},
|
|
92
|
+
};
|
|
@@ -1,29 +1,97 @@
|
|
|
1
|
-
import { ElementParams } from "../helpers/types";
|
|
2
|
-
import { createRef, waitFor } from "@twick/core";
|
|
3
|
-
import { Rect } from "@twick/2d";
|
|
4
|
-
import { DEFAULT_BACKGROUND_COLOR, ELEMENT_TYPES } from "../helpers/constants";
|
|
5
|
-
import { ImageElement } from "./image.element";
|
|
6
|
-
import { VideoElement } from "./video.element";
|
|
7
|
-
import { logger } from "../helpers/log.utils";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import { ElementParams } from "../helpers/types";
|
|
2
|
+
import { createRef, waitFor } from "@twick/core";
|
|
3
|
+
import { Rect } from "@twick/2d";
|
|
4
|
+
import { DEFAULT_BACKGROUND_COLOR, ELEMENT_TYPES } from "../helpers/constants";
|
|
5
|
+
import { ImageElement } from "./image.element";
|
|
6
|
+
import { VideoElement } from "./video.element";
|
|
7
|
+
import { logger } from "../helpers/log.utils";
|
|
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
|
+
*/
|
|
60
|
+
export const SceneElement = {
|
|
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
|
+
},
|
|
97
|
+
};
|
|
@@ -1,28 +1,102 @@
|
|
|
1
|
-
import { ElementParams } from "../helpers/types";
|
|
2
|
-
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
-
import { Txt } from "@twick/2d";
|
|
4
|
-
import { addAnimation, addTextEffect } from "../helpers/element.utils";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import { ElementParams } from "../helpers/types";
|
|
2
|
+
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
+
import { Txt } from "@twick/2d";
|
|
4
|
+
import { addAnimation, addTextEffect } from "../helpers/element.utils";
|
|
5
|
+
import { logger } from "../helpers/log.utils";
|
|
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
|
+
*/
|
|
63
|
+
export const TextElement = {
|
|
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
|
+
*/
|
|
82
|
+
*create({ containerRef, element, view }: ElementParams) {
|
|
83
|
+
const elementRef = createRef<any>();
|
|
84
|
+
|
|
85
|
+
yield* waitFor(element?.s);
|
|
86
|
+
yield containerRef().add(
|
|
87
|
+
<Txt
|
|
88
|
+
ref={elementRef}
|
|
89
|
+
key={element.id}
|
|
90
|
+
text={element.t}
|
|
91
|
+
{...element.props}
|
|
92
|
+
/>
|
|
93
|
+
);
|
|
94
|
+
yield* all(
|
|
95
|
+
addAnimation({ elementRef: elementRef, element: element, view }),
|
|
96
|
+
addTextEffect({ elementRef: elementRef, element: element }),
|
|
97
|
+
waitFor(Math.max(0, element.e - element.s))
|
|
98
|
+
);
|
|
99
|
+
yield elementRef().remove();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
28
102
|
|