@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
package/src/components/track.tsx
CHANGED
|
@@ -1,232 +1,237 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Track component that handles the creation and management of different types of tracks
|
|
3
|
-
* including video, audio, captions, scenes, and elements.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Layout, Rect, View2D, Audio } from "@twick/2d";
|
|
7
|
-
import { VisualizerTrack } from "../helpers/types";
|
|
8
|
-
import { all, Color, createRef, ThreadGenerator, waitFor } from "@twick/core";
|
|
9
|
-
import {
|
|
10
|
-
CAPTION_STYLE,
|
|
11
|
-
DEFAULT_CAPTION_COLORS,
|
|
12
|
-
DEFAULT_CAPTION_FONT,
|
|
13
|
-
} from "../helpers/constants";
|
|
14
|
-
import { logger } from "../helpers/log.utils";
|
|
15
|
-
import elementController from "../controllers/element.controller";
|
|
16
|
-
import { hexToRGB } from "../helpers/utils";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Creates a video track with specified configuration
|
|
20
|
-
* @param {Object} params - Parameters for video track creation
|
|
21
|
-
* @param {View2D} params.view - The 2D view to render the video in
|
|
22
|
-
* @param {VideoTrack} params.track - Video track configuration
|
|
23
|
-
* @returns {Generator} Generator function for video track animation
|
|
24
|
-
*/
|
|
25
|
-
export function* makeVideoTrack({
|
|
26
|
-
view,
|
|
27
|
-
track,
|
|
28
|
-
}: {
|
|
29
|
-
view: View2D;
|
|
30
|
-
track: VisualizerTrack;
|
|
31
|
-
}) {
|
|
32
|
-
const frameRef = createRef<any>();
|
|
33
|
-
let prevTime = 0;
|
|
34
|
-
view.add(<Layout size={"100%"} ref={frameRef} layout />);
|
|
35
|
-
for (const element of track.elements || []) {
|
|
36
|
-
yield* waitFor(element?.s - prevTime);
|
|
37
|
-
yield* elementController.get("video")?.create({
|
|
38
|
-
containerRef: frameRef,
|
|
39
|
-
element,
|
|
40
|
-
view,
|
|
41
|
-
});
|
|
42
|
-
prevTime = element.e;
|
|
43
|
-
}
|
|
44
|
-
yield frameRef().remove();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Creates an audio track with specified configuration
|
|
49
|
-
* @param {Object} params - Parameters for audio track creation
|
|
50
|
-
* @param {View2D} params.view - The 2D view to render the audio in
|
|
51
|
-
* @param {AudioTrack} params.track - Audio track configuration
|
|
52
|
-
* @returns {Generator} Generator function for audio track animation
|
|
53
|
-
*/
|
|
54
|
-
export function* makeAudioTrack({
|
|
55
|
-
view,
|
|
56
|
-
track,
|
|
57
|
-
}: {
|
|
58
|
-
view: View2D;
|
|
59
|
-
track: VisualizerTrack;
|
|
60
|
-
}) {
|
|
61
|
-
let prevTime = 0;
|
|
62
|
-
for (const audioElement of track.elements) {
|
|
63
|
-
const audioRef = createRef<any>();
|
|
64
|
-
yield* waitFor(audioElement?.s - prevTime);
|
|
65
|
-
prevTime = audioElement?.e;
|
|
66
|
-
logger(`Adding audio element ${audioElement.id}`);
|
|
67
|
-
view.add(
|
|
68
|
-
<Audio ref={audioRef} key={audioElement.id} {...audioElement.props} />
|
|
69
|
-
);
|
|
70
|
-
yield* waitFor(Math.max(0, audioElement.e - audioElement.s));
|
|
71
|
-
yield audioRef().playing(false);
|
|
72
|
-
yield audioRef().remove();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Creates a caption track with specified configuration
|
|
78
|
-
* @param {Object} params - Parameters for caption track creation
|
|
79
|
-
* @param {View2D} params.view - The 2D view to render the caption in
|
|
80
|
-
* @param {CaptionTrack} params.track - Caption track configuration
|
|
81
|
-
* @returns {Generator} Generator function for caption track animation
|
|
82
|
-
*/
|
|
83
|
-
export function* makeCaptionTrack({
|
|
84
|
-
view,
|
|
85
|
-
track,
|
|
86
|
-
}: {
|
|
87
|
-
view: View2D;
|
|
88
|
-
track: VisualizerTrack;
|
|
89
|
-
}) {
|
|
90
|
-
let prevTime = 0;
|
|
91
|
-
const captionTrackRef = createRef<any>();
|
|
92
|
-
view.add(<Layout size={"100%"} ref={captionTrackRef} />);
|
|
93
|
-
|
|
94
|
-
const tProps = track?.props;
|
|
95
|
-
|
|
96
|
-
const trackDefaultProps =
|
|
97
|
-
(CAPTION_STYLE[tProps?.capStyle ?? ""] || {}).word || {};
|
|
98
|
-
|
|
99
|
-
for (const element of track.elements) {
|
|
100
|
-
const eProps = element.props;
|
|
101
|
-
const rectStyle =
|
|
102
|
-
(CAPTION_STYLE[eProps?.capStyle ?? tProps?.capStyle ?? ""] || {}).rect ||
|
|
103
|
-
{};
|
|
104
|
-
// Cast alignItems/justifyContent as any to satisfy RectProps
|
|
105
|
-
const mappedRectStyle = {
|
|
106
|
-
...rectStyle,
|
|
107
|
-
justifyContent: rectStyle.justifyContent as any,
|
|
108
|
-
alignItems: rectStyle.alignItems as any,
|
|
109
|
-
};
|
|
110
|
-
const phraseProps = {
|
|
111
|
-
...trackDefaultProps,
|
|
112
|
-
colors: {
|
|
113
|
-
text:
|
|
114
|
-
eProps?.colors?.text ??
|
|
115
|
-
tProps?.colors?.text ??
|
|
116
|
-
DEFAULT_CAPTION_COLORS.text,
|
|
117
|
-
background:
|
|
118
|
-
eProps?.colors?.background ??
|
|
119
|
-
tProps?.colors?.background ??
|
|
120
|
-
DEFAULT_CAPTION_COLORS.background,
|
|
121
|
-
},
|
|
122
|
-
font: {
|
|
123
|
-
family:
|
|
124
|
-
eProps?.font?.family ??
|
|
125
|
-
tProps?.font?.family ??
|
|
126
|
-
DEFAULT_CAPTION_FONT.family,
|
|
127
|
-
size:
|
|
128
|
-
eProps?.font?.size ?? tProps?.font?.size ?? DEFAULT_CAPTION_FONT.size,
|
|
129
|
-
weight:
|
|
130
|
-
eProps?.font?.weight ??
|
|
131
|
-
tProps?.font?.weight ??
|
|
132
|
-
DEFAULT_CAPTION_FONT.weight,
|
|
133
|
-
},
|
|
134
|
-
fill:
|
|
135
|
-
eProps?.colors?.text ??
|
|
136
|
-
tProps?.colors?.text ??
|
|
137
|
-
DEFAULT_CAPTION_COLORS.text,
|
|
138
|
-
bgColor:
|
|
139
|
-
eProps?.colors?.background ??
|
|
140
|
-
tProps?.colors?.background ??
|
|
141
|
-
DEFAULT_CAPTION_COLORS.background,
|
|
142
|
-
bgOpacity: eProps?.bgOpacity ?? tProps?.bgOpacity ?? 1,
|
|
143
|
-
...(tProps?.captionProps || {}),
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
yield* waitFor(element?.s - prevTime);
|
|
147
|
-
const phraseRef = createRef<any>();
|
|
148
|
-
captionTrackRef().add(
|
|
149
|
-
<Rect
|
|
150
|
-
ref={phraseRef}
|
|
151
|
-
key={element.id}
|
|
152
|
-
{...mappedRectStyle}
|
|
153
|
-
x={eProps?.x ?? tProps?.x}
|
|
154
|
-
y={eProps?.y ?? tProps?.y}
|
|
155
|
-
layout
|
|
156
|
-
/>
|
|
157
|
-
);
|
|
158
|
-
if (tProps?.capStyle === "word_by_word_with_bg") {
|
|
159
|
-
const _color = new Color({...hexToRGB(phraseProps.bgColor), a: phraseProps?.bgOpacity ?? 1});
|
|
160
|
-
phraseRef().fill(_color);
|
|
161
|
-
}
|
|
162
|
-
yield* elementController.get("caption")?.create({
|
|
163
|
-
containerRef: phraseRef,
|
|
164
|
-
caption: {
|
|
165
|
-
...element,
|
|
166
|
-
t: element.t ?? "",
|
|
167
|
-
capStyle: eProps?.capStyle ?? tProps?.capStyle,
|
|
168
|
-
props: phraseProps,
|
|
169
|
-
},
|
|
170
|
-
view,
|
|
171
|
-
});
|
|
172
|
-
prevTime = element.e;
|
|
173
|
-
yield phraseRef().remove();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Creates a scene track with specified configuration
|
|
179
|
-
* @param {Object} params - Parameters for scene track creation
|
|
180
|
-
* @param {View2D} params.view - The 2D view to render the scene in
|
|
181
|
-
* @param {SceneTrack} params.track - Scene track configuration
|
|
182
|
-
* @returns {Generator} Generator function for scene track animation
|
|
183
|
-
*/
|
|
184
|
-
export function* makeSceneTrack({
|
|
185
|
-
view,
|
|
186
|
-
track,
|
|
187
|
-
}: {
|
|
188
|
-
view: View2D;
|
|
189
|
-
track: VisualizerTrack;
|
|
190
|
-
}) {
|
|
191
|
-
const frameRef = createRef<any>();
|
|
192
|
-
view.add(<Layout size={"100%"} ref={frameRef} layout />);
|
|
193
|
-
for (const sceneElement of track.elements || []) {
|
|
194
|
-
yield* elementController.get("scene")?.create({
|
|
195
|
-
containerRef: frameRef,
|
|
196
|
-
element: sceneElement,
|
|
197
|
-
view,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
yield frameRef().remove();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Creates an element track with specified configuration
|
|
205
|
-
* @param {Object} params - Parameters for element track creation
|
|
206
|
-
* @param {View2D} params.view - The 2D view to render the element in
|
|
207
|
-
* @param {ElementTrack} params.track - Element track configuration
|
|
208
|
-
* @returns {Generator} Generator function for element track animation
|
|
209
|
-
*/
|
|
210
|
-
export function* makeElementTrack({
|
|
211
|
-
view,
|
|
212
|
-
track,
|
|
213
|
-
}: {
|
|
214
|
-
view: View2D;
|
|
215
|
-
track: VisualizerTrack;
|
|
216
|
-
}) {
|
|
217
|
-
const elementTrackRef = createRef<any>();
|
|
218
|
-
view.add(<Layout size={"100%"} ref={elementTrackRef} />);
|
|
219
|
-
|
|
220
|
-
const sequence: ThreadGenerator[] = [];
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Track component that handles the creation and management of different types of tracks
|
|
3
|
+
* including video, audio, captions, scenes, and elements.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Layout, Rect, View2D, Audio } from "@twick/2d";
|
|
7
|
+
import { VisualizerTrack } from "../helpers/types";
|
|
8
|
+
import { all, Color, createRef, ThreadGenerator, waitFor } from "@twick/core";
|
|
9
|
+
import {
|
|
10
|
+
CAPTION_STYLE,
|
|
11
|
+
DEFAULT_CAPTION_COLORS,
|
|
12
|
+
DEFAULT_CAPTION_FONT,
|
|
13
|
+
} from "../helpers/constants";
|
|
14
|
+
import { logger } from "../helpers/log.utils";
|
|
15
|
+
import elementController from "../controllers/element.controller";
|
|
16
|
+
import { hexToRGB } from "../helpers/utils";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a video track with specified configuration
|
|
20
|
+
* @param {Object} params - Parameters for video track creation
|
|
21
|
+
* @param {View2D} params.view - The 2D view to render the video in
|
|
22
|
+
* @param {VideoTrack} params.track - Video track configuration
|
|
23
|
+
* @returns {Generator} Generator function for video track animation
|
|
24
|
+
*/
|
|
25
|
+
export function* makeVideoTrack({
|
|
26
|
+
view,
|
|
27
|
+
track,
|
|
28
|
+
}: {
|
|
29
|
+
view: View2D;
|
|
30
|
+
track: VisualizerTrack;
|
|
31
|
+
}) {
|
|
32
|
+
const frameRef = createRef<any>();
|
|
33
|
+
let prevTime = 0;
|
|
34
|
+
view.add(<Layout size={"100%"} ref={frameRef} layout />);
|
|
35
|
+
for (const element of track.elements || []) {
|
|
36
|
+
yield* waitFor(element?.s - prevTime);
|
|
37
|
+
yield* elementController.get("video")?.create({
|
|
38
|
+
containerRef: frameRef,
|
|
39
|
+
element,
|
|
40
|
+
view,
|
|
41
|
+
});
|
|
42
|
+
prevTime = element.e;
|
|
43
|
+
}
|
|
44
|
+
yield frameRef().remove();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates an audio track with specified configuration
|
|
49
|
+
* @param {Object} params - Parameters for audio track creation
|
|
50
|
+
* @param {View2D} params.view - The 2D view to render the audio in
|
|
51
|
+
* @param {AudioTrack} params.track - Audio track configuration
|
|
52
|
+
* @returns {Generator} Generator function for audio track animation
|
|
53
|
+
*/
|
|
54
|
+
export function* makeAudioTrack({
|
|
55
|
+
view,
|
|
56
|
+
track,
|
|
57
|
+
}: {
|
|
58
|
+
view: View2D;
|
|
59
|
+
track: VisualizerTrack;
|
|
60
|
+
}) {
|
|
61
|
+
let prevTime = 0;
|
|
62
|
+
for (const audioElement of track.elements) {
|
|
63
|
+
const audioRef = createRef<any>();
|
|
64
|
+
yield* waitFor(audioElement?.s - prevTime);
|
|
65
|
+
prevTime = audioElement?.e;
|
|
66
|
+
logger(`Adding audio element ${audioElement.id}`);
|
|
67
|
+
view.add(
|
|
68
|
+
<Audio ref={audioRef} key={audioElement.id} {...audioElement.props} />
|
|
69
|
+
);
|
|
70
|
+
yield* waitFor(Math.max(0, audioElement.e - audioElement.s));
|
|
71
|
+
yield audioRef().playing(false);
|
|
72
|
+
yield audioRef().remove();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Creates a caption track with specified configuration
|
|
78
|
+
* @param {Object} params - Parameters for caption track creation
|
|
79
|
+
* @param {View2D} params.view - The 2D view to render the caption in
|
|
80
|
+
* @param {CaptionTrack} params.track - Caption track configuration
|
|
81
|
+
* @returns {Generator} Generator function for caption track animation
|
|
82
|
+
*/
|
|
83
|
+
export function* makeCaptionTrack({
|
|
84
|
+
view,
|
|
85
|
+
track,
|
|
86
|
+
}: {
|
|
87
|
+
view: View2D;
|
|
88
|
+
track: VisualizerTrack;
|
|
89
|
+
}) {
|
|
90
|
+
let prevTime = 0;
|
|
91
|
+
const captionTrackRef = createRef<any>();
|
|
92
|
+
view.add(<Layout size={"100%"} ref={captionTrackRef} />);
|
|
93
|
+
|
|
94
|
+
const tProps = track?.props;
|
|
95
|
+
|
|
96
|
+
const trackDefaultProps =
|
|
97
|
+
(CAPTION_STYLE[tProps?.capStyle ?? ""] || {}).word || {};
|
|
98
|
+
|
|
99
|
+
for (const element of track.elements) {
|
|
100
|
+
const eProps = element.props;
|
|
101
|
+
const rectStyle =
|
|
102
|
+
(CAPTION_STYLE[eProps?.capStyle ?? tProps?.capStyle ?? ""] || {}).rect ||
|
|
103
|
+
{};
|
|
104
|
+
// Cast alignItems/justifyContent as any to satisfy RectProps
|
|
105
|
+
const mappedRectStyle = {
|
|
106
|
+
...rectStyle,
|
|
107
|
+
justifyContent: rectStyle.justifyContent as any,
|
|
108
|
+
alignItems: rectStyle.alignItems as any,
|
|
109
|
+
};
|
|
110
|
+
const phraseProps = {
|
|
111
|
+
...trackDefaultProps,
|
|
112
|
+
colors: {
|
|
113
|
+
text:
|
|
114
|
+
eProps?.colors?.text ??
|
|
115
|
+
tProps?.colors?.text ??
|
|
116
|
+
DEFAULT_CAPTION_COLORS.text,
|
|
117
|
+
background:
|
|
118
|
+
eProps?.colors?.background ??
|
|
119
|
+
tProps?.colors?.background ??
|
|
120
|
+
DEFAULT_CAPTION_COLORS.background,
|
|
121
|
+
},
|
|
122
|
+
font: {
|
|
123
|
+
family:
|
|
124
|
+
eProps?.font?.family ??
|
|
125
|
+
tProps?.font?.family ??
|
|
126
|
+
DEFAULT_CAPTION_FONT.family,
|
|
127
|
+
size:
|
|
128
|
+
eProps?.font?.size ?? tProps?.font?.size ?? DEFAULT_CAPTION_FONT.size,
|
|
129
|
+
weight:
|
|
130
|
+
eProps?.font?.weight ??
|
|
131
|
+
tProps?.font?.weight ??
|
|
132
|
+
DEFAULT_CAPTION_FONT.weight,
|
|
133
|
+
},
|
|
134
|
+
fill:
|
|
135
|
+
eProps?.colors?.text ??
|
|
136
|
+
tProps?.colors?.text ??
|
|
137
|
+
DEFAULT_CAPTION_COLORS.text,
|
|
138
|
+
bgColor:
|
|
139
|
+
eProps?.colors?.background ??
|
|
140
|
+
tProps?.colors?.background ??
|
|
141
|
+
DEFAULT_CAPTION_COLORS.background,
|
|
142
|
+
bgOpacity: eProps?.bgOpacity ?? tProps?.bgOpacity ?? 1,
|
|
143
|
+
...(tProps?.captionProps || {}),
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
yield* waitFor(element?.s - prevTime);
|
|
147
|
+
const phraseRef = createRef<any>();
|
|
148
|
+
captionTrackRef().add(
|
|
149
|
+
<Rect
|
|
150
|
+
ref={phraseRef}
|
|
151
|
+
key={element.id}
|
|
152
|
+
{...mappedRectStyle}
|
|
153
|
+
x={eProps?.x ?? tProps?.x}
|
|
154
|
+
y={eProps?.y ?? tProps?.y}
|
|
155
|
+
layout
|
|
156
|
+
/>
|
|
157
|
+
);
|
|
158
|
+
if (tProps?.capStyle === "word_by_word_with_bg") {
|
|
159
|
+
const _color = new Color({...hexToRGB(phraseProps.bgColor), a: phraseProps?.bgOpacity ?? 1});
|
|
160
|
+
phraseRef().fill(_color);
|
|
161
|
+
}
|
|
162
|
+
yield* elementController.get("caption")?.create({
|
|
163
|
+
containerRef: phraseRef,
|
|
164
|
+
caption: {
|
|
165
|
+
...element,
|
|
166
|
+
t: element.t ?? "",
|
|
167
|
+
capStyle: eProps?.capStyle ?? tProps?.capStyle,
|
|
168
|
+
props: phraseProps,
|
|
169
|
+
},
|
|
170
|
+
view,
|
|
171
|
+
});
|
|
172
|
+
prevTime = element.e;
|
|
173
|
+
yield phraseRef().remove();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Creates a scene track with specified configuration
|
|
179
|
+
* @param {Object} params - Parameters for scene track creation
|
|
180
|
+
* @param {View2D} params.view - The 2D view to render the scene in
|
|
181
|
+
* @param {SceneTrack} params.track - Scene track configuration
|
|
182
|
+
* @returns {Generator} Generator function for scene track animation
|
|
183
|
+
*/
|
|
184
|
+
export function* makeSceneTrack({
|
|
185
|
+
view,
|
|
186
|
+
track,
|
|
187
|
+
}: {
|
|
188
|
+
view: View2D;
|
|
189
|
+
track: VisualizerTrack;
|
|
190
|
+
}) {
|
|
191
|
+
const frameRef = createRef<any>();
|
|
192
|
+
view.add(<Layout size={"100%"} ref={frameRef} layout />);
|
|
193
|
+
for (const sceneElement of track.elements || []) {
|
|
194
|
+
yield* elementController.get("scene")?.create({
|
|
195
|
+
containerRef: frameRef,
|
|
196
|
+
element: sceneElement,
|
|
197
|
+
view,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
yield frameRef().remove();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Creates an element track with specified configuration
|
|
205
|
+
* @param {Object} params - Parameters for element track creation
|
|
206
|
+
* @param {View2D} params.view - The 2D view to render the element in
|
|
207
|
+
* @param {ElementTrack} params.track - Element track configuration
|
|
208
|
+
* @returns {Generator} Generator function for element track animation
|
|
209
|
+
*/
|
|
210
|
+
export function* makeElementTrack({
|
|
211
|
+
view,
|
|
212
|
+
track,
|
|
213
|
+
}: {
|
|
214
|
+
view: View2D;
|
|
215
|
+
track: VisualizerTrack;
|
|
216
|
+
}) {
|
|
217
|
+
const elementTrackRef = createRef<any>();
|
|
218
|
+
view.add(<Layout size={"100%"} ref={elementTrackRef} />);
|
|
219
|
+
|
|
220
|
+
const sequence: ThreadGenerator[] = [];
|
|
221
|
+
try {
|
|
222
|
+
for (const element of track.elements) {
|
|
223
|
+
sequence.push(
|
|
224
|
+
elementController.get(element.type)?.create({
|
|
225
|
+
containerRef: elementTrackRef,
|
|
226
|
+
element,
|
|
227
|
+
view,
|
|
228
|
+
})
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
} catch (error) {
|
|
232
|
+
logger("Error creating element track", error);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
yield* all(...sequence);
|
|
236
|
+
yield elementTrackRef().remove();
|
|
237
|
+
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { BlurAnimation } from "../animations/blur";
|
|
2
|
-
import { BreatheAnimation } from "../animations/breathe";
|
|
3
|
-
import { FadeAnimation } from "../animations/fade";
|
|
4
|
-
import { PhotoRiseAnimation } from "../animations/photo-rise";
|
|
5
|
-
import { PhotoZoomAnimation } from "../animations/photo-zoom";
|
|
6
|
-
import { RiseAnimation } from "../animations/rise";
|
|
7
|
-
import { SuccessionAnimation } from "../animations/succession";
|
|
8
|
-
import { Animation } from "../helpers/types";
|
|
9
|
-
|
|
10
|
-
export class AnimationController {
|
|
11
|
-
private animations: Map<string, Animation> = new Map();
|
|
12
|
-
|
|
13
|
-
register(animation: Animation) {
|
|
14
|
-
this.animations.set(animation.name, animation);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get(name: string): Animation | undefined {
|
|
18
|
-
return this.animations.get(name);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
list(): string[] {
|
|
22
|
-
return Array.from(this.animations.keys());
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const registerAnimations = () => {
|
|
27
|
-
animationController.register(FadeAnimation);
|
|
28
|
-
animationController.register(RiseAnimation);
|
|
29
|
-
animationController.register(BreatheAnimation);
|
|
30
|
-
animationController.register(SuccessionAnimation);
|
|
31
|
-
animationController.register(BlurAnimation);
|
|
32
|
-
animationController.register(PhotoZoomAnimation);
|
|
33
|
-
animationController.register(PhotoRiseAnimation);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const animationController = new AnimationController();
|
|
37
|
-
registerAnimations();
|
|
38
|
-
|
|
1
|
+
import { BlurAnimation } from "../animations/blur";
|
|
2
|
+
import { BreatheAnimation } from "../animations/breathe";
|
|
3
|
+
import { FadeAnimation } from "../animations/fade";
|
|
4
|
+
import { PhotoRiseAnimation } from "../animations/photo-rise";
|
|
5
|
+
import { PhotoZoomAnimation } from "../animations/photo-zoom";
|
|
6
|
+
import { RiseAnimation } from "../animations/rise";
|
|
7
|
+
import { SuccessionAnimation } from "../animations/succession";
|
|
8
|
+
import { Animation } from "../helpers/types";
|
|
9
|
+
|
|
10
|
+
export class AnimationController {
|
|
11
|
+
private animations: Map<string, Animation> = new Map();
|
|
12
|
+
|
|
13
|
+
register(animation: Animation) {
|
|
14
|
+
this.animations.set(animation.name, animation);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get(name: string): Animation | undefined {
|
|
18
|
+
return this.animations.get(name);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
list(): string[] {
|
|
22
|
+
return Array.from(this.animations.keys());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const registerAnimations = () => {
|
|
27
|
+
animationController.register(FadeAnimation);
|
|
28
|
+
animationController.register(RiseAnimation);
|
|
29
|
+
animationController.register(BreatheAnimation);
|
|
30
|
+
animationController.register(SuccessionAnimation);
|
|
31
|
+
animationController.register(BlurAnimation);
|
|
32
|
+
animationController.register(PhotoZoomAnimation);
|
|
33
|
+
animationController.register(PhotoRiseAnimation);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const animationController = new AnimationController();
|
|
37
|
+
registerAnimations();
|
|
38
|
+
|
|
39
39
|
export default animationController;
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { AudioElement } from "../elements/audio.element";
|
|
2
|
-
import { CaptionElement } from "../elements/caption.element";
|
|
3
|
-
import { CircleElement } from "../elements/circle.element";
|
|
4
|
-
import { IconElement } from "../elements/icon.element";
|
|
5
|
-
import { ImageElement } from "../elements/image.element";
|
|
6
|
-
import { RectElement } from "../elements/rect.element";
|
|
7
|
-
import { SceneElement } from "../elements/scene.element";
|
|
8
|
-
import { TextElement } from "../elements/text.element";
|
|
9
|
-
import { VideoElement } from "../elements/video.element";
|
|
10
|
-
import { Element } from "../helpers/types";
|
|
11
|
-
|
|
12
|
-
export class ElementController {
|
|
13
|
-
private elements: Map<string, Element> = new Map();
|
|
14
|
-
|
|
15
|
-
register(element: Element) {
|
|
16
|
-
this.elements.set(element.name, element);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get(name: string): Element | undefined {
|
|
20
|
-
return this.elements.get(name);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
list(): string[] {
|
|
24
|
-
return Array.from(this.elements.keys());
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const registerElements = () => {
|
|
29
|
-
elementController.register(VideoElement);
|
|
30
|
-
elementController.register(CaptionElement);
|
|
31
|
-
elementController.register(SceneElement);
|
|
32
|
-
elementController.register(ImageElement);
|
|
33
|
-
elementController.register(TextElement);
|
|
34
|
-
elementController.register(AudioElement);
|
|
35
|
-
elementController.register(CircleElement);
|
|
36
|
-
elementController.register(IconElement);
|
|
37
|
-
elementController.register(RectElement);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const elementController = new ElementController();
|
|
41
|
-
registerElements();
|
|
42
|
-
|
|
1
|
+
import { AudioElement } from "../elements/audio.element";
|
|
2
|
+
import { CaptionElement } from "../elements/caption.element";
|
|
3
|
+
import { CircleElement } from "../elements/circle.element";
|
|
4
|
+
import { IconElement } from "../elements/icon.element";
|
|
5
|
+
import { ImageElement } from "../elements/image.element";
|
|
6
|
+
import { RectElement } from "../elements/rect.element";
|
|
7
|
+
import { SceneElement } from "../elements/scene.element";
|
|
8
|
+
import { TextElement } from "../elements/text.element";
|
|
9
|
+
import { VideoElement } from "../elements/video.element";
|
|
10
|
+
import { Element } from "../helpers/types";
|
|
11
|
+
|
|
12
|
+
export class ElementController {
|
|
13
|
+
private elements: Map<string, Element> = new Map();
|
|
14
|
+
|
|
15
|
+
register(element: Element) {
|
|
16
|
+
this.elements.set(element.name, element);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get(name: string): Element | undefined {
|
|
20
|
+
return this.elements.get(name);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
list(): string[] {
|
|
24
|
+
return Array.from(this.elements.keys());
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const registerElements = () => {
|
|
29
|
+
elementController.register(VideoElement);
|
|
30
|
+
elementController.register(CaptionElement);
|
|
31
|
+
elementController.register(SceneElement);
|
|
32
|
+
elementController.register(ImageElement);
|
|
33
|
+
elementController.register(TextElement);
|
|
34
|
+
elementController.register(AudioElement);
|
|
35
|
+
elementController.register(CircleElement);
|
|
36
|
+
elementController.register(IconElement);
|
|
37
|
+
elementController.register(RectElement);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const elementController = new ElementController();
|
|
41
|
+
registerElements();
|
|
42
|
+
|
|
43
43
|
export default elementController;
|