var S=Object.defineProperty;var F=(s,r,a)=>r in s?S(s,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[r]=a;var m=(s,r,a)=>(F(s,typeof r!="symbol"?r+"":r,a),a);(function(){"use strict";const s="notebook.py";async function r(e,o){const t="/marimo";return await e.FS.mkdir(t),await e.FS.mount(e.FS.filesystems.IDBFS,{root:"."},t),e.runPython(`
  import os
  os.chdir('/marimo')
  `),await e.FS.analyzePath(s).exists||await e.FS.writeFile(s,o,{encoding:"utf8"}),o||""}const a={debug:(...e)=>{},log:(...e)=>{console.log(...e)},warn:(...e)=>{console.warn(...e)},error:(...e)=>{console.error(...e)}};async function u(){if(!loadPyodide)throw new Error("loadPyodide is not defined");const e=await loadPyodide();await e.loadPackage("micropip");const o=`${window.location.origin}/registry`;return await e.runPythonAsync(`
    import micropip

    micropip.add_mock_package("multiprocessing", "*", modules={
        "multiprocessing": None,
        "multiprocessing.connection": None,
        "multiprocessing.context": None,
        "multiprocessing.managers": None,
        "multiprocessing.pool": None,
        "multiprocessing.sharedctypes": None,
        "multiprocessing.shared_memory": None,
        "multiprocessing.spawn": None,
    })

    await micropip.install(
      [
        # Subset of marimo requirements
        "${o}/marimo-0.2.4-py3-none-any.whl",
        "markdown",
        "jedi",
        "docutils",
        "pymdown-extensions",
        "pygments",
      ],
      deps=False
    );
  `),e}async function f(e,o){return await r(e,o),await e.loadPackagesFromImports(o,{messageCallback:a.log,errorCallback:a.error}),await e.runPythonAsync(`
      print("[py] Starting marimo...")
      import asyncio
      from marimo._pyodide.pyodide_session import create_session, instantiate

      session, bridge = create_session(filename="${s}")
      instantiate(session)
      asyncio.create_task(session.start())

      bridge`)}function w(e,o){if(!e)throw new Error(o)}class h{constructor(){m(this,"promise");m(this,"resolve");m(this,"reject");this.promise=new Promise((o,t)=>{this.reject=t,this.resolve=o})}}async function k(){await import("https://cdn.jsdelivr.net/pyodide/v0.25.0/full/pyodide.js"),self.pyodide=await u()}const P=k(),d=new h;let g=!1;function b(e){g||(g=!0,f(self.pyodide,e).then(o=>{d.resolve(o),n({type:"initialized"})}))}async function y(){return d.promise}self.onmessage=async e=>{if(await P,e.data.type==="set-code"){b(e.data.code);return}if(e.data.type==="start-messages"){for(;;){const p=await y();for await(const l of p)n({type:"message",message:l})}return}const{id:o,functionName:t,payload:c}=e.data;try{if(t==="load_packages"){w(typeof c=="string","Expected a string payload for load_packages"),await self.pyodide.loadPackagesFromImports(c,{messageCallback:console.log,errorCallback:console.error}),n({type:"response",response:null,id:o});return}const i=await y(),p=c==null?null:typeof c=="string"?c:JSON.stringify(c),l=p==null?await i[t]():await i[t](p);n({type:"response",response:typeof l=="string"?JSON.parse(l):l,id:o})}catch(i){console.error("Error in worker",i),i instanceof Error?n({type:"error",error:i.message,id:o}):n({type:"error",error:String(i),id:o})}};function n(e){self.postMessage(e)}n({type:"ready"})})();
