@twick/visualizer 0.14.0 → 0.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.eslintrc.json +20 -20
  2. package/README.md +113 -13
  3. package/package.json +14 -14
  4. package/package.json.bak +34 -0
  5. package/src/animations/blur.tsx +96 -60
  6. package/src/animations/breathe.tsx +95 -60
  7. package/src/animations/fade.tsx +173 -60
  8. package/src/animations/index.ts +12 -0
  9. package/src/animations/photo-rise.tsx +103 -66
  10. package/src/animations/photo-zoom.tsx +109 -73
  11. package/src/animations/rise.tsx +157 -118
  12. package/src/animations/succession.tsx +112 -77
  13. package/src/components/frame-effects.tsx +188 -188
  14. package/src/components/track.tsx +237 -232
  15. package/src/controllers/animation.controller.ts +38 -38
  16. package/src/controllers/element.controller.ts +42 -42
  17. package/src/controllers/frame-effect.controller.tsx +29 -29
  18. package/src/controllers/text-effect.controller.ts +32 -32
  19. package/src/elements/audio.element.tsx +79 -17
  20. package/src/elements/caption.element.tsx +169 -87
  21. package/src/elements/circle.element.tsx +88 -20
  22. package/src/elements/icon.element.tsx +88 -20
  23. package/src/elements/image.element.tsx +134 -55
  24. package/src/elements/index.ts +14 -0
  25. package/src/elements/rect.element.tsx +92 -22
  26. package/src/elements/scene.element.tsx +97 -29
  27. package/src/elements/text.element.tsx +101 -27
  28. package/src/elements/video.element.tsx +274 -56
  29. package/src/frame-effects/circle.frame.tsx +168 -103
  30. package/src/frame-effects/index.ts +7 -0
  31. package/src/frame-effects/rect.frame.tsx +198 -103
  32. package/src/global.css +11 -11
  33. package/src/helpers/caption.utils.ts +29 -29
  34. package/src/helpers/constants.ts +162 -158
  35. package/src/helpers/element.utils.ts +331 -239
  36. package/src/helpers/event.utils.ts +21 -0
  37. package/src/helpers/filters.ts +127 -127
  38. package/src/helpers/log.utils.ts +55 -29
  39. package/src/helpers/timing.utils.ts +109 -109
  40. package/src/helpers/types.ts +361 -241
  41. package/src/helpers/utils.ts +36 -19
  42. package/src/index.ts +196 -6
  43. package/src/live.tsx +16 -16
  44. package/src/project.ts +6 -6
  45. package/src/sample.ts +247 -247
  46. package/src/text-effects/elastic.tsx +70 -39
  47. package/src/text-effects/erase.tsx +91 -58
  48. package/src/text-effects/index.ts +9 -0
  49. package/src/text-effects/stream-word.tsx +94 -60
  50. package/src/text-effects/typewriter.tsx +93 -59
  51. package/src/visualizer-grouped.ts +83 -0
  52. package/src/visualizer.tsx +182 -78
  53. package/tsconfig.json +11 -11
  54. package/typedoc.json +19 -14
  55. package/vite.config.ts +15 -15
  56. package/.turbo/turbo-build.log +0 -19
  57. package/.turbo/turbo-docs.log +0 -7
  58. package/LICENSE +0 -197
  59. package/dist/mp4.wasm +0 -0
  60. package/dist/project.css +0 -1
  61. package/dist/project.js +0 -145
  62. package/docs/.nojekyll +0 -1
  63. package/docs/README.md +0 -13
  64. package/docs/interfaces/Animation.md +0 -47
  65. package/docs/interfaces/Element.md +0 -47
  66. package/docs/interfaces/FrameEffectPlugin.md +0 -47
  67. package/docs/interfaces/TextEffect.md +0 -47
  68. package/docs/modules.md +0 -535
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,113 @@
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
- ```
1
+ # @twick/visualizer
2
+
3
+ A visualization library built on top of [@twick/2d](https://github.com/re-video/2d) for creating interactive visualizations and animations.
4
+
5
+ ## Overview
6
+
7
+ This package provides advanced visualization capabilities for creating interactive animations, effects, and visual elements in video editing applications. Built on top of a 2D graphics engine, it offers powerful tools for creating professional visual content.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @twick/visualizer
13
+ # or
14
+ pnpm add @twick/visualizer
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```typescript
20
+ import {
21
+ createVisualization,
22
+ addAnimation,
23
+ renderScene
24
+ } from '@twick/visualizer';
25
+
26
+ // Create a new visualization
27
+ const viz = createVisualization({
28
+ width: 1920,
29
+ height: 1080,
30
+ duration: 10
31
+ });
32
+
33
+ // Add animations and effects
34
+ addAnimation(viz, {
35
+ type: 'fade',
36
+ startTime: 0,
37
+ duration: 2
38
+ });
39
+
40
+ // Render the scene
41
+ const output = await renderScene(viz);
42
+ ```
43
+
44
+ ## Key Features
45
+
46
+ - **Interactive Visualizations**: Create dynamic visual content
47
+ - **Animation Engine**: Powerful animation system with keyframes
48
+ - **Effect Library**: Built-in effects and transitions
49
+ - **Performance Optimized**: Efficient rendering for real-time applications
50
+ - **Extensible**: Plugin system for custom effects
51
+ - **2D Graphics**: Full 2D graphics capabilities
52
+
53
+ ## Development
54
+
55
+ ### Installation
56
+
57
+ ```bash
58
+ pnpm install
59
+ ```
60
+
61
+ ### Build
62
+
63
+ ```bash
64
+ pnpm build
65
+ ```
66
+
67
+ ### Development Server
68
+
69
+ ```bash
70
+ pnpm dev
71
+ ```
72
+
73
+ ## API Reference
74
+
75
+ ### Core Functions
76
+
77
+ - `createVisualization`: Create a new visualization instance
78
+ - `addAnimation`: Add animations to the scene
79
+ - `renderScene`: Render the visualization to output
80
+ - `addEffect`: Apply visual effects
81
+ - `exportAnimation`: Export animations in various formats
82
+
83
+ ### Types
84
+
85
+ - `VisualizationConfig`: Configuration for visualizations
86
+ - `AnimationOptions`: Animation configuration options
87
+ - `EffectConfig`: Effect configuration interface
88
+ - `RenderOptions`: Rendering options
89
+
90
+ For complete API documentation, refer to the generated documentation.
91
+
92
+ ## Browser Support
93
+
94
+ This package requires a browser environment with support for:
95
+ - WebGL or Canvas 2D
96
+ - Modern JavaScript features (ES2020+)
97
+ - RequestAnimationFrame API
98
+
99
+ ## Documentation
100
+
101
+ For complete documentation, refer to the project documentation site.
102
+
103
+ ## License
104
+
105
+ This package is licensed under the **Sustainable Use License (SUL) Version 1.0**.
106
+
107
+ - Free for use in commercial and non-commercial apps
108
+ - Can be modified and self-hosted
109
+ - Cannot be sold, rebranded, or distributed as a standalone SDK
110
+
111
+ For commercial licensing inquiries, contact: contact@kifferai.com
112
+
113
+ For full license terms, see the main LICENSE.md file in the project root.
package/package.json CHANGED
@@ -1,20 +1,26 @@
1
1
  {
2
2
  "name": "@twick/visualizer",
3
- "version": "0.14.0",
4
- "license": "Apache-2.0",
3
+ "version": "0.14.3",
4
+ "license": "SEE LICENSE IN LICENSE.md",
5
+ "scripts": {
6
+ "start": "twick editor --projectFile ./src/live.tsx",
7
+ "build": "tsc && vite build",
8
+ "docs": "typedoc --out docs src/visualizer-grouped.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.3",
17
+ "@twick/core": "0.14.3",
18
+ "@twick/renderer": "0.14.3",
19
+ "@twick/vite-plugin": "0.14.3",
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.3"
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.3",
4
+ "license": "SEE LICENSE IN LICENSE.md",
5
+ "scripts": {
6
+ "start": "twick editor --projectFile ./src/live.tsx",
7
+ "build": "tsc && vite build",
8
+ "docs": "typedoc --out docs src/visualizer-grouped.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.3",
17
+ "@twick/core": "0.14.3",
18
+ "@twick/renderer": "0.14.3",
19
+ "@twick/vite-plugin": "0.14.3",
20
+ "date-fns": "^4.1.0",
21
+ "preact": "^10.19.2",
22
+ "crelt": "^1.0.6",
23
+ "@twick/media-utils": "0.14.3"
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,96 @@
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
+ * @group BlurAnimation
6
+ * BlurAnimation applies a blur effect to an element or its container during enter,
7
+ * exit, or both animations. Creates smooth blur transitions for professional
8
+ * visual effects that can focus attention or create depth.
9
+ *
10
+ * Available animation modes:
11
+ * - "enter": Starts blurred and gradually becomes clear
12
+ * - "exit": Starts clear and gradually becomes blurred
13
+ * - "both": Blurs in, clears, then blurs out
14
+ *
15
+ * @param elementRef - Reference to the main element to animate
16
+ * @param containerRef - Optional reference to a container element
17
+ * @param interval - Duration of blur transitions in seconds
18
+ * @param duration - Total duration of the animation in seconds
19
+ * @param intensity - Maximum blur strength (default: 25)
20
+ * @param animate - Animation phase ("enter" | "exit" | "both")
21
+ *
22
+ * @example
23
+ * ```js
24
+ * // Basic blur-in animation
25
+ * animation: {
26
+ * name: "blur",
27
+ * animate: "enter",
28
+ * duration: 2,
29
+ * intensity: 15
30
+ * }
31
+ *
32
+ * // Blur out effect
33
+ * animation: {
34
+ * name: "blur",
35
+ * animate: "exit",
36
+ * duration: 1.5,
37
+ * intensity: 30
38
+ * }
39
+ * ```
40
+ */
41
+ export const BlurAnimation = {
42
+ name: "blur",
43
+
44
+ /**
45
+ * Generator function controlling the blur animation.
46
+ * Handles blur transitions based on the specified animation mode and intensity.
47
+ *
48
+ * @param params - Animation parameters including element references and timing
49
+ * @returns Generator that controls the blur animation timeline
50
+ *
51
+ * @example
52
+ * ```js
53
+ * yield* BlurAnimation.run({
54
+ * elementRef: myElement,
55
+ * interval: 0.5,
56
+ * duration: 2,
57
+ * intensity: 25,
58
+ * animate: "enter"
59
+ * });
60
+ * ```
61
+ */
62
+ *run({
63
+ elementRef,
64
+ containerRef,
65
+ interval,
66
+ duration,
67
+ intensity = 25,
68
+ animate,
69
+ }: AnimationParams) {
70
+ // Choose containerRef if provided; otherwise, fallback to elementRef
71
+ const ref = containerRef ?? elementRef;
72
+
73
+ let animationInterval = Math.min(interval, duration);
74
+ if (animate === "enter") {
75
+ // Start fully blurred
76
+ ref().filters.blur(intensity);
77
+ // Animate to no blur over 'interval'
78
+ yield* ref().filters.blur(0, animationInterval);
79
+ } else if (animate === "exit") {
80
+ // Wait for the time before exit animation starts
81
+ yield* waitFor(duration - animationInterval);
82
+ // Animate from no blur to full blur over 'interval'
83
+ yield* ref().filters.blur(intensity, animationInterval);
84
+ } else if (animate === "both") {
85
+ animationInterval = Math.min(interval, duration/2);
86
+ // Start fully blurred
87
+ ref().filters.blur(intensity);
88
+ // Animate to no blur
89
+ yield* ref().filters.blur(0, animationInterval);
90
+ // Wait until exit animation
91
+ yield* waitFor(duration - animationInterval);
92
+ // Animate to full blur again
93
+ yield* ref().filters.blur(intensity, animationInterval);
94
+ }
95
+ },
96
+ };
@@ -1,60 +1,95 @@
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
+ * @group BreatheAnimation
7
+ * BreatheAnimation applies a smooth scale in/out effect to simulate a "breathing" motion.
8
+ * Creates gentle pulsing animations that add life and movement to static elements.
9
+ * Perfect for subtle background animations and attention-grabbing effects.
10
+ *
11
+ * Available modes:
12
+ * - "in": Gradually scales down (shrinks) to the target intensity
13
+ * - "out": Starts scaled down, then grows back to original size
14
+ *
15
+ * @param elementRef - Reference to the main element to animate
16
+ * @param containerRef - Optional reference to a container element
17
+ * @param mode - Animation phase ("in" | "out")
18
+ * @param duration - Duration of the scaling animation in seconds
19
+ * @param intensity - Target scale factor (default: 0.5)
20
+ *
21
+ * @example
22
+ * ```js
23
+ * // Gentle breathing in effect
24
+ * animation: {
25
+ * name: "breathe",
26
+ * mode: "in",
27
+ * duration: 2,
28
+ * intensity: 0.8
29
+ * }
30
+ *
31
+ * // Breathing out animation
32
+ * animation: {
33
+ * name: "breathe",
34
+ * mode: "out",
35
+ * duration: 1.5,
36
+ * intensity: 0.6
37
+ * }
38
+ * ```
39
+ */
40
+ export const BreatheAnimation = {
41
+ name: "breathe",
42
+
43
+ /**
44
+ * Generator function controlling the breathing scale animation.
45
+ * Handles smooth scaling transitions to create natural breathing motion.
46
+ *
47
+ * @param params - Animation parameters including element references and timing
48
+ * @returns Generator that controls the breathing animation timeline
49
+ *
50
+ * @example
51
+ * ```js
52
+ * yield* BreatheAnimation.run({
53
+ * elementRef: myElement,
54
+ * mode: "in",
55
+ * duration: 2,
56
+ * intensity: 0.8
57
+ * });
58
+ * ```
59
+ */
60
+ *run({
61
+ elementRef,
62
+ containerRef,
63
+ mode,
64
+ duration,
65
+ intensity = 0.5,
66
+ }: AnimationParams) {
67
+ // Use containerRef if provided, otherwise fallback to elementRef
68
+ const ref = containerRef ?? elementRef;
69
+
70
+ // Get the current scale of the element
71
+ const scale = ref().scale();
72
+
73
+ if (mode === "in") {
74
+ // Animate scaling down to (original scale * intensity)
75
+ yield* ref().scale(
76
+ new Vector2(scale.x * intensity, scale.y * intensity),
77
+ duration,
78
+ getTimingFunction("easeInSine")
79
+ );
80
+ }
81
+
82
+ if (mode === "out") {
83
+ // Immediately set to scaled down size
84
+ ref().scale(
85
+ new Vector2(scale.x * intensity, scale.y * intensity)
86
+ );
87
+ // Animate scaling back up to original size
88
+ yield* ref().scale(
89
+ new Vector2(scale.x, scale.y),
90
+ duration,
91
+ getTimingFunction("easeOutSine")
92
+ );
93
+ }
94
+ },
95
+ };