@revideo/2d 0.2.5 → 0.2.6-alpha.904
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.
- package/lib/components/Audio.d.ts +11 -11
- package/lib/components/Audio.d.ts.map +1 -1
- package/lib/components/Audio.js +109 -115
- package/lib/components/Code.d.ts +211 -244
- package/lib/components/Code.d.ts.map +1 -1
- package/lib/components/Code.js +269 -317
- package/lib/components/CodeBlock.d.ts +67 -109
- package/lib/components/CodeBlock.d.ts.map +1 -1
- package/lib/components/CodeBlock.js +373 -414
- package/lib/components/Curve.js +269 -270
- package/lib/components/Grid.js +56 -63
- package/lib/components/Icon.js +50 -58
- package/lib/components/Img.d.ts +79 -86
- package/lib/components/Img.d.ts.map +1 -1
- package/lib/components/Img.js +181 -193
- package/lib/components/Knot.js +60 -81
- package/lib/components/Latex.js +65 -77
- package/lib/components/Layout.d.ts +413 -455
- package/lib/components/Layout.d.ts.map +1 -1
- package/lib/components/Layout.js +681 -666
- package/lib/components/Line.js +193 -216
- package/lib/components/Media.d.ts +35 -35
- package/lib/components/Media.d.ts.map +1 -1
- package/lib/components/Media.js +134 -135
- package/lib/components/Node.d.ts +830 -875
- package/lib/components/Node.d.ts.map +1 -1
- package/lib/components/Node.js +1314 -1383
- package/lib/components/SVG.js +541 -609
- package/lib/components/Shape.d.ts +35 -44
- package/lib/components/Shape.d.ts.map +1 -1
- package/lib/components/Shape.js +127 -112
- package/lib/components/Spline.js +175 -190
- package/lib/components/Txt.d.ts +44 -55
- package/lib/components/Txt.d.ts.map +1 -1
- package/lib/components/Txt.js +155 -156
- package/lib/components/TxtLeaf.d.ts +16 -20
- package/lib/components/TxtLeaf.d.ts.map +1 -1
- package/lib/components/TxtLeaf.js +2 -2
- package/lib/components/Video.d.ts +45 -41
- package/lib/components/Video.d.ts.map +1 -1
- package/lib/components/Video.js +202 -138
- package/lib/components/View2D.d.ts +22 -21
- package/lib/components/View2D.d.ts.map +1 -1
- package/lib/components/View2D.js +89 -98
- package/lib/components/index.js +1 -1
- package/lib/components/types.js +1 -1
- package/lib/curves/ArcSegment.js +94 -145
- package/lib/scenes/Scene2D.d.ts +23 -42
- package/lib/scenes/Scene2D.d.ts.map +1 -1
- package/lib/scenes/Scene2D.js +152 -161
- package/lib/scenes/index.js +1 -1
- package/lib/scenes/makeScene2D.js +10 -10
- package/lib/scenes/useScene2D.js +3 -3
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/utils/CanvasUtils.d.ts +21 -93
- package/package.json +5 -5
- package/src/lib/components/Audio.ts +2 -2
- package/src/lib/components/Code.ts +4 -2
- package/src/lib/components/CodeBlock.ts +1 -1
- package/src/lib/components/Img.ts +2 -2
- package/src/lib/components/Layout.ts +2 -2
- package/src/lib/components/Media.ts +3 -1
- package/src/lib/components/Node.ts +9 -9
- package/src/lib/components/Shape.ts +2 -2
- package/src/lib/components/Txt.ts +2 -2
- package/src/lib/components/TxtLeaf.ts +1 -1
- package/src/lib/components/Video.ts +114 -8
- package/src/lib/components/View2D.ts +6 -2
- package/src/lib/scenes/Scene2D.ts +4 -3
|
@@ -1,93 +1,21 @@
|
|
|
1
|
-
import {BBox, Spacing, Vector2} from '@revideo/core';
|
|
2
|
-
import {CanvasStyle, Gradient, Pattern, PossibleCanvasStyle} from '../partials';
|
|
3
|
-
export declare function canvasStyleParser(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
): void;
|
|
17
|
-
export declare function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
): number;
|
|
23
|
-
export declare function drawRect(
|
|
24
|
-
context: CanvasRenderingContext2D | Path2D,
|
|
25
|
-
rect: BBox,
|
|
26
|
-
): void;
|
|
27
|
-
export declare function fillRect(
|
|
28
|
-
context: CanvasRenderingContext2D,
|
|
29
|
-
rect: BBox,
|
|
30
|
-
): void;
|
|
31
|
-
export declare function strokeRect(
|
|
32
|
-
context: CanvasRenderingContext2D,
|
|
33
|
-
rect: BBox,
|
|
34
|
-
): void;
|
|
35
|
-
export declare function drawPolygon(
|
|
36
|
-
path: CanvasRenderingContext2D | Path2D,
|
|
37
|
-
rect: BBox,
|
|
38
|
-
sides: number,
|
|
39
|
-
): void;
|
|
40
|
-
export declare function drawImage(
|
|
41
|
-
context: CanvasRenderingContext2D,
|
|
42
|
-
image: CanvasImageSource,
|
|
43
|
-
destination: BBox,
|
|
44
|
-
): void;
|
|
45
|
-
export declare function drawImage(
|
|
46
|
-
context: CanvasRenderingContext2D,
|
|
47
|
-
image: CanvasImageSource,
|
|
48
|
-
source: BBox,
|
|
49
|
-
destination: BBox,
|
|
50
|
-
): void;
|
|
51
|
-
export declare function moveTo(
|
|
52
|
-
context: CanvasRenderingContext2D | Path2D,
|
|
53
|
-
position: Vector2,
|
|
54
|
-
): void;
|
|
55
|
-
export declare function lineTo(
|
|
56
|
-
context: CanvasRenderingContext2D | Path2D,
|
|
57
|
-
position: Vector2,
|
|
58
|
-
): void;
|
|
59
|
-
export declare function arcTo(
|
|
60
|
-
context: CanvasRenderingContext2D | Path2D,
|
|
61
|
-
through: Vector2,
|
|
62
|
-
position: Vector2,
|
|
63
|
-
radius: number,
|
|
64
|
-
): void;
|
|
65
|
-
export declare function drawLine(
|
|
66
|
-
context: CanvasRenderingContext2D | Path2D,
|
|
67
|
-
points: Vector2[],
|
|
68
|
-
): void;
|
|
69
|
-
export declare function drawPivot(
|
|
70
|
-
context: CanvasRenderingContext2D | Path2D,
|
|
71
|
-
offset: Vector2,
|
|
72
|
-
radius?: number,
|
|
73
|
-
): void;
|
|
74
|
-
export declare function arc(
|
|
75
|
-
context: CanvasRenderingContext2D | Path2D,
|
|
76
|
-
center: Vector2,
|
|
77
|
-
radius: number,
|
|
78
|
-
startAngle?: number,
|
|
79
|
-
endAngle?: number,
|
|
80
|
-
counterclockwise?: boolean,
|
|
81
|
-
): void;
|
|
82
|
-
export declare function bezierCurveTo(
|
|
83
|
-
context: CanvasRenderingContext2D | Path2D,
|
|
84
|
-
controlPoint1: Vector2,
|
|
85
|
-
controlPoint2: Vector2,
|
|
86
|
-
to: Vector2,
|
|
87
|
-
): void;
|
|
88
|
-
export declare function quadraticCurveTo(
|
|
89
|
-
context: CanvasRenderingContext2D | Path2D,
|
|
90
|
-
controlPoint: Vector2,
|
|
91
|
-
to: Vector2,
|
|
92
|
-
): void;
|
|
93
|
-
//# sourceMappingURL=CanvasUtils.d.ts.map
|
|
1
|
+
import { BBox, Spacing, Vector2 } from '@revideo/core';
|
|
2
|
+
import { CanvasStyle, Gradient, Pattern, PossibleCanvasStyle } from '../partials';
|
|
3
|
+
export declare function canvasStyleParser(style: PossibleCanvasStyle): Gradient | Pattern | import("chroma-js").Color | null;
|
|
4
|
+
export declare function resolveCanvasStyle(style: CanvasStyle, context: CanvasRenderingContext2D): string | CanvasGradient | CanvasPattern;
|
|
5
|
+
export declare function drawRoundRect(context: CanvasRenderingContext2D | Path2D, rect: BBox, radius: Spacing, smoothCorners: boolean, cornerSharpness: number): void;
|
|
6
|
+
export declare function adjustRectRadius(radius: number, horizontal: number, vertical: number, rect: BBox): number;
|
|
7
|
+
export declare function drawRect(context: CanvasRenderingContext2D | Path2D, rect: BBox): void;
|
|
8
|
+
export declare function fillRect(context: CanvasRenderingContext2D, rect: BBox): void;
|
|
9
|
+
export declare function strokeRect(context: CanvasRenderingContext2D, rect: BBox): void;
|
|
10
|
+
export declare function drawPolygon(path: CanvasRenderingContext2D | Path2D, rect: BBox, sides: number): void;
|
|
11
|
+
export declare function drawImage(context: CanvasRenderingContext2D, image: CanvasImageSource, destination: BBox): void;
|
|
12
|
+
export declare function drawImage(context: CanvasRenderingContext2D, image: CanvasImageSource, source: BBox, destination: BBox): void;
|
|
13
|
+
export declare function moveTo(context: CanvasRenderingContext2D | Path2D, position: Vector2): void;
|
|
14
|
+
export declare function lineTo(context: CanvasRenderingContext2D | Path2D, position: Vector2): void;
|
|
15
|
+
export declare function arcTo(context: CanvasRenderingContext2D | Path2D, through: Vector2, position: Vector2, radius: number): void;
|
|
16
|
+
export declare function drawLine(context: CanvasRenderingContext2D | Path2D, points: Vector2[]): void;
|
|
17
|
+
export declare function drawPivot(context: CanvasRenderingContext2D | Path2D, offset: Vector2, radius?: number): void;
|
|
18
|
+
export declare function arc(context: CanvasRenderingContext2D | Path2D, center: Vector2, radius: number, startAngle?: number, endAngle?: number, counterclockwise?: boolean): void;
|
|
19
|
+
export declare function bezierCurveTo(context: CanvasRenderingContext2D | Path2D, controlPoint1: Vector2, controlPoint2: Vector2, to: Vector2): void;
|
|
20
|
+
export declare function quadraticCurveTo(context: CanvasRenderingContext2D | Path2D, controlPoint: Vector2, to: Vector2): void;
|
|
21
|
+
//# sourceMappingURL=CanvasUtils.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revideo/2d",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6-alpha.904+148b73f",
|
|
4
4
|
"description": "A 2D renderer for revideo",
|
|
5
5
|
"author": "revideo",
|
|
6
6
|
"homepage": "https://re.video/",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
],
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@preact/signals": "^1.2.1",
|
|
32
|
-
"@revideo/internal": "0.0.0",
|
|
33
|
-
"@revideo/ui": "^0.2.
|
|
32
|
+
"@revideo/internal": "^0.0.0",
|
|
33
|
+
"@revideo/ui": "^0.2.6-alpha.904+148b73f",
|
|
34
34
|
"clsx": "^2.0.0",
|
|
35
35
|
"jsdom": "^22.1.0",
|
|
36
36
|
"preact": "^10.19.2",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"@codemirror/language": "^6.10.1",
|
|
41
41
|
"@lezer/common": "^1.2.1",
|
|
42
42
|
"@lezer/highlight": "^1.2.0",
|
|
43
|
-
"@revideo/core": "^0.2.
|
|
43
|
+
"@revideo/core": "^0.2.6-alpha.904+148b73f",
|
|
44
44
|
"code-fns": "^0.8.2",
|
|
45
45
|
"mathjax-full": "^3.2.2",
|
|
46
46
|
"parse-svg-path": "^0.1.2"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "148b73fa3693f40d717c0fdf275799364769706f"
|
|
49
49
|
}
|
|
@@ -114,7 +114,7 @@ export class Audio extends Media {
|
|
|
114
114
|
return audio;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
protected override draw(context: CanvasRenderingContext2D) {
|
|
117
|
+
protected override async draw(context: CanvasRenderingContext2D) {
|
|
118
118
|
const playbackState = this.view().playbackState();
|
|
119
119
|
|
|
120
120
|
playbackState === PlaybackState.Playing ||
|
|
@@ -125,6 +125,6 @@ export class Audio extends Media {
|
|
|
125
125
|
context.save();
|
|
126
126
|
context.restore();
|
|
127
127
|
|
|
128
|
-
this.drawChildren(context);
|
|
128
|
+
await this.drawChildren(context);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
@@ -511,7 +511,9 @@ export class Code extends Shape {
|
|
|
511
511
|
return size;
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
-
protected override draw(
|
|
514
|
+
protected override async draw(
|
|
515
|
+
context: CanvasRenderingContext2D,
|
|
516
|
+
): Promise<void> {
|
|
515
517
|
this.requestFontUpdate();
|
|
516
518
|
this.applyStyle(context);
|
|
517
519
|
this.applyText(context);
|
|
@@ -534,7 +536,7 @@ export class Code extends Shape {
|
|
|
534
536
|
|
|
535
537
|
context.restore();
|
|
536
538
|
|
|
537
|
-
this.drawChildren(context);
|
|
539
|
+
await this.drawChildren(context);
|
|
538
540
|
}
|
|
539
541
|
|
|
540
542
|
protected override applyText(context: CanvasRenderingContext2D) {
|
|
@@ -335,7 +335,7 @@ export class CodeBlock extends Shape {
|
|
|
335
335
|
);
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
protected override draw(context: CanvasRenderingContext2D) {
|
|
338
|
+
protected override async draw(context: CanvasRenderingContext2D) {
|
|
339
339
|
if (!CodeBlock.initialized()) return;
|
|
340
340
|
|
|
341
341
|
this.requestFontUpdate();
|
|
@@ -221,7 +221,7 @@ about working with images.`,
|
|
|
221
221
|
return context;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
protected override draw(context: CanvasRenderingContext2D) {
|
|
224
|
+
protected override async draw(context: CanvasRenderingContext2D) {
|
|
225
225
|
this.drawShape(context);
|
|
226
226
|
const alpha = this.alpha();
|
|
227
227
|
if (alpha > 0) {
|
|
@@ -240,7 +240,7 @@ about working with images.`,
|
|
|
240
240
|
context.clip(this.getPath());
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
this.drawChildren(context);
|
|
243
|
+
await this.drawChildren(context);
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
protected override applyFlex() {
|
|
@@ -820,7 +820,7 @@ export class Layout extends Node {
|
|
|
820
820
|
return BBox.fromSizeCentered(this.computedSize());
|
|
821
821
|
}
|
|
822
822
|
|
|
823
|
-
protected override draw(context: CanvasRenderingContext2D) {
|
|
823
|
+
protected override async draw(context: CanvasRenderingContext2D) {
|
|
824
824
|
if (this.clip()) {
|
|
825
825
|
const size = this.computedSize();
|
|
826
826
|
if (size.width === 0 || size.height === 0) {
|
|
@@ -833,7 +833,7 @@ export class Layout extends Node {
|
|
|
833
833
|
context.clip();
|
|
834
834
|
}
|
|
835
835
|
|
|
836
|
-
this.drawChildren(context);
|
|
836
|
+
await this.drawChildren(context);
|
|
837
837
|
}
|
|
838
838
|
|
|
839
839
|
public override drawOverlay(
|
|
@@ -86,7 +86,9 @@ export abstract class Media extends Rect {
|
|
|
86
86
|
|
|
87
87
|
protected abstract fastSeekedMedia(): HTMLMediaElement;
|
|
88
88
|
|
|
89
|
-
protected abstract override draw(
|
|
89
|
+
protected abstract override draw(
|
|
90
|
+
context: CanvasRenderingContext2D,
|
|
91
|
+
): Promise<void>;
|
|
90
92
|
|
|
91
93
|
protected setCurrentTime(value: number) {
|
|
92
94
|
const media = this.mediaElement();
|
|
@@ -1355,7 +1355,7 @@ export class Node implements Promisable<Node> {
|
|
|
1355
1355
|
* Get a cache canvas with the contents of this node rendered onto it.
|
|
1356
1356
|
*/
|
|
1357
1357
|
@computed()
|
|
1358
|
-
protected cachedCanvas() {
|
|
1358
|
+
protected async cachedCanvas() {
|
|
1359
1359
|
const context = this.cacheCanvas();
|
|
1360
1360
|
const cache = this.worldSpaceCacheBBox();
|
|
1361
1361
|
const matrix = this.localToWorld();
|
|
@@ -1371,7 +1371,7 @@ export class Node implements Promisable<Node> {
|
|
|
1371
1371
|
matrix.e - cache.x,
|
|
1372
1372
|
matrix.f - cache.y,
|
|
1373
1373
|
);
|
|
1374
|
-
this.draw(context);
|
|
1374
|
+
await this.draw(context);
|
|
1375
1375
|
|
|
1376
1376
|
return context;
|
|
1377
1377
|
}
|
|
@@ -1629,7 +1629,7 @@ export class Node implements Promisable<Node> {
|
|
|
1629
1629
|
*
|
|
1630
1630
|
* @param context - The context to draw with.
|
|
1631
1631
|
*/
|
|
1632
|
-
public render(context: CanvasRenderingContext2D) {
|
|
1632
|
+
public async render(context: CanvasRenderingContext2D) {
|
|
1633
1633
|
if (this.absoluteOpacity() <= 0) {
|
|
1634
1634
|
return;
|
|
1635
1635
|
}
|
|
@@ -1640,7 +1640,7 @@ export class Node implements Promisable<Node> {
|
|
|
1640
1640
|
if (this.requiresCache()) {
|
|
1641
1641
|
const cacheRect = this.worldSpaceCacheBBox();
|
|
1642
1642
|
if (cacheRect.width !== 0 && cacheRect.height !== 0) {
|
|
1643
|
-
const cache = this.cachedCanvas().canvas;
|
|
1643
|
+
const cache = (await this.cachedCanvas()).canvas;
|
|
1644
1644
|
const source = this.shaderCanvas(context.canvas, cache);
|
|
1645
1645
|
if (source) {
|
|
1646
1646
|
this.renderFromSource(context, source, 0, 0);
|
|
@@ -1654,7 +1654,7 @@ export class Node implements Promisable<Node> {
|
|
|
1654
1654
|
}
|
|
1655
1655
|
}
|
|
1656
1656
|
} else {
|
|
1657
|
-
this.draw(context);
|
|
1657
|
+
await this.draw(context);
|
|
1658
1658
|
}
|
|
1659
1659
|
|
|
1660
1660
|
context.restore();
|
|
@@ -1670,13 +1670,13 @@ export class Node implements Promisable<Node> {
|
|
|
1670
1670
|
*
|
|
1671
1671
|
* @param context - The context to draw with.
|
|
1672
1672
|
*/
|
|
1673
|
-
protected draw(context: CanvasRenderingContext2D) {
|
|
1674
|
-
this.drawChildren(context);
|
|
1673
|
+
protected async draw(context: CanvasRenderingContext2D) {
|
|
1674
|
+
await this.drawChildren(context);
|
|
1675
1675
|
}
|
|
1676
1676
|
|
|
1677
|
-
protected drawChildren(context: CanvasRenderingContext2D) {
|
|
1677
|
+
protected async drawChildren(context: CanvasRenderingContext2D) {
|
|
1678
1678
|
for (const child of this.sortedChildren()) {
|
|
1679
|
-
child.render(context);
|
|
1679
|
+
await child.render(context);
|
|
1680
1680
|
}
|
|
1681
1681
|
}
|
|
1682
1682
|
|
|
@@ -88,12 +88,12 @@ export abstract class Shape extends Layout {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
protected override draw(context: CanvasRenderingContext2D) {
|
|
91
|
+
protected override async draw(context: CanvasRenderingContext2D) {
|
|
92
92
|
this.drawShape(context);
|
|
93
93
|
if (this.clip()) {
|
|
94
94
|
context.clip(this.getPath());
|
|
95
95
|
}
|
|
96
|
-
this.drawChildren(context);
|
|
96
|
+
await this.drawChildren(context);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
protected drawShape(context: CanvasRenderingContext2D) {
|
|
@@ -177,8 +177,8 @@ export class Txt extends Shape {
|
|
|
177
177
|
: 'block';
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
protected override draw(context: CanvasRenderingContext2D) {
|
|
181
|
-
this.drawChildren(context);
|
|
180
|
+
protected override async draw(context: CanvasRenderingContext2D) {
|
|
181
|
+
await this.drawChildren(context);
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
|
|
@@ -61,7 +61,7 @@ export class TxtLeaf extends Shape {
|
|
|
61
61
|
return parent instanceof Txt ? parent : null;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
protected override draw(context: CanvasRenderingContext2D) {
|
|
64
|
+
protected override async draw(context: CanvasRenderingContext2D) {
|
|
65
65
|
this.requestFontUpdate();
|
|
66
66
|
this.applyStyle(context);
|
|
67
67
|
this.applyText(context);
|
|
@@ -23,6 +23,71 @@ export interface VideoProps extends MediaProps {
|
|
|
23
23
|
smoothing?: SignalValue<boolean>;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
class ImageCommunication {
|
|
27
|
+
public constructor() {
|
|
28
|
+
if (!import.meta.hot) {
|
|
29
|
+
throw new Error('FfmpegVideoFrame can only be used with HMR.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
import.meta.hot.on(
|
|
33
|
+
'revideo/ffmpeg-video-frame-res',
|
|
34
|
+
this.handler.bind(this),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private nextFrameHandlers: ((event: MessageEvent) => void)[] = [];
|
|
39
|
+
|
|
40
|
+
private handler(event: MessageEvent) {
|
|
41
|
+
const handlers = this.nextFrameHandlers;
|
|
42
|
+
this.nextFrameHandlers = [];
|
|
43
|
+
|
|
44
|
+
for (const handler of handlers) {
|
|
45
|
+
handler(event);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public async getFrame(
|
|
50
|
+
id: string,
|
|
51
|
+
src: string,
|
|
52
|
+
time: number,
|
|
53
|
+
duration: number,
|
|
54
|
+
fps: number,
|
|
55
|
+
) {
|
|
56
|
+
return new Promise<HTMLImageElement>((resolve, reject) => {
|
|
57
|
+
if (!import.meta.hot) {
|
|
58
|
+
reject('FfmpegVideoFrame can only be used with HMR.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function handler(event: MessageEvent) {
|
|
63
|
+
const image = new Image();
|
|
64
|
+
|
|
65
|
+
const uint8Array = new Uint8Array(event.data.frame.data);
|
|
66
|
+
const blob = new Blob([uint8Array], {type: 'image/jpeg'});
|
|
67
|
+
const url = URL.createObjectURL(blob);
|
|
68
|
+
|
|
69
|
+
image.src = url;
|
|
70
|
+
|
|
71
|
+
image.onload = () => {
|
|
72
|
+
resolve(image);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.nextFrameHandlers.push(handler);
|
|
77
|
+
|
|
78
|
+
import.meta.hot.send('revideo/ffmpeg-video-frame', {
|
|
79
|
+
data: {
|
|
80
|
+
id: id,
|
|
81
|
+
filePath: src,
|
|
82
|
+
startTime: time,
|
|
83
|
+
duration,
|
|
84
|
+
fps,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
26
91
|
@nodeName('Video')
|
|
27
92
|
export class Video extends Media {
|
|
28
93
|
/**
|
|
@@ -51,6 +116,8 @@ export class Video extends Media {
|
|
|
51
116
|
|
|
52
117
|
private static readonly pool: Record<string, HTMLVideoElement> = {};
|
|
53
118
|
|
|
119
|
+
private static readonly imageCommunication = new ImageCommunication();
|
|
120
|
+
|
|
54
121
|
public constructor(props: VideoProps) {
|
|
55
122
|
super(props);
|
|
56
123
|
}
|
|
@@ -159,16 +226,55 @@ export class Video extends Media {
|
|
|
159
226
|
return video;
|
|
160
227
|
}
|
|
161
228
|
|
|
162
|
-
protected
|
|
229
|
+
protected lastFrame: HTMLImageElement | null = null;
|
|
230
|
+
|
|
231
|
+
protected async serverSeekedVideo(): Promise<HTMLImageElement> {
|
|
232
|
+
const video = this.video();
|
|
233
|
+
const time = this.clampTime(this.time());
|
|
234
|
+
const duration = this.getDuration();
|
|
235
|
+
|
|
236
|
+
video.playbackRate = this.playbackRate();
|
|
237
|
+
|
|
238
|
+
if (this.lastFrame && this.lastTime === time) {
|
|
239
|
+
return this.lastFrame;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const fps = this.view().fps() / this.playbackRate();
|
|
243
|
+
|
|
244
|
+
const frame = await Video.imageCommunication.getFrame(
|
|
245
|
+
this.key,
|
|
246
|
+
video.src,
|
|
247
|
+
time,
|
|
248
|
+
duration,
|
|
249
|
+
fps,
|
|
250
|
+
);
|
|
251
|
+
this.lastFrame = frame;
|
|
252
|
+
this.lastTime = time;
|
|
253
|
+
|
|
254
|
+
return frame;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
protected async seekFunction() {
|
|
258
|
+
const playbackState = this.view().playbackState();
|
|
259
|
+
if (
|
|
260
|
+
playbackState === PlaybackState.Playing ||
|
|
261
|
+
playbackState === PlaybackState.Presenting
|
|
262
|
+
) {
|
|
263
|
+
return this.fastSeekedVideo();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (playbackState === PlaybackState.Rendering) {
|
|
267
|
+
return this.serverSeekedVideo();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return this.seekedVideo();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
protected override async draw(context: CanvasRenderingContext2D) {
|
|
163
274
|
this.drawShape(context);
|
|
164
275
|
const alpha = this.alpha();
|
|
165
276
|
if (alpha > 0) {
|
|
166
|
-
const
|
|
167
|
-
const video =
|
|
168
|
-
playbackState === PlaybackState.Playing ||
|
|
169
|
-
playbackState === PlaybackState.Presenting
|
|
170
|
-
? this.fastSeekedVideo()
|
|
171
|
-
: this.seekedVideo();
|
|
277
|
+
const video = await this.seekFunction();
|
|
172
278
|
|
|
173
279
|
const box = BBox.fromSizeCentered(this.computedSize());
|
|
174
280
|
context.save();
|
|
@@ -185,7 +291,7 @@ export class Video extends Media {
|
|
|
185
291
|
context.clip(this.getPath());
|
|
186
292
|
}
|
|
187
293
|
|
|
188
|
-
this.drawChildren(context);
|
|
294
|
+
await this.drawChildren(context);
|
|
189
295
|
}
|
|
190
296
|
|
|
191
297
|
protected override applyFlex() {
|
|
@@ -37,6 +37,10 @@ export class View2D extends Rect {
|
|
|
37
37
|
@signal()
|
|
38
38
|
public declare readonly globalTime: SimpleSignal<number, this>;
|
|
39
39
|
|
|
40
|
+
@initial(0)
|
|
41
|
+
@signal()
|
|
42
|
+
public declare readonly fps: SimpleSignal<number, this>;
|
|
43
|
+
|
|
40
44
|
@signal()
|
|
41
45
|
public declare readonly assetHash: SimpleSignal<string, this>;
|
|
42
46
|
|
|
@@ -61,10 +65,10 @@ export class View2D extends Rect {
|
|
|
61
65
|
super.dispose();
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
public override render(context: CanvasRenderingContext2D) {
|
|
68
|
+
public override async render(context: CanvasRenderingContext2D) {
|
|
65
69
|
this.computedSize();
|
|
66
70
|
this.computedPosition();
|
|
67
|
-
super.render(context);
|
|
71
|
+
await super.render(context);
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
/**
|
|
@@ -43,15 +43,16 @@ export class Scene2D extends GeneratorScene<View2D> implements Inspectable {
|
|
|
43
43
|
return super.next();
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
public draw(context: CanvasRenderingContext2D) {
|
|
46
|
+
public async draw(context: CanvasRenderingContext2D) {
|
|
47
47
|
context.save();
|
|
48
48
|
this.renderLifecycle.dispatch([SceneRenderEvent.BeforeRender, context]);
|
|
49
49
|
context.save();
|
|
50
50
|
this.renderLifecycle.dispatch([SceneRenderEvent.BeginRender, context]);
|
|
51
51
|
this.getView()
|
|
52
52
|
.playbackState(this.playback.state)
|
|
53
|
-
.globalTime(this.playback.time)
|
|
54
|
-
|
|
53
|
+
.globalTime(this.playback.time)
|
|
54
|
+
.fps(this.playback.fps);
|
|
55
|
+
await this.getView().render(context);
|
|
55
56
|
this.renderLifecycle.dispatch([SceneRenderEvent.FinishRender, context]);
|
|
56
57
|
context.restore();
|
|
57
58
|
this.renderLifecycle.dispatch([SceneRenderEvent.AfterRender, context]);
|