// WASM loader for Rhai CodeMirror mode import init, { RhaiMode, init_codemirror_pass } from '@/wasm/rhai-codemirror/rhai_codemirror.js'; let wasmInitialized = false; let wasmModule: any = null; export const loadRhaiWasm = async () => { if (wasmInitialized) { return wasmModule; } try { // Initialize the WASM module wasmModule = await init(); wasmInitialized = true; return wasmModule; } catch (error) { console.error('Failed to load Rhai WASM module:', error); throw error; } }; export const initRhaiMode = (CodeMirror: any) => { if (!wasmInitialized || !wasmModule) { throw new Error('WASM module not loaded. Call loadRhaiWasm() first.'); } // Initialize CodeMirror Pass for the WASM module init_codemirror_pass(CodeMirror.Pass); // Define the Rhai mode using the WASM-based RhaiMode CodeMirror.defineMode("rhai", (config: any) => { return new RhaiMode(config.indentUnit || 4); }); }; export { RhaiMode };