11"use client" ;
22import React from "react" ;
33
4+ type CleanupImage = HTMLImageElement & { _cleanup ?: ( ) => void } ;
5+
46type PixelatedCanvasProps = {
57 src : string ;
68 width ?: number ;
@@ -114,7 +116,7 @@ export const PixelatedCanvas: React.FC<PixelatedCanvasProps> = ({
114116 const canvas = canvasRef . current ;
115117 if ( ! canvas ) return ;
116118
117- const img = new Image ( ) ;
119+ const img : CleanupImage = new Image ( ) ;
118120 img . crossOrigin = "anonymous" ;
119121 img . src = src ;
120122
@@ -242,7 +244,10 @@ export const PixelatedCanvas: React.FC<PixelatedCanvasProps> = ({
242244 return [ parseInt ( m [ 1 ] , 10 ) , parseInt ( m [ 2 ] , 10 ) , parseInt ( m [ 3 ] , 10 ) ] ;
243245 return null ;
244246 } ;
245- tintRGB = parse ( tintColor ) as any ;
247+ const parsedTint = parse ( tintColor ) ;
248+ if ( parsedTint ) {
249+ tintRGB = parsedTint ;
250+ }
246251 }
247252
248253 for ( let y = 0 ; y < offscreen . height ; y += cellSize ) {
@@ -498,7 +503,7 @@ export const PixelatedCanvas: React.FC<PixelatedCanvasProps> = ({
498503 canvasEl . removeEventListener ( "pointerleave" , onPointerLeave ) ;
499504 if ( rafRef . current ) cancelAnimationFrame ( rafRef . current ) ;
500505 } ;
501- ( img as any ) . _cleanup = cleanup ;
506+ img . _cleanup = cleanup ;
502507 } ;
503508
504509 img . onerror = ( ) => {
@@ -515,13 +520,13 @@ export const PixelatedCanvas: React.FC<PixelatedCanvasProps> = ({
515520 return ( ) => {
516521 isCancelled = true ;
517522 window . removeEventListener ( "resize" , onResize ) ;
518- if ( ( img as any ) . _cleanup ) ( img as any ) . _cleanup ( ) ;
523+ if ( img . _cleanup ) img . _cleanup ( ) ;
519524 } ;
520525 }
521526
522527 return ( ) => {
523528 isCancelled = true ;
524- if ( ( img as any ) . _cleanup ) ( img as any ) . _cleanup ( ) ;
529+ if ( img . _cleanup ) img . _cleanup ( ) ;
525530 } ;
526531 } , [
527532 src ,
0 commit comments