import { processPdf, renderProcess, svgToPng } from '../src/tools/mapper/render';
import type { ProcessState } from '../src/tools/mapper/core';

declare global { interface Window { essentialRender: (state: ProcessState, format: 'svg' | 'png' | 'pdf') => Promise<{ data: number[]; width: number; height: number }> } }
window.essentialRender = async (state, format) => {
  const render = await renderProcess(state, { id: 'essential-cli-process', container: document.getElementById('stage')! });
  const bytes = format === 'svg' ? new TextEncoder().encode(render.svg) : format === 'png' ? await svgToPng(render.svg) : await processPdf(render);
  return { data: Array.from(bytes), width: render.width, height: render.height };
};
