libpag 4.5.0 → 4.5.2

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.
Files changed (80) hide show
  1. package/LICENSE.txt +1589 -0
  2. package/README.md +172 -10
  3. package/README.zh_CN.md +114 -15
  4. package/lib/libpag.cjs.js +5420 -6176
  5. package/lib/libpag.cjs.js.map +1 -1
  6. package/lib/libpag.esm.js +5420 -6176
  7. package/lib/libpag.esm.js.map +1 -1
  8. package/lib/libpag.min.js +1 -1
  9. package/lib/libpag.min.js.map +1 -1
  10. package/lib/libpag.umd.js +5420 -6176
  11. package/lib/libpag.umd.js.map +1 -1
  12. package/lib/libpag.wasm +0 -0
  13. package/package.json +23 -11
  14. package/src/.pag.wasm-mt.md5 +1 -0
  15. package/src/.pag.wasm.md5 +1 -1
  16. package/src/core/matrix.ts +1 -2
  17. package/src/core/video-reader.ts +73 -94
  18. package/src/interfaces.ts +8 -17
  19. package/src/pag-composition.ts +12 -5
  20. package/src/pag-file.ts +146 -129
  21. package/src/pag-font.ts +1 -3
  22. package/src/pag-image-layer.ts +1 -2
  23. package/src/pag-image.ts +1 -3
  24. package/src/pag-layer.ts +2 -3
  25. package/src/pag-player.ts +7 -6
  26. package/src/pag-solid-layer.ts +1 -2
  27. package/src/pag-surface.ts +1 -2
  28. package/src/pag-text-layer.ts +1 -2
  29. package/src/pag-view.ts +3 -14
  30. package/src/pag.ts +0 -6
  31. package/src/types.ts +46 -3
  32. package/src/utils/decorators.ts +0 -42
  33. package/src/utils/type-utils.ts +1 -9
  34. package/src/utils/ua.ts +0 -1
  35. package/src/wasm/libpag.js +7 -6
  36. package/src/wasm/libpag.wasm +0 -0
  37. package/src/wasm-mt/libpag.js +2 -0
  38. package/src/wasm-mt/libpag.wasm +0 -0
  39. package/src/wechat/pag-file.ts +1 -2
  40. package/src/wechat/pag-image.ts +0 -2
  41. package/src/wechat/pag-view.ts +1 -2
  42. package/types/third_party/tgfx/web/src/core/path-rasterizer.d.ts +4 -0
  43. package/types/third_party/tgfx/web/src/core/scaler-context.d.ts +9 -2
  44. package/types/third_party/tgfx/web/src/utils/decorators.d.ts +0 -2
  45. package/types/web/src/core/video-reader.d.ts +4 -3
  46. package/types/web/src/interfaces.d.ts +8 -15
  47. package/types/web/src/pag-composition.d.ts +3 -3
  48. package/types/web/src/pag-file.d.ts +4 -4
  49. package/types/web/src/pag-player.d.ts +2 -2
  50. package/types/web/src/pag-view.d.ts +1 -1
  51. package/types/web/src/types.d.ts +12 -3
  52. package/types/web/src/utils/decorators.d.ts +0 -2
  53. package/types/web/src/utils/ua.d.ts +0 -1
  54. package/types/web/tsconfig.json +19 -0
  55. package/lib/libpag.worker.cjs.js +0 -794
  56. package/lib/libpag.worker.cjs.js.map +0 -1
  57. package/lib/libpag.worker.esm.js +0 -789
  58. package/lib/libpag.worker.esm.js.map +0 -1
  59. package/lib/libpag.worker.js +0 -800
  60. package/lib/libpag.worker.js.map +0 -1
  61. package/lib/libpag.worker.min.js +0 -2
  62. package/lib/libpag.worker.min.js.map +0 -1
  63. package/src/worker/client.ts +0 -76
  64. package/src/worker/events.ts +0 -41
  65. package/src/worker/pag-file.ts +0 -90
  66. package/src/worker/pag-image.ts +0 -43
  67. package/src/worker/pag-view.ts +0 -171
  68. package/src/worker/utils.ts +0 -29
  69. package/src/worker/video-reader.ts +0 -62
  70. package/src/worker/worker.ts +0 -169
  71. package/types/third_party/tgfx/web/src/core/web-mask.d.ts +0 -26
  72. package/types/web/src/utils/canvas.d.ts +0 -4
  73. package/types/web/src/worker/client.d.ts +0 -16
  74. package/types/web/src/worker/events.d.ts +0 -32
  75. package/types/web/src/worker/pag-file.d.ts +0 -33
  76. package/types/web/src/worker/pag-image.d.ts +0 -8
  77. package/types/web/src/worker/pag-view.d.ts +0 -67
  78. package/types/web/src/worker/utils.d.ts +0 -7
  79. package/types/web/src/worker/video-reader.d.ts +0 -16
  80. package/types/web/src/worker/worker.d.ts +0 -13
package/src/pag-file.ts CHANGED
@@ -1,134 +1,151 @@
1
- import { PAGModule } from './pag-module';
2
- import { PAGComposition } from './pag-composition';
3
- import { transferToArrayBuffer } from './utils/common';
4
- import { wasmAwaitRewind, wasmAsyncMethod, destroyVerify } from './utils/decorators';
5
- import { getLayerTypeName, layer2typeLayer, proxyVector } from './utils/type-utils';
1
+ import {PAGModule} from './pag-module';
2
+ import {PAGComposition} from './pag-composition';
3
+ import {transferToArrayBuffer} from './utils/common';
4
+ import {destroyVerify} from './utils/decorators';
5
+ import {getLayerTypeName, layer2typeLayer, proxyVector} from './utils/type-utils';
6
6
 
7
- import type { PAGImage } from './pag-image';
8
- import { LayerType, PAGTimeStretchMode, TextDocument } from './types';
7
+ import type {PAGImage} from './pag-image';
8
+ import {LayerType, PAGTimeStretchMode, TextDocument, VecArray} from './types';
9
9
 
10
10
  @destroyVerify
11
- @wasmAwaitRewind
12
11
  export class PAGFile extends PAGComposition {
13
- /**
14
- * Load pag file from file.
15
- */
16
- @wasmAsyncMethod
17
- public static async load(data: File | Blob | ArrayBuffer) {
18
- const buffer = await transferToArrayBuffer(data);
19
- if (!buffer)
20
- throw new Error(
21
- 'Initialize PAGFile data type error, please put check data type must to be File | Blob | ArrayBuffer!',
22
- );
23
- return PAGFile.loadFromBuffer(buffer);
24
- }
25
- /**
26
- * Load pag file from arrayBuffer
27
- */
28
- public static loadFromBuffer(buffer: ArrayBuffer) {
29
- if (!buffer || !(buffer.byteLength > 0)) throw new Error('Initialize PAGFile data not be empty!');
30
- const uint8Buffer = new Uint8Array(buffer);
31
- const wasmIns = PAGModule._PAGFile._Load(uint8Buffer);
32
- if (!wasmIns) throw new Error('Load PAGFile fail!');
33
- const pagFile = new PAGFile(wasmIns);
34
- return pagFile;
35
- }
36
- /**
37
- * The maximum tag level current SDK supports.
38
- */
39
- public static maxSupportedTagLevel(): number {
40
- return PAGModule._PAGFile._MaxSupportedTagLevel() as number;
41
- }
42
-
43
- /**
44
- * The tag level this pag file requires.
45
- */
46
- public tagLevel(): number {
47
- return this.wasmIns._tagLevel() as number;
48
- }
49
- /**
50
- * The number of replaceable texts.
51
- */
52
- public numTexts(): number {
53
- return this.wasmIns._numTexts() as number;
54
- }
55
- /**
56
- * The number of replaceable images.
57
- */
58
- public numImages(): number {
59
- return this.wasmIns._numImages() as number;
60
- }
61
- /**
62
- * The number of video compositions.
63
- */
64
- public numVideos(): number {
65
- return this.wasmIns._numVideos() as number;
66
- }
67
- /**
68
- * Get a text data of the specified index. The index ranges from 0 to numTexts - 1.
69
- * Note: It always returns the default text data.
70
- */
71
- public getTextData(editableTextIndex: number): TextDocument {
72
- return this.wasmIns._getTextData(editableTextIndex) as TextDocument;
73
- }
74
- /**
75
- * Replace the text data of the specified index. The index ranges from 0 to PAGFile.numTexts - 1.
76
- * Passing in null for the textData parameter will reset it to default text data.
77
- */
78
- public replaceText(editableTextIndex: number, textData: TextDocument): void {
79
- this.wasmIns._replaceText(editableTextIndex, textData);
80
- }
81
- /**
82
- * Replace the image content of the specified index with a PAGImage object. The index ranges from
83
- * 0 to PAGFile.numImages - 1. Passing in null for the image parameter will reset it to default
84
- * image content.
85
- */
86
- public replaceImage(editableImageIndex: number, pagImage: PAGImage): void {
87
- this.wasmIns._replaceImage(editableImageIndex, pagImage.wasmIns);
88
- }
89
- /**
90
- * Return an array of layers by specified editable index and layer type.
91
- */
92
- public getLayersByEditableIndex(editableIndex: Number, layerType: LayerType) {
93
- const wasmIns = this.wasmIns._getLayersByEditableIndex(editableIndex, layerType);
94
- if (!wasmIns) throw new Error(`Get ${getLayerTypeName(layerType)} layers by ${editableIndex} fail!`);
95
- return proxyVector(wasmIns, layer2typeLayer);
96
- }
97
- /**
98
- * Returns the indices of the editable layers in this PAGFile.
99
- * If the editableIndex of a PAGLayer is not present in the returned indices, the PAGLayer should
100
- * not be treated as editable.
101
- */
102
- public getEditableIndices(layerType: LayerType): Array<number> {
103
- return this.wasmIns._getEditableIndices(layerType);
104
- }
105
- /**
106
- * Indicate how to stretch the original duration to fit target duration when file's duration is
107
- * changed. The default value is PAGTimeStretchMode::Repeat.
108
- */
109
- public timeStretchMode(): PAGTimeStretchMode {
110
- return this.wasmIns._timeStretchMode() as PAGTimeStretchMode;
111
- }
112
- /**
113
- * Set the timeStretchMode of this file.
114
- */
115
- public setTimeStretchMode(value: PAGTimeStretchMode): void {
116
- this.wasmIns._setTimeStretchMode(value);
117
- }
118
- /**
119
- * Set the duration of this PAGFile. Passing a value less than or equal to 0 resets the duration
120
- * to its default value.
121
- */
122
- public setDuration(duration: number): void {
123
- this.wasmIns._setDuration(duration);
124
- }
125
- /**
126
- * Set the duration of this PAGFile. Passing a value less than or equal to 0 resets the duration
127
- * to its default value.
128
- */
129
- public copyOriginal(): PAGFile {
130
- const wasmIns = this.wasmIns._copyOriginal();
131
- if (!wasmIns) throw new Error(`Copy original fail!`);
132
- return new PAGFile(wasmIns);
133
- }
12
+ /**
13
+ * Load pag file from file.
14
+ */
15
+ public static async load(data: File | Blob | ArrayBuffer) {
16
+ const buffer = await transferToArrayBuffer(data);
17
+ if (!buffer)
18
+ throw new Error(
19
+ 'Initialize PAGFile data type error, please put check data type must to be File | Blob | ArrayBuffer!',
20
+ );
21
+ return PAGFile.loadFromBuffer(buffer);
22
+ }
23
+
24
+ /**
25
+ * Load pag file from arrayBuffer
26
+ */
27
+ public static loadFromBuffer(buffer: ArrayBuffer) {
28
+ if (!buffer || !(buffer.byteLength > 0)) throw new Error('Initialize PAGFile data not be empty!');
29
+ const uint8Buffer = new Uint8Array(buffer);
30
+ const wasmIns = PAGModule._PAGFile._Load(uint8Buffer);
31
+ if (!wasmIns) throw new Error('Load PAGFile fail!');
32
+ const pagFile = new PAGFile(wasmIns);
33
+ return pagFile;
34
+ }
35
+
36
+ /**
37
+ * The maximum tag level current SDK supports.
38
+ */
39
+ public static maxSupportedTagLevel(): number {
40
+ return PAGModule._PAGFile._MaxSupportedTagLevel() as number;
41
+ }
42
+
43
+ /**
44
+ * The tag level this pag file requires.
45
+ */
46
+ public tagLevel(): number {
47
+ return this.wasmIns._tagLevel() as number;
48
+ }
49
+
50
+ /**
51
+ * The number of replaceable texts.
52
+ */
53
+ public numTexts(): number {
54
+ return this.wasmIns._numTexts() as number;
55
+ }
56
+
57
+ /**
58
+ * The number of replaceable images.
59
+ */
60
+ public numImages(): number {
61
+ return this.wasmIns._numImages() as number;
62
+ }
63
+
64
+ /**
65
+ * The number of video compositions.
66
+ */
67
+ public numVideos(): number {
68
+ return this.wasmIns._numVideos() as number;
69
+ }
70
+
71
+ /**
72
+ * Get a text data of the specified index. The index ranges from 0 to numTexts - 1.
73
+ * Note: It always returns the default text data.
74
+ */
75
+ public getTextData(editableTextIndex: number): TextDocument {
76
+ return this.wasmIns._getTextData(editableTextIndex) as TextDocument;
77
+ }
78
+
79
+ /**
80
+ * Replace the text data of the specified index. The index ranges from 0 to PAGFile.numTexts - 1.
81
+ * Passing in null for the textData parameter will reset it to default text data.
82
+ */
83
+ public replaceText(editableTextIndex: number, textData: TextDocument): void {
84
+ this.wasmIns._replaceText(editableTextIndex, textData);
85
+ }
86
+
87
+ /**
88
+ * Replace the image content of the specified index with a PAGImage object. The index ranges from
89
+ * 0 to PAGFile.numImages - 1. Passing in null for the image parameter will reset it to default
90
+ * image content.
91
+ */
92
+ public replaceImage(editableImageIndex: number, pagImage: PAGImage): void {
93
+ this.wasmIns._replaceImage(editableImageIndex, pagImage.wasmIns);
94
+ }
95
+
96
+ /**
97
+ * Return an array of layers by specified editable index and layer type.
98
+ */
99
+ public getLayersByEditableIndex(editableIndex: Number, layerType: LayerType) {
100
+ const wasmIns = this.wasmIns._getLayersByEditableIndex(editableIndex, layerType);
101
+ if (!wasmIns) throw new Error(`Get ${getLayerTypeName(layerType)} layers by ${editableIndex} fail!`);
102
+
103
+ const layerArray = VecArray.create();
104
+ for (const wasmIn of wasmIns) {
105
+ layerArray.push(layer2typeLayer(wasmIn));
106
+ }
107
+ return layerArray;
108
+ }
109
+
110
+ /**
111
+ * Returns the indices of the editable layers in this PAGFile.
112
+ * If the editableIndex of a PAGLayer is not present in the returned indices, the PAGLayer should
113
+ * not be treated as editable.
114
+ */
115
+ public getEditableIndices(layerType: LayerType): Array<number> {
116
+ return this.wasmIns._getEditableIndices(layerType);
117
+ }
118
+
119
+ /**
120
+ * Indicate how to stretch the original duration to fit target duration when file's duration is
121
+ * changed. The default value is PAGTimeStretchMode::Repeat.
122
+ */
123
+ public timeStretchMode(): PAGTimeStretchMode {
124
+ return this.wasmIns._timeStretchMode() as PAGTimeStretchMode;
125
+ }
126
+
127
+ /**
128
+ * Set the timeStretchMode of this file.
129
+ */
130
+ public setTimeStretchMode(value: PAGTimeStretchMode): void {
131
+ this.wasmIns._setTimeStretchMode(value);
132
+ }
133
+
134
+ /**
135
+ * Set the duration of this PAGFile. Passing a value less than or equal to 0 resets the duration
136
+ * to its default value.
137
+ */
138
+ public setDuration(duration: number): void {
139
+ this.wasmIns._setDuration(duration);
140
+ }
141
+
142
+ /**
143
+ * Make a copy of the original file, any modification to current file has no effect on the result
144
+ * file.
145
+ */
146
+ public copyOriginal(): PAGFile {
147
+ const wasmIns = this.wasmIns._copyOriginal();
148
+ if (!wasmIns) throw new Error(`Copy original fail!`);
149
+ return new PAGFile(wasmIns);
150
+ }
134
151
  }
package/src/pag-font.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import { readFile } from './utils/common';
2
2
  import { defaultFontNames } from '@tgfx/utils/font-family';
3
- import { wasmAwaitRewind, wasmAsyncMethod, destroyVerify } from './utils/decorators';
3
+ import { destroyVerify } from './utils/decorators';
4
4
  import { PAGModule } from './pag-module';
5
5
 
6
6
  @destroyVerify
7
- @wasmAwaitRewind
8
7
  export class PAGFont {
9
8
  /**
10
9
  * Create PAGFont instance.
@@ -18,7 +17,6 @@ export class PAGFont {
18
17
  /**
19
18
  * Register custom font family in the browser.
20
19
  */
21
- @wasmAsyncMethod
22
20
  public static async registerFont(family: string, data: File) {
23
21
  const buffer = (await readFile(data)) as ArrayBuffer;
24
22
  if (!buffer || !(buffer.byteLength > 0)) {
@@ -1,13 +1,12 @@
1
1
  import { PAGModule } from './pag-module';
2
2
  import { PAGLayer } from './pag-layer';
3
- import { destroyVerify, wasmAwaitRewind } from './utils/decorators';
3
+ import { destroyVerify } from './utils/decorators';
4
4
  import { proxyVector } from './utils/type-utils';
5
5
 
6
6
  import type { PAGImage } from './pag-image';
7
7
  import type { PAGVideoRange } from './types';
8
8
 
9
9
  @destroyVerify
10
- @wasmAwaitRewind
11
10
  export class PAGImageLayer extends PAGLayer {
12
11
  /**
13
12
  * Make a empty PAGImageLayer with specified size.
package/src/pag-image.ts CHANGED
@@ -1,15 +1,13 @@
1
1
  import { AlphaType, ColorType, PAGScaleMode } from './types';
2
- import { wasmAwaitRewind, wasmAsyncMethod, destroyVerify } from './utils/decorators';
2
+ import { destroyVerify } from './utils/decorators';
3
3
  import { PAGModule } from './pag-module';
4
4
  import { Matrix } from './core/matrix';
5
5
 
6
6
  @destroyVerify
7
- @wasmAwaitRewind
8
7
  export class PAGImage {
9
8
  /**
10
9
  * Create pag image from image file.
11
10
  */
12
- @wasmAsyncMethod
13
11
  public static async fromFile(data: File): Promise<PAGImage> {
14
12
  return new Promise((resolve, reject) => {
15
13
  const image = new Image();
package/src/pag-layer.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { PAGComposition } from './pag-composition';
2
- import { destroyVerify, wasmAwaitRewind } from './utils/decorators';
2
+ import { destroyVerify } from './utils/decorators';
3
3
  import { Matrix } from './core/matrix';
4
4
  import { layer2typeLayer, proxyVector } from './utils/type-utils';
5
5
 
6
6
  import type { LayerType, Marker, Rect } from './types';
7
7
 
8
8
  @destroyVerify
9
- @wasmAwaitRewind
10
9
  export class PAGLayer {
11
10
  public wasmIns: any;
12
11
  public isDestroyed = false;
@@ -227,7 +226,7 @@ export class PAGLayer {
227
226
  * Returns this layer as a type layer.
228
227
  */
229
228
  public asTypeLayer() {
230
- return layer2typeLayer(this);
229
+ return layer2typeLayer(this.wasmIns);
231
230
  }
232
231
 
233
232
  public isDelete(): boolean {
package/src/pag-player.ts CHANGED
@@ -1,17 +1,16 @@
1
1
  import { PAGModule } from './pag-module';
2
2
  import { PAGFile } from './pag-file';
3
3
  import { PAGSurface } from './pag-surface';
4
- import { wasmAwaitRewind, wasmAsyncMethod, destroyVerify } from './utils/decorators';
4
+ import { destroyVerify } from './utils/decorators';
5
5
  import { getWasmIns, layer2typeLayer, proxyVector } from './utils/type-utils';
6
6
  import { Matrix } from './core/matrix';
7
7
 
8
8
  import { PAGComposition } from './pag-composition';
9
9
  import type { PAGLayer } from './pag-layer';
10
- import type { PAGScaleMode, Rect } from './types';
10
+ import {PAGScaleMode, Rect, VecArray} from './types';
11
11
  import type { VideoReader } from './interfaces';
12
12
 
13
13
  @destroyVerify
14
- @wasmAwaitRewind
15
14
  export class PAGPlayer {
16
15
  public static create(): PAGPlayer {
17
16
  const wasmIns = new PAGModule._PAGPlayer();
@@ -36,7 +35,6 @@ export class PAGPlayer {
36
35
  * Apply all pending changes to the target surface immediately. Returns true if the content has
37
36
  * changed.
38
37
  */
39
- @wasmAsyncMethod
40
38
  public async flush() {
41
39
  return PAGModule.webAssemblyQueue.exec<boolean>(this.wasmIns._flush, this.wasmIns);
42
40
  }
@@ -44,7 +42,6 @@ export class PAGPlayer {
44
42
  * [Internal] Apply all pending changes to the target surface immediately. Returns true if the content has
45
43
  * changed.
46
44
  */
47
- @wasmAsyncMethod
48
45
  public async flushInternal(callback: (res: boolean) => void) {
49
46
  const res = await PAGModule.webAssemblyQueue.exec<boolean>(async () => {
50
47
  PAGModule.currentPlayer = this;
@@ -239,7 +236,11 @@ export class PAGPlayer {
239
236
  public getLayersUnderPoint(localX: number, localY: number) {
240
237
  const wasmIns = this.wasmIns._getLayersUnderPoint(localX, localY);
241
238
  if (!wasmIns) throw new Error(`Get layers under point, x: ${localX} y:${localY} fail!`);
242
- return proxyVector(wasmIns, layer2typeLayer);
239
+ const layerArray = VecArray.create();
240
+ for (const wasmIn of wasmIns) {
241
+ layerArray.push(layer2typeLayer(wasmIn));
242
+ }
243
+ return layerArray;
243
244
  }
244
245
  /**
245
246
  * Evaluates the PAGLayer to see if it overlaps or intersects with the specified point. The point
@@ -1,11 +1,10 @@
1
1
  import { PAGModule } from './pag-module';
2
2
  import { PAGLayer } from './pag-layer';
3
- import { destroyVerify, wasmAwaitRewind } from './utils/decorators';
3
+ import { destroyVerify } from './utils/decorators';
4
4
 
5
5
  import type { Color } from './types';
6
6
 
7
7
  @destroyVerify
8
- @wasmAwaitRewind
9
8
  export class PAGSolidLayer extends PAGLayer {
10
9
  /**
11
10
  * Make a empty PAGSolidLayer with specified size.
@@ -1,9 +1,8 @@
1
1
  import { PAGModule } from './pag-module';
2
2
  import { AlphaType, ColorType } from './types';
3
- import { destroyVerify, wasmAwaitRewind } from './utils/decorators';
3
+ import { destroyVerify } from './utils/decorators';
4
4
 
5
5
  @destroyVerify
6
- @wasmAwaitRewind
7
6
  export class PAGSurface {
8
7
  /**
9
8
  * Make a PAGSurface from canvas.
@@ -1,12 +1,11 @@
1
1
  import { PAGModule } from './pag-module';
2
2
  import { PAGFont } from './pag-font';
3
3
  import { PAGLayer } from './pag-layer';
4
- import { destroyVerify, wasmAwaitRewind } from './utils/decorators';
4
+ import { destroyVerify } from './utils/decorators';
5
5
 
6
6
  import type { Color, TextDocument } from './types';
7
7
 
8
8
  @destroyVerify
9
- @wasmAwaitRewind
10
9
  export class PAGTextLayer extends PAGLayer {
11
10
  public static make(
12
11
  duration: number,
package/src/pag-view.ts CHANGED
@@ -7,7 +7,6 @@ import { BackendContext } from './core/backend-context';
7
7
  import { PAGModule } from './pag-module';
8
8
  import { RenderCanvas } from './core/render-canvas';
9
9
  import { Clock } from './utils/clock';
10
- import { WORKER } from './utils/ua';
11
10
  import { isInstanceOf } from './utils/type-utils';
12
11
 
13
12
  import type { PAGComposition } from './pag-composition';
@@ -397,8 +396,8 @@ export class PAGView {
397
396
  * Returns a ImageBitmap object capturing the contents of the PAGView. Subsequent rendering of
398
397
  * the PAGView will not be captured. Returns null if the PAGView hasn't been presented yet.
399
398
  */
400
- public makeSnapshot() {
401
- return createImageBitmap(this.canvasElement!);
399
+ public async makeSnapshot() {
400
+ return await createImageBitmap(this.canvasElement!);
402
401
  }
403
402
 
404
403
  public destroy() {
@@ -485,24 +484,14 @@ export class PAGView {
485
484
  }
486
485
 
487
486
  protected setTimer() {
488
- if (WORKER) {
489
- this.timer = self.setTimeout(() => {
490
- this.flushLoop();
491
- }, (1 / this.frameRate) * 1000);
492
- } else {
493
487
  this.timer = globalThis.requestAnimationFrame(() => {
494
488
  this.flushLoop();
495
489
  });
496
- }
497
490
  }
498
491
 
499
492
  protected clearTimer(): void {
500
493
  if (this.timer) {
501
- if (WORKER) {
502
- self.clearTimeout(this.timer);
503
- } else {
504
- globalThis.cancelAnimationFrame(this.timer);
505
- }
494
+ globalThis.cancelAnimationFrame(this.timer);
506
495
  this.timer = null;
507
496
  }
508
497
  }
package/src/pag.ts CHANGED
@@ -3,8 +3,6 @@ import { PAGBind } from './binding';
3
3
  import * as types from './types';
4
4
  import createPAG from './wasm/libpag';
5
5
  import { WebAssemblyQueue } from './utils/queue';
6
- import { workerInit } from './worker/worker';
7
- import { WORKER } from './utils/ua';
8
6
 
9
7
  export interface ModuleOption {
10
8
  /**
@@ -30,8 +28,4 @@ const PAGInit = (moduleOption: ModuleOption = {}): Promise<types.PAG> =>
30
28
  throw new Error('PAGInit fail! Please check .wasm file path valid.');
31
29
  });
32
30
 
33
- if (WORKER) {
34
- workerInit(PAGInit);
35
- }
36
-
37
31
  export { PAGInit, types };
package/src/types.ts CHANGED
@@ -17,9 +17,9 @@ import { PAGSolidLayer } from './pag-solid-layer';
17
17
  import { Matrix as ClassMatrix } from './core/matrix';
18
18
  import { RenderCanvas } from './core/render-canvas';
19
19
 
20
- import type { ScalerContextConstructor, VideoDecoderConstructor, WebMaskConstructor } from './interfaces';
20
+ import type { ScalerContextConstructor, VideoDecoderConstructor } from './interfaces';
21
21
 
22
- import type { ArrayBufferImage } from '@tgfx//wechat/array-buffer-image';
22
+ import type { ArrayBufferImage } from '@tgfx/wechat/array-buffer-image';
23
23
  import type { TGFXPathFillType, TGFXLineCap, TGFXLineJoin, EmscriptenGL, ctor, Point, Vector, Rect, } from '@tgfx/types';
24
24
  export type { EmscriptenGL, ctor, Point, Vector, Rect };
25
25
 
@@ -104,7 +104,6 @@ export interface PAG extends EmscriptenModule {
104
104
  PAGTextLayer: typeof PAGTextLayer;
105
105
  PAGImageLayer: typeof PAGImageLayer;
106
106
  PAGSolidLayer: typeof PAGSolidLayer;
107
- WebMask: WebMaskConstructor;
108
107
  ScalerContext: ScalerContextConstructor;
109
108
  VideoReader: VideoDecoderConstructor;
110
109
  GlobalCanvas: typeof GlobalCanvas;
@@ -520,3 +519,47 @@ export declare class SoftwareDecoder {
520
519
  export declare class SoftwareDecoderFactory {
521
520
  public createSoftwareDecoder(pag: PAG): SoftwareDecoder | null;
522
521
  }
522
+
523
+
524
+ export class VecArray extends Array {
525
+ private isDeleted = false;
526
+
527
+ private constructor(...items: any[]) {
528
+ super(...items);
529
+ Object.setPrototypeOf(this, VecArray.prototype);
530
+ }
531
+
532
+ public static create(): VecArray {
533
+ return new VecArray();
534
+ }
535
+
536
+ public get(index: number): any {
537
+ this.ensureNotDeleted();
538
+ if (index < 0 || index >= this.length) {
539
+ throw new RangeError('Index out of bounds');
540
+ }
541
+ return this[index];
542
+ }
543
+
544
+ public push_back(value: any): void {
545
+ this.ensureNotDeleted();
546
+ this.push(value);
547
+ }
548
+
549
+ public size(): number {
550
+ this.ensureNotDeleted();
551
+ return this.length;
552
+ }
553
+
554
+ public delete(): void {
555
+ this.ensureNotDeleted();
556
+ this.length = 0;
557
+ this.isDeleted = true;
558
+ }
559
+
560
+ private ensureNotDeleted(): void {
561
+ if (this.isDeleted) {
562
+ throw new Error('This VecArray instance has been deleted.');
563
+ }
564
+ }
565
+ }
@@ -1,47 +1,5 @@
1
1
  import { PAGModule } from '../pag-module';
2
2
 
3
- export function wasmAwaitRewind(constructor: any) {
4
- const ignoreStaticFunctions = ['length', 'name', 'prototype', 'wasmAsyncMethods'];
5
- let staticFunctions = Object.getOwnPropertyNames(constructor).filter(
6
- (name) => ignoreStaticFunctions.indexOf(name) === -1,
7
- );
8
- if (constructor.wasmAsyncMethods && constructor.wasmAsyncMethods.length > 0) {
9
- staticFunctions = staticFunctions.filter((name) => constructor.wasmAsyncMethods.indexOf(name) === -1);
10
- }
11
-
12
- let functions = Object.getOwnPropertyNames(constructor.prototype).filter(
13
- (name) => name !== 'constructor' && typeof constructor.prototype[name] === 'function',
14
- );
15
- if (constructor.prototype.wasmAsyncMethods && constructor.prototype.wasmAsyncMethods.length > 0) {
16
- functions = functions.filter((name) => constructor.prototype.wasmAsyncMethods.indexOf(name) === -1);
17
- }
18
-
19
- const proxyFn = (target: { [prop: string]: (...args: any[]) => any }, methodName: string) => {
20
- const fn = target[methodName];
21
- target[methodName] = function (...args) {
22
- if (PAGModule.Asyncify.currData !== null) {
23
- const currData = PAGModule.Asyncify.currData;
24
- PAGModule.Asyncify.currData = null;
25
- const ret = fn.call(this, ...args);
26
- PAGModule.Asyncify.currData = currData;
27
- return ret;
28
- } else {
29
- return fn.call(this, ...args);
30
- }
31
- };
32
- };
33
-
34
- staticFunctions.forEach((name) => proxyFn(constructor, name));
35
- functions.forEach((name) => proxyFn(constructor.prototype, name));
36
- }
37
-
38
- export function wasmAsyncMethod(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
39
- if (!target.wasmAsyncMethods) {
40
- target.wasmAsyncMethods = [];
41
- }
42
- target.wasmAsyncMethods.push(propertyKey);
43
- }
44
-
45
3
  export function destroyVerify(constructor: any) {
46
4
  let functions = Object.getOwnPropertyNames(constructor.prototype).filter(
47
5
  (name) => name !== 'constructor' && typeof constructor.prototype[name] === 'function',
@@ -7,15 +7,7 @@ import type { PAGSolidLayer } from '../pag-solid-layer';
7
7
  import type { PAGTextLayer } from '../pag-text-layer';
8
8
 
9
9
  const rewindData = (fn: (...args: any[]) => any, scope: any, ...args: any[]) => {
10
- if (PAGModule.Asyncify.currData !== null) {
11
- const currData = PAGModule.Asyncify.currData;
12
- PAGModule.Asyncify.currData = null;
13
- const ret = fn.call(scope, ...args);
14
- PAGModule.Asyncify.currData = currData;
15
- return ret;
16
- } else {
17
- return fn.call(scope, ...args);
18
- }
10
+ return fn.call(scope, ...args);
19
11
  };
20
12
 
21
13
  export const proxyVector = <T extends (...args: any) => any>(
package/src/utils/ua.ts CHANGED
@@ -5,4 +5,3 @@ export const MACOS = !(/(mobile)/i.test(nav) || MOBILE) && /Mac OS X/i.test(nav)
5
5
  export const IPHONE = /(iphone|ipad|ipod)/i.test(nav);
6
6
  export const WECHAT = /MicroMessenger/i.test(nav);
7
7
  export const SAFARI_OR_IOS_WEBVIEW = /^((?!chrome|android).)*safari/i.test(nav) || IPHONE;
8
- export const WORKER = typeof (globalThis as any).importScripts === 'function';