@twick/visualizer 0.0.1 → 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.
Files changed (53) hide show
  1. package/.eslintrc.json +20 -20
  2. package/README.md +12 -12
  3. package/package.json +34 -31
  4. package/package.json.bak +34 -0
  5. package/src/animations/blur.tsx +60 -0
  6. package/src/animations/breathe.tsx +60 -0
  7. package/src/animations/fade.tsx +60 -0
  8. package/src/animations/photo-rise.tsx +66 -0
  9. package/src/animations/photo-zoom.tsx +73 -0
  10. package/src/animations/rise.tsx +118 -0
  11. package/src/animations/succession.tsx +77 -0
  12. package/src/components/frame-effects.tsx +188 -190
  13. package/src/components/track.tsx +237 -0
  14. package/src/controllers/animation.controller.ts +39 -0
  15. package/src/controllers/element.controller.ts +43 -0
  16. package/src/controllers/frame-effect.controller.tsx +30 -0
  17. package/src/controllers/text-effect.controller.ts +33 -0
  18. package/src/elements/audio.element.tsx +17 -0
  19. package/src/elements/caption.element.tsx +87 -0
  20. package/src/elements/circle.element.tsx +20 -0
  21. package/src/elements/icon.element.tsx +20 -0
  22. package/src/elements/image.element.tsx +53 -0
  23. package/src/elements/rect.element.tsx +22 -0
  24. package/src/elements/scene.element.tsx +29 -0
  25. package/src/elements/text.element.tsx +28 -0
  26. package/src/elements/video.element.tsx +55 -0
  27. package/src/frame-effects/circle.frame.tsx +103 -0
  28. package/src/frame-effects/rect.frame.tsx +103 -0
  29. package/src/global.css +11 -11
  30. package/src/helpers/caption.utils.ts +30 -40
  31. package/src/helpers/constants.ts +162 -158
  32. package/src/helpers/element.utils.ts +239 -85
  33. package/src/helpers/event.utils.ts +6 -0
  34. package/src/helpers/filters.ts +127 -127
  35. package/src/helpers/log.utils.ts +29 -32
  36. package/src/helpers/timing.utils.ts +110 -129
  37. package/src/helpers/types.ts +242 -146
  38. package/src/helpers/utils.ts +20 -0
  39. package/src/index.ts +6 -4
  40. package/src/live.tsx +16 -16
  41. package/src/project.ts +6 -6
  42. package/src/sample.ts +247 -449
  43. package/src/text-effects/elastic.tsx +39 -0
  44. package/src/text-effects/erase.tsx +58 -0
  45. package/src/text-effects/stream-word.tsx +60 -0
  46. package/src/text-effects/typewriter.tsx +59 -0
  47. package/src/visualizer.tsx +98 -78
  48. package/tsconfig.json +11 -10
  49. package/typedoc.json +14 -14
  50. package/vite.config.ts +15 -15
  51. package/src/components/animation.tsx +0 -7
  52. package/src/components/element.tsx +0 -344
  53. package/src/components/timeline.tsx +0 -225
@@ -1,129 +1,110 @@
1
- import {
2
- linear,
3
- easeInSine,
4
- easeOutSine,
5
- easeInOutSine,
6
- easeInQuad,
7
- easeOutQuad,
8
- easeInOutQuad,
9
- easeInCubic,
10
- easeOutCubic,
11
- easeInOutCubic,
12
- easeInQuart,
13
- easeOutQuart,
14
- easeInOutQuart,
15
- easeInQuint,
16
- easeOutQuint,
17
- easeInOutQuint,
18
- easeInExpo,
19
- easeOutExpo,
20
- easeInOutExpo,
21
- easeInCirc,
22
- easeOutCirc,
23
- easeInOutCirc,
24
- easeInBack,
25
- easeOutBack,
26
- easeInOutBack,
27
- easeInElastic,
28
- easeOutElastic,
29
- easeInOutElastic,
30
- easeInBounce,
31
- easeOutBounce,
32
- easeInOutBounce,
33
- } from "@revideo/core";
34
-
35
- /**
36
- * Timing utilities for the visualizer package.
37
- * Provides functions for handling timing and animation calculations.
38
- */
39
-
40
- /**
41
- * Gets the timing function based on the provided name
42
- * @param {string} name - Name of the timing function
43
- * @returns {Function} The timing function
44
- */
45
- export function getTimingFunction(name: string) {
46
- switch (name) {
47
- case "easeInSine":
48
- return easeInSine;
49
- case "easeOutSine":
50
- return easeOutSine;
51
- case "easeInOutSine":
52
- return easeInOutSine;
53
- case "easeInQuad":
54
- return easeInQuad;
55
- case "easeOutQuad":
56
- return easeOutQuad;
57
- case "easeInOutQuad":
58
- return easeInOutQuad;
59
- case "easeInCubic":
60
- return easeInCubic;
61
- case "easeOutCubic":
62
- return easeOutCubic;
63
- case "easeInOutCubic":
64
- return easeInOutCubic;
65
- case "easeInQuart":
66
- return easeInQuart;
67
- case "easeOutQuart":
68
- return easeOutQuart;
69
- case "easeInOutQuart":
70
- return easeInOutQuart;
71
- case "easeInQuint":
72
- return easeInQuint;
73
- case "easeOutQuint":
74
- return easeOutQuint;
75
- case "easeInOutQuint":
76
- return easeInOutQuint;
77
- case "easeInExpo":
78
- return easeInExpo;
79
- case "easeOutExpo":
80
- return easeOutExpo;
81
- case "easeInOutExpo":
82
- return easeInOutExpo;
83
- case "easeInCirc":
84
- return easeInCirc;
85
- case "easeOutCirc":
86
- return easeOutCirc;
87
- case "easeInOutCirc":
88
- return easeInOutCirc;
89
- case "easeInBack":
90
- return easeInBack;
91
- case "easeOutBack":
92
- return easeOutBack;
93
- case "easeInOutBack":
94
- return easeInOutBack;
95
- case "easeInElastic":
96
- return easeInElastic;
97
- case "easeOutElastic":
98
- return easeOutElastic;
99
- case "easeInOutElastic":
100
- return easeInOutElastic;
101
- case "easeInBounce":
102
- return easeInBounce;
103
- case "easeOutBounce":
104
- return easeOutBounce;
105
- case "easeInOutBounce":
106
- return easeInOutBounce;
107
- default:
108
- return linear;
109
- }
110
- }
111
-
112
- /**
113
- * Calculates the duration between two timestamps
114
- * @param {number} startTime - Start timestamp
115
- * @param {number} endTime - End timestamp
116
- * @returns {number} Duration in milliseconds
117
- */
118
- export function calculateDuration(startTime: number, endTime: number) {
119
- // ... existing code ...
120
- }
121
-
122
- /**
123
- * Formats a timestamp into a readable time string
124
- * @param {number} timestamp - Timestamp to format
125
- * @returns {string} Formatted time string
126
- */
127
- export function formatTime(timestamp: number) {
128
- // ... existing code ...
129
- }
1
+ import {
2
+ linear,
3
+ easeInSine,
4
+ easeOutSine,
5
+ easeInOutSine,
6
+ easeInQuad,
7
+ easeOutQuad,
8
+ easeInOutQuad,
9
+ easeInCubic,
10
+ easeOutCubic,
11
+ easeInOutCubic,
12
+ easeInQuart,
13
+ easeOutQuart,
14
+ easeInOutQuart,
15
+ easeInQuint,
16
+ easeOutQuint,
17
+ easeInOutQuint,
18
+ easeInExpo,
19
+ easeOutExpo,
20
+ easeInOutExpo,
21
+ easeInCirc,
22
+ easeOutCirc,
23
+ easeInOutCirc,
24
+ easeInBack,
25
+ easeOutBack,
26
+ easeInOutBack,
27
+ easeInElastic,
28
+ easeOutElastic,
29
+ easeInOutElastic,
30
+ easeInBounce,
31
+ easeOutBounce,
32
+ easeInOutBounce,
33
+ } from "@twick/core";
34
+
35
+ /**
36
+ * Timing utilities for the visualizer package.
37
+ * Provides functions for handling timing and animation calculations.
38
+ */
39
+
40
+ /**
41
+ * Gets the timing function based on the provided name
42
+ * @param {string} name - Name of the timing function
43
+ * @returns {Function} The timing function
44
+ */
45
+ export function getTimingFunction(name: string) {
46
+ switch (name) {
47
+ case "easeInSine":
48
+ return easeInSine;
49
+ case "easeOutSine":
50
+ return easeOutSine;
51
+ case "easeInOutSine":
52
+ return easeInOutSine;
53
+ case "easeInQuad":
54
+ return easeInQuad;
55
+ case "easeOutQuad":
56
+ return easeOutQuad;
57
+ case "easeInOutQuad":
58
+ return easeInOutQuad;
59
+ case "easeInCubic":
60
+ return easeInCubic;
61
+ case "easeOutCubic":
62
+ return easeOutCubic;
63
+ case "easeInOutCubic":
64
+ return easeInOutCubic;
65
+ case "easeInQuart":
66
+ return easeInQuart;
67
+ case "easeOutQuart":
68
+ return easeOutQuart;
69
+ case "easeInOutQuart":
70
+ return easeInOutQuart;
71
+ case "easeInQuint":
72
+ return easeInQuint;
73
+ case "easeOutQuint":
74
+ return easeOutQuint;
75
+ case "easeInOutQuint":
76
+ return easeInOutQuint;
77
+ case "easeInExpo":
78
+ return easeInExpo;
79
+ case "easeOutExpo":
80
+ return easeOutExpo;
81
+ case "easeInOutExpo":
82
+ return easeInOutExpo;
83
+ case "easeInCirc":
84
+ return easeInCirc;
85
+ case "easeOutCirc":
86
+ return easeOutCirc;
87
+ case "easeInOutCirc":
88
+ return easeInOutCirc;
89
+ case "easeInBack":
90
+ return easeInBack;
91
+ case "easeOutBack":
92
+ return easeOutBack;
93
+ case "easeInOutBack":
94
+ return easeInOutBack;
95
+ case "easeInElastic":
96
+ return easeInElastic;
97
+ case "easeOutElastic":
98
+ return easeOutElastic;
99
+ case "easeInOutElastic":
100
+ return easeInOutElastic;
101
+ case "easeInBounce":
102
+ return easeInBounce;
103
+ case "easeOutBounce":
104
+ return easeOutBounce;
105
+ case "easeInOutBounce":
106
+ return easeInOutBounce;
107
+ default:
108
+ return linear;
109
+ }
110
+ }
@@ -1,146 +1,242 @@
1
- export type VideoInput = {
2
- backgroundColor: string;
3
- properties: {
4
- width: number;
5
- height: number;
6
- };
7
- timeline: VisualizerTimeline[];
8
- };
9
-
10
- export type MediaType = "video" | "image";
11
-
12
- export type ObjectFit = "contain" | "cover" | "fill" | "none";
13
-
14
- export type SizeVector = {
15
- x: number;
16
- y: number;
17
- };
18
-
19
- export type Size = {
20
- width: number;
21
- height: number;
22
- };
23
-
24
- export type SizeArray = [number, number];
25
-
26
- export type Position = {
27
- x: number;
28
- y: number;
29
- };
30
-
31
- export type FrameEffect = {
32
- s: number;
33
- e: number;
34
- props: FrameEffectProps;
35
- };
36
-
37
-
38
- export type FrameEffectProps = {
39
- frameSize: SizeArray;
40
- frameShape: "circle" | "rect";
41
- framePosition: Position;
42
- radius: number;
43
- objectFit: ObjectFit;
44
- transitionDuration: number;
45
- transitionEasing?: string;
46
- elementPosition: Position;
47
- };
48
-
49
- export type CaptionStyle = {
50
- rect: {
51
- alignItems?: string;
52
- gap?: number;
53
- justifyContent?: string;
54
- padding?: [number, number];
55
- radius?: number;
56
- };
57
- word: {
58
- lineWidth: number;
59
- stroke: string;
60
- fontWeight: number;
61
- shadowOffset?: number[];
62
- shadowColor?: string;
63
- shadowBlur?: number;
64
- fill: string;
65
- fontFamily: string;
66
- bgColor?: string;
67
- bgOffsetWidth?: number;
68
- bgOffsetHeight?: number;
69
- fontSize: number;
70
- strokeFirst?: boolean;
71
- };
72
- };
73
-
74
- export type Caption = {
75
- t: string;
76
- s: number;
77
- e: number;
78
- props?: CaptionProps;
79
- }
80
-
81
- export type CaptionProps = {
82
- colors: CaptionColors;
83
- font: CaptionFont;
84
- bgOpacity?: number;
85
- bgOffsetWidth?: number;
86
- bgOffsetHeight?: number;
87
- bgMargin?: [number, number];
88
- bgRadius?: number;
89
- bgPadding?: [number, number];
90
- x?: number;
91
- y?: number;
92
- };
93
-
94
- export type CaptionColors = {
95
- text?: string;
96
- background?: string;
97
- highlight?: string;
98
- };
99
-
100
- export type CaptionFont = {
101
- family?: string;
102
- size?: number;
103
- weight?: number;
104
- style?: string;
105
- };
106
-
107
- export type VisualizerElement = {
108
- id: string;
109
- frame?: any;
110
- props?: any;
111
- objectFit?: 'contain' | 'cover' | 'fill';
112
- type?: string;
113
- s: number;
114
- e: number;
115
- backgroundColor?: string;
116
- elements?: VisualizerElement[];
117
- animations?: any[];
118
- scale?: number;
119
- t?: string;
120
- hWords?: any;
121
- };
122
-
123
- export type VisualizerTimeline = {
124
- id: string;
125
- type: string;
126
- elements: VisualizerElement[];
127
- captions?: Caption[];
128
- props?: {
129
- capStyle?: string;
130
- bgOpacity?: number;
131
- x?: number;
132
- y?: number;
133
- colors?: {
134
- text?: string;
135
- background?: string;
136
- highlight?: string;
137
- };
138
- font?: {
139
- family?: string;
140
- size?: number;
141
- weight?: number;
142
- style?: string;
143
- };
144
- captionProps?: CaptionProps;
145
- };
146
- };
1
+ import { View2D } from "@twick/2d";
2
+ import { Reference, ThreadGenerator, Vector2 } from "@twick/core";
3
+
4
+ export type VideoInput = {
5
+ playerId: string,
6
+ backgroundColor: string;
7
+ properties: {
8
+ width: number;
9
+ height: number;
10
+ };
11
+ tracks: VisualizerTrack[];
12
+ };
13
+
14
+ export type MediaType = "video" | "image";
15
+
16
+ export type ObjectFit = "contain" | "cover" | "fill" | "none";
17
+
18
+ export type SizeVector = {
19
+ x: number;
20
+ y: number;
21
+ };
22
+
23
+ export type Size = {
24
+ width: number;
25
+ height: number;
26
+ };
27
+
28
+ export type SizeArray = [number, number];
29
+
30
+ export type Position = {
31
+ x: number;
32
+ y: number;
33
+ };
34
+
35
+ export type FrameEffect = {
36
+ name: string;
37
+ s: number;
38
+ e: number;
39
+ props: FrameEffectProps;
40
+ };
41
+
42
+ export type FrameEffectProps = {
43
+ frameSize: SizeArray;
44
+ frameShape: "circle" | "rect";
45
+ framePosition: Position;
46
+ radius: number;
47
+ objectFit: ObjectFit;
48
+ transitionDuration: number;
49
+ transitionEasing?: string;
50
+ elementPosition: Position;
51
+ };
52
+
53
+ export type CaptionStyle = {
54
+ rect: {
55
+ alignItems?: string;
56
+ gap?: number;
57
+ justifyContent?: string;
58
+ padding?: [number, number];
59
+ radius?: number;
60
+ };
61
+ word: {
62
+ lineWidth: number;
63
+ stroke: string;
64
+ fontWeight: number;
65
+ shadowOffset?: number[];
66
+ shadowColor?: string;
67
+ shadowBlur?: number;
68
+ fill: string;
69
+ fontFamily: string;
70
+ bgColor?: string;
71
+ bgOffsetWidth?: number;
72
+ bgOffsetHeight?: number;
73
+ fontSize: number;
74
+ strokeFirst?: boolean;
75
+ };
76
+ };
77
+
78
+ export type Caption = {
79
+ t: string;
80
+ s: number;
81
+ e: number;
82
+ capStyle?: string;
83
+ props?: CaptionProps;
84
+ };
85
+
86
+ export type CaptionProps = {
87
+ colors: CaptionColors;
88
+ font: CaptionFont;
89
+ bgOpacity?: number;
90
+ bgOffsetWidth?: number;
91
+ bgOffsetHeight?: number;
92
+ bgMargin?: [number, number];
93
+ bgRadius?: number;
94
+ bgPadding?: [number, number];
95
+ x?: number;
96
+ y?: number;
97
+ };
98
+
99
+ export type CaptionColors = {
100
+ text?: string;
101
+ background?: string;
102
+ highlight?: string;
103
+ };
104
+
105
+ export type CaptionFont = {
106
+ family?: string;
107
+ size?: number;
108
+ weight?: number;
109
+ style?: string;
110
+ };
111
+
112
+ export type VisualizerElement = {
113
+ id: string;
114
+ trackId?: string;
115
+ frame?: any;
116
+ props?: any;
117
+ objectFit?: "contain" | "cover" | "fill";
118
+ type?: string;
119
+ s: number;
120
+ e: number;
121
+ backgroundColor?: string;
122
+ animation?: AnimationProps;
123
+ textEffect: TextEffectProps;
124
+ frameEffects?: FrameEffect[];
125
+ scale?: number;
126
+ t?: string;
127
+ hWords?: any;
128
+ };
129
+
130
+ export type VisualizerTrack = {
131
+ id: string;
132
+ type: string;
133
+ elements: VisualizerElement[];
134
+ props?: {
135
+ capStyle?: string;
136
+ bgOpacity?: number;
137
+ x?: number;
138
+ y?: number;
139
+ colors?: {
140
+ text?: string;
141
+ background?: string;
142
+ highlight?: string;
143
+ };
144
+ font?: {
145
+ family?: string;
146
+ size?: number;
147
+ weight?: number;
148
+ style?: string;
149
+ };
150
+ captionProps?: CaptionProps;
151
+ };
152
+ };
153
+
154
+ export type ElementParams = {
155
+ view: View2D;
156
+ containerRef: Reference<any>;
157
+ element?: VisualizerElement;
158
+ caption?: Caption;
159
+ waitOnStart?: boolean;
160
+ };
161
+
162
+ export interface Element<Params = ElementParams> {
163
+ name: string;
164
+ create(params: Params): ThreadGenerator;
165
+ }
166
+
167
+ export type TextEffectParams = {
168
+ elementRef: Reference<any>;
169
+ interval?: number;
170
+ duration?: number;
171
+ bufferTime?: number;
172
+ delay?: number;
173
+ direction?: "left" | "right" | "center";
174
+ };
175
+
176
+ export type TextEffectProps = {
177
+ name: string;
178
+ interval?: number;
179
+ duration?: number;
180
+ bufferTime?: number;
181
+ delay?: number;
182
+ direction?: "left" | "right" | "center";
183
+ };
184
+
185
+ export interface TextEffect<Params = TextEffectParams> {
186
+ name: string;
187
+ run(params: Params): Generator;
188
+ }
189
+
190
+ export type AnimationParams = {
191
+ elementRef: Reference<any>;
192
+ containerRef?: Reference<any>;
193
+ view: View2D;
194
+ interval?: number;
195
+ duration?: number;
196
+ intensity?: number;
197
+ mode?: "in" | "out";
198
+ animate?: "enter" | "exit" | "both";
199
+ direction?: "left" | "right" | "center" | "up" | "down";
200
+ };
201
+
202
+ export type AnimationProps = {
203
+ name: string;
204
+ interval?: number;
205
+ duration?: number;
206
+ intensity?: number;
207
+ mode?: "in" | "out";
208
+ animate?: "enter" | "exit" | "both";
209
+ direction?: "left" | "right" | "center" | "up" | "down";
210
+ };
211
+
212
+ export interface Animation<Params = AnimationParams> {
213
+ name: string;
214
+ run(params: Params): ThreadGenerator;
215
+ }
216
+
217
+ export type FrameEffectParams = {
218
+ elementRef: Reference<any>;
219
+ containerRef?: Reference<any>;
220
+ initFrameState: FrameState;
221
+ frameEffect: FrameEffect;
222
+ };
223
+
224
+ export interface FrameEffectPlugin<Params = FrameEffectParams> {
225
+ name: string;
226
+ run(params: Params): ThreadGenerator;
227
+ }
228
+
229
+ export type FrameState = {
230
+ frame: {
231
+ size: Vector2;
232
+ pos: Vector2;
233
+ radius: number;
234
+ scale: Vector2;
235
+ rotation: number;
236
+ };
237
+ element: {
238
+ size: Vector2;
239
+ pos: Vector2;
240
+ scale: Vector2;
241
+ };
242
+ };
@@ -0,0 +1,20 @@
1
+ export const hexToRGB = (color: string) => {
2
+ // Remove leading '#' if present
3
+ let hex = color.replace(/^#/, '');
4
+
5
+ // Handle shorthand hex (e.g., #abc)
6
+ if (hex.length === 3) {
7
+ hex = hex.split('').map(c => c + c).join('');
8
+ }
9
+
10
+ if (hex.length !== 6) {
11
+ throw new Error('Invalid hex color');
12
+ }
13
+
14
+ const num = parseInt(hex, 16);
15
+ const r = (num >> 16) & 255;
16
+ const g = (num >> 8) & 255;
17
+ const b = num & 255;
18
+
19
+ return { r, g, b };
20
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
- export * from './visualizer';
2
- export * from './components/element';
3
- export * from './helpers/types';
4
-
1
+ // Types
2
+ export * from './helpers/types';
3
+
4
+ // Components
5
+ export * from './visualizer';
6
+