import * as vizLite from 'viz.js/viz-lite' ; import { parsePlain } from './dot-layout' ; const ctx = self as any ; const fns = { vizLite , generateDotGraph , } ; function generateDotGraph ( digraph ) { const plain = vizLite ( digraph , { format : 'plain' , totalMemory : 16777216 * 4 , } ) ; return parsePlain ( plain ) ; } ctx . addEventListener ( 'message' , ( { data } ) => { const { fn , args , id } = data ; try { const result = fns [ fn ] ( ... args ) ; ctx . postMessage ( { id , result , } ) ; } catch ( error ) { ctx . postMessage ( { id , error , } ) ; } } ) ; ctx . postMessage ( { message : 'Hello from worker!' } ) ;