@twick/visualizer 0.0.1 → 0.14.0

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.
Files changed (61) hide show
  1. package/.turbo/turbo-build.log +19 -0
  2. package/.turbo/turbo-docs.log +7 -0
  3. package/LICENSE +197 -0
  4. package/README.md +1 -1
  5. package/dist/mp4.wasm +0 -0
  6. package/dist/project.css +1 -0
  7. package/dist/project.js +145 -0
  8. package/docs/.nojekyll +1 -0
  9. package/docs/README.md +13 -0
  10. package/docs/interfaces/Animation.md +47 -0
  11. package/docs/interfaces/Element.md +47 -0
  12. package/docs/interfaces/FrameEffectPlugin.md +47 -0
  13. package/docs/interfaces/TextEffect.md +47 -0
  14. package/docs/modules.md +535 -0
  15. package/package.json +34 -31
  16. package/src/animations/blur.tsx +60 -0
  17. package/src/animations/breathe.tsx +60 -0
  18. package/src/animations/fade.tsx +60 -0
  19. package/src/animations/photo-rise.tsx +66 -0
  20. package/src/animations/photo-zoom.tsx +73 -0
  21. package/src/animations/rise.tsx +118 -0
  22. package/src/animations/succession.tsx +77 -0
  23. package/src/components/frame-effects.tsx +2 -4
  24. package/src/components/track.tsx +232 -0
  25. package/src/controllers/animation.controller.ts +39 -0
  26. package/src/controllers/element.controller.ts +43 -0
  27. package/src/controllers/frame-effect.controller.tsx +30 -0
  28. package/src/controllers/text-effect.controller.ts +33 -0
  29. package/src/elements/audio.element.tsx +17 -0
  30. package/src/elements/caption.element.tsx +87 -0
  31. package/src/elements/circle.element.tsx +20 -0
  32. package/src/elements/icon.element.tsx +20 -0
  33. package/src/elements/image.element.tsx +55 -0
  34. package/src/elements/rect.element.tsx +22 -0
  35. package/src/elements/scene.element.tsx +29 -0
  36. package/src/elements/text.element.tsx +28 -0
  37. package/src/elements/video.element.tsx +56 -0
  38. package/src/frame-effects/circle.frame.tsx +103 -0
  39. package/src/frame-effects/rect.frame.tsx +103 -0
  40. package/src/helpers/caption.utils.ts +4 -14
  41. package/src/helpers/constants.ts +1 -1
  42. package/src/helpers/element.utils.ts +222 -68
  43. package/src/helpers/filters.ts +1 -1
  44. package/src/helpers/log.utils.ts +0 -3
  45. package/src/helpers/timing.utils.ts +2 -21
  46. package/src/helpers/types.ts +103 -8
  47. package/src/helpers/utils.ts +20 -0
  48. package/src/index.ts +4 -2
  49. package/src/live.tsx +1 -1
  50. package/src/project.ts +1 -1
  51. package/src/sample.ts +16 -218
  52. package/src/text-effects/elastic.tsx +39 -0
  53. package/src/text-effects/erase.tsx +58 -0
  54. package/src/text-effects/stream-word.tsx +60 -0
  55. package/src/text-effects/typewriter.tsx +59 -0
  56. package/src/visualizer.tsx +27 -27
  57. package/tsconfig.json +3 -2
  58. package/vite.config.ts +1 -1
  59. package/src/components/animation.tsx +0 -7
  60. package/src/components/element.tsx +0 -344
  61. package/src/components/timeline.tsx +0 -225
@@ -1,225 +0,0 @@
1
- /**
2
- * Timeline component that handles the creation and management of different types of timelines
3
- * including video, audio, captions, scenes, and elements.
4
- */
5
-
6
- import { Layout, Rect, View2D, Audio } from "@revideo/2d";
7
- import { VisualizerTimeline } from "../helpers/types";
8
- import { all, Color, createRef, waitFor } from "@revideo/core";
9
- import { addAudioElement, addCaptionElement, addCircleElement, addIconElement, addMediaElement, addRectElement, addTextElement, makeSceneElements } from "./element";
10
- import { CAPTION_STYLE, DEFAULT_CAPTION_COLORS, DEFAULT_CAPTION_FONT, ELEMENT_TYPES } from "../helpers/constants";
11
- import { logger } from "../helpers/log.utils";
12
-
13
- /**
14
- * Creates a video timeline with specified configuration
15
- * @param {Object} params - Parameters for video timeline creation
16
- * @param {View2D} params.view - The 2D view to render the video in
17
- * @param {VideoTimeline} params.timeline - Video timeline configuration
18
- * @returns {Generator} Generator function for video timeline animation
19
- */
20
- export function* makeVideoTimeline({
21
- view,
22
- timeline,
23
- }: {
24
- view: View2D;
25
- timeline: VisualizerTimeline;
26
- }) {
27
- const frameRef = createRef<any>();
28
- let prevTime = 0;
29
- view.add(<Layout size={"100%"} ref={frameRef} layout />);
30
- for (const element of timeline.elements || []) {
31
- yield* waitFor(element?.s - prevTime);
32
- yield* addMediaElement({
33
- containerRef: frameRef,
34
- element,
35
- mediaType: ELEMENT_TYPES.VIDEO,
36
- waitOnStart: false,
37
- });
38
- prevTime = element.e;
39
- }
40
- yield frameRef().remove();
41
- }
42
-
43
- /**
44
- * Creates an audio timeline with specified configuration
45
- * @param {Object} params - Parameters for audio timeline creation
46
- * @param {View2D} params.view - The 2D view to render the audio in
47
- * @param {AudioTimeline} params.timeline - Audio timeline configuration
48
- * @returns {Generator} Generator function for audio timeline animation
49
- */
50
- export function* makeAudioTimeline({
51
- view,
52
- timeline,
53
- }: {
54
- view: View2D;
55
- timeline: VisualizerTimeline;
56
- }) {
57
- let prevTime = 0;
58
- for (const audioElement of timeline.elements) {
59
- const audioRef = createRef<any>();
60
- yield* waitFor(audioElement?.s - prevTime);
61
- prevTime = audioElement?.e;
62
- logger(`Adding audio element ${audioElement.id}`);
63
- view.add(
64
- <Audio ref={audioRef} key={audioElement.id} {...audioElement.props} />
65
- );
66
- yield* waitFor(Math.max(0, audioElement.e - audioElement.s));
67
- yield audioRef().playing(false);
68
- yield audioRef().remove();
69
- }
70
- }
71
-
72
- /**
73
- * Creates a caption timeline with specified configuration
74
- * @param {Object} params - Parameters for caption timeline creation
75
- * @param {View2D} params.view - The 2D view to render the caption in
76
- * @param {CaptionTimeline} params.timeline - Caption timeline configuration
77
- * @returns {Generator} Generator function for caption timeline animation
78
- */
79
- export function* makeCaptionTimeline({ view, timeline }: { view: View2D; timeline: VisualizerTimeline }) {
80
- let prevTime = 0;
81
- const captionTimelineRef = createRef<any>();
82
- view.add(<Layout size={"100%"} ref={captionTimelineRef} />);
83
-
84
- const tProps = timeline?.props;
85
-
86
- const timelineDefaultProps = (CAPTION_STYLE[tProps?.capStyle ?? ""] || {}).word || {};
87
-
88
- for (const element of timeline.elements) {
89
- const eProps = element.props;
90
- const rectStyle = (CAPTION_STYLE[eProps?.capStyle ?? tProps?.capStyle ?? ""] || {}).rect || {};
91
- // Cast alignItems/justifyContent as any to satisfy RectProps
92
- const mappedRectStyle = {
93
- ...rectStyle,
94
- justifyContent: rectStyle.justifyContent as any,
95
- alignItems: rectStyle.alignItems as any,
96
- };
97
- const phraseProps = {
98
- ...timelineDefaultProps,
99
- colors: {
100
- text: eProps?.colors?.text ?? tProps?.colors?.text ?? DEFAULT_CAPTION_COLORS.text,
101
- background: eProps?.colors?.background ?? tProps?.colors?.background ?? DEFAULT_CAPTION_COLORS.background,
102
- },
103
- font: {
104
- family: eProps?.font?.family ?? tProps?.font?.family ?? DEFAULT_CAPTION_FONT.family,
105
- size: eProps?.font?.size ?? tProps?.font?.size ?? DEFAULT_CAPTION_FONT.size,
106
- weight: eProps?.font?.weight ?? tProps?.font?.weight ?? DEFAULT_CAPTION_FONT.weight
107
- },
108
- fill: eProps?.colors?.text ?? tProps?.colors?.text ?? DEFAULT_CAPTION_COLORS.text,
109
- bgColor: eProps?.colors?.background ?? tProps?.colors?.background ??DEFAULT_CAPTION_COLORS.background,
110
- bgOpacity: eProps?.bgOpacity ?? tProps?.bgOpacity ?? 1,
111
- ...(tProps?.captionProps || {}),
112
- };
113
-
114
- yield* waitFor(element?.s - prevTime);
115
- const phraseRef = createRef<any>();
116
- captionTimelineRef().add(
117
- <Rect
118
- ref={phraseRef}
119
- key={element.id}
120
- {...mappedRectStyle}
121
- x={eProps?.x ?? tProps?.x}
122
- y={eProps?.y ?? tProps?.y}
123
- layout
124
- />
125
- );
126
- if (tProps?.capStyle === "word_by_word_with_bg") {
127
- phraseRef().fill(
128
- new Color(phraseProps.bgColor).alpha(phraseProps.bgOpacity)
129
- );
130
- }
131
- yield* addCaptionElement({
132
- caption: {...element, t: element.t ?? ""},
133
- captionProps: phraseProps,
134
- containerRef: phraseRef,
135
- capStyle: eProps?.capStyle ?? tProps?.capStyle,
136
- });
137
- prevTime = element.e;
138
- yield phraseRef().remove();
139
- }
140
- }
141
-
142
- /**
143
- * Creates a scene timeline with specified configuration
144
- * @param {Object} params - Parameters for scene timeline creation
145
- * @param {View2D} params.view - The 2D view to render the scene in
146
- * @param {SceneTimeline} params.timeline - Scene timeline configuration
147
- * @returns {Generator} Generator function for scene timeline animation
148
- */
149
- export function* makeSceneTimeline({ view, timeline }: { view: View2D; timeline: VisualizerTimeline }) {
150
- const frameRef = createRef<any>();
151
- let prevTime = 0;
152
- view.add(<Layout size={"100%"} ref={frameRef} layout />);
153
- for (const sceneElement of timeline.elements || []) {
154
- yield* waitFor(sceneElement?.s - prevTime);
155
- yield* makeSceneElements({
156
- containerRef: frameRef,
157
- element: sceneElement,
158
- });
159
- prevTime = sceneElement.e;
160
- }
161
- yield frameRef().remove();
162
- }
163
-
164
- /**
165
- * Creates an element timeline with specified configuration
166
- * @param {Object} params - Parameters for element timeline creation
167
- * @param {View2D} params.view - The 2D view to render the element in
168
- * @param {ElementTimeline} params.timeline - Element timeline configuration
169
- * @returns {Generator} Generator function for element timeline animation
170
- */
171
- export function* makeElementTimeline({ view, timeline }: { view: View2D; timeline: VisualizerTimeline }) {
172
- const elementTimelineRef = createRef<any>();
173
- view.add(<Layout size={"100%"} ref={elementTimelineRef} />);
174
-
175
- const sequence = [];
176
- for (const element of timeline.elements) {
177
- switch (element.type) {
178
- case ELEMENT_TYPES.RECT:
179
- sequence.push(
180
- addRectElement({ containerRef: elementTimelineRef, element })
181
- );
182
- break;
183
- case ELEMENT_TYPES.TEXT:
184
- sequence.push(
185
- addTextElement({ containerRef: elementTimelineRef, element })
186
- );
187
- break;
188
- case ELEMENT_TYPES.IMAGE:
189
- sequence.push(
190
- addMediaElement({
191
- containerRef: elementTimelineRef,
192
- element,
193
- mediaType: ELEMENT_TYPES.IMAGE,
194
- })
195
- );
196
- break;
197
- case ELEMENT_TYPES.VIDEO:
198
- sequence.push(
199
- addMediaElement({
200
- containerRef: elementTimelineRef,
201
- element,
202
- mediaType: ELEMENT_TYPES.VIDEO,
203
- })
204
- );
205
- break;
206
- case ELEMENT_TYPES.AUDIO:
207
- sequence.push(
208
- addAudioElement({ containerRef: elementTimelineRef, element })
209
- );
210
- break;
211
- case ELEMENT_TYPES.CIRCLE:
212
- sequence.push(
213
- addCircleElement({ containerRef: elementTimelineRef, element })
214
- );
215
- break;
216
- case ELEMENT_TYPES.ICON:
217
- sequence.push(
218
- addIconElement({ containerRef: elementTimelineRef, element })
219
- );
220
- break;
221
- }
222
- }
223
- yield* all(...sequence);
224
- yield elementTimelineRef().remove();
225
- }