/*global Viz: false */

this.importScripts('{{ script_source }}');

this.onmessage = async (message) => {
  const dotUrl = message.data;
  if (!dotUrl) return;

  try {
    const response = await fetch(dotUrl);
    const dot = await response.text();
    const svg = Viz(dot, {format: 'svg', engine: 'dot'});
    this.postMessage(svg);
  } catch (e) {
    console.log('dotUrl',dotUrl);
    console.error('Error:', e);
  }
};
