import { wrap } from 'comlink';
import { workerCode } from '../workers/worker-code';
let url;
/**
 * Asynchronously creates and returns a Remote<MatrixRenderer> instance.
 * This function simplifies the process of creating and accessing MatrixRenderer instances.
 */
export const createMatrixRenderer = async () => {
    if (url === undefined) {
        const blob = new Blob([workerCode], { type: 'text/javascript' });
        url = URL.createObjectURL(blob);
    }
    const worker = new Worker(url);
    // eslint-disable-next-line @typescript-eslint/naming-convention
    const RemoteMatrixRenderer = wrap(worker);
    const matrixRenderer = await new RemoteMatrixRenderer();
    const terminate = () => worker.terminate();
    return {
        matrixRenderer,
        terminate
    };
};
//# sourceMappingURL=create-matrix-renderer.js.map