@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,60 +1,173 @@
1
- import { waitFor } from "@twick/core";
2
- import { AnimationParams } from "../helpers/types";
3
-
4
- /**
5
- * FadeAnimation applies a simple fade-in and fade-out effect
6
- * by adjusting opacity.
7
- *
8
- * Available animation modes:
9
- * - "enter": Starts transparent and fades in to fully opaque.
10
- * - "exit": Waits, then fades out to transparent.
11
- * - "both": Fades in, waits, then 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 the fade transition (in frames or ms).
16
- * @param duration - Total duration of the animation.
17
- * @param animate - Animation phase ("enter" | "exit" | "both").
18
- */
19
- export const FadeAnimation = {
20
- name: "fade",
21
-
22
- /**
23
- * Generator function controlling the fade 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
- let animationInterval = Math.min(interval, duration);
36
- if (animate === "enter") {
37
- // Start fully transparent
38
- ref().opacity(0);
39
- // Fade in to full opacity over 'interval'
40
- yield* ref().opacity(1, animationInterval);
41
-
42
- } else if (animate === "exit") {
43
- // Wait until it's time to start fading out
44
- yield* waitFor(duration - animationInterval);
45
- // Fade out to transparent over 'interval'
46
- yield* ref().opacity(0, animationInterval);
47
-
48
- } else if (animate === "both") {
49
- animationInterval = Math.min(interval, duration/2);
50
- // Start fully transparent
51
- ref().opacity(0);
52
- // Fade in to full opacity
53
- yield* ref().opacity(1, animationInterval);
54
- // Wait for the remaining duration before fade-out
55
- yield* waitFor(duration - animationInterval);
56
- // Fade out to transparent
57
- yield* ref().opacity(0, animationInterval);
58
- }
59
- },
60
- };
1
+ import { waitFor } from "@twick/core";
2
+ import { AnimationParams } from "../helpers/types";
3
+
4
+ /**
5
+ * @group FadeAnimation
6
+ * @description Simple fade-in and fade-out effects for smooth element transitions
7
+ *
8
+ * FadeAnimation applies a simple fade-in and fade-out effect by adjusting opacity.
9
+ * Creates smooth opacity transitions for elements entering or exiting the scene.
10
+ * Perfect for subtle, professional animations that don't distract from content.
11
+ *
12
+ * ## Animation Modes
13
+ *
14
+ * - **"enter"**: Starts transparent and fades in to fully opaque
15
+ * - **"exit"**: Waits, then fades out to transparent
16
+ * - **"both"**: Fades in, waits, then fades out
17
+ *
18
+ * ## Use Cases
19
+ *
20
+ * - **Text overlays**: Smooth introduction of captions and titles
21
+ * - **Background elements**: Subtle scene transitions
22
+ * - **UI components**: Professional interface animations
23
+ * - **Content reveals**: Gentle disclosure of information
24
+ *
25
+ * ## Best Practices
26
+ *
27
+ * - **Duration**: 1-3 seconds for most use cases
28
+ * - **Timing**: Use "enter" for introductions, "exit" for conclusions
29
+ * - **Combination**: Pair with other animations for complex effects
30
+ * - **Performance**: Lightweight and efficient for multiple elements
31
+ *
32
+ * ## Integration Examples
33
+ *
34
+ * ### Basic Text Fade
35
+ * ```js
36
+ * {
37
+ * id: "welcome-text",
38
+ * type: "text",
39
+ * s: 0, e: 5,
40
+ * t: "Welcome!",
41
+ * animation: {
42
+ * name: "fade",
43
+ * animate: "enter",
44
+ * duration: 2
45
+ * }
46
+ * }
47
+ * ```
48
+ *
49
+ * ### Video with Fade Transition
50
+ * ```js
51
+ * {
52
+ * id: "intro-video",
53
+ * type: "video",
54
+ * s: 0, e: 10,
55
+ * props: { src: "intro.mp4" },
56
+ * animation: {
57
+ * name: "fade",
58
+ * animate: "both",
59
+ * duration: 3,
60
+ * interval: 1
61
+ * }
62
+ * }
63
+ * ```
64
+ *
65
+ * ### Multi-Element Fade Sequence
66
+ * ```js
67
+ * // Fade in multiple elements with staggered timing
68
+ * const elements = [
69
+ * {
70
+ * id: "title",
71
+ * type: "text",
72
+ * s: 0, e: 8,
73
+ * t: "Main Title",
74
+ * animation: { name: "fade", animate: "enter", duration: 2 }
75
+ * },
76
+ * {
77
+ * id: "subtitle",
78
+ * type: "text",
79
+ * s: 1, e: 8,
80
+ * t: "Subtitle",
81
+ * animation: { name: "fade", animate: "enter", duration: 2 }
82
+ * },
83
+ * {
84
+ * id: "background",
85
+ * type: "rect",
86
+ * s: 0, e: 10,
87
+ * props: { fill: "#000000", opacity: 0.5 },
88
+ * animation: { name: "fade", animate: "enter", duration: 1.5 }
89
+ * }
90
+ * ];
91
+ * ```
92
+ *
93
+ * @param elementRef - Reference to the main element to animate
94
+ * @param containerRef - Optional reference to a container element
95
+ * @param duration - Duration of the fade transition in seconds
96
+ * @param totalDuration - Total duration of the animation in seconds
97
+ * @param animate - Animation phase ("enter" | "exit" | "both")
98
+ *
99
+ * @example
100
+ * ```js
101
+ * // Basic fade-in animation
102
+ * animation: {
103
+ * name: "fade",
104
+ * animate: "enter",
105
+ * duration: 2,
106
+ * direction: "center"
107
+ * }
108
+ *
109
+ * // Fade in and out
110
+ * animation: {
111
+ * name: "fade",
112
+ * animate: "both",
113
+ * duration: 3,
114
+ * interval: 1
115
+ * }
116
+ * ```
117
+ */
118
+ export const FadeAnimation = {
119
+ name: "fade",
120
+
121
+ /**
122
+ * Generator function controlling the fade animation.
123
+ * Handles opacity transitions based on the specified animation mode.
124
+ *
125
+ * @param params - Animation parameters including element references and timing
126
+ * @returns Generator that controls the fade animation timeline
127
+ *
128
+ * @example
129
+ * ```js
130
+ * yield* FadeAnimation.run({
131
+ * elementRef: myElement,
132
+ * interval: 1,
133
+ * duration: 3,
134
+ * animate: "enter"
135
+ * });
136
+ * ```
137
+ */
138
+ *run({
139
+ elementRef,
140
+ containerRef,
141
+ interval,
142
+ duration,
143
+ animate,
144
+ }: AnimationParams) {
145
+ // Use containerRef if provided, otherwise fallback to elementRef
146
+ const ref = containerRef ?? elementRef;
147
+
148
+ let animationInterval = Math.min(interval, duration);
149
+ if (animate === "enter") {
150
+ // Start fully transparent
151
+ ref().opacity(0);
152
+ // Fade in to full opacity over 'interval'
153
+ yield* ref().opacity(1, animationInterval);
154
+
155
+ } else if (animate === "exit") {
156
+ // Wait until it's time to start fading out
157
+ yield* waitFor(duration - animationInterval);
158
+ // Fade out to transparent over 'interval'
159
+ yield* ref().opacity(0, animationInterval);
160
+
161
+ } else if (animate === "both") {
162
+ animationInterval = Math.min(interval, duration/2);
163
+ // Start fully transparent
164
+ ref().opacity(0);
165
+ // Fade in to full opacity
166
+ yield* ref().opacity(1, animationInterval);
167
+ // Wait for the remaining duration before fade-out
168
+ yield* waitFor(duration - animationInterval);
169
+ // Fade out to transparent
170
+ yield* ref().opacity(0, animationInterval);
171
+ }
172
+ },
173
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @group Animations
3
+ * @description Motion effects and transitions for elements
4
+ */
5
+
6
+ export { FadeAnimation } from './fade';
7
+ export { RiseAnimation } from './rise';
8
+ export { BlurAnimation } from './blur';
9
+ export { BreatheAnimation } from './breathe';
10
+ export { SuccessionAnimation } from './succession';
11
+ export { PhotoRiseAnimation } from './photo-rise';
12
+ export { PhotoZoomAnimation } from './photo-zoom';
@@ -1,66 +1,103 @@
1
- import { AnimationParams } from "../helpers/types";
2
-
3
- /**
4
- * PhotoRiseAnimation applies a smooth directional movement to a photo element.
5
- *
6
- * Behavior:
7
- * - Starts offset in a given direction (up, down, left, or right).
8
- * - Animates back to the original position over the specified duration.
9
- *
10
- * Available directions:
11
- * - "up": Starts below and moves upward.
12
- * - "down": Starts above and moves downward.
13
- * - "left": Starts to the right and moves leftward.
14
- * - "right": Starts to the left and moves rightward.
15
- *
16
- * @param elementRef - Reference to the photo element to animate.
17
- * @param containerRef - Optional reference to a container element (required for this animation).
18
- * @param direction - Direction of the movement ("up" | "down" | "left" | "right").
19
- * @param duration - Duration of the movement animation.
20
- * @param intensity - Offset distance in pixels (default: 200).
21
- */
22
- export const PhotoRiseAnimation = {
23
- name: "photo-rise",
24
-
25
- /**
26
- * Generator function controlling the photo rise animation.
27
- */
28
- *run({
29
- elementRef,
30
- containerRef,
31
- direction,
32
- duration,
33
- intensity = 200,
34
- }: AnimationParams) {
35
- // Only run if a containerRef is provided
36
- if (containerRef) {
37
- // Get the element's current position
38
- const pos = elementRef().position();
39
-
40
- if (direction === "up") {
41
- // Start offset below
42
- elementRef().y(pos.y + intensity);
43
- // Animate moving upward to the original position
44
- yield* elementRef().y(pos.y, duration);
45
-
46
- } else if (direction === "down") {
47
- // Start offset above
48
- elementRef().y(pos.y - intensity);
49
- // Animate moving downward to the original position
50
- yield* elementRef().y(pos.y, duration);
51
-
52
- } else if (direction === "left") {
53
- // Start offset to the right
54
- elementRef().x(pos.x + intensity);
55
- // Animate moving left to the original position
56
- yield* elementRef().x(pos.x, duration);
57
-
58
- } else if (direction === "right") {
59
- // Start offset to the left
60
- elementRef().x(pos.x - intensity);
61
- // Animate moving right to the original position
62
- yield* elementRef().x(pos.x, duration);
63
- }
64
- }
65
- },
66
- };
1
+ import { AnimationParams } from "../helpers/types";
2
+
3
+ /**
4
+ * @group PhotoRiseAnimation
5
+ * PhotoRiseAnimation applies a smooth directional movement to a photo element.
6
+ * Creates elegant slide-in animations that bring photos into view from any direction.
7
+ * Perfect for photo galleries, presentations, and content reveals.
8
+ *
9
+ * Behavior:
10
+ * - Starts offset in a given direction (up, down, left, or right)
11
+ * - Animates back to the original position over the specified duration
12
+ *
13
+ * Available directions:
14
+ * - "up": Starts below and moves upward
15
+ * - "down": Starts above and moves downward
16
+ * - "left": Starts to the right and moves leftward
17
+ * - "right": Starts to the left and moves rightward
18
+ *
19
+ * @param elementRef - Reference to the photo element to animate
20
+ * @param containerRef - Optional reference to a container element (required for this animation)
21
+ * @param direction - Direction of the movement ("up" | "down" | "left" | "right")
22
+ * @param duration - Duration of the movement animation in seconds
23
+ * @param intensity - Offset distance in pixels (default: 200)
24
+ *
25
+ * @example
26
+ * ```js
27
+ * // Slide in from bottom
28
+ * animation: {
29
+ * name: "photo-rise",
30
+ * direction: "up",
31
+ * duration: 1.5,
32
+ * intensity: 300
33
+ * }
34
+ *
35
+ * // Slide in from left
36
+ * animation: {
37
+ * name: "photo-rise",
38
+ * direction: "left",
39
+ * duration: 2,
40
+ * intensity: 400
41
+ * }
42
+ * ```
43
+ */
44
+ export const PhotoRiseAnimation = {
45
+ name: "photo-rise",
46
+
47
+ /**
48
+ * Generator function controlling the photo rise animation.
49
+ * Handles directional movement animations for photo elements.
50
+ *
51
+ * @param params - Animation parameters including element references and direction
52
+ * @returns Generator that controls the photo rise animation timeline
53
+ *
54
+ * @example
55
+ * ```js
56
+ * yield* PhotoRiseAnimation.run({
57
+ * elementRef: photoElement,
58
+ * containerRef: container,
59
+ * direction: "up",
60
+ * duration: 1.5,
61
+ * intensity: 200
62
+ * });
63
+ * ```
64
+ */
65
+ *run({
66
+ elementRef,
67
+ containerRef,
68
+ direction,
69
+ duration,
70
+ intensity = 200,
71
+ }: AnimationParams) {
72
+ // Only run if a containerRef is provided
73
+ if (containerRef) {
74
+ // Get the element's current position
75
+ const pos = elementRef().position();
76
+
77
+ if (direction === "up") {
78
+ // Start offset below
79
+ elementRef().y(pos.y + intensity);
80
+ // Animate moving upward to the original position
81
+ yield* elementRef().y(pos.y, duration);
82
+
83
+ } else if (direction === "down") {
84
+ // Start offset above
85
+ elementRef().y(pos.y - intensity);
86
+ // Animate moving downward to the original position
87
+ yield* elementRef().y(pos.y, duration);
88
+
89
+ } else if (direction === "left") {
90
+ // Start offset to the right
91
+ elementRef().x(pos.x + intensity);
92
+ // Animate moving left to the original position
93
+ yield* elementRef().x(pos.x, duration);
94
+
95
+ } else if (direction === "right") {
96
+ // Start offset to the left
97
+ elementRef().x(pos.x - intensity);
98
+ // Animate moving right to the original position
99
+ yield* elementRef().x(pos.x, duration);
100
+ }
101
+ }
102
+ },
103
+ };
@@ -1,73 +1,109 @@
1
- import { Vector2 } from "@twick/core";
2
- import { AnimationParams } from "../helpers/types";
3
-
4
- /**
5
- * PhotoZoomAnimation applies a smooth zoom-in or zoom-out effect
6
- * on a photo element.
7
- *
8
- * Available animation modes:
9
- * - "in": Starts zoomed in and smoothly scales back to the original size.
10
- * - "out": Starts at normal size and smoothly scales up to the target zoom level.
11
- *
12
- * @param elementRef - Reference to the photo element to animate.
13
- * @param containerRef - Optional reference to a container element (required for this animation).
14
- * @param mode - Animation phase ("in" | "out").
15
- * @param duration - Duration of the zoom animation.
16
- * @param intensity - Zoom scale multiplier (default: 1.5).
17
- */
18
- export const PhotoZoomAnimation = {
19
- name: "photo-zoom",
20
-
21
- /**
22
- * Generator function controlling the photo zoom animation.
23
- */
24
- *run({
25
- elementRef,
26
- containerRef,
27
- mode,
28
- duration,
29
- intensity = 1.5,
30
- }: AnimationParams) {
31
- // Only run if a containerRef is provided
32
- if (containerRef) {
33
- // Get the element's current scale
34
- const elementScale = elementRef().scale();
35
-
36
- if (mode === "in") {
37
- // Instantly set to zoomed-in scale
38
- yield elementRef().scale(
39
- new Vector2(
40
- elementScale.x * intensity,
41
- elementScale.y * intensity
42
- )
43
- );
44
- // Smoothly scale back to original size over 'duration'
45
- yield* elementRef().scale(
46
- new Vector2(
47
- elementScale.x,
48
- elementScale.y
49
- ),
50
- duration
51
- );
52
- }
53
-
54
- if (mode === "out") {
55
- // Start at original scale
56
- elementRef().scale(
57
- new Vector2(
58
- elementScale.x,
59
- elementScale.y
60
- )
61
- );
62
- // Smoothly scale up to zoomed-in scale over 'duration'
63
- yield* elementRef().scale(
64
- new Vector2(
65
- elementScale.x * intensity,
66
- elementScale.y * intensity
67
- ),
68
- duration
69
- );
70
- }
71
- }
72
- },
73
- };
1
+ import { Vector2 } from "@twick/core";
2
+ import { AnimationParams } from "../helpers/types";
3
+
4
+ /**
5
+ * @group PhotoZoomAnimation
6
+ * PhotoZoomAnimation applies a smooth zoom-in or zoom-out effect on a photo element.
7
+ * Creates dynamic zoom effects that add depth and focus to photo content.
8
+ * Perfect for highlighting details or creating cinematic photo presentations.
9
+ *
10
+ * Available animation modes:
11
+ * - "in": Starts zoomed in and smoothly scales back to the original size
12
+ * - "out": Starts at normal size and smoothly scales up to the target zoom level
13
+ *
14
+ * @param elementRef - Reference to the photo element to animate
15
+ * @param containerRef - Optional reference to a container element (required for this animation)
16
+ * @param mode - Animation phase ("in" | "out")
17
+ * @param duration - Duration of the zoom animation in seconds
18
+ * @param intensity - Zoom scale multiplier (default: 1.5)
19
+ *
20
+ * @example
21
+ * ```js
22
+ * // Zoom in effect
23
+ * animation: {
24
+ * name: "photo-zoom",
25
+ * mode: "in",
26
+ * duration: 2,
27
+ * intensity: 1.8
28
+ * }
29
+ *
30
+ * // Zoom out effect
31
+ * animation: {
32
+ * name: "photo-zoom",
33
+ * mode: "out",
34
+ * duration: 1.5,
35
+ * intensity: 2.0
36
+ * }
37
+ * ```
38
+ */
39
+ export const PhotoZoomAnimation = {
40
+ name: "photo-zoom",
41
+
42
+ /**
43
+ * Generator function controlling the photo zoom animation.
44
+ * Handles smooth scaling transitions for zoom effects on photo elements.
45
+ *
46
+ * @param params - Animation parameters including element references and zoom settings
47
+ * @returns Generator that controls the photo zoom animation timeline
48
+ *
49
+ * @example
50
+ * ```js
51
+ * yield* PhotoZoomAnimation.run({
52
+ * elementRef: photoElement,
53
+ * containerRef: container,
54
+ * mode: "in",
55
+ * duration: 2,
56
+ * intensity: 1.5
57
+ * });
58
+ * ```
59
+ */
60
+ *run({
61
+ elementRef,
62
+ containerRef,
63
+ mode,
64
+ duration,
65
+ intensity = 1.5,
66
+ }: AnimationParams) {
67
+ // Only run if a containerRef is provided
68
+ if (containerRef) {
69
+ // Get the element's current scale
70
+ const elementScale = elementRef().scale();
71
+
72
+ if (mode === "in") {
73
+ // Instantly set to zoomed-in scale
74
+ yield elementRef().scale(
75
+ new Vector2(
76
+ elementScale.x * intensity,
77
+ elementScale.y * intensity
78
+ )
79
+ );
80
+ // Smoothly scale back to original size over 'duration'
81
+ yield* elementRef().scale(
82
+ new Vector2(
83
+ elementScale.x,
84
+ elementScale.y
85
+ ),
86
+ duration
87
+ );
88
+ }
89
+
90
+ if (mode === "out") {
91
+ // Start at original scale
92
+ elementRef().scale(
93
+ new Vector2(
94
+ elementScale.x,
95
+ elementScale.y
96
+ )
97
+ );
98
+ // Smoothly scale up to zoomed-in scale over 'duration'
99
+ yield* elementRef().scale(
100
+ new Vector2(
101
+ elementScale.x * intensity,
102
+ elementScale.y * intensity
103
+ ),
104
+ duration
105
+ );
106
+ }
107
+ }
108
+ },
109
+ };