@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
@@ -1,188 +1,188 @@
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, Reference, waitFor } from "@twick/core";
7
- import { getTimingFunction } from "../helpers/timing.utils";
8
- import { fitElement } from "../helpers/element.utils";
9
- import { DEFAULT_POSITION, DEFAULT_TIMING_FUNCTION, FRAME_SHAPE } from "../helpers/constants";
10
- import { FrameEffect } from "../helpers/types";
11
- import { View2D } from "@twick/2d";
12
-
13
- /**
14
- * Applies frame effects to a view or element
15
- * @param {Object} params - Parameters for applying frame effects
16
- * @param {View2D} params.view - The 2D view to apply effects to
17
- * @param {FrameEffect[]} params.effects - Array of effects to apply
18
- * @returns {void}
19
- */
20
- export function applyFrameEffects({ view, effects }: { view: View2D; effects: FrameEffect[] }) {
21
- // ... existing code ...
22
- }
23
-
24
- export function* addFrameEffect({
25
- containerRef,
26
- elementRef,
27
- frameElement,
28
- }: {
29
- containerRef: Reference<any>;
30
- elementRef: Reference<any>;
31
- frameElement: any;
32
- }) {
33
- let frameEffects = [];
34
- const initProps = {
35
- frame: {
36
- size: containerRef().size(),
37
- pos: containerRef().position(),
38
- radius: containerRef().radius(),
39
- scale: containerRef().scale(),
40
- rotation: containerRef().rotation(),
41
- },
42
- element: {
43
- size: containerRef().size(),
44
- pos: elementRef().position(),
45
- scale: elementRef().scale(),
46
- },
47
- };
48
-
49
- for (let i = 0; i < frameElement?.frameEffects?.length; i++) {
50
- const frameEffect = frameElement.frameEffects[i];
51
- const restore =
52
- i === frameElement.frameEffects.length - 1 ||
53
- frameElement.frameEffects[i + 1].s !== frameEffect.e;
54
- frameEffects.push(
55
- getFrameEffect({
56
- containerRef,
57
- elementRef,
58
- frameEffect,
59
- element: frameElement,
60
- restore,
61
- initProps,
62
- })
63
- );
64
- }
65
- yield* all(...frameEffects);
66
- }
67
-
68
- function* getFrameEffect({
69
- containerRef,
70
- elementRef,
71
- frameEffect,
72
- element,
73
- initProps,
74
- restore = true,
75
- }: {
76
- containerRef: Reference<any>;
77
- elementRef: Reference<any>;
78
- frameEffect: FrameEffect;
79
- element: any;
80
- initProps: any;
81
- restore?: boolean;
82
- }) {
83
- yield* waitFor(frameEffect.s);
84
- const props = frameEffect.props;
85
- const sequence = [];
86
-
87
- if (restore) {
88
- sequence.push(
89
- restoreState({
90
- containerRef,
91
- elementRef,
92
- frameEffect,
93
- element,
94
- initProps,
95
- })
96
- );
97
- }
98
-
99
- sequence.push(
100
- containerRef().size(
101
- props.frameSize,
102
- props.transitionDuration,
103
- getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
104
- )
105
- );
106
-
107
- sequence.push(
108
- containerRef().position(
109
- props.framePosition ?? { x: 0, y: 0 },
110
- props.transitionDuration,
111
- getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
112
- )
113
- );
114
-
115
- sequence.push(
116
- elementRef().position(
117
- props.elementPosition ?? DEFAULT_POSITION,
118
- props.transitionDuration,
119
- getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
120
- )
121
- );
122
-
123
- switch (props.frameShape) {
124
- case FRAME_SHAPE.CIRCLE:
125
- sequence.push(
126
- containerRef().radius(
127
- props.frameSize[0] / 2,
128
- props.transitionDuration,
129
- getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
130
- )
131
- );
132
- break;
133
- default:
134
- sequence.push(
135
- containerRef().radius(
136
- props.radius ?? 0,
137
- props.transitionDuration,
138
- getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
139
- )
140
- );
141
- }
142
-
143
- if (props.objectFit) {
144
- sequence.push(
145
- fitElement({
146
- elementRef,
147
- containerSize: { x: props.frameSize[0], y: props.frameSize[1] },
148
- elementSize: initProps.element.size,
149
- objectFit: props.objectFit,
150
- })
151
- );
152
- }
153
- yield* all(...sequence);
154
- }
155
-
156
- function* restoreState({
157
- containerRef,
158
- elementRef,
159
- frameEffect,
160
- element,
161
- initProps,
162
- }: {
163
- containerRef: Reference<any>;
164
- elementRef: Reference<any>;
165
- frameEffect: any;
166
- element: any;
167
- initProps: any;
168
- }) {
169
- yield* waitFor(frameEffect.e - frameEffect.s);
170
- let sequence = [];
171
- sequence.push(containerRef().size(initProps.frame.size));
172
- sequence.push(containerRef().position(initProps.frame.pos));
173
- sequence.push(containerRef().scale(initProps.frame.scale));
174
- sequence.push(containerRef().rotation(initProps.frame.rotation));
175
- sequence.push(containerRef().radius(initProps.frame.radius));
176
- sequence.push(elementRef().size(initProps.element.size));
177
- sequence.push(elementRef().position(initProps.element.pos));
178
- sequence.push(elementRef().scale(initProps.element.scale));
179
- sequence.push(
180
- fitElement({
181
- elementRef,
182
- containerSize: initProps.frame.size,
183
- elementSize: initProps.element.size,
184
- objectFit: element.objectFit ?? "none",
185
- })
186
- );
187
- yield* all(...sequence);
188
- }
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, Reference, waitFor } from "@twick/core";
7
+ import { getTimingFunction } from "../helpers/timing.utils";
8
+ import { fitElement } from "../helpers/element.utils";
9
+ import { DEFAULT_POSITION, DEFAULT_TIMING_FUNCTION, FRAME_SHAPE } from "../helpers/constants";
10
+ import { FrameEffect } from "../helpers/types";
11
+ import { View2D } from "@twick/2d";
12
+
13
+ /**
14
+ * Applies frame effects to a view or element
15
+ * @param {Object} params - Parameters for applying frame effects
16
+ * @param {View2D} params.view - The 2D view to apply effects to
17
+ * @param {FrameEffect[]} params.effects - Array of effects to apply
18
+ * @returns {void}
19
+ */
20
+ export function applyFrameEffects({ view, effects }: { view: View2D; effects: FrameEffect[] }) {
21
+ // ... existing code ...
22
+ }
23
+
24
+ export function* addFrameEffect({
25
+ containerRef,
26
+ elementRef,
27
+ frameElement,
28
+ }: {
29
+ containerRef: Reference<any>;
30
+ elementRef: Reference<any>;
31
+ frameElement: any;
32
+ }) {
33
+ let frameEffects = [];
34
+ const initProps = {
35
+ frame: {
36
+ size: containerRef().size(),
37
+ pos: containerRef().position(),
38
+ radius: containerRef().radius(),
39
+ scale: containerRef().scale(),
40
+ rotation: containerRef().rotation(),
41
+ },
42
+ element: {
43
+ size: containerRef().size(),
44
+ pos: elementRef().position(),
45
+ scale: elementRef().scale(),
46
+ },
47
+ };
48
+
49
+ for (let i = 0; i < frameElement?.frameEffects?.length; i++) {
50
+ const frameEffect = frameElement.frameEffects[i];
51
+ const restore =
52
+ i === frameElement.frameEffects.length - 1 ||
53
+ frameElement.frameEffects[i + 1].s !== frameEffect.e;
54
+ frameEffects.push(
55
+ getFrameEffect({
56
+ containerRef,
57
+ elementRef,
58
+ frameEffect,
59
+ element: frameElement,
60
+ restore,
61
+ initProps,
62
+ })
63
+ );
64
+ }
65
+ yield* all(...frameEffects);
66
+ }
67
+
68
+ function* getFrameEffect({
69
+ containerRef,
70
+ elementRef,
71
+ frameEffect,
72
+ element,
73
+ initProps,
74
+ restore = true,
75
+ }: {
76
+ containerRef: Reference<any>;
77
+ elementRef: Reference<any>;
78
+ frameEffect: FrameEffect;
79
+ element: any;
80
+ initProps: any;
81
+ restore?: boolean;
82
+ }) {
83
+ yield* waitFor(frameEffect.s);
84
+ const props = frameEffect.props;
85
+ const sequence = [];
86
+
87
+ if (restore) {
88
+ sequence.push(
89
+ restoreState({
90
+ containerRef,
91
+ elementRef,
92
+ frameEffect,
93
+ element,
94
+ initProps,
95
+ })
96
+ );
97
+ }
98
+
99
+ sequence.push(
100
+ containerRef().size(
101
+ props.frameSize,
102
+ props.transitionDuration,
103
+ getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
104
+ )
105
+ );
106
+
107
+ sequence.push(
108
+ containerRef().position(
109
+ props.framePosition ?? { x: 0, y: 0 },
110
+ props.transitionDuration,
111
+ getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
112
+ )
113
+ );
114
+
115
+ sequence.push(
116
+ elementRef().position(
117
+ props.elementPosition ?? DEFAULT_POSITION,
118
+ props.transitionDuration,
119
+ getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
120
+ )
121
+ );
122
+
123
+ switch (props.frameShape) {
124
+ case FRAME_SHAPE.CIRCLE:
125
+ sequence.push(
126
+ containerRef().radius(
127
+ props.frameSize[0] / 2,
128
+ props.transitionDuration,
129
+ getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
130
+ )
131
+ );
132
+ break;
133
+ default:
134
+ sequence.push(
135
+ containerRef().radius(
136
+ props.radius ?? 0,
137
+ props.transitionDuration,
138
+ getTimingFunction(props.transitionEasing ?? DEFAULT_TIMING_FUNCTION)
139
+ )
140
+ );
141
+ }
142
+
143
+ if (props.objectFit) {
144
+ sequence.push(
145
+ fitElement({
146
+ elementRef,
147
+ containerSize: { x: props.frameSize[0], y: props.frameSize[1] },
148
+ elementSize: initProps.element.size,
149
+ objectFit: props.objectFit,
150
+ })
151
+ );
152
+ }
153
+ yield* all(...sequence);
154
+ }
155
+
156
+ function* restoreState({
157
+ containerRef,
158
+ elementRef,
159
+ frameEffect,
160
+ element,
161
+ initProps,
162
+ }: {
163
+ containerRef: Reference<any>;
164
+ elementRef: Reference<any>;
165
+ frameEffect: any;
166
+ element: any;
167
+ initProps: any;
168
+ }) {
169
+ yield* waitFor(frameEffect.e - frameEffect.s);
170
+ let sequence = [];
171
+ sequence.push(containerRef().size(initProps.frame.size));
172
+ sequence.push(containerRef().position(initProps.frame.pos));
173
+ sequence.push(containerRef().scale(initProps.frame.scale));
174
+ sequence.push(containerRef().rotation(initProps.frame.rotation));
175
+ sequence.push(containerRef().radius(initProps.frame.radius));
176
+ sequence.push(elementRef().size(initProps.element.size));
177
+ sequence.push(elementRef().position(initProps.element.pos));
178
+ sequence.push(elementRef().scale(initProps.element.scale));
179
+ sequence.push(
180
+ fitElement({
181
+ elementRef,
182
+ containerSize: initProps.frame.size,
183
+ elementSize: initProps.element.size,
184
+ objectFit: element.objectFit ?? "none",
185
+ })
186
+ );
187
+ yield* all(...sequence);
188
+ }