@twick/visualizer 0.14.0 → 0.14.2
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 +12 -12
- package/package.json +13 -13
- package/package.json.bak +34 -0
- package/src/animations/blur.tsx +60 -60
- package/src/animations/breathe.tsx +60 -60
- package/src/animations/fade.tsx +60 -60
- package/src/animations/photo-rise.tsx +66 -66
- package/src/animations/photo-zoom.tsx +73 -73
- package/src/animations/rise.tsx +118 -118
- package/src/animations/succession.tsx +77 -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 +17 -17
- package/src/elements/caption.element.tsx +87 -87
- package/src/elements/circle.element.tsx +20 -20
- package/src/elements/icon.element.tsx +20 -20
- package/src/elements/image.element.tsx +53 -55
- package/src/elements/rect.element.tsx +22 -22
- package/src/elements/scene.element.tsx +29 -29
- package/src/elements/text.element.tsx +27 -27
- package/src/elements/video.element.tsx +55 -56
- package/src/frame-effects/circle.frame.tsx +103 -103
- package/src/frame-effects/rect.frame.tsx +103 -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 +239 -239
- package/src/helpers/event.utils.ts +6 -0
- package/src/helpers/filters.ts +127 -127
- package/src/helpers/log.utils.ts +29 -29
- package/src/helpers/timing.utils.ts +109 -109
- package/src/helpers/types.ts +242 -241
- package/src/helpers/utils.ts +19 -19
- package/src/index.ts +6 -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 +39 -39
- package/src/text-effects/erase.tsx +58 -58
- package/src/text-effects/stream-word.tsx +60 -60
- package/src/text-effects/typewriter.tsx +59 -59
- package/src/visualizer.tsx +98 -78
- package/tsconfig.json +11 -11
- package/typedoc.json +14 -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,28 +1,28 @@
|
|
|
1
|
-
import { ElementParams } from "../helpers/types";
|
|
2
|
-
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
-
import { Txt } from "@twick/2d";
|
|
4
|
-
import { addAnimation, addTextEffect } from "../helpers/element.utils";
|
|
5
|
-
|
|
6
|
-
export const TextElement = {
|
|
7
|
-
name: "text",
|
|
8
|
-
*create({ containerRef, element, view }: ElementParams) {
|
|
9
|
-
const elementRef = createRef<any>();
|
|
10
|
-
|
|
11
|
-
yield* waitFor(element?.s);
|
|
12
|
-
yield containerRef().add(
|
|
13
|
-
<Txt
|
|
14
|
-
ref={elementRef}
|
|
15
|
-
key={element.id}
|
|
16
|
-
text={element.t}
|
|
17
|
-
{...element.props}
|
|
18
|
-
/>
|
|
19
|
-
);
|
|
20
|
-
yield* all(
|
|
21
|
-
addAnimation({ elementRef: elementRef, element: element, view }),
|
|
22
|
-
addTextEffect({ elementRef: elementRef, element: element }),
|
|
23
|
-
waitFor(Math.max(0, element.e - element.s))
|
|
24
|
-
);
|
|
25
|
-
yield elementRef().remove();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
import { ElementParams } from "../helpers/types";
|
|
2
|
+
import { all, createRef, waitFor } from "@twick/core";
|
|
3
|
+
import { Txt } from "@twick/2d";
|
|
4
|
+
import { addAnimation, addTextEffect } from "../helpers/element.utils";
|
|
5
|
+
|
|
6
|
+
export const TextElement = {
|
|
7
|
+
name: "text",
|
|
8
|
+
*create({ containerRef, element, view }: ElementParams) {
|
|
9
|
+
const elementRef = createRef<any>();
|
|
10
|
+
|
|
11
|
+
yield* waitFor(element?.s);
|
|
12
|
+
yield containerRef().add(
|
|
13
|
+
<Txt
|
|
14
|
+
ref={elementRef}
|
|
15
|
+
key={element.id}
|
|
16
|
+
text={element.t}
|
|
17
|
+
{...element.props}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
yield* all(
|
|
21
|
+
addAnimation({ elementRef: elementRef, element: element, view }),
|
|
22
|
+
addTextEffect({ elementRef: elementRef, element: element }),
|
|
23
|
+
waitFor(Math.max(0, element.e - element.s))
|
|
24
|
+
);
|
|
25
|
+
yield elementRef().remove();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
28
|
|
|
@@ -1,56 +1,55 @@
|
|
|
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 {
|
|
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
|
-
yield frameElementRef().
|
|
52
|
-
yield
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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 { applyColorFilter } from "../helpers/filters";
|
|
6
|
+
|
|
7
|
+
export const VideoElement = {
|
|
8
|
+
name: "video",
|
|
9
|
+
*create({ containerRef, element, view }: ElementParams) {
|
|
10
|
+
yield* waitFor(element?.s);
|
|
11
|
+
const frameContainerRef = createRef<any>();
|
|
12
|
+
const frameElementRef = createRef<any>();
|
|
13
|
+
|
|
14
|
+
yield containerRef().add(
|
|
15
|
+
<Rect ref={frameContainerRef} key={element.id} {...element.frame}>
|
|
16
|
+
<Video
|
|
17
|
+
ref={frameElementRef}
|
|
18
|
+
key={`child-${element.id}`}
|
|
19
|
+
play={true}
|
|
20
|
+
{...element.props}
|
|
21
|
+
/>
|
|
22
|
+
</Rect>
|
|
23
|
+
);
|
|
24
|
+
if (frameContainerRef()) {
|
|
25
|
+
yield fitElement({
|
|
26
|
+
elementRef: frameElementRef,
|
|
27
|
+
containerSize: frameContainerRef().size(),
|
|
28
|
+
elementSize: frameElementRef().size(),
|
|
29
|
+
objectFit: element.objectFit,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (element?.props?.mediaFilter) {
|
|
33
|
+
applyColorFilter(frameElementRef, element.props.mediaFilter);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
yield* all(
|
|
37
|
+
addAnimation({
|
|
38
|
+
elementRef: frameElementRef,
|
|
39
|
+
containerRef: frameContainerRef,
|
|
40
|
+
element: element,
|
|
41
|
+
view,
|
|
42
|
+
}),
|
|
43
|
+
addFrameEffect({
|
|
44
|
+
containerRef: frameContainerRef,
|
|
45
|
+
elementRef: frameElementRef,
|
|
46
|
+
element,
|
|
47
|
+
}),
|
|
48
|
+
waitFor(Math.max(0, element.e - element.s))
|
|
49
|
+
);
|
|
50
|
+
yield frameElementRef().play(false);
|
|
51
|
+
yield frameElementRef().remove();
|
|
52
|
+
yield frameContainerRef().remove();
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
};
|
|
@@ -1,103 +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
|
-
};
|
|
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
|
+
};
|
|
@@ -1,103 +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
|
-
};
|
|
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
|
+
};
|
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');
|