@revideo/2d 0.2.14-alpha.937 → 0.3.1

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.
@@ -21,6 +21,10 @@ export interface VideoProps extends MediaProps {
21
21
  * {@inheritDoc Video.smoothing}
22
22
  */
23
23
  smoothing?: SignalValue<boolean>;
24
+ /**
25
+ * {@inheritDoc Video.transparency}
26
+ */
27
+ transparency?: SignalValue<boolean>;
24
28
  }
25
29
 
26
30
  class ImageCommunication {
@@ -52,6 +56,7 @@ class ImageCommunication {
52
56
  time: number,
53
57
  duration: number,
54
58
  fps: number,
59
+ transparency: boolean,
55
60
  ) {
56
61
  return new Promise<HTMLImageElement>((resolve, reject) => {
57
62
  if (!import.meta.hot) {
@@ -63,7 +68,8 @@ class ImageCommunication {
63
68
  const image = new Image();
64
69
 
65
70
  const uint8Array = new Uint8Array(event.data.frame.data);
66
- const blob = new Blob([uint8Array], {type: 'image/png'});
71
+ const type = transparency ? 'image/png' : 'image/jpeg';
72
+ const blob = new Blob([uint8Array], {type});
67
73
  const url = URL.createObjectURL(blob);
68
74
 
69
75
  image.src = url;
@@ -82,6 +88,7 @@ class ImageCommunication {
82
88
  startTime: time,
83
89
  duration,
84
90
  fps,
91
+ transparency,
85
92
  },
86
93
  });
87
94
  });
@@ -114,6 +121,19 @@ export class Video extends Media {
114
121
  @signal()
115
122
  public declare readonly smoothing: SimpleSignal<boolean, this>;
116
123
 
124
+ /**
125
+ * Whether the video should be rendered as partially transparent.
126
+ *
127
+ * @remarks
128
+ * When enabled, the video frames will be extracted as PNGs with an alpha
129
+ * channel. This is significantly slower than using JPEGs which is the default.
130
+ *
131
+ * @defaultValue false
132
+ */
133
+ @initial(false)
134
+ @signal()
135
+ public declare readonly transparency: SimpleSignal<boolean, this>;
136
+
117
137
  private static readonly pool: Record<string, HTMLVideoElement> = {};
118
138
 
119
139
  private static readonly imageCommunication = !import.meta.hot
@@ -260,6 +280,7 @@ export class Video extends Media {
260
280
  time,
261
281
  duration,
262
282
  fps,
283
+ this.transparency(),
263
284
  );
264
285
  this.lastFrame = frame;
265
286
  this.lastTime = time;