Skip to content

Commit 7ddf7b4

Browse files
committed
Fix PAGComposition bindings error.
1 parent 26b2c86 commit 7ddf7b4

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

Diff for: web/demo/index.ts

+24-26
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ window.onload = async () => {
3535
'viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no',
3636
);
3737
await loadScript('https://unpkg.com/vconsole@latest/dist/vconsole.min.js');
38-
new window.VConsole();
38+
const vconsole = new window.VConsole();
3939
canvasElementSize = 320;
4040
const canvas = document.getElementById('pag') as HTMLCanvasElement;
4141
canvas.width = canvasElementSize;
@@ -56,7 +56,7 @@ window.onload = async () => {
5656
});
5757
document.getElementById('upload-font').addEventListener('change', async (event) => {
5858
const file = (event.target as HTMLInputElement).files[0];
59-
document.getElementById('upload-font-text').innerText = `已加载${file.name}`;
59+
document.getElementById('upload-font-text').innerText = `已加载${file.name}`;
6060
await PAG.PAGFont.registerFont('test', file);
6161
});
6262
// 加载测试字体
@@ -256,8 +256,8 @@ window.onload = async () => {
256256
});
257257
};
258258

259-
const existsLayer = (pagLayerWasm: object) => {
260-
if (pagLayerWasm) return true;
259+
const existsLayer = (pagLayer: object) => {
260+
if (pagLayer) return true;
261261
console.log('no Layer');
262262
return false;
263263
};
@@ -275,15 +275,13 @@ const testPAGComposition = {
275275
console.log(`test numChildren: ${pagComposition.numChildren()}`);
276276
},
277277
getLayerAt: () => {
278-
const pagLayerWasm = pagComposition.getLayerAt(0);
279-
if (!existsLayer(pagLayerWasm)) return;
280-
const pagLayer = new PAG.PAGLayer(pagLayerWasm);
278+
const pagLayer = pagComposition.getLayerAt(0);
279+
if (!existsLayer(pagLayer)) return;
281280
console.log(`test getLayerAt index 0, layerName: ${pagLayer.layerName()}`);
282281
},
283282
getLayersByName: () => {
284-
const pagLayerWasm = pagComposition.getLayerAt(0);
285-
if (!existsLayer(pagLayerWasm)) return;
286-
const pagLayer = new PAG.PAGLayer(pagLayerWasm);
283+
const pagLayer = pagComposition.getLayerAt(0);
284+
if (!existsLayer(pagLayer)) return;
287285
const layerName = pagLayer.layerName();
288286
const vectorPagLayer = pagComposition.getLayersByName(layerName);
289287
for (let j = 0; j < vectorPagLayer.size(); j++) {
@@ -316,17 +314,17 @@ const testPAGComposition = {
316314
swapLayer('swapLayer');
317315
},
318316
contains: () => {
319-
const pagLayerWasm = pagComposition.getLayerAt(0);
320-
const isContains = pagComposition.contains(pagLayerWasm);
317+
const pagLayer = pagComposition.getLayerAt(0);
318+
const isContains = pagComposition.contains(pagLayer);
321319
if (isContains) {
322320
console.log('test contains');
323321
}
324322
},
325323
addLayer: () => {
326-
const pagLayerWasm = pagComposition.getLayerAt(0);
324+
const pagLayer = pagComposition.getLayerAt(0);
327325
pagComposition.removeLayerAt(0);
328326
const oldNum = pagComposition.numChildren();
329-
const isSuccess: boolean = pagComposition.addLayer(pagLayerWasm);
327+
const isSuccess: boolean = pagComposition.addLayer(pagLayer);
330328
if (isSuccess) {
331329
console.log(`test addLayer success: old num ${oldNum} current num ${pagComposition.numChildren()}`);
332330
}
@@ -357,23 +355,23 @@ const testPAGCompositionAPi = () => {
357355
};
358356

359357
const swapLayer = (type: string) => {
360-
const pagLayerWasm_0 = pagComposition.getLayerAt(0);
361-
const pagLayerWasm_1 = pagComposition.getLayerAt(1);
362-
if (!pagLayerWasm_0 || !pagLayerWasm_1) {
358+
const pagLayer_0 = pagComposition.getLayerAt(0);
359+
const pagLayer_1 = pagComposition.getLayerAt(1);
360+
if (!pagLayer_0 || !pagLayer_1) {
363361
console.log('No layer switching');
364362
return;
365363
}
366-
const pagLayer_name_0 = new PAG.PAGLayer(pagLayerWasm_0).layerName();
367-
const pagLayer_name_1 = new PAG.PAGLayer(pagLayerWasm_1).layerName();
364+
const pagLayer_name_0 = pagLayer_0.layerName();
365+
const pagLayer_name_1 = pagLayer_1.layerName();
368366
if (type === 'swapLayer') {
369-
pagComposition.swapLayer(pagLayerWasm_0, pagLayerWasm_1);
367+
pagComposition.swapLayer(pagLayer_0, pagLayer_1);
370368
} else {
371369
pagComposition.swapLayerAt(0, 1);
372370
}
373-
const pagLayerWasm_exch_0 = pagComposition.getLayerAt(0);
374-
const pagLayerWasm_exch_1 = pagComposition.getLayerAt(1);
375-
const pagLayer__exch_0 = new PAG.PAGLayer(pagLayerWasm_exch_0).layerName();
376-
const pagLayer__exch_1 = new PAG.PAGLayer(pagLayerWasm_exch_1).layerName();
371+
const pagLayer_exch_0 = pagComposition.getLayerAt(0);
372+
const pagLayer_exch_1 = pagComposition.getLayerAt(1);
373+
const pagLayer__exch_0 = pagLayer_exch_0.layerName();
374+
const pagLayer__exch_1 = pagLayer_exch_1.layerName();
377375
console.log(
378376
`test ${type}: oldLayerName_0=${pagLayer_name_0}, oldLayerName_1=${pagLayer_name_1} exchange LayerName_0=${pagLayer__exch_0}, LayerName_1=${pagLayer__exch_1} `,
379377
);
@@ -533,8 +531,8 @@ const loadScript = (url) => {
533531
scriptEl.onload = () => {
534532
resolve(true);
535533
};
536-
scriptEl.onerror = () => {
537-
reject(false);
534+
scriptEl.onerror = (e) => {
535+
reject(e);
538536
};
539537
scriptEl.src = url;
540538
document.body.appendChild(scriptEl);

Diff for: web/src/pag-composition.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class PAGComposition extends PAGLayer {
6060
* Swap the layers at the specified index.
6161
*/
6262
public swapLayer(pagLayer1: PAGLayer, pagLayer2: PAGLayer): void {
63-
this.wasmIns._swapLayer(pagLayer1, pagLayer2);
63+
this.wasmIns._swapLayer(pagLayer1.wasmIns, pagLayer2.wasmIns);
6464
}
6565
/**
6666
* Swap the layers at the specified index.
@@ -72,23 +72,23 @@ export class PAGComposition extends PAGLayer {
7272
* Check whether current PAGComposition contains the specified pagLayer.
7373
*/
7474
public contains(pagLayer: PAGLayer): boolean {
75-
return this.wasmIns._contains(pagLayer) as boolean;
75+
return this.wasmIns._contains(pagLayer.wasmIns) as boolean;
7676
}
7777
/**
7878
* Add a PAGLayer to current PAGComposition at the top. If you add a layer that already has a
7979
* different PAGComposition object as a parent, the layer is removed from the other PAGComposition
8080
* object.
8181
*/
82-
public addLayer(layer: PAGLayer): boolean {
83-
return this.wasmIns._addLayer(layer) as boolean;
82+
public addLayer(pagLayer: PAGLayer): boolean {
83+
return this.wasmIns._addLayer(pagLayer.wasmIns) as boolean;
8484
}
8585
/**
8686
* Add a PAGLayer to current PAGComposition at the top. If you add a layer that already has a
8787
* different PAGComposition object as a parent, the layer is removed from the other PAGComposition
8888
* object.
8989
*/
90-
public addLayerAt(layer: PAGLayer, index: number): boolean {
91-
return this.wasmIns._addLayerAt(layer, index) as boolean;
90+
public addLayerAt(pagLayer: PAGLayer, index: number): boolean {
91+
return this.wasmIns._addLayerAt(pagLayer.wasmIns, index) as boolean;
9292
}
9393
/**
9494
* Indicates when the first frame of the audio plays in the composition's timeline.

0 commit comments

Comments
 (0)