@twick/visualizer 0.0.1 → 0.14.0
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/.turbo/turbo-build.log +19 -0
- package/.turbo/turbo-docs.log +7 -0
- package/LICENSE +197 -0
- package/README.md +1 -1
- package/dist/mp4.wasm +0 -0
- package/dist/project.css +1 -0
- package/dist/project.js +145 -0
- package/docs/.nojekyll +1 -0
- package/docs/README.md +13 -0
- package/docs/interfaces/Animation.md +47 -0
- package/docs/interfaces/Element.md +47 -0
- package/docs/interfaces/FrameEffectPlugin.md +47 -0
- package/docs/interfaces/TextEffect.md +47 -0
- package/docs/modules.md +535 -0
- package/package.json +34 -31
- package/src/animations/blur.tsx +60 -0
- package/src/animations/breathe.tsx +60 -0
- package/src/animations/fade.tsx +60 -0
- package/src/animations/photo-rise.tsx +66 -0
- package/src/animations/photo-zoom.tsx +73 -0
- package/src/animations/rise.tsx +118 -0
- package/src/animations/succession.tsx +77 -0
- package/src/components/frame-effects.tsx +2 -4
- package/src/components/track.tsx +232 -0
- package/src/controllers/animation.controller.ts +39 -0
- package/src/controllers/element.controller.ts +43 -0
- package/src/controllers/frame-effect.controller.tsx +30 -0
- package/src/controllers/text-effect.controller.ts +33 -0
- package/src/elements/audio.element.tsx +17 -0
- package/src/elements/caption.element.tsx +87 -0
- package/src/elements/circle.element.tsx +20 -0
- package/src/elements/icon.element.tsx +20 -0
- package/src/elements/image.element.tsx +55 -0
- package/src/elements/rect.element.tsx +22 -0
- package/src/elements/scene.element.tsx +29 -0
- package/src/elements/text.element.tsx +28 -0
- package/src/elements/video.element.tsx +56 -0
- package/src/frame-effects/circle.frame.tsx +103 -0
- package/src/frame-effects/rect.frame.tsx +103 -0
- package/src/helpers/caption.utils.ts +4 -14
- package/src/helpers/constants.ts +1 -1
- package/src/helpers/element.utils.ts +222 -68
- package/src/helpers/filters.ts +1 -1
- package/src/helpers/log.utils.ts +0 -3
- package/src/helpers/timing.utils.ts +2 -21
- package/src/helpers/types.ts +103 -8
- package/src/helpers/utils.ts +20 -0
- package/src/index.ts +4 -2
- package/src/live.tsx +1 -1
- package/src/project.ts +1 -1
- package/src/sample.ts +16 -218
- package/src/text-effects/elastic.tsx +39 -0
- package/src/text-effects/erase.tsx +58 -0
- package/src/text-effects/stream-word.tsx +60 -0
- package/src/text-effects/typewriter.tsx +59 -0
- package/src/visualizer.tsx +27 -27
- package/tsconfig.json +3 -2
- package/vite.config.ts +1 -1
- package/src/components/animation.tsx +0 -7
- package/src/components/element.tsx +0 -344
- package/src/components/timeline.tsx +0 -225
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ElementParams } from "../helpers/types";
|
|
2
|
+
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
+
import { Rect, Video } from "@twick/2d";
|
|
4
|
+
import { addAnimation, addFrameEffect, fitElement } from "../helpers/element.utils";
|
|
5
|
+
import { logger } from "../helpers/log.utils";
|
|
6
|
+
import { applyColorFilter } from "../helpers/filters";
|
|
7
|
+
|
|
8
|
+
export const VideoElement = {
|
|
9
|
+
name: "video",
|
|
10
|
+
*create({ containerRef, element, view }: ElementParams) {
|
|
11
|
+
yield* waitFor(element?.s);
|
|
12
|
+
logger(`Adding video element ${element.id}`);
|
|
13
|
+
const frameContainerRef = createRef<any>();
|
|
14
|
+
const frameElementRef = createRef<any>();
|
|
15
|
+
|
|
16
|
+
yield containerRef().add(
|
|
17
|
+
<Rect ref={frameContainerRef} key={element.id} {...element.frame}>
|
|
18
|
+
<Video
|
|
19
|
+
ref={frameElementRef}
|
|
20
|
+
key={`child-${element.id}`}
|
|
21
|
+
{...element.props}
|
|
22
|
+
/>
|
|
23
|
+
</Rect>
|
|
24
|
+
);
|
|
25
|
+
if (frameContainerRef()) {
|
|
26
|
+
yield fitElement({
|
|
27
|
+
elementRef: frameElementRef,
|
|
28
|
+
containerSize: frameContainerRef().size(),
|
|
29
|
+
elementSize: frameElementRef().size(),
|
|
30
|
+
objectFit: element.objectFit,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (element?.props?.mediaFilter) {
|
|
34
|
+
applyColorFilter(frameElementRef, element.props.mediaFilter);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
yield* all(
|
|
38
|
+
addAnimation({
|
|
39
|
+
elementRef: frameElementRef,
|
|
40
|
+
containerRef: frameContainerRef,
|
|
41
|
+
element: element,
|
|
42
|
+
view,
|
|
43
|
+
}),
|
|
44
|
+
addFrameEffect({
|
|
45
|
+
containerRef: frameContainerRef,
|
|
46
|
+
elementRef: frameElementRef,
|
|
47
|
+
element,
|
|
48
|
+
}),
|
|
49
|
+
waitFor(Math.max(0, element.e - element.s))
|
|
50
|
+
);
|
|
51
|
+
yield frameElementRef().playing(false);
|
|
52
|
+
yield frameElementRef().remove();
|
|
53
|
+
yield frameContainerRef().remove();
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
* CircleFrameEffect animates a frame transitioning into a circular shape,
|
|
17
|
+
* resizing, repositioning, and optionally fitting its content.
|
|
18
|
+
*
|
|
19
|
+
* Behavior:
|
|
20
|
+
* - Waits for the specified start time.
|
|
21
|
+
* - Resizes and repositions the frame container smoothly.
|
|
22
|
+
* - Animates the corner radius to create a perfect circle.
|
|
23
|
+
* - Repositions the content element if needed.
|
|
24
|
+
* - Optionally fits the element inside the container based on object-fit.
|
|
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 CircleFrameEffect = {
|
|
32
|
+
name: "circle",
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generator function controlling the circle frame animation.
|
|
36
|
+
*/
|
|
37
|
+
*run({
|
|
38
|
+
containerRef,
|
|
39
|
+
elementRef,
|
|
40
|
+
initFrameState,
|
|
41
|
+
frameEffect,
|
|
42
|
+
}: FrameEffectParams) {
|
|
43
|
+
// Wait for the specified start time before starting animation
|
|
44
|
+
yield* waitFor(frameEffect.s);
|
|
45
|
+
|
|
46
|
+
const props = frameEffect.props;
|
|
47
|
+
const sequence = [];
|
|
48
|
+
|
|
49
|
+
// Animate resizing the container to target size
|
|
50
|
+
sequence.push(
|
|
51
|
+
containerRef().size(
|
|
52
|
+
{ x: props.frameSize[0], y: props.frameSize[1] },
|
|
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 rounding corners to create a circle (radius = half the width)
|
|
77
|
+
sequence.push(
|
|
78
|
+
containerRef().radius(
|
|
79
|
+
props.frameSize[0] / 2,
|
|
80
|
+
props.transitionDuration,
|
|
81
|
+
getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// Optionally fit the element inside the resized container
|
|
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
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
};
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Splits a phrase into words with timing information
|
|
8
|
-
* @param {string}
|
|
9
|
-
* @param {number}
|
|
10
|
-
* @param {number}
|
|
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
11
|
* @returns {Array} Array of words with timing information
|
|
12
12
|
*/
|
|
13
13
|
export function splitPhraseTiming({ t, s, e }: { t: string, s: number, e: number }) {
|
|
@@ -27,14 +27,4 @@ export function splitPhraseTiming({ t, s, e }: { t: string, s: number, e: number
|
|
|
27
27
|
e: parseFloat(wordEnd.toFixed(2)),
|
|
28
28
|
};
|
|
29
29
|
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Formats caption text with specified style
|
|
34
|
-
* @param {string} text - The text to format
|
|
35
|
-
* @param {Object} style - The style to apply
|
|
36
|
-
* @returns {string} Formatted text
|
|
37
|
-
*/
|
|
38
|
-
export function formatCaptionText(text: string, style: any) {
|
|
39
|
-
// ... existing code ...
|
|
40
|
-
}
|
|
30
|
+
}
|
package/src/helpers/constants.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { Reference } from "@
|
|
2
|
-
import { ObjectFit, SizeVector } from "./types";
|
|
1
|
+
import { all, Reference, waitFor } from "@twick/core";
|
|
2
|
+
import { FrameState, ObjectFit, SizeVector, VisualizerElement } from "./types";
|
|
3
3
|
import { OBJECT_FIT } from "./constants";
|
|
4
|
+
import textEffectController from "../controllers/text-effect.controller";
|
|
5
|
+
import animationController from "../controllers/animation.controller";
|
|
6
|
+
import { View2D } from "@twick/2d";
|
|
7
|
+
import frameEffectController from "../controllers/frame-effect.controller";
|
|
8
|
+
import { logger } from "./log.utils";
|
|
4
9
|
|
|
5
10
|
/**
|
|
6
11
|
* Element utilities for the visualizer package.
|
|
@@ -16,70 +21,219 @@ import { OBJECT_FIT } from "./constants";
|
|
|
16
21
|
* @param {string} [params.objectFit] - The fit mode (contain, cover, fill)
|
|
17
22
|
* @returns {Object} Updated element dimensions
|
|
18
23
|
*/
|
|
19
|
-
export function* fitElement({
|
|
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
|
-
break;
|
|
54
|
-
case OBJECT_FIT.COVER:
|
|
55
|
-
if (elementAspectRatio > containerAspectRatio) {
|
|
56
|
-
yield elementRef().size({
|
|
57
|
-
x: containerSize.y * elementAspectRatio,
|
|
58
|
-
y: containerSize.y,
|
|
59
|
-
});
|
|
60
|
-
yield elementRef().scale(
|
|
61
|
-
(containerSize.y * elementAspectRatio) / elementSize.x,
|
|
62
|
-
containerSize.y / elementSize.y
|
|
63
|
-
);
|
|
64
|
-
} else {
|
|
65
|
-
yield elementRef().size({
|
|
66
|
-
x: containerSize.x,
|
|
67
|
-
y: containerSize.x / elementAspectRatio,
|
|
68
|
-
});
|
|
69
|
-
yield elementRef().scale(
|
|
70
|
-
containerSize.x / elementSize.x,
|
|
71
|
-
(containerSize.x * elementAspectRatio) / elementSize.y
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
break;
|
|
75
|
-
case OBJECT_FIT.FILL:
|
|
76
|
-
yield elementRef().size(containerSize);
|
|
77
|
-
yield elementRef().scale(
|
|
78
|
-
containerSize.x / elementSize.x,
|
|
79
|
-
containerSize.x / elementSize.y
|
|
80
|
-
);
|
|
81
|
-
break;
|
|
82
|
-
default:
|
|
83
|
-
break;
|
|
24
|
+
export function* fitElement({
|
|
25
|
+
containerSize,
|
|
26
|
+
elementSize,
|
|
27
|
+
elementRef,
|
|
28
|
+
objectFit,
|
|
29
|
+
}: {
|
|
30
|
+
containerSize: SizeVector;
|
|
31
|
+
elementSize: SizeVector;
|
|
32
|
+
elementRef: Reference<any>;
|
|
33
|
+
objectFit?: ObjectFit;
|
|
34
|
+
}) {
|
|
35
|
+
const containerAspectRatio = containerSize.x / containerSize.y;
|
|
36
|
+
const elementAspectRatio = elementSize.x / elementSize.y;
|
|
37
|
+
switch (objectFit) {
|
|
38
|
+
case OBJECT_FIT.CONTAIN:
|
|
39
|
+
if (elementAspectRatio > containerAspectRatio) {
|
|
40
|
+
yield elementRef().size({
|
|
41
|
+
x: containerSize.x,
|
|
42
|
+
y: containerSize.x / elementAspectRatio,
|
|
43
|
+
});
|
|
44
|
+
yield elementRef().scale(
|
|
45
|
+
containerSize.x / elementSize.x,
|
|
46
|
+
(containerSize.x * elementAspectRatio) / elementSize.y
|
|
47
|
+
);
|
|
48
|
+
} else {
|
|
49
|
+
yield elementRef().size({
|
|
50
|
+
x: containerSize.y * elementAspectRatio,
|
|
51
|
+
y: containerSize.y,
|
|
52
|
+
});
|
|
53
|
+
yield elementRef().scale(
|
|
54
|
+
(containerSize.y * elementAspectRatio) / elementSize.x,
|
|
55
|
+
containerSize.y / elementSize.y
|
|
56
|
+
);
|
|
84
57
|
}
|
|
85
|
-
|
|
58
|
+
break;
|
|
59
|
+
case OBJECT_FIT.COVER:
|
|
60
|
+
if (elementAspectRatio > containerAspectRatio) {
|
|
61
|
+
yield elementRef().size({
|
|
62
|
+
x: containerSize.y * elementAspectRatio,
|
|
63
|
+
y: containerSize.y,
|
|
64
|
+
});
|
|
65
|
+
yield elementRef().scale(
|
|
66
|
+
(containerSize.y * elementAspectRatio) / elementSize.x,
|
|
67
|
+
containerSize.y / elementSize.y
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
yield elementRef().size({
|
|
71
|
+
x: containerSize.x,
|
|
72
|
+
y: containerSize.x / elementAspectRatio,
|
|
73
|
+
});
|
|
74
|
+
yield elementRef().scale(
|
|
75
|
+
containerSize.x / elementSize.x,
|
|
76
|
+
(containerSize.x * elementAspectRatio) / elementSize.y
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case OBJECT_FIT.FILL:
|
|
81
|
+
yield elementRef().size(containerSize);
|
|
82
|
+
yield elementRef().scale(
|
|
83
|
+
containerSize.x / elementSize.x,
|
|
84
|
+
containerSize.x / elementSize.y
|
|
85
|
+
);
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function* addTextEffect({
|
|
93
|
+
elementRef,
|
|
94
|
+
element,
|
|
95
|
+
}: {
|
|
96
|
+
elementRef: Reference<any>;
|
|
97
|
+
element: VisualizerElement;
|
|
98
|
+
}) {
|
|
99
|
+
yield elementRef();
|
|
100
|
+
if (element.textEffect) {
|
|
101
|
+
const effect = textEffectController.get(element.textEffect.name);
|
|
102
|
+
if (effect) {
|
|
103
|
+
yield* effect.run({
|
|
104
|
+
elementRef,
|
|
105
|
+
duration: element.e - element.s,
|
|
106
|
+
...element.textEffect,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function* addAnimation({
|
|
113
|
+
elementRef,
|
|
114
|
+
containerRef,
|
|
115
|
+
element,
|
|
116
|
+
view,
|
|
117
|
+
}: {
|
|
118
|
+
elementRef: Reference<any>;
|
|
119
|
+
containerRef?: Reference<any>;
|
|
120
|
+
element: VisualizerElement;
|
|
121
|
+
view: View2D;
|
|
122
|
+
}) {
|
|
123
|
+
yield elementRef();
|
|
124
|
+
if (element.animation) {
|
|
125
|
+
const animation = animationController.get(element.animation.name);
|
|
126
|
+
if (animation) {
|
|
127
|
+
yield* animation.run({
|
|
128
|
+
elementRef,
|
|
129
|
+
containerRef,
|
|
130
|
+
view,
|
|
131
|
+
duration: element.e - element.s,
|
|
132
|
+
...element.animation,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
export function* addFrameEffect({
|
|
140
|
+
containerRef,
|
|
141
|
+
elementRef,
|
|
142
|
+
element,
|
|
143
|
+
}: {
|
|
144
|
+
containerRef: Reference<any>;
|
|
145
|
+
elementRef: Reference<any>;
|
|
146
|
+
element: VisualizerElement;
|
|
147
|
+
}) {
|
|
148
|
+
let frameEffects = [];
|
|
149
|
+
const initProps = getFrameState({
|
|
150
|
+
containerRef,
|
|
151
|
+
elementRef,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
for (let i = 0; i < element?.frameEffects?.length; i++) {
|
|
155
|
+
const frameEffect = element.frameEffects[i];
|
|
156
|
+
const restore =
|
|
157
|
+
i === element.frameEffects.length - 1 ||
|
|
158
|
+
element.frameEffects[i + 1].s !== frameEffect.e;
|
|
159
|
+
const frameEffectPlugin = frameEffectController.get(frameEffect.name);
|
|
160
|
+
if (frameEffectPlugin) {
|
|
161
|
+
yield* frameEffectPlugin.run({
|
|
162
|
+
containerRef,
|
|
163
|
+
elementRef,
|
|
164
|
+
initFrameState: initProps,
|
|
165
|
+
frameEffect,
|
|
166
|
+
});
|
|
167
|
+
if (restore) {
|
|
168
|
+
yield* restoreFrameState({
|
|
169
|
+
containerRef,
|
|
170
|
+
elementRef,
|
|
171
|
+
duration: frameEffect.e - frameEffect.s,
|
|
172
|
+
element,
|
|
173
|
+
initProps,
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
// frameEffects.push(...sequence);
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// yield* all(...frameEffects);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function getFrameState({
|
|
184
|
+
containerRef,
|
|
185
|
+
elementRef,
|
|
186
|
+
}: {
|
|
187
|
+
containerRef: Reference<any>;
|
|
188
|
+
elementRef: Reference<any>;
|
|
189
|
+
}): FrameState {
|
|
190
|
+
return {
|
|
191
|
+
frame: {
|
|
192
|
+
size: containerRef().size(),
|
|
193
|
+
pos: containerRef().position(),
|
|
194
|
+
radius: containerRef().radius(),
|
|
195
|
+
scale: containerRef().scale(),
|
|
196
|
+
rotation: containerRef().rotation(),
|
|
197
|
+
},
|
|
198
|
+
element: {
|
|
199
|
+
size: containerRef().size(),
|
|
200
|
+
pos: elementRef().position(),
|
|
201
|
+
scale: elementRef().scale(),
|
|
202
|
+
},
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function* restoreFrameState({
|
|
207
|
+
containerRef,
|
|
208
|
+
elementRef,
|
|
209
|
+
duration,
|
|
210
|
+
element,
|
|
211
|
+
initProps,
|
|
212
|
+
}: {
|
|
213
|
+
containerRef: Reference<any>;
|
|
214
|
+
elementRef: Reference<any>;
|
|
215
|
+
duration: number;
|
|
216
|
+
element: VisualizerElement;
|
|
217
|
+
initProps: FrameState;
|
|
218
|
+
}) {
|
|
219
|
+
yield* waitFor(duration);
|
|
220
|
+
logger(`restoreFrameState: ${JSON.stringify(initProps)}`);
|
|
221
|
+
let sequence = [];
|
|
222
|
+
sequence.push(containerRef().size(initProps.frame.size));
|
|
223
|
+
sequence.push(containerRef().position(initProps.frame.pos));
|
|
224
|
+
sequence.push(containerRef().scale(initProps.frame.scale));
|
|
225
|
+
sequence.push(containerRef().rotation(initProps.frame.rotation));
|
|
226
|
+
sequence.push(containerRef().radius(initProps.frame.radius));
|
|
227
|
+
sequence.push(elementRef().size(initProps.element.size));
|
|
228
|
+
sequence.push(elementRef().position(initProps.element.pos));
|
|
229
|
+
sequence.push(elementRef().scale(initProps.element.scale));
|
|
230
|
+
sequence.push(
|
|
231
|
+
fitElement({
|
|
232
|
+
elementRef,
|
|
233
|
+
containerSize: initProps.frame.size,
|
|
234
|
+
elementSize: initProps.element.size,
|
|
235
|
+
objectFit: element.objectFit ?? "none",
|
|
236
|
+
})
|
|
237
|
+
);
|
|
238
|
+
yield* all(...sequence);
|
|
239
|
+
}
|
package/src/helpers/filters.ts
CHANGED
package/src/helpers/log.utils.ts
CHANGED
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
easeInBounce,
|
|
31
31
|
easeOutBounce,
|
|
32
32
|
easeInOutBounce,
|
|
33
|
-
} from "@
|
|
33
|
+
} from "@twick/core";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Timing utilities for the visualizer package.
|
|
@@ -107,23 +107,4 @@ export function getTimingFunction(name: string) {
|
|
|
107
107
|
default:
|
|
108
108
|
return linear;
|
|
109
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
|
-
}
|
|
110
|
+
}
|