@revideo/2d 0.5.6 → 0.5.7-alpha.1076

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.
@@ -1,10 +1,8 @@
1
1
  import {
2
2
  BBox,
3
- boolLerp,
3
+ DependencyContext,
4
4
  InterpolationFunction,
5
- modify,
6
5
  Origin,
7
- originToOffset,
8
6
  PossibleSpacing,
9
7
  PossibleVector2,
10
8
  SerializedVector2,
@@ -13,14 +11,18 @@ import {
13
11
  SimpleSignal,
14
12
  SimpleVector2Signal,
15
13
  SpacingSignal,
16
- threadable,
17
14
  ThreadGenerator,
18
15
  TimingFunction,
19
- tween,
20
16
  Vector2,
21
17
  Vector2Signal,
18
+ boolLerp,
19
+ modify,
20
+ originToOffset,
21
+ threadable,
22
+ tween,
22
23
  } from '@revideo/core';
23
24
  import {
25
+ Vector2LengthSignal,
24
26
  addInitializer,
25
27
  cloneable,
26
28
  computed,
@@ -30,7 +32,6 @@ import {
30
32
  interpolation,
31
33
  nodeName,
32
34
  signal,
33
- Vector2LengthSignal,
34
35
  vector2Signal,
35
36
  } from '../decorators';
36
37
  import {spacingSignal} from '../decorators/spacingSignal';
@@ -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,15 @@ 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
+ }
975
+
964
976
  this.element.style.fontFamily = this.fontFamily.isInitial()
965
977
  ? ''
966
978
  : this.fontFamily();
@@ -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) {
@@ -52,6 +52,7 @@ describe('clone', () => {
52
52
  const template = (
53
53
  <Circle lineWidth={8} startAngle={signal} end={0.5} />
54
54
  ) as Circle;
55
+ template.toPromise();
55
56
  const clone = template.snapshotClone({end: 0});
56
57
 
57
58
  expect(clone.lineWidth()).toBe(8);
@@ -12,6 +12,7 @@ describe('state', () => {
12
12
  const circle = (
13
13
  <Circle lineWidth={8} startAngle={signal} end={0.5} />
14
14
  ) as Circle;
15
+ circle.toPromise();
15
16
  circle.save();
16
17
 
17
18
  circle.lineWidth(16);