@twick/visualizer 0.14.2 → 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/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
package/src/animations/rise.tsx
CHANGED
|
@@ -1,28 +1,67 @@
|
|
|
1
|
-
import { all,
|
|
1
|
+
import { all, delay, waitFor } from "@twick/core";
|
|
2
2
|
import { AnimationParams } from "../helpers/types";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* RiseAnimation
|
|
6
|
-
* to create a "rising"
|
|
5
|
+
* @group RiseAnimation
|
|
6
|
+
* RiseAnimation combines vertical motion and opacity transitions to create a "rising"
|
|
7
|
+
* (or "falling") appearance/disappearance effect. Moves elements vertically with
|
|
8
|
+
* optional scaling effects for dynamic visual impact.
|
|
7
9
|
*
|
|
8
10
|
* 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
|
|
11
|
+
* - "enter": Starts offset and transparent, moves into position while fading in
|
|
12
|
+
* - "exit": Waits, then moves out of position while fading out
|
|
13
|
+
* - "both": Enters, waits, and exits in a continuous sequence
|
|
12
14
|
*
|
|
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
|
|
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
|
|
15
|
+
* @param elementRef - Reference to the main element to animate
|
|
16
|
+
* @param containerRef - Optional reference to a container element
|
|
17
|
+
* @param interval - Duration of movement and opacity transitions in seconds
|
|
18
|
+
* @param duration - Total duration of the animation in seconds
|
|
19
|
+
* @param animate - Animation phase ("enter" | "exit" | "both")
|
|
20
|
+
* @param direction - Direction to animate ("up" or "down")
|
|
21
|
+
* @param intensity - Number of units to offset position vertically
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```js
|
|
25
|
+
* // Rise up animation
|
|
26
|
+
* animation: {
|
|
27
|
+
* name: "rise",
|
|
28
|
+
* animate: "enter",
|
|
29
|
+
* duration: 1.5,
|
|
30
|
+
* direction: "up",
|
|
31
|
+
* intensity: 0.8
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* // Fall down animation
|
|
35
|
+
* animation: {
|
|
36
|
+
* name: "rise",
|
|
37
|
+
* animate: "exit",
|
|
38
|
+
* duration: 2,
|
|
39
|
+
* direction: "down",
|
|
40
|
+
* intensity: 300
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
20
43
|
*/
|
|
21
44
|
export const RiseAnimation = {
|
|
22
45
|
name: "rise",
|
|
23
46
|
|
|
24
47
|
/**
|
|
25
48
|
* Generator function controlling the rise/fall animation.
|
|
49
|
+
* Handles vertical movement and opacity transitions based on direction and intensity.
|
|
50
|
+
*
|
|
51
|
+
* @param params - Animation parameters including element references, timing, and direction
|
|
52
|
+
* @returns Generator that controls the rise animation timeline
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```js
|
|
56
|
+
* yield* RiseAnimation.run({
|
|
57
|
+
* elementRef: myElement,
|
|
58
|
+
* interval: 0.25,
|
|
59
|
+
* duration: 1.5,
|
|
60
|
+
* animate: "enter",
|
|
61
|
+
* direction: "up",
|
|
62
|
+
* intensity: 200
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
26
65
|
*/
|
|
27
66
|
*run({
|
|
28
67
|
elementRef,
|
|
@@ -2,25 +2,60 @@ import { all, delay, Vector2, waitFor } from "@twick/core";
|
|
|
2
2
|
import { AnimationParams } from "../helpers/types";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* SuccessionAnimation
|
|
6
|
-
* to create an appearing
|
|
5
|
+
* @group SuccessionAnimation
|
|
6
|
+
* SuccessionAnimation combines scaling and opacity transitions to create an appearing
|
|
7
|
+
* and disappearing zoom effect. Creates dynamic zoom animations that draw attention
|
|
8
|
+
* to content with smooth scaling and fade transitions.
|
|
7
9
|
*
|
|
8
10
|
* 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
|
|
11
|
+
* - "enter": Starts scaled down and transparent, then scales up while fading in
|
|
12
|
+
* - "exit": Waits, then scales down while fading out
|
|
13
|
+
* - "both": Scales up and fades in, waits, then scales down and fades out
|
|
12
14
|
*
|
|
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")
|
|
15
|
+
* @param elementRef - Reference to the main element to animate
|
|
16
|
+
* @param containerRef - Optional reference to a container element
|
|
17
|
+
* @param interval - Duration of scaling and opacity transitions in seconds
|
|
18
|
+
* @param duration - Total duration of the animation in seconds
|
|
19
|
+
* @param animate - Animation phase ("enter" | "exit" | "both")
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```js
|
|
23
|
+
* // Zoom in effect
|
|
24
|
+
* animation: {
|
|
25
|
+
* name: "succession",
|
|
26
|
+
* animate: "enter",
|
|
27
|
+
* duration: 2,
|
|
28
|
+
* interval: 0.5
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* // Zoom out effect
|
|
32
|
+
* animation: {
|
|
33
|
+
* name: "succession",
|
|
34
|
+
* animate: "exit",
|
|
35
|
+
* duration: 1.5,
|
|
36
|
+
* interval: 0.3
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
18
39
|
*/
|
|
19
40
|
export const SuccessionAnimation = {
|
|
20
41
|
name: "succession",
|
|
21
42
|
|
|
22
43
|
/**
|
|
23
44
|
* Generator function controlling the succession animation.
|
|
45
|
+
* Handles scaling and opacity transitions to create zoom effects.
|
|
46
|
+
*
|
|
47
|
+
* @param params - Animation parameters including element references and timing
|
|
48
|
+
* @returns Generator that controls the succession animation timeline
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```js
|
|
52
|
+
* yield* SuccessionAnimation.run({
|
|
53
|
+
* elementRef: myElement,
|
|
54
|
+
* interval: 0.5,
|
|
55
|
+
* duration: 2,
|
|
56
|
+
* animate: "enter"
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
24
59
|
*/
|
|
25
60
|
*run({
|
|
26
61
|
elementRef,
|
|
@@ -1,9 +1,71 @@
|
|
|
1
1
|
import { ElementParams } from "../helpers/types";
|
|
2
|
-
import { createRef, waitFor } from "@twick/core";
|
|
2
|
+
import { all, createRef, waitFor } from "@twick/core";
|
|
3
3
|
import { Audio } from "@twick/2d";
|
|
4
|
+
import { addAnimation } from "../helpers/element.utils";
|
|
5
|
+
import { logger } from "../helpers/log.utils";
|
|
4
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @group AudioElement
|
|
9
|
+
* AudioElement creates and manages audio content in the visualizer scene.
|
|
10
|
+
* Handles audio playback, timing, and synchronization for background music,
|
|
11
|
+
* sound effects, and audio narration in video presentations.
|
|
12
|
+
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - Audio playback with start/end timing control
|
|
15
|
+
* - Automatic play/pause management
|
|
16
|
+
* - Resource cleanup and memory management
|
|
17
|
+
* - Synchronization with visual elements
|
|
18
|
+
*
|
|
19
|
+
* @param containerRef - Reference to the container element
|
|
20
|
+
* @param element - Audio element configuration and properties
|
|
21
|
+
* @param view - The main scene view for rendering
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```js
|
|
25
|
+
* // Basic audio element
|
|
26
|
+
* {
|
|
27
|
+
* id: "background-music",
|
|
28
|
+
* type: "audio",
|
|
29
|
+
* s: 0,
|
|
30
|
+
* e: 30,
|
|
31
|
+
* props: {
|
|
32
|
+
* src: "music.mp3",
|
|
33
|
+
* volume: 0.7
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* // Sound effect with timing
|
|
38
|
+
* {
|
|
39
|
+
* id: "sound-effect",
|
|
40
|
+
* type: "audio",
|
|
41
|
+
* s: 5,
|
|
42
|
+
* e: 8,
|
|
43
|
+
* props: {
|
|
44
|
+
* src: "effect.wav",
|
|
45
|
+
* volume: 1.0
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
5
50
|
export const AudioElement = {
|
|
6
51
|
name: "audio",
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Generator function that creates and manages audio elements in the scene.
|
|
55
|
+
* Handles audio creation, playback control, and cleanup.
|
|
56
|
+
*
|
|
57
|
+
* @param params - Element parameters including container reference, element config, and view
|
|
58
|
+
* @returns Generator that controls the audio element lifecycle
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```js
|
|
62
|
+
* yield* AudioElement.create({
|
|
63
|
+
* containerRef: mainContainer,
|
|
64
|
+
* element: audioConfig,
|
|
65
|
+
* view: sceneView
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
7
69
|
*create({ containerRef, element, view }: ElementParams) {
|
|
8
70
|
const elementRef = createRef<any>();
|
|
9
71
|
yield* waitFor(element?.s);
|
|
@@ -5,8 +5,90 @@ import { splitPhraseTiming } from "../helpers/caption.utils";
|
|
|
5
5
|
import { TRANSPARENT_COLOR } from "../helpers/constants";
|
|
6
6
|
import { hexToRGB } from "../helpers/utils";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @group CaptionElement
|
|
10
|
+
* CaptionElement creates and manages styled text overlays in the visualizer scene.
|
|
11
|
+
* Handles caption rendering, text effects, background styling, and timing
|
|
12
|
+
* for professional video presentations and content creation.
|
|
13
|
+
*
|
|
14
|
+
* Features:
|
|
15
|
+
* - Styled text with custom fonts, colors, and backgrounds
|
|
16
|
+
* - Word-by-word timing and animation
|
|
17
|
+
* - Background highlighting and styling options
|
|
18
|
+
* - Text effects and animations
|
|
19
|
+
* - Automatic timing and synchronization
|
|
20
|
+
*
|
|
21
|
+
* @param containerRef - Reference to the container element
|
|
22
|
+
* @param caption - Caption configuration including text, styling, and timing
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```js
|
|
26
|
+
* // Basic caption
|
|
27
|
+
* {
|
|
28
|
+
* id: "welcome-caption",
|
|
29
|
+
* type: "caption",
|
|
30
|
+
* s: 2,
|
|
31
|
+
* e: 8,
|
|
32
|
+
* t: "Welcome to our presentation!",
|
|
33
|
+
* props: {
|
|
34
|
+
* colors: {
|
|
35
|
+
* text: "#ffffff",
|
|
36
|
+
* background: "rgba(0,0,0,0.7)"
|
|
37
|
+
* },
|
|
38
|
+
* font: {
|
|
39
|
+
* family: "Arial",
|
|
40
|
+
* size: 48,
|
|
41
|
+
* weight: 600
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* // Caption with background highlighting
|
|
47
|
+
* {
|
|
48
|
+
* id: "highlighted-caption",
|
|
49
|
+
* type: "caption",
|
|
50
|
+
* s: 3,
|
|
51
|
+
* e: 10,
|
|
52
|
+
* t: "Important information",
|
|
53
|
+
* capStyle: "highlight_bg",
|
|
54
|
+
* props: {
|
|
55
|
+
* colors: {
|
|
56
|
+
* text: "#ffffff",
|
|
57
|
+
* background: "rgba(255,0,0,0.8)"
|
|
58
|
+
* },
|
|
59
|
+
* font: {
|
|
60
|
+
* family: "Helvetica",
|
|
61
|
+
* size: 36,
|
|
62
|
+
* weight: 700
|
|
63
|
+
* },
|
|
64
|
+
* bgOpacity: 0.9,
|
|
65
|
+
* bgOffsetWidth: 20,
|
|
66
|
+
* bgOffsetHeight: 10,
|
|
67
|
+
* bgMargin: [10, 5],
|
|
68
|
+
* bgRadius: 15,
|
|
69
|
+
* bgPadding: [20, 15]
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
8
74
|
export const CaptionElement = {
|
|
9
75
|
name: "caption",
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Generator function that creates and manages caption elements in the scene.
|
|
79
|
+
* Handles caption creation, word timing, styling, and text effects.
|
|
80
|
+
*
|
|
81
|
+
* @param params - Element parameters including container reference and caption config
|
|
82
|
+
* @returns Generator that controls the caption element lifecycle
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```js
|
|
86
|
+
* yield* CaptionElement.create({
|
|
87
|
+
* containerRef: mainContainer,
|
|
88
|
+
* caption: captionConfig
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
10
92
|
*create({ containerRef, caption }: ElementParams) {
|
|
11
93
|
const words = splitPhraseTiming(caption);
|
|
12
94
|
let phraseStart = 0;
|
|
@@ -3,9 +3,77 @@ import { all, createRef, waitFor } from "@twick/core";
|
|
|
3
3
|
import { Circle } from "@twick/2d";
|
|
4
4
|
import { addAnimation } from "../helpers/element.utils";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @group CircleElement
|
|
8
|
+
* CircleElement creates and manages circular shape elements in the visualizer scene.
|
|
9
|
+
* Handles circle rendering, styling, and animations for UI elements and
|
|
10
|
+
* visual design components.
|
|
11
|
+
*
|
|
12
|
+
* Features:
|
|
13
|
+
* - Circle rendering with custom styling
|
|
14
|
+
* - Radius and position control
|
|
15
|
+
* - Color and border customization
|
|
16
|
+
* - Animation support
|
|
17
|
+
*
|
|
18
|
+
* @param containerRef - Reference to the container element
|
|
19
|
+
* @param element - Circle element configuration and properties
|
|
20
|
+
* @param view - The main scene view for rendering
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```js
|
|
24
|
+
* // Basic circle element
|
|
25
|
+
* {
|
|
26
|
+
* id: "background-circle",
|
|
27
|
+
* type: "circle",
|
|
28
|
+
* s: 0,
|
|
29
|
+
* e: 20,
|
|
30
|
+
* props: {
|
|
31
|
+
* radius: 100,
|
|
32
|
+
* fill: "#000000",
|
|
33
|
+
* opacity: 0.5
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* // Circle with animation
|
|
38
|
+
* {
|
|
39
|
+
* id: "animated-circle",
|
|
40
|
+
* type: "circle",
|
|
41
|
+
* s: 2,
|
|
42
|
+
* e: 15,
|
|
43
|
+
* props: {
|
|
44
|
+
* radius: 50,
|
|
45
|
+
* fill: "#ff0000",
|
|
46
|
+
* stroke: "#ffffff",
|
|
47
|
+
* strokeWidth: 2
|
|
48
|
+
* },
|
|
49
|
+
* animation: {
|
|
50
|
+
* name: "fade",
|
|
51
|
+
* animate: "enter",
|
|
52
|
+
* duration: 2
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
6
57
|
export const CircleElement = {
|
|
7
|
-
|
|
8
|
-
|
|
58
|
+
name: "circle",
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Generator function that creates and manages circle elements in the scene.
|
|
62
|
+
* Handles circle creation, styling, and cleanup.
|
|
63
|
+
*
|
|
64
|
+
* @param params - Element parameters including container reference, element config, and view
|
|
65
|
+
* @returns Generator that controls the circle element lifecycle
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```js
|
|
69
|
+
* yield* CircleElement.create({
|
|
70
|
+
* containerRef: mainContainer,
|
|
71
|
+
* element: circleConfig,
|
|
72
|
+
* view: sceneView
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
*create({ containerRef, element, view }: ElementParams) {
|
|
9
77
|
const elementRef = createRef<any>();
|
|
10
78
|
yield* waitFor(element?.s);
|
|
11
79
|
yield containerRef().add(
|
|
@@ -3,9 +3,77 @@ import { all, createRef, waitFor } from "@twick/core";
|
|
|
3
3
|
import { Icon } from "@twick/2d";
|
|
4
4
|
import { addAnimation } from "../helpers/element.utils";
|
|
5
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
|
+
*/
|
|
6
57
|
export const IconElement = {
|
|
7
|
-
|
|
8
|
-
|
|
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) {
|
|
9
77
|
const elementRef = createRef<any>();
|
|
10
78
|
yield* waitFor(element?.s);
|
|
11
79
|
yield containerRef().add(
|
|
@@ -3,9 +3,90 @@ import { all, createRef, waitFor } from "@twick/core";
|
|
|
3
3
|
import { Img, 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 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
|
+
*/
|
|
7
71
|
export const ImageElement = {
|
|
8
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
|
+
*/
|
|
9
90
|
*create({ containerRef, element, view }: ElementParams) {
|
|
10
91
|
yield* waitFor(element?.s);
|
|
11
92
|
const frameContainerRef = createRef<any>();
|
|
@@ -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';
|
|
@@ -4,9 +4,79 @@ import { Rect } from "@twick/2d";
|
|
|
4
4
|
import { addAnimation } from "../helpers/element.utils";
|
|
5
5
|
import { logger } from "../helpers/log.utils";
|
|
6
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
|
+
*/
|
|
7
60
|
export const RectElement = {
|
|
8
|
-
|
|
9
|
-
|
|
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) {
|
|
10
80
|
const elementRef = createRef<any>();
|
|
11
81
|
yield* waitFor(element?.s);
|
|
12
82
|
logger(`RectElement: ${JSON.stringify(element)}`);
|