@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,30 +1,30 @@
1
-
2
- import { CircleFrameEffect } from "../frame-effects/circle.frame";
3
- import { RectFrameEffect } from "../frame-effects/rect.frame";
4
- import { FrameEffectPlugin } from "../helpers/types";
5
-
6
- export class FrameEffectController {
7
- private frameEffects: Map<string, FrameEffectPlugin> = new Map();
8
-
9
- register(frameEffect: FrameEffectPlugin) {
10
- this.frameEffects.set(frameEffect.name, frameEffect);
11
- }
12
-
13
- get(name: string): FrameEffectPlugin | undefined {
14
- return this.frameEffects.get(name);
15
- }
16
-
17
- list(): string[] {
18
- return Array.from(this.frameEffects.keys());
19
- }
20
- }
21
-
22
- export const registerFrameEffects = () => {
23
- frameEffectController.register(CircleFrameEffect);
24
- frameEffectController.register(RectFrameEffect);
25
- }
26
-
27
- const frameEffectController = new FrameEffectController();
28
- registerFrameEffects();
29
-
1
+
2
+ import { CircleFrameEffect } from "../frame-effects/circle.frame";
3
+ import { RectFrameEffect } from "../frame-effects/rect.frame";
4
+ import { FrameEffectPlugin } from "../helpers/types";
5
+
6
+ export class FrameEffectController {
7
+ private frameEffects: Map<string, FrameEffectPlugin> = new Map();
8
+
9
+ register(frameEffect: FrameEffectPlugin) {
10
+ this.frameEffects.set(frameEffect.name, frameEffect);
11
+ }
12
+
13
+ get(name: string): FrameEffectPlugin | undefined {
14
+ return this.frameEffects.get(name);
15
+ }
16
+
17
+ list(): string[] {
18
+ return Array.from(this.frameEffects.keys());
19
+ }
20
+ }
21
+
22
+ export const registerFrameEffects = () => {
23
+ frameEffectController.register(CircleFrameEffect);
24
+ frameEffectController.register(RectFrameEffect);
25
+ }
26
+
27
+ const frameEffectController = new FrameEffectController();
28
+ registerFrameEffects();
29
+
30
30
  export default frameEffectController;
@@ -1,33 +1,33 @@
1
- import { ElasticEffect } from "../text-effects/elastic";
2
- import { EraseEffect } from "../text-effects/erase";
3
- import { StreamWordEffect } from "../text-effects/stream-word";
4
- import { TypewriterEffect } from "../text-effects/typewriter";
5
- import { TextEffect } from "../helpers/types";
6
-
7
- export class TextEffectController {
8
- private effects: Map<string, TextEffect> = new Map();
9
-
10
- register(effect: TextEffect) {
11
- this.effects.set(effect.name, effect);
12
- }
13
-
14
- get(name: string): TextEffect | undefined {
15
- return this.effects.get(name);
16
- }
17
-
18
- list(): string[] {
19
- return Array.from(this.effects.keys());
20
- }
21
- }
22
-
23
- export const registerTextEffects = () => {
24
- textEffectController.register(TypewriterEffect);
25
- textEffectController.register(StreamWordEffect);
26
- textEffectController.register(EraseEffect);
27
- textEffectController.register(ElasticEffect);
28
- }
29
-
30
- const textEffectController = new TextEffectController();
31
- registerTextEffects();
32
-
1
+ import { ElasticEffect } from "../text-effects/elastic";
2
+ import { EraseEffect } from "../text-effects/erase";
3
+ import { StreamWordEffect } from "../text-effects/stream-word";
4
+ import { TypewriterEffect } from "../text-effects/typewriter";
5
+ import { TextEffect } from "../helpers/types";
6
+
7
+ export class TextEffectController {
8
+ private effects: Map<string, TextEffect> = new Map();
9
+
10
+ register(effect: TextEffect) {
11
+ this.effects.set(effect.name, effect);
12
+ }
13
+
14
+ get(name: string): TextEffect | undefined {
15
+ return this.effects.get(name);
16
+ }
17
+
18
+ list(): string[] {
19
+ return Array.from(this.effects.keys());
20
+ }
21
+ }
22
+
23
+ export const registerTextEffects = () => {
24
+ textEffectController.register(TypewriterEffect);
25
+ textEffectController.register(StreamWordEffect);
26
+ textEffectController.register(EraseEffect);
27
+ textEffectController.register(ElasticEffect);
28
+ }
29
+
30
+ const textEffectController = new TextEffectController();
31
+ registerTextEffects();
32
+
33
33
  export default textEffectController;
@@ -1,17 +1,17 @@
1
- import { ElementParams } from "../helpers/types";
2
- import { createRef, waitFor } from "@twick/core";
3
- import { Audio } from "@twick/2d";
4
-
5
- export const AudioElement = {
6
- name: "audio",
7
- *create({ containerRef, element, view }: ElementParams) {
8
- const elementRef = createRef<any>();
9
- yield* waitFor(element?.s);
10
- yield containerRef().add(
11
- <Audio ref={elementRef} key={element.id} {...element.props} />
12
- );
13
- yield* waitFor(Math.max(0, element.e - element.s));
14
- yield elementRef().playing(false);
15
- yield elementRef().remove();
16
- },
17
- };
1
+ import { ElementParams } from "../helpers/types";
2
+ import { createRef, waitFor } from "@twick/core";
3
+ import { Audio } from "@twick/2d";
4
+
5
+ export const AudioElement = {
6
+ name: "audio",
7
+ *create({ containerRef, element, view }: ElementParams) {
8
+ const elementRef = createRef<any>();
9
+ yield* waitFor(element?.s);
10
+ yield containerRef().add(
11
+ <Audio ref={elementRef} key={element.id} play={true} {...element.props} />
12
+ );
13
+ yield* waitFor(Math.max(0, element.e - element.s));
14
+ yield elementRef().play(false);
15
+ yield elementRef().remove();
16
+ },
17
+ };
@@ -1,87 +1,87 @@
1
- import { CaptionProps, ElementParams } from "../helpers/types";
2
- import { Color, createRef, Reference, waitFor } from "@twick/core";
3
- import { Rect, Txt } from "@twick/2d";
4
- import { splitPhraseTiming } from "../helpers/caption.utils";
5
- import { TRANSPARENT_COLOR } from "../helpers/constants";
6
- import { hexToRGB } from "../helpers/utils";
7
-
8
- export const CaptionElement = {
9
- name: "caption",
10
- *create({ containerRef, caption }: ElementParams) {
11
- const words = splitPhraseTiming(caption);
12
- let phraseStart = 0;
13
- if (words?.length) {
14
- phraseStart = words[0].s;
15
- }
16
- let wordsState: {
17
- refs: Array<{ bgRef?: Reference<any>; textRef: Reference<any> }>;
18
- props: CaptionProps[];
19
- idx: number;
20
- prevTime: number;
21
- } = {
22
- refs: [],
23
- props: [],
24
- idx: 0,
25
- prevTime: phraseStart,
26
- };
27
- for (const word of words) {
28
- wordsState.props.push(caption.props);
29
- const textRef = createRef<Txt>();
30
- const captionProps = caption.props;
31
- containerRef().add(
32
- <Txt ref={textRef} {...captionProps} text={word.t} opacity={0} />
33
- );
34
- if (caption.capStyle == "highlight_bg") {
35
- const bgContainerRef = createRef();
36
- const childTextRef = createRef();
37
- const _color = new Color({...hexToRGB(captionProps.colors.background), a: captionProps?.bgOpacity ?? 1});
38
- containerRef().add(
39
- <Rect
40
- ref={bgContainerRef}
41
- fill={_color}
42
- width={textRef().width() + (captionProps.bgOffsetWidth ?? 30)}
43
- height={textRef().height() + (captionProps.bgOffsetHeight ?? 10)}
44
- margin={captionProps.bgMargin ?? [0, -5]}
45
- radius={captionProps.bgRadius ?? 10}
46
- padding={captionProps.bgPadding ?? [0, 15]}
47
- opacity={0}
48
- alignItems={"center"}
49
- justifyContent={"center"}
50
- layout
51
- >
52
- <Txt ref={childTextRef} {...captionProps} text={word.t} />
53
- </Rect>
54
- );
55
- textRef().remove();
56
- wordsState.refs.push({
57
- bgRef: bgContainerRef,
58
- textRef: childTextRef,
59
- });
60
- } else {
61
- wordsState.refs.push({
62
- textRef: textRef,
63
- });
64
- }
65
- wordsState.prevTime = word.e;
66
- wordsState.idx = wordsState.idx + 1;
67
- }
68
-
69
- wordsState.prevTime = phraseStart;
70
- wordsState.idx = 0;
71
-
72
- for (const word of words) {
73
- if (caption.capStyle == "highlight_bg") {
74
- yield* wordsState.refs[wordsState.idx]?.bgRef?.().opacity(1, 0);
75
- yield* waitFor(Math.max(0, word.e - word.s));
76
- yield* wordsState.refs[wordsState.idx]
77
- ?.bgRef?.()
78
- .fill(TRANSPARENT_COLOR, 0);
79
- } else {
80
- yield* wordsState.refs[wordsState.idx]?.textRef?.().opacity(1, 0);
81
- yield* waitFor(Math.max(0, word.e - word.s));
82
- }
83
- wordsState.prevTime = word.e;
84
- wordsState.idx = wordsState.idx + 1;
85
- }
86
- },
87
- };
1
+ import { CaptionProps, ElementParams } from "../helpers/types";
2
+ import { Color, createRef, Reference, waitFor } from "@twick/core";
3
+ import { Rect, Txt } from "@twick/2d";
4
+ import { splitPhraseTiming } from "../helpers/caption.utils";
5
+ import { TRANSPARENT_COLOR } from "../helpers/constants";
6
+ import { hexToRGB } from "../helpers/utils";
7
+
8
+ export const CaptionElement = {
9
+ name: "caption",
10
+ *create({ containerRef, caption }: ElementParams) {
11
+ const words = splitPhraseTiming(caption);
12
+ let phraseStart = 0;
13
+ if (words?.length) {
14
+ phraseStart = words[0].s;
15
+ }
16
+ let wordsState: {
17
+ refs: Array<{ bgRef?: Reference<any>; textRef: Reference<any> }>;
18
+ props: CaptionProps[];
19
+ idx: number;
20
+ prevTime: number;
21
+ } = {
22
+ refs: [],
23
+ props: [],
24
+ idx: 0,
25
+ prevTime: phraseStart,
26
+ };
27
+ for (const word of words) {
28
+ wordsState.props.push(caption.props);
29
+ const textRef = createRef<Txt>();
30
+ const captionProps = caption.props;
31
+ containerRef().add(
32
+ <Txt ref={textRef} {...captionProps} text={word.t} opacity={0} />
33
+ );
34
+ if (caption.capStyle == "highlight_bg") {
35
+ const bgContainerRef = createRef();
36
+ const childTextRef = createRef();
37
+ const _color = new Color({...hexToRGB(captionProps.colors.background), a: captionProps?.bgOpacity ?? 1});
38
+ containerRef().add(
39
+ <Rect
40
+ ref={bgContainerRef}
41
+ fill={_color}
42
+ width={textRef().width() + (captionProps.bgOffsetWidth ?? 30)}
43
+ height={textRef().height() + (captionProps.bgOffsetHeight ?? 10)}
44
+ margin={captionProps.bgMargin ?? [0, -5]}
45
+ radius={captionProps.bgRadius ?? 10}
46
+ padding={captionProps.bgPadding ?? [0, 15]}
47
+ opacity={0}
48
+ alignItems={"center"}
49
+ justifyContent={"center"}
50
+ layout
51
+ >
52
+ <Txt ref={childTextRef} {...captionProps} text={word.t} />
53
+ </Rect>
54
+ );
55
+ textRef().remove();
56
+ wordsState.refs.push({
57
+ bgRef: bgContainerRef,
58
+ textRef: childTextRef,
59
+ });
60
+ } else {
61
+ wordsState.refs.push({
62
+ textRef: textRef,
63
+ });
64
+ }
65
+ wordsState.prevTime = word.e;
66
+ wordsState.idx = wordsState.idx + 1;
67
+ }
68
+
69
+ wordsState.prevTime = phraseStart;
70
+ wordsState.idx = 0;
71
+
72
+ for (const word of words) {
73
+ if (caption.capStyle == "highlight_bg") {
74
+ yield* wordsState.refs[wordsState.idx]?.bgRef?.().opacity(1, 0);
75
+ yield* waitFor(Math.max(0, word.e - word.s));
76
+ yield* wordsState.refs[wordsState.idx]
77
+ ?.bgRef?.()
78
+ .fill(TRANSPARENT_COLOR, 0);
79
+ } else {
80
+ yield* wordsState.refs[wordsState.idx]?.textRef?.().opacity(1, 0);
81
+ yield* waitFor(Math.max(0, word.e - word.s));
82
+ }
83
+ wordsState.prevTime = word.e;
84
+ wordsState.idx = wordsState.idx + 1;
85
+ }
86
+ },
87
+ };
@@ -1,20 +1,20 @@
1
- import { ElementParams } from "../helpers/types";
2
- import { all, createRef, waitFor } from "@twick/core";
3
- import { Circle } from "@twick/2d";
4
- import { addAnimation } from "../helpers/element.utils";
5
-
6
- export const CircleElement = {
7
- name: "circle",
8
- *create({ containerRef, element, view }: ElementParams) {
9
- const elementRef = createRef<any>();
10
- yield* waitFor(element?.s);
11
- yield containerRef().add(
12
- <Circle ref={elementRef} key={element.id} {...element.props} />
13
- );
14
- yield* all(
15
- addAnimation({ elementRef: elementRef, element: element, view }),
16
- waitFor(Math.max(0, element.e - element.s))
17
- );
18
- yield elementRef().remove();
19
- },
20
- };
1
+ import { ElementParams } from "../helpers/types";
2
+ import { all, createRef, waitFor } from "@twick/core";
3
+ import { Circle } from "@twick/2d";
4
+ import { addAnimation } from "../helpers/element.utils";
5
+
6
+ export const CircleElement = {
7
+ name: "circle",
8
+ *create({ containerRef, element, view }: ElementParams) {
9
+ const elementRef = createRef<any>();
10
+ yield* waitFor(element?.s);
11
+ yield containerRef().add(
12
+ <Circle ref={elementRef} key={element.id} {...element.props} />
13
+ );
14
+ yield* all(
15
+ addAnimation({ elementRef: elementRef, element: element, view }),
16
+ waitFor(Math.max(0, element.e - element.s))
17
+ );
18
+ yield elementRef().remove();
19
+ },
20
+ };
@@ -1,20 +1,20 @@
1
- import { ElementParams } from "../helpers/types";
2
- import { all, createRef, waitFor } from "@twick/core";
3
- import { Icon } from "@twick/2d";
4
- import { addAnimation } from "../helpers/element.utils";
5
-
6
- export const IconElement = {
7
- name: "icon",
8
- *create({ containerRef, element, view }: ElementParams) {
9
- const elementRef = createRef<any>();
10
- yield* waitFor(element?.s);
11
- yield containerRef().add(
12
- <Icon ref={elementRef} key={element.id} {...element.props} />
13
- );
14
- yield* all(
15
- addAnimation({ elementRef: elementRef, element: element, view }),
16
- waitFor(Math.max(0, element.e - element.s))
17
- );
18
- yield elementRef().remove();
19
- },
20
- };
1
+ import { ElementParams } from "../helpers/types";
2
+ import { all, createRef, waitFor } from "@twick/core";
3
+ import { Icon } from "@twick/2d";
4
+ import { addAnimation } from "../helpers/element.utils";
5
+
6
+ export const IconElement = {
7
+ name: "icon",
8
+ *create({ containerRef, element, view }: ElementParams) {
9
+ const elementRef = createRef<any>();
10
+ yield* waitFor(element?.s);
11
+ yield containerRef().add(
12
+ <Icon ref={elementRef} key={element.id} {...element.props} />
13
+ );
14
+ yield* all(
15
+ addAnimation({ elementRef: elementRef, element: element, view }),
16
+ waitFor(Math.max(0, element.e - element.s))
17
+ );
18
+ yield elementRef().remove();
19
+ },
20
+ };
@@ -1,55 +1,53 @@
1
- import { ElementParams } from "../helpers/types";
2
- import { all, createRef, waitFor } from "@twick/core";
3
- import { Img, Rect } 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 ImageElement = {
9
- name: "image",
10
- *create({ containerRef, element, view }: ElementParams) {
11
- yield* waitFor(element?.s);
12
- logger(`Adding image 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
- <Img
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().remove();
52
- yield frameContainerRef().remove();
53
- }
54
- },
55
- };
1
+ import { ElementParams } from "../helpers/types";
2
+ import { all, createRef, waitFor } from "@twick/core";
3
+ import { Img, Rect } from "@twick/2d";
4
+ import { addAnimation, addFrameEffect, fitElement } from "../helpers/element.utils";
5
+ import { applyColorFilter } from "../helpers/filters";
6
+
7
+ export const ImageElement = {
8
+ name: "image",
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
+ <Img
17
+ ref={frameElementRef}
18
+ key={`child-${element.id}`}
19
+ {...element.props}
20
+ />
21
+ </Rect>
22
+ );
23
+ if (frameContainerRef()) {
24
+ yield fitElement({
25
+ elementRef: frameElementRef,
26
+ containerSize: frameContainerRef().size(),
27
+ elementSize: frameElementRef().size(),
28
+ objectFit: element.objectFit,
29
+ });
30
+
31
+ if (element?.props?.mediaFilter) {
32
+ applyColorFilter(frameElementRef, element.props.mediaFilter);
33
+ }
34
+
35
+ yield* all(
36
+ addAnimation({
37
+ elementRef: frameElementRef,
38
+ containerRef: frameContainerRef,
39
+ element: element,
40
+ view,
41
+ }),
42
+ addFrameEffect({
43
+ containerRef: frameContainerRef,
44
+ elementRef: frameElementRef,
45
+ element,
46
+ }),
47
+ waitFor(Math.max(0, element.e - element.s))
48
+ );
49
+ yield frameElementRef().remove();
50
+ yield frameContainerRef().remove();
51
+ }
52
+ },
53
+ };
@@ -1,22 +1,22 @@
1
- import { ElementParams } from "../helpers/types";
2
- import { all, createRef, waitFor } from "@twick/core";
3
- import { Rect } from "@twick/2d";
4
- import { addAnimation } from "../helpers/element.utils";
5
- import { logger } from "../helpers/log.utils";
6
-
7
- export const RectElement = {
8
- name: "rect",
9
- *create({ containerRef, element, view }: ElementParams) {
10
- const elementRef = createRef<any>();
11
- yield* waitFor(element?.s);
12
- logger(`RectElement: ${JSON.stringify(element)}`);
13
- yield containerRef().add(
14
- <Rect ref={elementRef} key={element.id} {...element.props}/>
15
- );
16
- yield* all(
17
- addAnimation({ elementRef: elementRef, element: element, view }),
18
- waitFor(Math.max(0, element.e - element.s))
19
- );
20
- yield elementRef().remove();
21
- },
22
- };
1
+ import { ElementParams } from "../helpers/types";
2
+ import { all, createRef, waitFor } from "@twick/core";
3
+ import { Rect } from "@twick/2d";
4
+ import { addAnimation } from "../helpers/element.utils";
5
+ import { logger } from "../helpers/log.utils";
6
+
7
+ export const RectElement = {
8
+ name: "rect",
9
+ *create({ containerRef, element, view }: ElementParams) {
10
+ const elementRef = createRef<any>();
11
+ yield* waitFor(element?.s);
12
+ logger(`RectElement: ${JSON.stringify(element)}`);
13
+ yield containerRef().add(
14
+ <Rect ref={elementRef} key={element.id} {...element.props}/>
15
+ );
16
+ yield* all(
17
+ addAnimation({ elementRef: elementRef, element: element, view }),
18
+ waitFor(Math.max(0, element.e - element.s))
19
+ );
20
+ yield elementRef().remove();
21
+ },
22
+ };
@@ -1,29 +1,29 @@
1
- import { ElementParams } from "../helpers/types";
2
- import { createRef, waitFor } from "@twick/core";
3
- import { Rect } from "@twick/2d";
4
- import { DEFAULT_BACKGROUND_COLOR, ELEMENT_TYPES } from "../helpers/constants";
5
- import { ImageElement } from "./image.element";
6
- import { VideoElement } from "./video.element";
7
- import { logger } from "../helpers/log.utils";
8
-
9
- export const SceneElement = {
10
- name: "scene",
11
- *create({ containerRef, element, view }: ElementParams) {
12
- yield* waitFor(element?.s);
13
- const mediaContainerRef = createRef<any>();
14
- logger(`SceneElement: ${JSON.stringify(element)}`);
15
- yield containerRef().add(
16
- <Rect
17
- ref={mediaContainerRef}
18
- fill={element.backgroundColor ?? DEFAULT_BACKGROUND_COLOR}
19
- size={"100%"}
20
- />
21
- );
22
- if (element.type === ELEMENT_TYPES.IMAGE) {
23
- yield* ImageElement.create({ containerRef, element, view });
24
- } else if (element.type === ELEMENT_TYPES.VIDEO) {
25
- yield* VideoElement.create({ containerRef, element, view });
26
- }
27
- yield mediaContainerRef().remove();
28
- },
29
- };
1
+ import { ElementParams } from "../helpers/types";
2
+ import { createRef, waitFor } from "@twick/core";
3
+ import { Rect } from "@twick/2d";
4
+ import { DEFAULT_BACKGROUND_COLOR, ELEMENT_TYPES } from "../helpers/constants";
5
+ import { ImageElement } from "./image.element";
6
+ import { VideoElement } from "./video.element";
7
+ import { logger } from "../helpers/log.utils";
8
+
9
+ export const SceneElement = {
10
+ name: "scene",
11
+ *create({ containerRef, element, view }: ElementParams) {
12
+ yield* waitFor(element?.s);
13
+ const mediaContainerRef = createRef<any>();
14
+ logger(`SceneElement: ${JSON.stringify(element)}`);
15
+ yield containerRef().add(
16
+ <Rect
17
+ ref={mediaContainerRef}
18
+ fill={element.backgroundColor ?? DEFAULT_BACKGROUND_COLOR}
19
+ size={"100%"}
20
+ />
21
+ );
22
+ if (element.type === ELEMENT_TYPES.IMAGE) {
23
+ yield* ImageElement.create({ containerRef, element, view });
24
+ } else if (element.type === ELEMENT_TYPES.VIDEO) {
25
+ yield* VideoElement.create({ containerRef, element, view });
26
+ }
27
+ yield mediaContainerRef().remove();
28
+ },
29
+ };