@revideo/2d 0.5.5-alpha.1062 → 0.5.5-alpha.1065
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/editor/editor/tsconfig.build.tsbuildinfo +1 -1
- package/lib/components/Asset.d.ts.map +1 -1
- package/lib/components/Asset.js +2 -4
- package/lib/components/Layout.d.ts +1 -0
- package/lib/components/Layout.d.ts.map +1 -1
- package/lib/components/Layout.js +9 -2
- package/lib/components/Media.d.ts +1 -1
- package/lib/components/Media.d.ts.map +1 -1
- package/lib/components/Media.js +8 -9
- package/lib/components/TxtLeaf.js +2 -2
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/lib/components/Asset.ts +1 -4
- package/src/lib/components/Layout.ts +11 -0
- package/src/lib/components/Media.ts +6 -10
- package/src/lib/components/Txt.test.tsx +2 -0
- package/src/lib/components/TxtLeaf.ts +1 -1
- package/src/lib/components/__tests__/clone.test.tsx +1 -0
- package/src/lib/components/__tests__/state.test.tsx +1 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BBox,
|
|
3
3
|
boolLerp,
|
|
4
|
+
DependencyContext,
|
|
4
5
|
InterpolationFunction,
|
|
5
6
|
modify,
|
|
6
7
|
Origin,
|
|
@@ -283,6 +284,8 @@ export class Layout extends Node {
|
|
|
283
284
|
@signal()
|
|
284
285
|
public declare readonly textAlign: SimpleSignal<CanvasTextAlign, this>;
|
|
285
286
|
|
|
287
|
+
protected fontLoaded: boolean = false;
|
|
288
|
+
|
|
286
289
|
protected getX(): number {
|
|
287
290
|
if (this.isLayoutRoot()) {
|
|
288
291
|
return this.x.context.getter();
|
|
@@ -961,6 +964,14 @@ export class Layout extends Node {
|
|
|
961
964
|
|
|
962
965
|
@computed()
|
|
963
966
|
protected applyFont() {
|
|
967
|
+
if (!this.fontLoaded) {
|
|
968
|
+
DependencyContext.collectPromise(
|
|
969
|
+
(async () => {
|
|
970
|
+
await document.fonts?.ready;
|
|
971
|
+
this.fontLoaded = true;
|
|
972
|
+
})(),
|
|
973
|
+
);
|
|
974
|
+
}
|
|
964
975
|
this.element.style.fontFamily = this.fontFamily.isInitial()
|
|
965
976
|
? ''
|
|
966
977
|
: this.fontFamily();
|
|
@@ -39,7 +39,9 @@ export abstract class Media extends Asset {
|
|
|
39
39
|
@signal()
|
|
40
40
|
protected declare readonly playing: SimpleSignal<boolean, this>;
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
@initial(1)
|
|
43
|
+
@signal()
|
|
44
|
+
protected declare readonly volume: SimpleSignal<number, this>;
|
|
43
45
|
|
|
44
46
|
protected lastTime = -1;
|
|
45
47
|
|
|
@@ -48,7 +50,6 @@ export abstract class Media extends Asset {
|
|
|
48
50
|
if (props.play) {
|
|
49
51
|
this.play();
|
|
50
52
|
}
|
|
51
|
-
this.volume = props.volume ?? 1;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
public isPlaying(): boolean {
|
|
@@ -64,7 +65,7 @@ export abstract class Media extends Asset {
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
public getVolume(): number {
|
|
67
|
-
return this.volume;
|
|
68
|
+
return this.mediaElement().volume;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
public override dispose() {
|
|
@@ -108,14 +109,9 @@ export abstract class Media extends Asset {
|
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
protected setVolume(volume: number) {
|
|
111
|
-
if (volume < 0) {
|
|
112
|
-
console.warn(
|
|
113
|
-
`volumes cannot be negative - the value will be clamped to 0.`,
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
if (volume > 1) {
|
|
112
|
+
if (volume < 0 || volume > 1) {
|
|
117
113
|
console.warn(
|
|
118
|
-
|
|
114
|
+
`${volume} is an incorrect value for volume, has to be in range [0,1]. We're clamping to the nearest value`,
|
|
119
115
|
);
|
|
120
116
|
}
|
|
121
117
|
this.mediaElement().volume = Math.min(Math.max(volume, 0), 1);
|
|
@@ -10,6 +10,7 @@ describe('Txt', () => {
|
|
|
10
10
|
|
|
11
11
|
it('Handle plain text', () => {
|
|
12
12
|
const node = (<Txt lineWidth={8}>test</Txt>) as Txt;
|
|
13
|
+
node.toPromise();
|
|
13
14
|
|
|
14
15
|
const parseSpy = vi.spyOn(node as any, 'parseChildren');
|
|
15
16
|
const leaf = node.childAs<TxtLeaf>(0);
|
|
@@ -38,6 +39,7 @@ describe('Txt', () => {
|
|
|
38
39
|
Apple <Txt>Banana</Txt> Cherry
|
|
39
40
|
</Txt>
|
|
40
41
|
) as Txt;
|
|
42
|
+
node.toPromise();
|
|
41
43
|
|
|
42
44
|
const first = node.childAs<TxtLeaf>(0);
|
|
43
45
|
const second = node.childAs<Txt>(1);
|
|
@@ -61,9 +61,9 @@ export class TxtLeaf extends Shape {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
protected override async draw(context: CanvasRenderingContext2D) {
|
|
64
|
-
await document.fonts?.ready;
|
|
65
64
|
this.requestFontUpdate();
|
|
66
65
|
this.applyStyle(context);
|
|
66
|
+
await document.fonts?.ready;
|
|
67
67
|
this.applyText(context);
|
|
68
68
|
context.font = this.styles.font;
|
|
69
69
|
if ('letterSpacing' in context) {
|