@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,118 +1,157 @@
1
- import { all, waitFor, delay } from "@twick/core";
2
- import { AnimationParams } from "../helpers/types";
3
-
4
- /**
5
- * RiseAnimation combines vertical motion and opacity transitions
6
- * to create a "rising" (or "falling") appearance/disappearance effect.
7
- *
8
- * 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.
12
- *
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 (default: 0.25).
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 (default: 200).
20
- */
21
- export const RiseAnimation = {
22
- name: "rise",
23
-
24
- /**
25
- * Generator function controlling the rise/fall animation.
26
- */
27
- *run({
28
- elementRef,
29
- containerRef,
30
- interval = 0.25,
31
- duration,
32
- animate,
33
- direction,
34
- intensity = 200,
35
- }: AnimationParams) {
36
- // Use containerRef if provided, otherwise fallback to elementRef
37
- const ref = containerRef ?? elementRef;
38
-
39
- // Get the element's current position
40
- const pos = ref().position();
41
-
42
- let animationInterval = Math.min(interval, duration);
43
-
44
- if (animate === "enter") {
45
- // Start fully transparent
46
- ref().opacity(0);
47
-
48
- if (direction === "up") {
49
- // Offset element below final position
50
- ref().y(pos.y + intensity);
51
- // Animate moving up while fading in
52
- yield* all(
53
- ref().opacity(1, animationInterval / 4),
54
- ref().y(pos.y, animationInterval)
55
- );
56
- } else if (direction === "down") {
57
- // Offset element above final position
58
- ref().y(pos.y - intensity);
59
- // Animate moving down while fading in
60
- yield* all(
61
- ref().opacity(1, animationInterval / 4),
62
- ref().y(pos.y, animationInterval)
63
- );
64
- }
65
- } else if (animate === "exit") {
66
- // Wait until exit animation starts
67
- yield* waitFor(duration - animationInterval);
68
-
69
- if (direction === "up") {
70
- // Animate moving up while fading out (opacity fades slightly after motion starts)
71
- yield* all(
72
- delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
73
- ref().y(pos.y - intensity, animationInterval)
74
- );
75
- } else if (direction === "down") {
76
- // Animate moving down while fading out
77
- yield* all(
78
- delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
79
- ref().y(pos.y + intensity, animationInterval)
80
- );
81
- }
82
- } else if (animate === "both") {
83
- animationInterval = Math.min(interval, duration/2);
84
- // Start fully transparent
85
- ref().opacity(0);
86
-
87
- if (direction === "up") {
88
- // Enter animation: move up while fading in
89
- ref().y(pos.y + intensity);
90
- yield* all(
91
- ref().opacity(1, animationInterval / 4),
92
- ref().y(pos.y, animationInterval)
93
- );
94
- // Wait for the remaining duration
95
- yield* waitFor(duration - animationInterval);
96
- // Exit animation: move up further while fading out
97
- yield* all(
98
- delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
99
- ref().y(pos.y - intensity, animationInterval)
100
- );
101
- } else if (direction === "down") {
102
- // Enter animation: move down while fading in
103
- ref().y(pos.y - intensity);
104
- yield* all(
105
- ref().opacity(1, animationInterval / 4),
106
- ref().y(pos.y, animationInterval)
107
- );
108
- // Wait for the remaining duration
109
- yield* waitFor(duration - animationInterval);
110
- // Exit animation: move down further while fading out
111
- yield* all(
112
- delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
113
- ref().y(pos.y + intensity, animationInterval)
114
- );
115
- }
116
- }
117
- },
118
- };
1
+ import { all, delay, waitFor } from "@twick/core";
2
+ import { AnimationParams } from "../helpers/types";
3
+
4
+ /**
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.
9
+ *
10
+ * Available animation modes:
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
14
+ *
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
+ * ```
43
+ */
44
+ export const RiseAnimation = {
45
+ name: "rise",
46
+
47
+ /**
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
+ * ```
65
+ */
66
+ *run({
67
+ elementRef,
68
+ containerRef,
69
+ interval = 0.25,
70
+ duration,
71
+ animate,
72
+ direction,
73
+ intensity = 200,
74
+ }: AnimationParams) {
75
+ // Use containerRef if provided, otherwise fallback to elementRef
76
+ const ref = containerRef ?? elementRef;
77
+
78
+ // Get the element's current position
79
+ const pos = ref().position();
80
+
81
+ let animationInterval = Math.min(interval, duration);
82
+
83
+ if (animate === "enter") {
84
+ // Start fully transparent
85
+ ref().opacity(0);
86
+
87
+ if (direction === "up") {
88
+ // Offset element below final position
89
+ ref().y(pos.y + intensity);
90
+ // Animate moving up while fading in
91
+ yield* all(
92
+ ref().opacity(1, animationInterval / 4),
93
+ ref().y(pos.y, animationInterval)
94
+ );
95
+ } else if (direction === "down") {
96
+ // Offset element above final position
97
+ ref().y(pos.y - intensity);
98
+ // Animate moving down while fading in
99
+ yield* all(
100
+ ref().opacity(1, animationInterval / 4),
101
+ ref().y(pos.y, animationInterval)
102
+ );
103
+ }
104
+ } else if (animate === "exit") {
105
+ // Wait until exit animation starts
106
+ yield* waitFor(duration - animationInterval);
107
+
108
+ if (direction === "up") {
109
+ // Animate moving up while fading out (opacity fades slightly after motion starts)
110
+ yield* all(
111
+ delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
112
+ ref().y(pos.y - intensity, animationInterval)
113
+ );
114
+ } else if (direction === "down") {
115
+ // Animate moving down while fading out
116
+ yield* all(
117
+ delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
118
+ ref().y(pos.y + intensity, animationInterval)
119
+ );
120
+ }
121
+ } else if (animate === "both") {
122
+ animationInterval = Math.min(interval, duration/2);
123
+ // Start fully transparent
124
+ ref().opacity(0);
125
+
126
+ if (direction === "up") {
127
+ // Enter animation: move up while fading in
128
+ ref().y(pos.y + intensity);
129
+ yield* all(
130
+ ref().opacity(1, animationInterval / 4),
131
+ ref().y(pos.y, animationInterval)
132
+ );
133
+ // Wait for the remaining duration
134
+ yield* waitFor(duration - animationInterval);
135
+ // Exit animation: move up further while fading out
136
+ yield* all(
137
+ delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
138
+ ref().y(pos.y - intensity, animationInterval)
139
+ );
140
+ } else if (direction === "down") {
141
+ // Enter animation: move down while fading in
142
+ ref().y(pos.y - intensity);
143
+ yield* all(
144
+ ref().opacity(1, animationInterval / 4),
145
+ ref().y(pos.y, animationInterval)
146
+ );
147
+ // Wait for the remaining duration
148
+ yield* waitFor(duration - animationInterval);
149
+ // Exit animation: move down further while fading out
150
+ yield* all(
151
+ delay((3 * animationInterval) / 4, ref().opacity(0, animationInterval / 4)),
152
+ ref().y(pos.y + intensity, animationInterval)
153
+ );
154
+ }
155
+ }
156
+ },
157
+ };
@@ -1,77 +1,112 @@
1
- import { all, delay, Vector2, waitFor } from "@twick/core";
2
- import { AnimationParams } from "../helpers/types";
3
-
4
- /**
5
- * SuccessionAnimation combines scaling and opacity transitions
6
- * to create an appearing and disappearing zoom effect.
7
- *
8
- * 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.
12
- *
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").
18
- */
19
- export const SuccessionAnimation = {
20
- name: "succession",
21
-
22
- /**
23
- * Generator function controlling the succession animation.
24
- */
25
- *run({
26
- elementRef,
27
- containerRef,
28
- interval,
29
- duration,
30
- animate,
31
- }: AnimationParams) {
32
- // Use containerRef if provided, otherwise fallback to elementRef
33
- const ref = containerRef ?? elementRef;
34
-
35
- // Capture the element's original scale
36
- const scale = ref().scale();
37
-
38
- let animationInterval = Math.min(interval, duration);
39
- if (animate === "enter") {
40
- // Start fully transparent and scaled down to 50%
41
- ref().opacity(0);
42
- ref().scale(new Vector2(scale.x / 2, scale.y / 2));
43
- // Animate scaling up to original size and fading in
44
- yield* all(
45
- ref().scale(scale, animationInterval),
46
- ref().opacity(1, animationInterval / 2)
47
- );
48
-
49
- } else if (animate === "exit") {
50
- // Wait until exit animation should start
51
- yield* waitFor(duration - animationInterval);
52
- // Animate scaling down to 50% and fading out (opacity starts after half the interval)
53
- yield* all(
54
- ref().scale(new Vector2(scale.x / 2, scale.y / 2), animationInterval),
55
- delay(animationInterval / 2, ref().opacity(0, animationInterval / 2))
56
- );
57
-
58
- } else if (animate === "both") {
59
- animationInterval = Math.min(interval, duration/2);
60
- // Start fully transparent and scaled down to 50%
61
- ref().opacity(0);
62
- ref().scale(new Vector2(scale.x / 2, scale.y / 2));
63
- // Animate scaling up and fading in
64
- yield* all(
65
- ref().scale(scale, animationInterval),
66
- ref().opacity(1, animationInterval / 2)
67
- );
68
- // Wait for the remaining duration
69
- yield* waitFor(duration - animationInterval);
70
- // Animate scaling down and fading out
71
- yield* all(
72
- ref().scale(new Vector2(scale.x / 2, scale.y / 2), animationInterval),
73
- delay(animationInterval / 2, ref().opacity(0, animationInterval / 2))
74
- );
75
- }
76
- },
77
- };
1
+ import { all, delay, Vector2, waitFor } from "@twick/core";
2
+ import { AnimationParams } from "../helpers/types";
3
+
4
+ /**
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.
9
+ *
10
+ * Available animation modes:
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
14
+ *
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
+ * ```
39
+ */
40
+ export const SuccessionAnimation = {
41
+ name: "succession",
42
+
43
+ /**
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
+ * ```
59
+ */
60
+ *run({
61
+ elementRef,
62
+ containerRef,
63
+ interval,
64
+ duration,
65
+ animate,
66
+ }: AnimationParams) {
67
+ // Use containerRef if provided, otherwise fallback to elementRef
68
+ const ref = containerRef ?? elementRef;
69
+
70
+ // Capture the element's original scale
71
+ const scale = ref().scale();
72
+
73
+ let animationInterval = Math.min(interval, duration);
74
+ if (animate === "enter") {
75
+ // Start fully transparent and scaled down to 50%
76
+ ref().opacity(0);
77
+ ref().scale(new Vector2(scale.x / 2, scale.y / 2));
78
+ // Animate scaling up to original size and fading in
79
+ yield* all(
80
+ ref().scale(scale, animationInterval),
81
+ ref().opacity(1, animationInterval / 2)
82
+ );
83
+
84
+ } else if (animate === "exit") {
85
+ // Wait until exit animation should start
86
+ yield* waitFor(duration - animationInterval);
87
+ // Animate scaling down to 50% and fading out (opacity starts after half the interval)
88
+ yield* all(
89
+ ref().scale(new Vector2(scale.x / 2, scale.y / 2), animationInterval),
90
+ delay(animationInterval / 2, ref().opacity(0, animationInterval / 2))
91
+ );
92
+
93
+ } else if (animate === "both") {
94
+ animationInterval = Math.min(interval, duration/2);
95
+ // Start fully transparent and scaled down to 50%
96
+ ref().opacity(0);
97
+ ref().scale(new Vector2(scale.x / 2, scale.y / 2));
98
+ // Animate scaling up and fading in
99
+ yield* all(
100
+ ref().scale(scale, animationInterval),
101
+ ref().opacity(1, animationInterval / 2)
102
+ );
103
+ // Wait for the remaining duration
104
+ yield* waitFor(duration - animationInterval);
105
+ // Animate scaling down and fading out
106
+ yield* all(
107
+ ref().scale(new Vector2(scale.x / 2, scale.y / 2), animationInterval),
108
+ delay(animationInterval / 2, ref().opacity(0, animationInterval / 2))
109
+ );
110
+ }
111
+ },
112
+ };