@@ -43,11 +43,18 @@ async function getTransparentBlobFor(
4343 }
4444}
4545
46- // `as any` because: https://github.com/Microsoft/TypeScript/issues/20595
4746const worker : ImageBitmapDataURLResponseWorker = self ;
47+ let logDebug : boolean = false ;
48+
49+ const debug = ( ...args : any [ ] ) => {
50+ if ( logDebug ) {
51+ console . debug ( ...args ) ;
52+ }
53+ } ;
4854
4955// eslint-disable-next-line @typescript-eslint/no-misused-promises
5056worker . onmessage = async function ( e ) {
57+ logDebug = ! ! e . data . logDebug ;
5158 if ( 'OffscreenCanvas' in globalThis ) {
5259 const { id, bitmap, width, height, dx, dy, dw, dh, dataURLOptions } =
5360 e . data ;
@@ -71,7 +78,7 @@ worker.onmessage = async function (e) {
7178 // on first try we should check if canvas is transparent,
7279 // no need to save it's contents in that case
7380 if ( ! lastBlobMap . has ( id ) && ( await transparentBase64 ) === base64 ) {
74- console . debug ( '[highlight-worker] canvas bitmap is transparent' , {
81+ debug ( '[highlight-worker] canvas bitmap is transparent' , {
7582 id,
7683 base64,
7784 } ) ;
@@ -81,13 +88,13 @@ worker.onmessage = async function (e) {
8188
8289 // unchanged
8390 if ( lastBlobMap . get ( id ) === base64 ) {
84- console . debug ( '[highlight-worker] canvas bitmap is unchanged' , {
91+ debug ( '[highlight-worker] canvas bitmap is unchanged' , {
8592 id,
8693 base64,
8794 } ) ;
8895 return worker . postMessage ( { id, status : 'unchanged' } ) ;
8996 }
90- console . debug ( '[highlight-worker] canvas bitmap processed' , {
97+ debug ( '[highlight-worker] canvas bitmap processed' , {
9198 id,
9299 base64,
93100 } ) ;
@@ -104,7 +111,7 @@ worker.onmessage = async function (e) {
104111 } ) ;
105112 lastBlobMap . set ( id , base64 ) ;
106113 } else {
107- console . debug ( '[highlight-worker] no offscreencanvas support' , {
114+ debug ( '[highlight-worker] no offscreencanvas support' , {
108115 id : e . data . id ,
109116 } ) ;
110117 return worker . postMessage ( { id : e . data . id , status : 'unsupported' } ) ;
0 commit comments