libpag 4.5.46 → 4.5.47

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.
Binary file
@@ -105,7 +105,7 @@ export class PAGView extends NativePAGView {
105
105
  }
106
106
 
107
107
  protected override async flushLoop(force = false) {
108
- if (!this.isPlaying) return;
108
+ if (!this.isPlaying || this.isDestroyed) return;
109
109
  this.setTimer();
110
110
  if (this.flushingNextFrame) return;
111
111
  try {
@@ -114,6 +114,9 @@ export class PAGView extends NativePAGView {
114
114
  this.flushingNextFrame = false;
115
115
  } catch (e: any) {
116
116
  this.flushingNextFrame = false;
117
+ if (e.message !== 'The play() request was interrupted because the document was hidden!') {
118
+ this.clearTimer();
119
+ }
117
120
  console.error(e);
118
121
  }
119
122
  }
@@ -46,6 +46,7 @@ export class VideoReader {
46
46
  public isPlaying = false; // Web SDK use this property to check if video is playing
47
47
  public isDestroyed = false;
48
48
  private player: PAGPlayer | null = null;
49
+ private error: any = null;
49
50
 
50
51
  private readonly frameRate: number;
51
52
  private currentFrame: number;
@@ -85,15 +86,17 @@ export class VideoReader {
85
86
  }
86
87
 
87
88
  public async prepare(targetFrame: number) {
88
- if (targetFrame === this.currentFrame) return;
89
+ if (this.isDestroyed || targetFrame === this.currentFrame) return;
89
90
  this.isSought = false;
90
91
  // Wait for videoDecoder ready
91
92
  await this.videoDecoderPromise;
93
+ if (this.isDestroyed) return;
92
94
  if (this.frameDataBuffers.length > 0) {
93
95
  const index = this.frameDataBuffers.findIndex((frameData) => frameData.id === targetFrame);
94
96
  if (index !== -1) {
95
97
  this.frameDataBuffers = this.frameDataBuffers.slice(index);
96
98
  this.arrayBufferImage.setFrameData(await this.getFrameData());
99
+ if (this.isDestroyed) return;
97
100
  this.currentFrame = targetFrame;
98
101
  return;
99
102
  }
@@ -105,9 +108,14 @@ export class VideoReader {
105
108
  this.isSought = true;
106
109
  this.bufferIndex = targetFrame;
107
110
  await this.videoDecoder.seek(Math.floor((targetFrame / this.frameRate) * 1000));
111
+ if (this.isDestroyed) {
112
+ this.seeking = false;
113
+ return;
114
+ }
108
115
  this.seeking = false;
109
116
  }
110
117
  this.arrayBufferImage.setFrameData(await this.getFrameData());
118
+ if (this.isDestroyed) return;
111
119
  this.currentFrame = targetFrame;
112
120
  return;
113
121
  }
@@ -133,11 +141,15 @@ export class VideoReader {
133
141
  }
134
142
 
135
143
  public getError(): any {
136
- // Web SDK use this function to get video error.
137
- return null;
144
+ return this.error;
138
145
  }
139
146
 
140
147
  public onDestroy() {
148
+ this.isDestroyed = true;
149
+ if (this.getFrameDataResolve) {
150
+ this.getFrameDataResolve({ id: -1, data: new ArrayBuffer(0), width: 0, height: 0 });
151
+ this.getFrameDataResolve = null;
152
+ }
141
153
  if (this.player) {
142
154
  this.player.unlinkVideoReader(this);
143
155
  this.player = null;
@@ -147,7 +159,6 @@ export class VideoReader {
147
159
  if (this.mp4Path) {
148
160
  removeFile(this.mp4Path);
149
161
  }
150
- this.isDestroyed = true;
151
162
  }
152
163
 
153
164
  private getFrameData() {
@@ -176,10 +187,12 @@ export class VideoReader {
176
187
  }
177
188
 
178
189
  private getFrameDataLoop() {
190
+ if (this.isDestroyed) return;
179
191
  if (this.seeking) return;
180
192
  if (!this.videoDecoder) {
181
193
  this.clearFrameDataLoop();
182
- throw new Error('VideoDecoder is not ready!');
194
+ this.error = 'VideoDecoder is not ready.';
195
+ return;
183
196
  }
184
197
  if (this.frameDataBuffers.length >= BUFFER_MAX_SIZE) {
185
198
  this.getFrameDataLooping = false;
@@ -212,4 +225,4 @@ export class VideoReader {
212
225
  player.linkVideoReader(this);
213
226
  }
214
227
  }
215
- }
228
+ }
@@ -31,6 +31,12 @@ export declare class ScalerContext {
31
31
  join: ctor;
32
32
  miterLimit: number;
33
33
  }): Uint8Array;
34
+ getGlyphCanvas(text: string, bounds: Rect, fauxBold: boolean, stroke?: {
35
+ width: number;
36
+ cap: ctor;
37
+ join: ctor;
38
+ miterLimit: number;
39
+ }, padding?: number): HTMLCanvasElement | OffscreenCanvas | null;
34
40
  protected loadCanvas(): void;
35
41
  private measureText;
36
42
  }
@@ -1,6 +1,6 @@
1
1
  import { getCanvas2D } from './utils/canvas';
2
2
  import { BitmapImage } from './core/bitmap-image';
3
- import type { EmscriptenGL, TGFX } from './types';
3
+ import { EmscriptenGL, TGFX, WindowColorSpace } from './types';
4
4
  export declare const createImage: (source: string) => Promise<HTMLImageElement>;
5
5
  export declare const createImageFromBytes: (bytes: ArrayBuffer) => Promise<HTMLImageElement>;
6
6
  export declare const readImagePixels: (module: TGFX, image: CanvasImageSource, width: number, height: number) => Uint8Array;
@@ -9,7 +9,8 @@ export declare const getSourceSize: (source: TexImageSource | OffscreenCanvas) =
9
9
  width: number;
10
10
  height: number;
11
11
  };
12
- export declare const uploadToTexture: (GL: EmscriptenGL, source: TexImageSource | OffscreenCanvas | BitmapImage, textureID: number, alphaOnly: boolean) => void;
12
+ export declare const uploadToTexture: (GL: EmscriptenGL, source: TexImageSource | OffscreenCanvas | BitmapImage, textureID: number, offsetX: number, offsetY: number, alphaOnly: boolean) => void;
13
+ export declare const setColorSpace: (GL: EmscriptenGL, colorSpace: WindowColorSpace) => boolean;
13
14
  export declare const isAndroidMiniprogram: () => boolean;
14
15
  export declare const releaseNativeImage: (source: TexImageSource | OffscreenCanvas) => void;
15
16
  export declare const getBytesFromPath: (module: TGFX, path: string) => Promise<Uint8Array>;
@@ -26,6 +26,12 @@ export declare const enum MatrixIndex {
26
26
  d = 4,
27
27
  ty = 5
28
28
  }
29
+ export declare const enum WindowColorSpace {
30
+ None = 0,
31
+ SRGB = 1,
32
+ DisplayP3 = 2,
33
+ Others = 3
34
+ }
29
35
  export interface ctor {
30
36
  value: number;
31
37
  }
@@ -18,6 +18,7 @@ export declare class VideoReader {
18
18
  private bitmapCtx;
19
19
  private currentFrame;
20
20
  private targetFrame;
21
+ private visibilityHandle;
21
22
  constructor(source: Uint8Array | HTMLVideoElement, width: number, height: number, frameRate: number, staticTimeRanges: TimeRange[]);
22
23
  prepare(targetFrame: number, playbackRate: number): Promise<void>;
23
24
  getCurrentFrame(): number;
@@ -29,6 +30,7 @@ export declare class VideoReader {
29
30
  onDestroy(): void;
30
31
  private seek;
31
32
  private setError;
33
+ private clearVisibilityListener;
32
34
  private linkPlayer;
33
35
  }
34
36
  export declare class StaticTimeRanges {