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.
- package/LICENSE.txt +1589 -0
- package/README.md +172 -10
- package/README.zh_CN.md +114 -15
- package/lib/libpag.cjs.js +5420 -6176
- package/lib/libpag.cjs.js.map +1 -1
- package/lib/libpag.esm.js +5420 -6176
- package/lib/libpag.esm.js.map +1 -1
- package/lib/libpag.min.js +1 -1
- package/lib/libpag.min.js.map +1 -1
- package/lib/libpag.umd.js +5420 -6176
- package/lib/libpag.umd.js.map +1 -1
- package/lib/libpag.wasm +0 -0
- package/package.json +23 -11
- package/src/.pag.wasm-mt.md5 +1 -0
- package/src/.pag.wasm.md5 +1 -1
- package/src/core/matrix.ts +1 -2
- package/src/core/video-reader.ts +73 -94
- package/src/interfaces.ts +8 -17
- package/src/pag-composition.ts +12 -5
- package/src/pag-file.ts +146 -129
- package/src/pag-font.ts +1 -3
- package/src/pag-image-layer.ts +1 -2
- package/src/pag-image.ts +1 -3
- package/src/pag-layer.ts +2 -3
- package/src/pag-player.ts +7 -6
- package/src/pag-solid-layer.ts +1 -2
- package/src/pag-surface.ts +1 -2
- package/src/pag-text-layer.ts +1 -2
- package/src/pag-view.ts +3 -14
- package/src/pag.ts +0 -6
- package/src/types.ts +46 -3
- package/src/utils/decorators.ts +0 -42
- package/src/utils/type-utils.ts +1 -9
- package/src/utils/ua.ts +0 -1
- package/src/wasm/libpag.js +7 -6
- package/src/wasm/libpag.wasm +0 -0
- package/src/wasm-mt/libpag.js +2 -0
- package/src/wasm-mt/libpag.wasm +0 -0
- package/src/wechat/pag-file.ts +1 -2
- package/src/wechat/pag-image.ts +0 -2
- package/src/wechat/pag-view.ts +1 -2
- package/types/third_party/tgfx/web/src/core/path-rasterizer.d.ts +4 -0
- package/types/third_party/tgfx/web/src/core/scaler-context.d.ts +9 -2
- package/types/third_party/tgfx/web/src/utils/decorators.d.ts +0 -2
- package/types/web/src/core/video-reader.d.ts +4 -3
- package/types/web/src/interfaces.d.ts +8 -15
- package/types/web/src/pag-composition.d.ts +3 -3
- package/types/web/src/pag-file.d.ts +4 -4
- package/types/web/src/pag-player.d.ts +2 -2
- package/types/web/src/pag-view.d.ts +1 -1
- package/types/web/src/types.d.ts +12 -3
- package/types/web/src/utils/decorators.d.ts +0 -2
- package/types/web/src/utils/ua.d.ts +0 -1
- package/types/web/tsconfig.json +19 -0
- package/lib/libpag.worker.cjs.js +0 -794
- package/lib/libpag.worker.cjs.js.map +0 -1
- package/lib/libpag.worker.esm.js +0 -789
- package/lib/libpag.worker.esm.js.map +0 -1
- package/lib/libpag.worker.js +0 -800
- package/lib/libpag.worker.js.map +0 -1
- package/lib/libpag.worker.min.js +0 -2
- package/lib/libpag.worker.min.js.map +0 -1
- package/src/worker/client.ts +0 -76
- package/src/worker/events.ts +0 -41
- package/src/worker/pag-file.ts +0 -90
- package/src/worker/pag-image.ts +0 -43
- package/src/worker/pag-view.ts +0 -171
- package/src/worker/utils.ts +0 -29
- package/src/worker/video-reader.ts +0 -62
- package/src/worker/worker.ts +0 -169
- package/types/third_party/tgfx/web/src/core/web-mask.d.ts +0 -26
- package/types/web/src/utils/canvas.d.ts +0 -4
- package/types/web/src/worker/client.d.ts +0 -16
- package/types/web/src/worker/events.d.ts +0 -32
- package/types/web/src/worker/pag-file.d.ts +0 -33
- package/types/web/src/worker/pag-image.d.ts +0 -8
- package/types/web/src/worker/pag-view.d.ts +0 -67
- package/types/web/src/worker/utils.d.ts +0 -7
- package/types/web/src/worker/video-reader.d.ts +0 -16
- package/types/web/src/worker/worker.d.ts +0 -13
package/src/pag-file.ts
CHANGED
|
@@ -1,134 +1,151 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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 {
|
|
8
|
-
import {
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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 {
|
|
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)) {
|
package/src/pag-image-layer.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { PAGModule } from './pag-module';
|
|
2
2
|
import { PAGLayer } from './pag-layer';
|
|
3
|
-
import { destroyVerify
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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
|
-
|
|
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
|
package/src/pag-solid-layer.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { PAGModule } from './pag-module';
|
|
2
2
|
import { PAGLayer } from './pag-layer';
|
|
3
|
-
import { destroyVerify
|
|
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.
|
package/src/pag-surface.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { PAGModule } from './pag-module';
|
|
2
2
|
import { AlphaType, ColorType } from './types';
|
|
3
|
-
import { destroyVerify
|
|
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.
|
package/src/pag-text-layer.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
|
20
|
+
import type { ScalerContextConstructor, VideoDecoderConstructor } from './interfaces';
|
|
21
21
|
|
|
22
|
-
import type { ArrayBufferImage } from '@tgfx
|
|
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
|
+
}
|
package/src/utils/decorators.ts
CHANGED
|
@@ -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',
|
package/src/utils/type-utils.ts
CHANGED
|
@@ -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
|
-
|
|
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';
|