[Canvas worker] revert monkey patching
diff --git a/player/js/modules/canvas_worker.js b/player/js/modules/canvas_worker.js
deleted file mode 100644
index 2019e47..0000000
--- a/player/js/modules/canvas_worker.js
+++ /dev/null
@@ -1,80 +0,0 @@
-import lottie from './canvas';
-import AnimationItem from '../animation/AnimationItem';
-import CanvasRenderer from '../renderers/CanvasRenderer';
-
-// Monkey patch some methods to work correctly with Worker
-AnimationItem.prototype.resize = function (width, height) {
- this.renderer.updateContainerSize(width, height);
-};
-
-CanvasRenderer.prototype.updateContainerSize = function (width, height) {
- this.reset();
- var elementWidth = width || this.canvasContext.canvas.width;
- var elementHeight = height || this.canvasContext.canvas.height;
-
- // Resize canvas
- this.canvasContext.canvas.width = elementWidth;
- this.canvasContext.canvas.height = elementHeight;
-
- // Transform canvas
- var elementRel;
- var animationRel;
-
- if (this.renderConfig.preserveAspectRatio.indexOf('meet') !== -1 || this.renderConfig.preserveAspectRatio.indexOf('slice') !== -1) {
- var par = this.renderConfig.preserveAspectRatio.split(' ');
- var fillType = par[1] || 'meet';
- var pos = par[0] || 'xMidYMid';
- var xPos = pos.substr(0, 4);
- var yPos = pos.substr(4);
- elementRel = elementWidth / elementHeight;
- animationRel = this.transformCanvas.w / this.transformCanvas.h;
- if ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice')) {
- this.transformCanvas.sx = elementWidth / this.transformCanvas.w;
- this.transformCanvas.sy = elementWidth / this.transformCanvas.w;
- } else {
- this.transformCanvas.sx = elementHeight / this.transformCanvas.h;
- this.transformCanvas.sy = elementHeight / this.transformCanvas.h;
- }
-
- if (xPos === 'xMid' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) {
- this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) / 2;
- } else if (xPos === 'xMax' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) {
- this.transformCanvas.tx = elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h);
- } else {
- this.transformCanvas.tx = 0;
- }
- if (yPos === 'YMid' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
- this.transformCanvas.ty = (elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) / 2;
- } else if (yPos === 'YMax' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
- this.transformCanvas.ty = (elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w));
- } else {
- this.transformCanvas.ty = 0;
- }
- } else if (this.renderConfig.preserveAspectRatio === 'none') {
- this.transformCanvas.sx = elementWidth / this.transformCanvas.w;
- this.transformCanvas.sy = elementHeight / this.transformCanvas.h;
- this.transformCanvas.tx = 0;
- this.transformCanvas.ty = 0;
- } else {
- this.transformCanvas.sx = 1;
- this.transformCanvas.sy = 1;
- this.transformCanvas.tx = 0;
- this.transformCanvas.ty = 0;
- }
- this.transformCanvas.props = [this.transformCanvas.sx, 0, 0, 0, 0, this.transformCanvas.sy, 0, 0, 0, 0, 1, 0, this.transformCanvas.tx, this.transformCanvas.ty, 0, 1];
- /* var i, len = this.elements.length;
- for(i=0;i<len;i+=1){
- if(this.elements[i] && this.elements[i].data.ty === 0){
- this.elements[i].resize(this.globalData.transformCanvas);
- }
- } */
- this.ctxTransform(this.transformCanvas.props);
- this.canvasContext.beginPath();
- this.canvasContext.rect(0, 0, this.transformCanvas.w, this.transformCanvas.h);
- this.canvasContext.closePath();
- this.canvasContext.clip();
-
- this.renderFrame(this.renderedFrame, true);
-};
-
-export default lottie;
diff --git a/rollup.config.js b/rollup.config.js
index 87bb5c3..0d7ad02 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -93,14 +93,6 @@
file: 'lottie_light_canvas.min.js',
esm: true,
},
- // Temporary file to wrap code with Worker, it'll be overridden by build_worker.js eventually
- {
- input: 'player/js/modules/canvas_worker.js',
- dest: `${destinationBuildFolder}`,
- file: 'lottie_canvas_worker.js',
- esm: false,
- skipTerser: true,
- },
{
input: 'player/js/modules/canvas.js',
dest: `${destinationBuildFolder}`,
diff --git a/tasks/build_worker.js b/tasks/build_worker.js
index 4b75fef..272e22a 100644
--- a/tasks/build_worker.js
+++ b/tasks/build_worker.js
@@ -73,7 +73,7 @@
try {
let scriptsString = '';
// Get code for Worker from rollup build
- scriptsString += fs.readFileSync(`${buildFolder}lottie_canvas_worker.js`, {encoding: 'utf8'});
+ scriptsString += fs.readFileSync(`${buildFolder}lottie.js`, {encoding: 'utf8'});
scriptsString += '\r\n';
return scriptsString;
} catch(err) {