@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.
- package/.eslintrc.json +20 -20
- package/README.md +113 -13
- package/package.json +14 -14
- package/package.json.bak +34 -0
- package/src/animations/blur.tsx +96 -60
- package/src/animations/breathe.tsx +95 -60
- package/src/animations/fade.tsx +173 -60
- package/src/animations/index.ts +12 -0
- package/src/animations/photo-rise.tsx +103 -66
- package/src/animations/photo-zoom.tsx +109 -73
- package/src/animations/rise.tsx +157 -118
- package/src/animations/succession.tsx +112 -77
- package/src/components/frame-effects.tsx +188 -188
- package/src/components/track.tsx +237 -232
- package/src/controllers/animation.controller.ts +38 -38
- package/src/controllers/element.controller.ts +42 -42
- package/src/controllers/frame-effect.controller.tsx +29 -29
- package/src/controllers/text-effect.controller.ts +32 -32
- package/src/elements/audio.element.tsx +79 -17
- package/src/elements/caption.element.tsx +169 -87
- package/src/elements/circle.element.tsx +88 -20
- package/src/elements/icon.element.tsx +88 -20
- package/src/elements/image.element.tsx +134 -55
- package/src/elements/index.ts +14 -0
- package/src/elements/rect.element.tsx +92 -22
- package/src/elements/scene.element.tsx +97 -29
- package/src/elements/text.element.tsx +101 -27
- package/src/elements/video.element.tsx +274 -56
- package/src/frame-effects/circle.frame.tsx +168 -103
- package/src/frame-effects/index.ts +7 -0
- package/src/frame-effects/rect.frame.tsx +198 -103
- package/src/global.css +11 -11
- package/src/helpers/caption.utils.ts +29 -29
- package/src/helpers/constants.ts +162 -158
- package/src/helpers/element.utils.ts +331 -239
- package/src/helpers/event.utils.ts +21 -0
- package/src/helpers/filters.ts +127 -127
- package/src/helpers/log.utils.ts +55 -29
- package/src/helpers/timing.utils.ts +109 -109
- package/src/helpers/types.ts +361 -241
- package/src/helpers/utils.ts +36 -19
- package/src/index.ts +196 -6
- package/src/live.tsx +16 -16
- package/src/project.ts +6 -6
- package/src/sample.ts +247 -247
- package/src/text-effects/elastic.tsx +70 -39
- package/src/text-effects/erase.tsx +91 -58
- package/src/text-effects/index.ts +9 -0
- package/src/text-effects/stream-word.tsx +94 -60
- package/src/text-effects/typewriter.tsx +93 -59
- package/src/visualizer-grouped.ts +83 -0
- package/src/visualizer.tsx +182 -78
- package/tsconfig.json +11 -11
- package/typedoc.json +19 -14
- package/vite.config.ts +15 -15
- package/.turbo/turbo-build.log +0 -19
- package/.turbo/turbo-docs.log +0 -7
- package/LICENSE +0 -197
- package/dist/mp4.wasm +0 -0
- package/dist/project.css +0 -1
- package/dist/project.js +0 -145
- package/docs/.nojekyll +0 -1
- package/docs/README.md +0 -13
- package/docs/interfaces/Animation.md +0 -47
- package/docs/interfaces/Element.md +0 -47
- package/docs/interfaces/FrameEffectPlugin.md +0 -47
- package/docs/interfaces/TextEffect.md +0 -47
- package/docs/modules.md +0 -535
|
@@ -1,103 +1,198 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
}
|