const controller = bodymovin.loadAnimation({
container,
path: src,
renderer: 'canvas',
loop: true,
autoplay: true,
name,
});
const asset = scrawl.makeRawAsset({
name: `${name}-asset`,
userAttributes: [{
key: 'lottie',
defaultValue: controller,
setter: () => {},
},{
key: 'lottieCanvas',
defaultValue: null,
setter: () => {},
},{
key: 'canvasWidth',
defaultValue: 0,
setter: () => {},
},{
key: 'canvasHeight',
defaultValue: 0,
setter: () => {},
},{
key: 'trigger',
defaultValue: false,
setter: function (item) { this.dirtyData = item },
}],
updateSource: function (assetWrapper) {
let { element, engine, canvasWidth, canvasHeight, lottieCanvas } = assetWrapper;
if (!lottieCanvas) {
const c = container.querySelector('canvas');
if (c) {
lottieCanvas = this.lottieCanvas = c;
canvasWidth = this.canvasWidth = c.width;
canvasHeight = this.canvasHeight = c.height;
}
}
if (lottieCanvas) {
element.width = canvasWidth;
element.height = canvasHeight;
engine.drawImage(lottieCanvas, 0, 0, canvasWidth, canvasHeight);
}
},
});
return {
asset,
controller,
kill: () => {
asset.kill();
controller.destroy();
hold.remove();
},
}
};