@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.
Files changed (68) hide show
  1. package/.eslintrc.json +20 -20
  2. package/README.md +113 -13
  3. package/package.json +14 -14
  4. package/package.json.bak +34 -0
  5. package/src/animations/blur.tsx +96 -60
  6. package/src/animations/breathe.tsx +95 -60
  7. package/src/animations/fade.tsx +173 -60
  8. package/src/animations/index.ts +12 -0
  9. package/src/animations/photo-rise.tsx +103 -66
  10. package/src/animations/photo-zoom.tsx +109 -73
  11. package/src/animations/rise.tsx +157 -118
  12. package/src/animations/succession.tsx +112 -77
  13. package/src/components/frame-effects.tsx +188 -188
  14. package/src/components/track.tsx +237 -232
  15. package/src/controllers/animation.controller.ts +38 -38
  16. package/src/controllers/element.controller.ts +42 -42
  17. package/src/controllers/frame-effect.controller.tsx +29 -29
  18. package/src/controllers/text-effect.controller.ts +32 -32
  19. package/src/elements/audio.element.tsx +79 -17
  20. package/src/elements/caption.element.tsx +169 -87
  21. package/src/elements/circle.element.tsx +88 -20
  22. package/src/elements/icon.element.tsx +88 -20
  23. package/src/elements/image.element.tsx +134 -55
  24. package/src/elements/index.ts +14 -0
  25. package/src/elements/rect.element.tsx +92 -22
  26. package/src/elements/scene.element.tsx +97 -29
  27. package/src/elements/text.element.tsx +101 -27
  28. package/src/elements/video.element.tsx +274 -56
  29. package/src/frame-effects/circle.frame.tsx +168 -103
  30. package/src/frame-effects/index.ts +7 -0
  31. package/src/frame-effects/rect.frame.tsx +198 -103
  32. package/src/global.css +11 -11
  33. package/src/helpers/caption.utils.ts +29 -29
  34. package/src/helpers/constants.ts +162 -158
  35. package/src/helpers/element.utils.ts +331 -239
  36. package/src/helpers/event.utils.ts +21 -0
  37. package/src/helpers/filters.ts +127 -127
  38. package/src/helpers/log.utils.ts +55 -29
  39. package/src/helpers/timing.utils.ts +109 -109
  40. package/src/helpers/types.ts +361 -241
  41. package/src/helpers/utils.ts +36 -19
  42. package/src/index.ts +196 -6
  43. package/src/live.tsx +16 -16
  44. package/src/project.ts +6 -6
  45. package/src/sample.ts +247 -247
  46. package/src/text-effects/elastic.tsx +70 -39
  47. package/src/text-effects/erase.tsx +91 -58
  48. package/src/text-effects/index.ts +9 -0
  49. package/src/text-effects/stream-word.tsx +94 -60
  50. package/src/text-effects/typewriter.tsx +93 -59
  51. package/src/visualizer-grouped.ts +83 -0
  52. package/src/visualizer.tsx +182 -78
  53. package/tsconfig.json +11 -11
  54. package/typedoc.json +19 -14
  55. package/vite.config.ts +15 -15
  56. package/.turbo/turbo-build.log +0 -19
  57. package/.turbo/turbo-docs.log +0 -7
  58. package/LICENSE +0 -197
  59. package/dist/mp4.wasm +0 -0
  60. package/dist/project.css +0 -1
  61. package/dist/project.js +0 -145
  62. package/docs/.nojekyll +0 -1
  63. package/docs/README.md +0 -13
  64. package/docs/interfaces/Animation.md +0 -47
  65. package/docs/interfaces/Element.md +0 -47
  66. package/docs/interfaces/FrameEffectPlugin.md +0 -47
  67. package/docs/interfaces/TextEffect.md +0 -47
  68. package/docs/modules.md +0 -535
@@ -1,103 +1,198 @@
1
- /**
2
- * Frame effects component that handles the application of various visual effects
3
- * to frames and elements in the scene.
4
- */
5
-
6
- import { all, waitFor } from "@twick/core";
7
- import { getTimingFunction } from "../helpers/timing.utils";
8
- import { fitElement } from "../helpers/element.utils";
9
- import {
10
- DEFAULT_POSITION,
11
- DEFAULT_TIMING_FUNCTION,
12
- } from "../helpers/constants";
13
- import { FrameEffectParams } from "../helpers/types";
14
-
15
- /**
16
- * RectFrameEffect applies frame transformations such as resizing,
17
- * repositioning, rounding corners, and optionally fitting the element
18
- * within the frame according to an object-fit mode.
19
- *
20
- * Behavior:
21
- * - Waits for the specified start time.
22
- * - Resizes and repositions the container and element smoothly.
23
- * - Adjusts corner radius if provided.
24
- * - Optionally fits the element inside the container.
25
- *
26
- * @param containerRef - Reference to the frame container element.
27
- * @param elementRef - Reference to the content element inside the frame.
28
- * @param initFrameState - Initial size and position state of the element.
29
- * @param frameEffect - Frame transformation configuration and timing.
30
- */
31
- export const RectFrameEffect = {
32
- name: "rect",
33
-
34
- /**
35
- * Generator function controlling the frame resizing and positioning animation.
36
- */
37
- *run({
38
- containerRef,
39
- elementRef,
40
- initFrameState,
41
- frameEffect,
42
- }: FrameEffectParams) {
43
- // Wait until the effect start time
44
- yield* waitFor(frameEffect.s);
45
-
46
- const props = frameEffect.props;
47
- const sequence = [];
48
-
49
- // Animate resizing the container
50
- sequence.push(
51
- containerRef().size(
52
- props.frameSize,
53
- props.transitionDuration,
54
- getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
55
- )
56
- );
57
-
58
- // Animate repositioning the container
59
- sequence.push(
60
- containerRef().position(
61
- props.framePosition ?? { x: 0, y: 0 },
62
- props.transitionDuration,
63
- getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
64
- )
65
- );
66
-
67
- // Animate repositioning the element inside the container
68
- sequence.push(
69
- elementRef().position(
70
- props.elementPosition ?? DEFAULT_POSITION,
71
- props.transitionDuration,
72
- getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
73
- )
74
- );
75
-
76
- // Animate corner radius if specified
77
- sequence.push(
78
- containerRef().radius(
79
- props.radius ?? 0,
80
- props.transitionDuration,
81
- getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
82
- )
83
- );
84
-
85
- // Optionally fit the element within the container based on object-fit
86
- if (props.objectFit) {
87
- sequence.push(
88
- fitElement({
89
- elementRef,
90
- containerSize: {
91
- x: props.frameSize[0],
92
- y: props.frameSize[1],
93
- },
94
- elementSize: initFrameState.element.size,
95
- objectFit: props.objectFit,
96
- })
97
- );
98
- }
99
-
100
- // Run all animations in parallel
101
- yield* all(...sequence);
102
- },
103
- };
1
+ /**
2
+ * @group RectFrameEffect
3
+ * RectFrameEffect applies frame transformations such as resizing, repositioning,
4
+ * rounding corners, and optionally fitting the element within the frame according
5
+ * to an object-fit mode. Creates rectangular masks and containers for content
6
+ * presentation with smooth transitions.
7
+ *
8
+ * Behavior:
9
+ * - Waits for the specified start time
10
+ * - Resizes and repositions the container and element smoothly
11
+ * - Adjusts corner radius if provided
12
+ * - Optionally fits the element inside the container
13
+ *
14
+ * @param containerRef - Reference to the frame container element
15
+ * @param elementRef - Reference to the content element inside the frame
16
+ * @param initFrameState - Initial size and position state of the element
17
+ * @param frameEffect - Frame transformation configuration and timing
18
+ *
19
+ * @example
20
+ * ```js
21
+ * // Basic rectangular frame
22
+ * frameEffects: [{
23
+ * name: "rect",
24
+ * s: 0,
25
+ * e: 10,
26
+ * props: {
27
+ * frameSize: [600, 400],
28
+ * frameShape: "rect",
29
+ * framePosition: { x: 960, y: 540 },
30
+ * radius: 20,
31
+ * objectFit: "cover",
32
+ * transitionDuration: 1.5
33
+ * }
34
+ * }]
35
+ *
36
+ * // Rounded rectangle frame
37
+ * frameEffects: [{
38
+ * name: "rect",
39
+ * s: 2,
40
+ * e: 15,
41
+ * props: {
42
+ * frameSize: [800, 600],
43
+ * frameShape: "rect",
44
+ * framePosition: { x: 960, y: 540 },
45
+ * radius: 50,
46
+ * objectFit: "contain",
47
+ * transitionDuration: 2
48
+ * }
49
+ * }]
50
+ * ```
51
+ */
52
+
53
+ import { all, waitFor } from "@twick/core";
54
+ import { getTimingFunction } from "../helpers/timing.utils";
55
+ import { fitElement } from "../helpers/element.utils";
56
+ import {
57
+ DEFAULT_POSITION,
58
+ DEFAULT_TIMING_FUNCTION,
59
+ } from "../helpers/constants";
60
+ import { FrameEffectParams } from "../helpers/types";
61
+
62
+ /**
63
+ * RectFrameEffect applies frame transformations such as resizing, repositioning,
64
+ * rounding corners, and optionally fitting the element within the frame according
65
+ * to an object-fit mode. Creates rectangular masks and containers for content
66
+ * presentation with smooth transitions.
67
+ *
68
+ * Behavior:
69
+ * - Waits for the specified start time
70
+ * - Resizes and repositions the container and element smoothly
71
+ * - Adjusts corner radius if provided
72
+ * - Optionally fits the element inside the container
73
+ *
74
+ * @param containerRef - Reference to the frame container element
75
+ * @param elementRef - Reference to the content element inside the frame
76
+ * @param initFrameState - Initial size and position state of the element
77
+ * @param frameEffect - Frame transformation configuration and timing
78
+ *
79
+ * @example
80
+ * ```js
81
+ * // Basic rectangular frame
82
+ * frameEffects: [{
83
+ * name: "rect",
84
+ * s: 0,
85
+ * e: 10,
86
+ * props: {
87
+ * frameSize: [600, 400],
88
+ * frameShape: "rect",
89
+ * framePosition: { x: 960, y: 540 },
90
+ * radius: 20,
91
+ * objectFit: "cover",
92
+ * transitionDuration: 1.5
93
+ * }
94
+ * }]
95
+ *
96
+ * // Rounded rectangle frame
97
+ * frameEffects: [{
98
+ * name: "rect",
99
+ * s: 2,
100
+ * e: 15,
101
+ * props: {
102
+ * frameSize: [800, 600],
103
+ * frameShape: "rect",
104
+ * framePosition: { x: 960, y: 540 },
105
+ * radius: 50,
106
+ * objectFit: "contain",
107
+ * transitionDuration: 2
108
+ * }
109
+ * }]
110
+ * ```
111
+ */
112
+ export const RectFrameEffect = {
113
+ name: "rect",
114
+
115
+ /**
116
+ * Generator function controlling the frame resizing and positioning animation.
117
+ * Handles rectangular frame transformations with smooth transitions and content fitting.
118
+ *
119
+ * @param params - Frame effect parameters including element references and configuration
120
+ * @returns Generator that controls the rectangular frame animation timeline
121
+ *
122
+ * @example
123
+ * ```js
124
+ * yield* RectFrameEffect.run({
125
+ * containerRef: frameContainer,
126
+ * elementRef: contentElement,
127
+ * initFrameState: initialState,
128
+ * frameEffect: rectConfig
129
+ * });
130
+ * ```
131
+ */
132
+ *run({
133
+ containerRef,
134
+ elementRef,
135
+ initFrameState,
136
+ frameEffect,
137
+ }: FrameEffectParams) {
138
+ // Wait until the effect start time
139
+ yield* waitFor(frameEffect.s);
140
+
141
+ const props = frameEffect.props;
142
+ const sequence = [];
143
+
144
+ // Animate resizing the container
145
+ sequence.push(
146
+ containerRef().size(
147
+ props.frameSize,
148
+ props.transitionDuration,
149
+ getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
150
+ )
151
+ );
152
+
153
+ // Animate repositioning the container
154
+ sequence.push(
155
+ containerRef().position(
156
+ props.framePosition ?? { x: 0, y: 0 },
157
+ props.transitionDuration,
158
+ getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
159
+ )
160
+ );
161
+
162
+ // Animate repositioning the element inside the container
163
+ sequence.push(
164
+ elementRef().position(
165
+ props.elementPosition ?? DEFAULT_POSITION,
166
+ props.transitionDuration,
167
+ getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
168
+ )
169
+ );
170
+
171
+ // Animate corner radius if specified
172
+ sequence.push(
173
+ containerRef().radius(
174
+ props.radius ?? 0,
175
+ props.transitionDuration,
176
+ getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
177
+ )
178
+ );
179
+
180
+ // Optionally fit the element within the container based on object-fit
181
+ if (props.objectFit) {
182
+ sequence.push(
183
+ fitElement({
184
+ elementRef,
185
+ containerSize: {
186
+ x: props.frameSize[0],
187
+ y: props.frameSize[1],
188
+ },
189
+ elementSize: initFrameState.element.size,
190
+ objectFit: props.objectFit,
191
+ })
192
+ );
193
+ }
194
+
195
+ // Run all animations in parallel
196
+ yield* all(...sequence);
197
+ },
198
+ };
package/src/global.css CHANGED
@@ -1,12 +1,12 @@
1
- @import url('https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap');
2
- @import url('https://fonts.googleapis.com/css2?family=Mulish:ital,wght@0,200..1000;1,200..1000&display=swap');
3
- @import url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&family=Mulish:ital,wght@0,200..1000;1,200..1000&family=Playfair+Display:ital,wght@0,400..900;1,400..900&display=swap');
4
- @import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');
5
- @import url('https://fonts.googleapis.com/css2?family=Bangers&family=Birthstone&family=Corinthia:wght@400;700&family=Imperial+Script&family=Kumar+One+Outline&family=Londrina+Outline&family=Marck+Script&family=Montserrat:ital,wght@0,100..900;1,100..900&family=Pattaya&family=Playfair+Display:ital,wght@0,400..900;1,400..900&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
6
- @import url('https://fonts.cdnfonts.com/css/peralta');
7
- @import url('https://fonts.cdnfonts.com/css/impact');
8
- @import url('https://fonts.cdnfonts.com/css/lumanosimo');
9
- @import url('https://fonts.cdnfonts.com/css/kapakana');
10
- @import url('https://fonts.cdnfonts.com/css/handyrush');
11
- @import url('https://fonts.cdnfonts.com/css/dasher');
1
+ @import url('https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap');
2
+ @import url('https://fonts.googleapis.com/css2?family=Mulish:ital,wght@0,200..1000;1,200..1000&display=swap');
3
+ @import url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&family=Mulish:ital,wght@0,200..1000;1,200..1000&family=Playfair+Display:ital,wght@0,400..900;1,400..900&display=swap');
4
+ @import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');
5
+ @import url('https://fonts.googleapis.com/css2?family=Bangers&family=Birthstone&family=Corinthia:wght@400;700&family=Imperial+Script&family=Kumar+One+Outline&family=Londrina+Outline&family=Marck+Script&family=Montserrat:ital,wght@0,100..900;1,100..900&family=Pattaya&family=Playfair+Display:ital,wght@0,400..900;1,400..900&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
6
+ @import url('https://fonts.cdnfonts.com/css/peralta');
7
+ @import url('https://fonts.cdnfonts.com/css/impact');
8
+ @import url('https://fonts.cdnfonts.com/css/lumanosimo');
9
+ @import url('https://fonts.cdnfonts.com/css/kapakana');
10
+ @import url('https://fonts.cdnfonts.com/css/handyrush');
11
+ @import url('https://fonts.cdnfonts.com/css/dasher');
12
12
  @import url('https://fonts.cdnfonts.com/css/brittany-signature');
@@ -1,30 +1,30 @@
1
- /**
2
- * Caption utilities for the visualizer package.
3
- * Provides functions for handling caption text formatting and timing.
4
- */
5
-
6
- /**
7
- * Splits a phrase into words with timing information
8
- * @param {string} t - The phrase to split
9
- * @param {number} s - Start time of the phrase
10
- * @param {number} e - End time of the phrase
11
- * @returns {Array} Array of words with timing information
12
- */
13
- export function splitPhraseTiming({ t, s, e }: { t: string, s: number, e: number }) {
14
- const words = t.split(" ");
15
- const totalDuration = e - s;
16
- const totalLength = words.join("").length; // Total character length without spaces
17
-
18
- let currentTime = s;
19
- return words.map((word) => {
20
- const wordDuration = (word.length / totalLength) * totalDuration;
21
- const wordStart = currentTime;
22
- const wordEnd = wordStart + wordDuration;
23
- currentTime = wordEnd;
24
- return {
25
- t: word,
26
- s: parseFloat(wordStart.toFixed(2)),
27
- e: parseFloat(wordEnd.toFixed(2)),
28
- };
29
- });
1
+ /**
2
+ * Caption utilities for the visualizer package.
3
+ * Provides functions for handling caption text formatting and timing.
4
+ */
5
+
6
+ /**
7
+ * Splits a phrase into words with timing information
8
+ * @param {string} t - The phrase to split
9
+ * @param {number} s - Start time of the phrase
10
+ * @param {number} e - End time of the phrase
11
+ * @returns {Array} Array of words with timing information
12
+ */
13
+ export function splitPhraseTiming({ t, s, e }: { t: string, s: number, e: number }) {
14
+ const words = t.split(" ");
15
+ const totalDuration = e - s;
16
+ const totalLength = words.join("").length; // Total character length without spaces
17
+
18
+ let currentTime = s;
19
+ return words.map((word) => {
20
+ const wordDuration = (word.length / totalLength) * totalDuration;
21
+ const wordStart = currentTime;
22
+ const wordEnd = wordStart + wordDuration;
23
+ currentTime = wordEnd;
24
+ return {
25
+ t: word,
26
+ s: parseFloat(wordStart.toFixed(2)),
27
+ e: parseFloat(wordEnd.toFixed(2)),
28
+ };
29
+ });
30
30
  }