license declare global { function importScripts ( ... urls ) ; } import { BarcodeWasmModule } from '../../defs/barcode.js' ; import { DEBUG_LEVEL , enableLogLevel , log } from '../utils/logger.js' ; function getDetectorModule ( ) { return ( self as any ) . Module as BarcodeWasmModule ; } enableLogLevel ( DEBUG_LEVEL . WARNING ) ; class WasmBarcodeDetector { process ( data ) { const Module = getDetectorModule ( ) ; const fileData = data . data ; const buffer = Module . _malloc ( fileData . length ) ; Module . HEAPU8 . set ( fileData , buffer ) ; const result = Module . readBarcodeFromPng ( data . data , data . width , data . height ) ; Module . _free ( buffer ) ; if ( result . text && result . format ) { return [ { rawValue : result . text , format : result . format . toLowerCase ( ) } ] ; } return [ ] ; } } const detector = new WasmBarcodeDetector ( ) ; self . onmessage = ( e ) => { if ( typeof e . data === 'string' ) { const pathPrefix = e . data ; ( self as any ) . Module = { locateFile ( url ) { if ( url . endsWith ( '.wasm' ) ) { return `${ pathPrefix }third_party/zxing/${ url }` ; } return url ; } , onRuntimeInitialized ( ) { ( self as any ) . postMessage ( 'ready' ) ; } } as BarcodeWasmModule ; if ( 'importScripts' in self ) { importScripts ( `${ pathPrefix }third_party/zxing/zxing_reader.js` ) ; } return ; } const data = detector . process ( e . data ) ; ( self as any ) . postMessage ( data ) ; } ;