From 379d06d80de6fa3d2b944a5c2a6a87721b6b3bd3 Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Sun, 19 Jan 2025 06:53:46 +0700 Subject: [PATCH 1/4] fix: error when used on server side via SVGRenderer --- src/libs/lottie.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/libs/lottie.js b/src/libs/lottie.js index e6e503df..c9993679 100644 --- a/src/libs/lottie.js +++ b/src/libs/lottie.js @@ -1175,15 +1175,7 @@ const lottie = /* @__PURE__ */ (() => { })() const ImagePreloader = (function () { - var proxyImage = (function () { - var canvas = createTag('canvas') - canvas.width = 1 - canvas.height = 1 - var ctx = canvas.getContext('2d') - ctx.fillStyle = 'rgba(0,0,0,0)' - ctx.fillRect(0, 0, 1, 1) - return canvas - })() + var proxyImage function imageLoaded() { this.loadedAssets += 1 @@ -1364,6 +1356,15 @@ const lottie = /* @__PURE__ */ (() => { } function ImagePreloaderFactory() { + proxyImage = (function () { + var canvas = createTag('canvas') + canvas.width = 1 + canvas.height = 1 + var ctx = canvas.getContext('2d') + ctx.fillStyle = 'rgba(0,0,0,0)' + ctx.fillRect(0, 0, 1, 1) + return canvas + })() this._imageLoaded = imageLoaded.bind(this) this._footageLoaded = footageLoaded.bind(this) this.testImageLoaded = testImageLoaded.bind(this) From 3330fafb8418498bb4a367b9339d08ed50ea0fef Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Sun, 19 Jan 2025 19:56:42 +0700 Subject: [PATCH 2/4] Revert "fix: error when used on server side via SVGRenderer" This reverts commit 379d06d80de6fa3d2b944a5c2a6a87721b6b3bd3. --- src/libs/lottie.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/libs/lottie.js b/src/libs/lottie.js index c9993679..e6e503df 100644 --- a/src/libs/lottie.js +++ b/src/libs/lottie.js @@ -1175,7 +1175,15 @@ const lottie = /* @__PURE__ */ (() => { })() const ImagePreloader = (function () { - var proxyImage + var proxyImage = (function () { + var canvas = createTag('canvas') + canvas.width = 1 + canvas.height = 1 + var ctx = canvas.getContext('2d') + ctx.fillStyle = 'rgba(0,0,0,0)' + ctx.fillRect(0, 0, 1, 1) + return canvas + })() function imageLoaded() { this.loadedAssets += 1 @@ -1356,15 +1364,6 @@ const lottie = /* @__PURE__ */ (() => { } function ImagePreloaderFactory() { - proxyImage = (function () { - var canvas = createTag('canvas') - canvas.width = 1 - canvas.height = 1 - var ctx = canvas.getContext('2d') - ctx.fillStyle = 'rgba(0,0,0,0)' - ctx.fillRect(0, 0, 1, 1) - return canvas - })() this._imageLoaded = imageLoaded.bind(this) this._footageLoaded = footageLoaded.bind(this) this.testImageLoaded = testImageLoaded.bind(this) From ddfabcc0db3944e6edeed43601671bda720421a0 Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Sun, 19 Jan 2025 20:02:39 +0700 Subject: [PATCH 3/4] fix(lottie): check if CanvasRenderingContext2D available --- src/libs/lottie.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/lottie.js b/src/libs/lottie.js index e6e503df..2c3bc2d9 100644 --- a/src/libs/lottie.js +++ b/src/libs/lottie.js @@ -1,5 +1,5 @@ const lottie = /* @__PURE__ */ (() => { - if (typeof navigator === 'undefined' || typeof document === 'undefined') return {} + if (typeof navigator === 'undefined' || typeof document === 'undefined' || typeof CanvasRenderingContext2D === "undefined") return {} const svgNS = 'http://www.w3.org/2000/svg' From a39536c4f93dadd194e9d09a992eb2c095bc5217 Mon Sep 17 00:00:00 2001 From: Cody Bennett Date: Sun, 19 Jan 2025 13:33:08 -0600 Subject: [PATCH 4/4] chore: cleanup --- src/libs/lottie.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/lottie.js b/src/libs/lottie.js index 2c3bc2d9..fecc85a5 100644 --- a/src/libs/lottie.js +++ b/src/libs/lottie.js @@ -1,5 +1,10 @@ const lottie = /* @__PURE__ */ (() => { - if (typeof navigator === 'undefined' || typeof document === 'undefined' || typeof CanvasRenderingContext2D === "undefined") return {} + if ( + typeof navigator === 'undefined' || + typeof document === 'undefined' || + typeof CanvasRenderingContext2D === 'undefined' + ) + return {} const svgNS = 'http://www.w3.org/2000/svg'