@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.
Files changed (63) hide show
  1. package/.eslintrc.json +20 -20
  2. package/README.md +12 -12
  3. package/package.json +13 -13
  4. package/package.json.bak +34 -0
  5. package/src/animations/blur.tsx +60 -60
  6. package/src/animations/breathe.tsx +60 -60
  7. package/src/animations/fade.tsx +60 -60
  8. package/src/animations/photo-rise.tsx +66 -66
  9. package/src/animations/photo-zoom.tsx +73 -73
  10. package/src/animations/rise.tsx +118 -118
  11. package/src/animations/succession.tsx +77 -77
  12. package/src/components/frame-effects.tsx +188 -188
  13. package/src/components/track.tsx +237 -232
  14. package/src/controllers/animation.controller.ts +38 -38
  15. package/src/controllers/element.controller.ts +42 -42
  16. package/src/controllers/frame-effect.controller.tsx +29 -29
  17. package/src/controllers/text-effect.controller.ts +32 -32
  18. package/src/elements/audio.element.tsx +17 -17
  19. package/src/elements/caption.element.tsx +87 -87
  20. package/src/elements/circle.element.tsx +20 -20
  21. package/src/elements/icon.element.tsx +20 -20
  22. package/src/elements/image.element.tsx +53 -55
  23. package/src/elements/rect.element.tsx +22 -22
  24. package/src/elements/scene.element.tsx +29 -29
  25. package/src/elements/text.element.tsx +27 -27
  26. package/src/elements/video.element.tsx +55 -56
  27. package/src/frame-effects/circle.frame.tsx +103 -103
  28. package/src/frame-effects/rect.frame.tsx +103 -103
  29. package/src/global.css +11 -11
  30. package/src/helpers/caption.utils.ts +29 -29
  31. package/src/helpers/constants.ts +162 -158
  32. package/src/helpers/element.utils.ts +239 -239
  33. package/src/helpers/event.utils.ts +6 -0
  34. package/src/helpers/filters.ts +127 -127
  35. package/src/helpers/log.utils.ts +29 -29
  36. package/src/helpers/timing.utils.ts +109 -109
  37. package/src/helpers/types.ts +242 -241
  38. package/src/helpers/utils.ts +19 -19
  39. package/src/index.ts +6 -6
  40. package/src/live.tsx +16 -16
  41. package/src/project.ts +6 -6
  42. package/src/sample.ts +247 -247
  43. package/src/text-effects/elastic.tsx +39 -39
  44. package/src/text-effects/erase.tsx +58 -58
  45. package/src/text-effects/stream-word.tsx +60 -60
  46. package/src/text-effects/typewriter.tsx +59 -59
  47. package/src/visualizer.tsx +98 -78
  48. package/tsconfig.json +11 -11
  49. package/typedoc.json +14 -14
  50. package/vite.config.ts +15 -15
  51. package/.turbo/turbo-build.log +0 -19
  52. package/.turbo/turbo-docs.log +0 -7
  53. package/LICENSE +0 -197
  54. package/dist/mp4.wasm +0 -0
  55. package/dist/project.css +0 -1
  56. package/dist/project.js +0 -145
  57. package/docs/.nojekyll +0 -1
  58. package/docs/README.md +0 -13
  59. package/docs/interfaces/Animation.md +0 -47
  60. package/docs/interfaces/Element.md +0 -47
  61. package/docs/interfaces/FrameEffectPlugin.md +0 -47
  62. package/docs/interfaces/TextEffect.md +0 -47
  63. package/docs/modules.md +0 -535
package/.eslintrc.json CHANGED
@@ -1,21 +1,21 @@
1
- {
2
- "root": true,
3
- "extends": [
4
- "eslint:recommended",
5
- "plugin:@typescript-eslint/recommended"
6
- ],
7
- "parser": "@typescript-eslint/parser",
8
- "plugins": ["@typescript-eslint"],
9
- "parserOptions": {
10
- "ecmaVersion": "latest",
11
- "sourceType": "module"
12
- },
13
- "env": {
14
- "es2022": true,
15
- "node": true
16
- },
17
- "rules": {
18
- "@typescript-eslint/no-explicit-any": "warn",
19
- "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
20
- }
1
+ {
2
+ "root": true,
3
+ "extends": [
4
+ "eslint:recommended",
5
+ "plugin:@typescript-eslint/recommended"
6
+ ],
7
+ "parser": "@typescript-eslint/parser",
8
+ "plugins": ["@typescript-eslint"],
9
+ "parserOptions": {
10
+ "ecmaVersion": "latest",
11
+ "sourceType": "module"
12
+ },
13
+ "env": {
14
+ "es2022": true,
15
+ "node": true
16
+ },
17
+ "rules": {
18
+ "@typescript-eslint/no-explicit-any": "warn",
19
+ "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
20
+ }
21
21
  }
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
- # @twick/visualizer
2
-
3
- A visualization library built on top of [@twick/2d](https://github.com/re-video/2d) for creating interactive visualizations.
4
-
5
- ## Installation
6
- ```
7
- pnpm install
8
- ```
9
-
10
- ## Build
11
- ```
12
- pnpm build
1
+ # @twick/visualizer
2
+
3
+ A visualization library built on top of [@twick/2d](https://github.com/re-video/2d) for creating interactive visualizations.
4
+
5
+ ## Installation
6
+ ```
7
+ pnpm install
8
+ ```
9
+
10
+ ## Build
11
+ ```
12
+ pnpm build
13
13
  ```
package/package.json CHANGED
@@ -1,20 +1,26 @@
1
1
  {
2
2
  "name": "@twick/visualizer",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "license": "Apache-2.0",
5
+ "scripts": {
6
+ "start": "twick editor --projectFile ./src/live.tsx",
7
+ "build": "tsc && vite build",
8
+ "docs": "typedoc --out docs src/index.ts",
9
+ "clean": "rimraf .turbo node_modules dist"
10
+ },
5
11
  "publishConfig": {
6
12
  "access": "public"
7
13
  },
8
14
  "dependencies": {
9
15
  "@preact/signals": "^1.2.1",
10
- "@twick/2d": "^0.14.0",
11
- "@twick/core": "^0.14.0",
12
- "@twick/renderer": "^0.14.0",
13
- "@twick/vite-plugin": "^0.14.0",
16
+ "@twick/2d": "0.14.2",
17
+ "@twick/core": "0.14.2",
18
+ "@twick/renderer": "0.14.2",
19
+ "@twick/vite-plugin": "0.14.2",
14
20
  "date-fns": "^4.1.0",
15
21
  "preact": "^10.19.2",
16
22
  "crelt": "^1.0.6",
17
- "@twick/media-utils": "0.14.0"
23
+ "@twick/media-utils": "0.14.2"
18
24
  },
19
25
  "devDependencies": {
20
26
  "@twick/cli": "0.14.0",
@@ -24,11 +30,5 @@
24
30
  "typedoc-plugin-markdown": "^3.17.1",
25
31
  "vite-plugin-dts": "^3.7.3",
26
32
  "vite": "^5.1.4"
27
- },
28
- "scripts": {
29
- "start": "twick editor --projectFile ./src/live.tsx",
30
- "build": "tsc && vite build",
31
- "docs": "typedoc --out docs src/index.ts",
32
- "clean": "rimraf .turbo node_modules dist"
33
33
  }
34
- }
34
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@twick/visualizer",
3
+ "version": "0.14.2",
4
+ "license": "Apache-2.0",
5
+ "scripts": {
6
+ "start": "twick editor --projectFile ./src/live.tsx",
7
+ "build": "tsc && vite build",
8
+ "docs": "typedoc --out docs src/index.ts",
9
+ "clean": "rimraf .turbo node_modules dist"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "dependencies": {
15
+ "@preact/signals": "^1.2.1",
16
+ "@twick/2d": "0.14.2",
17
+ "@twick/core": "0.14.2",
18
+ "@twick/renderer": "0.14.2",
19
+ "@twick/vite-plugin": "0.14.2",
20
+ "date-fns": "^4.1.0",
21
+ "preact": "^10.19.2",
22
+ "crelt": "^1.0.6",
23
+ "@twick/media-utils": "0.14.2"
24
+ },
25
+ "devDependencies": {
26
+ "@twick/cli": "0.14.0",
27
+ "@twick/ui": "0.14.0",
28
+ "typescript": "5.4.2",
29
+ "typedoc": "^0.25.8",
30
+ "typedoc-plugin-markdown": "^3.17.1",
31
+ "vite-plugin-dts": "^3.7.3",
32
+ "vite": "^5.1.4"
33
+ }
34
+ }
@@ -1,60 +1,60 @@
1
- import { waitFor } from "@twick/core";
2
- import { AnimationParams } from "../helpers/types";
3
-
4
- /**
5
- * BlurAnimation applies a blur effect to an element or its container
6
- * during enter, exit, or both animations.
7
- *
8
- * Available animation modes:
9
- * - "enter": Starts blurred and gradually becomes clear.
10
- * - "exit": Starts clear and gradually becomes blurred.
11
- * - "both": Blurs in, clears, then blurs out.
12
- *
13
- * @param elementRef - Reference to the main element.
14
- * @param containerRef - Optional reference to a container element.
15
- * @param interval - Duration (in frames or ms) of each blur transition.
16
- * @param duration - Total duration of the animation.
17
- * @param intensity - Maximum blur strength (default: 25).
18
- * @param animate - Animation phase ("enter" | "exit" | "both").
19
- */
20
- export const BlurAnimation = {
21
- name: "blur",
22
-
23
- /**
24
- * Generator function controlling the blur animation.
25
- */
26
- *run({
27
- elementRef,
28
- containerRef,
29
- interval,
30
- duration,
31
- intensity = 25,
32
- animate,
33
- }: AnimationParams) {
34
- // Choose containerRef if provided; otherwise, fallback to elementRef
35
- const ref = containerRef ?? elementRef;
36
-
37
- let animationInterval = Math.min(interval, duration);
38
- if (animate === "enter") {
39
- // Start fully blurred
40
- ref().filters.blur(intensity);
41
- // Animate to no blur over 'interval'
42
- yield* ref().filters.blur(0, animationInterval);
43
- } else if (animate === "exit") {
44
- // Wait for the time before exit animation starts
45
- yield* waitFor(duration - animationInterval);
46
- // Animate from no blur to full blur over 'interval'
47
- yield* ref().filters.blur(intensity, animationInterval);
48
- } else if (animate === "both") {
49
- animationInterval = Math.min(interval, duration/2);
50
- // Start fully blurred
51
- ref().filters.blur(intensity);
52
- // Animate to no blur
53
- yield* ref().filters.blur(0, animationInterval);
54
- // Wait until exit animation
55
- yield* waitFor(duration - animationInterval);
56
- // Animate to full blur again
57
- yield* ref().filters.blur(intensity, animationInterval);
58
- }
59
- },
60
- };
1
+ import { waitFor } from "@twick/core";
2
+ import { AnimationParams } from "../helpers/types";
3
+
4
+ /**
5
+ * BlurAnimation applies a blur effect to an element or its container
6
+ * during enter, exit, or both animations.
7
+ *
8
+ * Available animation modes:
9
+ * - "enter": Starts blurred and gradually becomes clear.
10
+ * - "exit": Starts clear and gradually becomes blurred.
11
+ * - "both": Blurs in, clears, then blurs out.
12
+ *
13
+ * @param elementRef - Reference to the main element.
14
+ * @param containerRef - Optional reference to a container element.
15
+ * @param interval - Duration (in frames or ms) of each blur transition.
16
+ * @param duration - Total duration of the animation.
17
+ * @param intensity - Maximum blur strength (default: 25).
18
+ * @param animate - Animation phase ("enter" | "exit" | "both").
19
+ */
20
+ export const BlurAnimation = {
21
+ name: "blur",
22
+
23
+ /**
24
+ * Generator function controlling the blur animation.
25
+ */
26
+ *run({
27
+ elementRef,
28
+ containerRef,
29
+ interval,
30
+ duration,
31
+ intensity = 25,
32
+ animate,
33
+ }: AnimationParams) {
34
+ // Choose containerRef if provided; otherwise, fallback to elementRef
35
+ const ref = containerRef ?? elementRef;
36
+
37
+ let animationInterval = Math.min(interval, duration);
38
+ if (animate === "enter") {
39
+ // Start fully blurred
40
+ ref().filters.blur(intensity);
41
+ // Animate to no blur over 'interval'
42
+ yield* ref().filters.blur(0, animationInterval);
43
+ } else if (animate === "exit") {
44
+ // Wait for the time before exit animation starts
45
+ yield* waitFor(duration - animationInterval);
46
+ // Animate from no blur to full blur over 'interval'
47
+ yield* ref().filters.blur(intensity, animationInterval);
48
+ } else if (animate === "both") {
49
+ animationInterval = Math.min(interval, duration/2);
50
+ // Start fully blurred
51
+ ref().filters.blur(intensity);
52
+ // Animate to no blur
53
+ yield* ref().filters.blur(0, animationInterval);
54
+ // Wait until exit animation
55
+ yield* waitFor(duration - animationInterval);
56
+ // Animate to full blur again
57
+ yield* ref().filters.blur(intensity, animationInterval);
58
+ }
59
+ },
60
+ };
@@ -1,60 +1,60 @@
1
- import { Vector2 } from "@twick/core";
2
- import { AnimationParams } from "../helpers/types";
3
- import { getTimingFunction } from "../helpers/timing.utils";
4
-
5
- /**
6
- * BreatheAnimation applies a smooth scale in/out effect to simulate
7
- * a "breathing" motion.
8
- *
9
- * Available modes:
10
- * - "in": Gradually scales down (shrinks) to the target intensity.
11
- * - "out": Starts scaled down, then grows back to original size.
12
- *
13
- * @param elementRef - Reference to the main element to animate.
14
- * @param containerRef - Optional reference to a container element.
15
- * @param mode - Animation phase ("in" | "out").
16
- * @param duration - Duration of the scaling animation.
17
- * @param intensity - Target scale factor (default: 0.5).
18
- */
19
- export const BreatheAnimation = {
20
- name: "breathe",
21
-
22
- /**
23
- * Generator function controlling the breathing scale animation.
24
- */
25
- *run({
26
- elementRef,
27
- containerRef,
28
- mode,
29
- duration,
30
- intensity = 0.5,
31
- }: AnimationParams) {
32
- // Use containerRef if provided, otherwise fallback to elementRef
33
- const ref = containerRef ?? elementRef;
34
-
35
- // Get the current scale of the element
36
- const scale = ref().scale();
37
-
38
- if (mode === "in") {
39
- // Animate scaling down to (original scale * intensity)
40
- yield* ref().scale(
41
- new Vector2(scale.x * intensity, scale.y * intensity),
42
- duration,
43
- getTimingFunction("easeInSine")
44
- );
45
- }
46
-
47
- if (mode === "out") {
48
- // Immediately set to scaled down size
49
- ref().scale(
50
- new Vector2(scale.x * intensity, scale.y * intensity)
51
- );
52
- // Animate scaling back up to original size
53
- yield* ref().scale(
54
- new Vector2(scale.x, scale.y),
55
- duration,
56
- getTimingFunction("easeOutSine")
57
- );
58
- }
59
- },
60
- };
1
+ import { Vector2 } from "@twick/core";
2
+ import { AnimationParams } from "../helpers/types";
3
+ import { getTimingFunction } from "../helpers/timing.utils";
4
+
5
+ /**
6
+ * BreatheAnimation applies a smooth scale in/out effect to simulate
7
+ * a "breathing" motion.
8
+ *
9
+ * Available modes:
10
+ * - "in": Gradually scales down (shrinks) to the target intensity.
11
+ * - "out": Starts scaled down, then grows back to original size.
12
+ *
13
+ * @param elementRef - Reference to the main element to animate.
14
+ * @param containerRef - Optional reference to a container element.
15
+ * @param mode - Animation phase ("in" | "out").
16
+ * @param duration - Duration of the scaling animation.
17
+ * @param intensity - Target scale factor (default: 0.5).
18
+ */
19
+ export const BreatheAnimation = {
20
+ name: "breathe",
21
+
22
+ /**
23
+ * Generator function controlling the breathing scale animation.
24
+ */
25
+ *run({
26
+ elementRef,
27
+ containerRef,
28
+ mode,
29
+ duration,
30
+ intensity = 0.5,
31
+ }: AnimationParams) {
32
+ // Use containerRef if provided, otherwise fallback to elementRef
33
+ const ref = containerRef ?? elementRef;
34
+
35
+ // Get the current scale of the element
36
+ const scale = ref().scale();
37
+
38
+ if (mode === "in") {
39
+ // Animate scaling down to (original scale * intensity)
40
+ yield* ref().scale(
41
+ new Vector2(scale.x * intensity, scale.y * intensity),
42
+ duration,
43
+ getTimingFunction("easeInSine")
44
+ );
45
+ }
46
+
47
+ if (mode === "out") {
48
+ // Immediately set to scaled down size
49
+ ref().scale(
50
+ new Vector2(scale.x * intensity, scale.y * intensity)
51
+ );
52
+ // Animate scaling back up to original size
53
+ yield* ref().scale(
54
+ new Vector2(scale.x, scale.y),
55
+ duration,
56
+ getTimingFunction("easeOutSine")
57
+ );
58
+ }
59
+ },
60
+ };
@@ -1,60 +1,60 @@
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
+ * 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,66 +1,66 @@
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
+ * 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
+ };