@stlite/desktop 0.58.0 → 0.58.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "/static/css/main.6fb7674e.css",
4
- "main.js": "/static/js/main.e800a125.js",
5
- "static/js/2921.32cf8135.chunk.js": "/static/js/2921.32cf8135.chunk.js",
4
+ "main.js": "/static/js/main.0dfc6435.js",
5
+ "static/js/8798.2b850d38.chunk.js": "/static/js/8798.2b850d38.chunk.js",
6
6
  "static/js/4994.2d981099.chunk.js": "/static/js/4994.2d981099.chunk.js",
7
7
  "static/js/3685.39209b63.chunk.js": "/static/js/3685.39209b63.chunk.js",
8
8
  "static/js/4785.0c41f474.chunk.js": "/static/js/4785.0c41f474.chunk.js",
@@ -163,6 +163,6 @@
163
163
  },
164
164
  "entrypoints": [
165
165
  "static/css/main.6fb7674e.css",
166
- "static/js/main.e800a125.js"
166
+ "static/js/main.0dfc6435.js"
167
167
  ]
168
168
  }
@@ -1,2 +1,2 @@
1
1
  var Je=Object.create;var Y=Object.defineProperty;var Ce=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,He=Object.prototype.hasOwnProperty;var Le=(i,a)=>()=>(a||i((a={exports:{}}).exports,a),a.exports);var qe=(i,a,f,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let g of Ue(a))!He.call(i,g)&&g!==f&&Y(i,g,{get:()=>a[g],enumerable:!(c=Ce(a,g))||c.enumerable});return i};var M=(i,a,f)=>(f=i!=null?Je(Be(i)):{},qe(a||!i||!i.__esModule?Y(f,"default",{value:i,enumerable:!0}):f,i));var Z=Le((R,X)=>{(function(i,a){typeof R=="object"&&typeof X<"u"?a(R):typeof define=="function"&&define.amd?define(["exports"],a):(i=typeof globalThis<"u"?globalThis:i||self,a(i.Superstruct={}))})(R,function(i){"use strict";class a extends TypeError{constructor(n,t){let r,{message:o,explanation:s,...d}=n,{path:h}=n,b=h.length===0?o:`At path: ${h.join(".")} -- ${o}`;super(s??b),s!=null&&(this.cause=b),Object.assign(this,d),this.name=this.constructor.name,this.failures=()=>r??(r=[n,...t()])}}function f(e){return c(e)&&typeof e[Symbol.iterator]=="function"}function c(e){return typeof e=="object"&&e!=null}function g(e){if(Object.prototype.toString.call(e)!=="[object Object]")return!1;let n=Object.getPrototypeOf(e);return n===null||n===Object.prototype}function p(e){return typeof e=="symbol"?e.toString():typeof e=="string"?JSON.stringify(e):`${e}`}function E(e){let{done:n,value:t}=e.next();return n?void 0:t}function _(e,n,t,r){if(e===!0)return;e===!1?e={}:typeof e=="string"&&(e={message:e});let{path:o,branch:s}=n,{type:d}=t,{refinement:h,message:b=`Expected a value of type \`${d}\`${h?` with refinement \`${h}\``:""}, but received: \`${p(r)}\``}=e;return{value:r,type:d,refinement:h,key:o[o.length-1],path:o,branch:s,...e,message:b}}function*w(e,n,t,r){f(e)||(e=[e]);for(let o of e){let s=_(o,n,t,r);s&&(yield s)}}function*k(e,n,t={}){let{path:r=[],branch:o=[e],coerce:s=!1,mask:d=!1}=t,h={path:r,branch:o};if(s&&(e=n.coercer(e,h),d&&n.type!=="type"&&c(n.schema)&&c(e)&&!Array.isArray(e)))for(let m in e)n.schema[m]===void 0&&delete e[m];let b="valid";for(let m of n.validator(e,h))m.explanation=t.message,b="not_valid",yield[m,void 0];for(let[m,S,Re]of n.entries(e,h)){let ve=k(S,Re,{path:m===void 0?r:[...r,m],branch:m===void 0?o:[...o,S],coerce:s,mask:d,message:t.message});for(let W of ve)W[0]?(b=W[0].refinement!=null?"not_refined":"not_valid",yield[W[0],void 0]):s&&(S=W[1],m===void 0?e=S:e instanceof Map?e.set(m,S):e instanceof Set?e.add(S):c(e)&&(S!==void 0||m in e)&&(e[m]=S))}if(b!=="not_valid")for(let m of n.refiner(e,h))m.explanation=t.message,b="not_refined",yield[m,void 0];b==="valid"&&(yield[void 0,e])}class u{constructor(n){let{type:t,schema:r,validator:o,refiner:s,coercer:d=b=>b,entries:h=function*(){}}=n;this.type=t,this.schema=r,this.entries=h,this.coercer=d,o?this.validator=(b,m)=>{let S=o(b,m);return w(S,m,this,b)}:this.validator=()=>[],s?this.refiner=(b,m)=>{let S=s(b,m);return w(S,m,this,b)}:this.refiner=()=>[]}assert(n,t){return $(n,this,t)}create(n,t){return z(n,this,t)}is(n){return v(n,this)}mask(n,t){return T(n,this,t)}validate(n,t={}){return A(n,this,t)}}function $(e,n,t){let r=A(e,n,{message:t});if(r[0])throw r[0]}function z(e,n,t){let r=A(e,n,{coerce:!0,message:t});if(r[0])throw r[0];return r[1]}function T(e,n,t){let r=A(e,n,{coerce:!0,mask:!0,message:t});if(r[0])throw r[0];return r[1]}function v(e,n){return!A(e,n)[0]}function A(e,n,t={}){let r=k(e,n,t),o=E(r);return o[0]?[new a(o[0],function*(){for(let d of r)d[0]&&(yield d[0])}),void 0]:[void 0,o[1]]}function te(...e){let n=e[0].type==="type",t=e.map(o=>o.schema),r=Object.assign({},...t);return n?I(r):F(r)}function P(e,n){return new u({type:e,schema:null,validator:n})}function re(e,n){return new u({...e,refiner:(t,r)=>t===void 0||e.refiner(t,r),validator(t,r){return t===void 0?!0:(n(t,r),e.validator(t,r))}})}function ie(e){return new u({type:"dynamic",schema:null,*entries(n,t){yield*e(n,t).entries(n,t)},validator(n,t){return e(n,t).validator(n,t)},coercer(n,t){return e(n,t).coercer(n,t)},refiner(n,t){return e(n,t).refiner(n,t)}})}function oe(e){let n;return new u({type:"lazy",schema:null,*entries(t,r){n??(n=e()),yield*n.entries(t,r)},validator(t,r){return n??(n=e()),n.validator(t,r)},coercer(t,r){return n??(n=e()),n.coercer(t,r)},refiner(t,r){return n??(n=e()),n.refiner(t,r)}})}function se(e,n){let{schema:t}=e,r={...t};for(let o of n)delete r[o];switch(e.type){case"type":return I(r);default:return F(r)}}function ae(e){let n=e instanceof u,t=n?{...e.schema}:{...e};for(let r in t)t[r]=H(t[r]);return n&&e.type==="type"?I(t):F(t)}function ce(e,n){let{schema:t}=e,r={};for(let o of n)r[o]=t[o];switch(e.type){case"type":return I(r);default:return F(r)}}function fe(e,n){return console.warn("superstruct@0.11 - The `struct` helper has been renamed to `define`."),P(e,n)}function de(){return P("any",()=>!0)}function ue(e){return new u({type:"array",schema:e,*entries(n){if(e&&Array.isArray(n))for(let[t,r]of n.entries())yield[t,r,e]},coercer(n){return Array.isArray(n)?n.slice():n},validator(n){return Array.isArray(n)||`Expected an array value, but received: ${p(n)}`}})}function le(){return P("bigint",e=>typeof e=="bigint")}function pe(){return P("boolean",e=>typeof e=="boolean")}function me(){return P("date",e=>e instanceof Date&&!isNaN(e.getTime())||`Expected a valid \`Date\` object, but received: ${p(e)}`)}function ye(e){let n={},t=e.map(r=>p(r)).join();for(let r of e)n[r]=r;return new u({type:"enums",schema:n,validator(r){return e.includes(r)||`Expected one of \`${t}\`, but received: ${p(r)}`}})}function he(){return P("func",e=>typeof e=="function"||`Expected a function, but received: ${p(e)}`)}function be(e){return P("instance",n=>n instanceof e||`Expected a \`${e.name}\` instance, but received: ${p(n)}`)}function ge(){return P("integer",e=>typeof e=="number"&&!isNaN(e)&&Number.isInteger(e)||`Expected an integer, but received: ${p(e)}`)}function we(e){return new u({type:"intersection",schema:null,*entries(n,t){for(let r of e)yield*r.entries(n,t)},*validator(n,t){for(let r of e)yield*r.validator(n,t)},*refiner(n,t){for(let r of e)yield*r.refiner(n,t)}})}function ke(e){let n=p(e),t=typeof e;return new u({type:"literal",schema:t==="string"||t==="number"||t==="boolean"?e:null,validator(r){return r===e||`Expected the literal \`${n}\`, but received: ${p(r)}`}})}function $e(e,n){return new u({type:"map",schema:null,*entries(t){if(e&&n&&t instanceof Map)for(let[r,o]of t.entries())yield[r,r,e],yield[r,o,n]},coercer(t){return t instanceof Map?new Map(t):t},validator(t){return t instanceof Map||`Expected a \`Map\` object, but received: ${p(t)}`}})}function J(){return P("never",()=>!1)}function Pe(e){return new u({...e,validator:(n,t)=>n===null||e.validator(n,t),refiner:(n,t)=>n===null||e.refiner(n,t)})}function je(){return P("number",e=>typeof e=="number"&&!isNaN(e)||`Expected a number, but received: ${p(e)}`)}function F(e){let n=e?Object.keys(e):[],t=J();return new u({type:"object",schema:e||null,*entries(r){if(e&&c(r)){let o=new Set(Object.keys(r));for(let s of n)o.delete(s),yield[s,r[s],e[s]];for(let s of o)yield[s,r[s],t]}},validator(r){return c(r)||`Expected an object, but received: ${p(r)}`},coercer(r){return c(r)?{...r}:r}})}function H(e){return new u({...e,validator:(n,t)=>n===void 0||e.validator(n,t),refiner:(n,t)=>n===void 0||e.refiner(n,t)})}function Ee(e,n){return new u({type:"record",schema:null,*entries(t){if(c(t))for(let r in t){let o=t[r];yield[r,r,e],yield[r,o,n]}},validator(t){return c(t)||`Expected an object, but received: ${p(t)}`}})}function Se(){return P("regexp",e=>e instanceof RegExp)}function _e(e){return new u({type:"set",schema:null,*entries(n){if(e&&n instanceof Set)for(let t of n)yield[t,t,e]},coercer(n){return n instanceof Set?new Set(n):n},validator(n){return n instanceof Set||`Expected a \`Set\` object, but received: ${p(n)}`}})}function L(){return P("string",e=>typeof e=="string"||`Expected a string, but received: ${p(e)}`)}function Me(e){let n=J();return new u({type:"tuple",schema:null,*entries(t){if(Array.isArray(t)){let r=Math.max(e.length,t.length);for(let o=0;o<r;o++)yield[o,t[o],e[o]||n]}},validator(t){return Array.isArray(t)||`Expected an array, but received: ${p(t)}`}})}function I(e){let n=Object.keys(e);return new u({type:"type",schema:e,*entries(t){if(c(t))for(let r of n)yield[r,t[r],e[r]]},validator(t){return c(t)||`Expected an object, but received: ${p(t)}`},coercer(t){return c(t)?{...t}:t}})}function Ne(e){let n=e.map(t=>t.type).join(" | ");return new u({type:"union",schema:null,coercer(t){for(let r of e){let[o,s]=r.validate(t,{coerce:!0});if(!o)return s}return t},validator(t,r){let o=[];for(let s of e){let[...d]=k(t,s,r),[h]=d;if(h[0])for(let[b]of d)b&&o.push(b);else return[]}return[`Expected the value to satisfy a union of \`${n}\`, but received: ${p(t)}`,...o]}})}function q(){return P("unknown",()=>!0)}function C(e,n,t){return new u({...e,coercer:(r,o)=>v(r,n)?e.coercer(t(r,o),o):e.coercer(r,o)})}function Oe(e,n,t={}){return C(e,q(),r=>{let o=typeof n=="function"?n():n;if(r===void 0)return o;if(!t.strict&&g(r)&&g(o)){let s={...r},d=!1;for(let h in o)s[h]===void 0&&(s[h]=o[h],d=!0);if(d)return s}return r})}function Ae(e){return C(e,L(),n=>n.trim())}function De(e){return O(e,"empty",n=>{let t=V(n);return t===0||`Expected an empty ${e.type} but received one with a size of \`${t}\``})}function V(e){return e instanceof Map||e instanceof Set?e.size:e.length}function Fe(e,n,t={}){let{exclusive:r}=t;return O(e,"max",o=>r?o<n:o<=n||`Expected a ${e.type} less than ${r?"":"or equal to "}${n} but received \`${o}\``)}function Ie(e,n,t={}){let{exclusive:r}=t;return O(e,"min",o=>r?o>n:o>=n||`Expected a ${e.type} greater than ${r?"":"or equal to "}${n} but received \`${o}\``)}function ze(e){return O(e,"nonempty",n=>V(n)>0||`Expected a nonempty ${e.type} but received an empty one`)}function Te(e,n){return O(e,"pattern",t=>n.test(t)||`Expected a ${e.type} matching \`/${n.source}/\` but received "${t}"`)}function We(e,n,t=n){let r=`Expected a ${e.type}`,o=n===t?`of \`${n}\``:`between \`${n}\` and \`${t}\``;return O(e,"size",s=>{if(typeof s=="number"||s instanceof Date)return n<=s&&s<=t||`${r} ${o} but received \`${s}\``;if(s instanceof Map||s instanceof Set){let{size:d}=s;return n<=d&&d<=t||`${r} with a size ${o} but received one with a size of \`${d}\``}else{let{length:d}=s;return n<=d&&d<=t||`${r} with a length ${o} but received one with a length of \`${d}\``}})}function O(e,n,t){return new u({...e,*refiner(r,o){yield*e.refiner(r,o);let s=t(r,o),d=w(s,o,e,r);for(let h of d)yield{...h,refinement:n}}})}i.Struct=u,i.StructError=a,i.any=de,i.array=ue,i.assert=$,i.assign=te,i.bigint=le,i.boolean=pe,i.coerce=C,i.create=z,i.date=me,i.defaulted=Oe,i.define=P,i.deprecated=re,i.dynamic=ie,i.empty=De,i.enums=ye,i.func=he,i.instance=be,i.integer=ge,i.intersection=we,i.is=v,i.lazy=oe,i.literal=ke,i.map=$e,i.mask=T,i.max=Fe,i.min=Ie,i.never=J,i.nonempty=ze,i.nullable=Pe,i.number=je,i.object=F,i.omit=se,i.optional=H,i.partial=ae,i.pattern=Te,i.pick=ce,i.record=Ee,i.refine=O,i.regexp=Se,i.set=_e,i.size=We,i.string=L,i.struct=fe,i.trimmed=Ae,i.tuple=Me,i.type=I,i.union=Ne,i.unknown=q,i.validate=A})});var l=require("electron"),j=M(require("path")),U=M(require("fs/promises")),B=M(require("node:worker_threads"));var D=M(require("fs/promises")),N=M(require("path"));async function G(i){let a={},f=await D.readdir(i);return await Promise.all(f.map(async c=>{let g=N.join(i,c);if((await D.stat(g)).isDirectory()){let E=await G(g);Object.assign(a,E)}else{let E=await D.readFile(g);a[g]=E}})),a}async function Q(i){let a=await G(i),f={};return Object.keys(a).forEach(c=>{let p=N.relative(i,c).split(N.sep).join(N.posix.sep);f[p]=a[c]}),f}var K=M(require("path")),x=M(require("fs/promises")),y=M(Z()),Ve=y.object({entrypoint:y.string(),embed:y.defaulted(y.boolean(),!1),idbfsMountpoints:y.optional(y.array(y.string())),nodeJsWorker:y.defaulted(y.boolean(),!1),nodefsMountpoints:y.optional(y.record(y.string(),y.string()))});async function ee(){let i=K.resolve(__dirname,"../stlite-manifest.json"),a=await x.readFile(i,{encoding:"utf-8"}),f=JSON.parse(a);return y.assert(f,Ve),f}var ne=async()=>{let i=await ee(),a=[];a.push(`--entrypoint=${JSON.stringify(i.entrypoint)}`),i.idbfsMountpoints&&a.push(`--idbfs-mountpoints=${JSON.stringify(i.idbfsMountpoints)}`),i.nodeJsWorker&&a.push("--nodejs-worker");let f=new l.BrowserWindow({width:1280,height:720,webPreferences:{preload:j.join(__dirname,"preload.js"),sandbox:!0,additionalArguments:a}}),c=new URL((l.app.isPackaged,"file:///index.html")),g=new URLSearchParams;i.embed&&g.set("embed","true"),c.search=g.toString();let p=c.toString(),E=w=>w.url===p;l.ipcMain.handle("readSitePackagesSnapshot",w=>{if(!E(w.senderFrame))throw new Error("Invalid IPC sender");let k=j.resolve(__dirname,"../site-packages-snapshot.tar.gz");return U.readFile(k)}),l.ipcMain.handle("readPrebuiltPackageNames",async w=>{if(!E(w.senderFrame))throw new Error("Invalid IPC sender");let k=j.resolve(__dirname,"../prebuilt-packages.txt");return(await U.readFile(k,{encoding:"utf-8"})).split(`
2
- `).map($=>$.trim()).filter($=>$.length>0)}),l.ipcMain.handle("readStreamlitAppDirectory",async w=>{if(!E(w.senderFrame))throw new Error("Invalid IPC sender");let k=j.resolve(__dirname,"../app_files");return Q(k)}),f.on("closed",()=>{l.ipcMain.removeHandler("readSitePackagesSnapshot"),l.ipcMain.removeHandler("readPrebuiltPackageNames"),l.ipcMain.removeHandler("readStreamlitAppDirectory")});let _=null;l.ipcMain.handle("initializeNodeJsWorker",w=>{if(!E(w.senderFrame))throw new Error("Invalid IPC sender");let k=j.resolve(__dirname,"../pyodide/pyodide.mjs");function u($){f.webContents.send("messageFromNodeJsWorker",$)}_=new B.default.Worker(j.resolve(__dirname,"./worker.js"),{env:{PYODIDE_URL:k,...i.nodefsMountpoints&&{NODEFS_MOUNTPOINTS:JSON.stringify(i.nodefsMountpoints)}}}),_.on("message",$=>{u($)})}),l.ipcMain.on("messageToNodeJsWorker",(w,{data:k,portId:u})=>{if(!E(w.senderFrame))throw new Error("Invalid IPC sender");if(_==null)return;let $=new B.default.MessageChannel;$.port1.on("message",T=>{w.reply(`nodeJsWorker-portMessage-${u}`,T)});let z={data:k,port:$.port2};_.postMessage(z,[$.port2])}),l.ipcMain.handle("terminate",(w,{data:k,portId:u})=>{if(!E(w.senderFrame))throw new Error("Invalid IPC sender");_?.terminate(),_=null}),f.on("closed",()=>{l.ipcMain.removeHandler("initializeNodeJsWorker"),l.ipcMain.removeHandler("messageToNodeJsWorker"),l.ipcMain.removeHandler("terminate")}),f.loadURL(p),l.app.isPackaged||f.webContents.openDevTools()};l.app.enableSandbox();l.app.whenReady().then(()=>{let i=j.resolve(__dirname,"..");l.protocol.interceptFileProtocol("file",function(a,f){let c=new URL(a.url).pathname;if(j.isAbsolute(c)){let g=j.join(i,c);f(j.normalize(g))}else f(c)}),ne(),l.app.on("activate",()=>{l.BrowserWindow.getAllWindows().length===0&&ne()})});l.app.on("window-all-closed",()=>{process.platform!=="darwin"&&l.app.quit()});l.app.on("web-contents-created",(i,a)=>{a.on("will-attach-webview",(f,c,g)=>{f.preventDefault()}),a.on("will-navigate",(f,c)=>{console.debug("will-navigate",c),f.preventDefault()}),a.setWindowOpenHandler(({url:f})=>(console.error("Opening a new window is not allowed."),{action:"deny"}))});
2
+ `).map($=>$.trim()).filter($=>$.length>0)}),l.ipcMain.handle("readStreamlitAppDirectory",async w=>{if(!E(w.senderFrame))throw new Error("Invalid IPC sender");let k=j.resolve(__dirname,"../app_files");return Q(k)}),f.on("closed",()=>{l.ipcMain.removeHandler("readSitePackagesSnapshot"),l.ipcMain.removeHandler("readPrebuiltPackageNames"),l.ipcMain.removeHandler("readStreamlitAppDirectory")});let _=null;l.ipcMain.handle("initializeNodeJsWorker",w=>{if(!E(w.senderFrame))throw new Error("Invalid IPC sender");let k=j.resolve(__dirname,"..","pyodide","pyodide.mjs");function u($){f.webContents.send("messageFromNodeJsWorker",$)}_=new B.default.Worker(j.resolve(__dirname,"worker.js"),{env:{PYODIDE_URL:k,...i.nodefsMountpoints&&{NODEFS_MOUNTPOINTS:JSON.stringify(i.nodefsMountpoints)}}}),_.on("message",$=>{u($)})}),l.ipcMain.on("messageToNodeJsWorker",(w,{data:k,portId:u})=>{if(!E(w.senderFrame))throw new Error("Invalid IPC sender");if(_==null)return;let $=new B.default.MessageChannel;$.port1.on("message",T=>{w.reply(`nodeJsWorker-portMessage-${u}`,T)});let z={data:k,port:$.port2};_.postMessage(z,[$.port2])}),l.ipcMain.handle("terminate",(w,{data:k,portId:u})=>{if(!E(w.senderFrame))throw new Error("Invalid IPC sender");_?.terminate(),_=null}),f.on("closed",()=>{l.ipcMain.removeHandler("initializeNodeJsWorker"),l.ipcMain.removeHandler("messageToNodeJsWorker"),l.ipcMain.removeHandler("terminate")}),f.loadURL(p),l.app.isPackaged||f.webContents.openDevTools()};l.app.enableSandbox();l.app.whenReady().then(()=>{let i=j.resolve(__dirname,"..");l.protocol.interceptFileProtocol("file",function(a,f){let c=new URL(a.url).pathname;if(j.isAbsolute(c)){let g=j.join(i,c);f(j.normalize(g))}else f(c)}),ne(),l.app.on("activate",()=>{l.BrowserWindow.getAllWindows().length===0&&ne()})});l.app.on("window-all-closed",()=>{process.platform!=="darwin"&&l.app.quit()});l.app.on("web-contents-created",(i,a)=>{a.on("will-attach-webview",(f,c,g)=>{f.preventDefault()}),a.on("will-navigate",(f,c)=>{console.debug("will-navigate",c),f.preventDefault()}),a.setWindowOpenHandler(({url:f})=>(console.error("Opening a new window is not allowed."),{action:"deny"}))});
@@ -1,5 +1,5 @@
1
- var fe=Object.create;var K=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var M=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var he=(o,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of pe(e))!ye.call(o,r)&&r!==t&&K(o,r,{get:()=>e[r],enumerable:!(s=me(e,r))||s.enumerable});return o};var V=(o,e,t)=>(t=o!=null?fe(_e(o)):{},he(e||!o||!o.__esModule?K(t,"default",{value:o,enumerable:!0}):t,o));var X=M(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.validateRequirements=void 0;var ve="[",be="(<=>!~",Pe=";",we="@",Se=new RegExp(`[${ve+be+Pe+we}]`);function ke(o){return o.split(Se)[0].trim()}function Ae(o){return o.forEach(t=>{let s;try{s=new URL(t)}catch{return}if(s.protocol==="emfs:"||s.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)}),o.filter(t=>ke(t)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${t}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}L.validateRequirements=Ae});var G=M(T=>{"use strict";Object.defineProperty(T,"__esModule",{value:!0});T.parseRequirementsTxt=void 0;var Fe=/\s#.*$/;function Re(o){return o.split(`
2
- `).filter(e=>!e.startsWith("#")).map(e=>e.replace(Fe,"")).map(e=>e.trim()).filter(e=>e!=="")}T.parseRequirementsTxt=Re});var Q=M(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.PromiseDelegate=void 0;var D=class{constructor(){this.promise=new Promise((e,t)=>{this.resolveInternal=e,this.rejectInternal=t})}resolve(e){this.resolveInternal(e)}reject(e){this.rejectInternal(e)}};N.PromiseDelegate=D});var Y=M(w=>{"use strict";var Me=w&&w.__createBinding||(Object.create?function(o,e,t,s){s===void 0&&(s=t);var r=Object.getOwnPropertyDescriptor(e,t);(!r||("get"in r?!e.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(o,s,r)}:function(o,e,t,s){s===void 0&&(s=t),o[s]=e[t]}),q=w&&w.__exportStar||function(o,e){for(var t in o)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Me(e,o,t)};Object.defineProperty(w,"__esModule",{value:!0});q(X(),w);q(G(),w);q(Q(),w)});var te=M((Je,ee)=>{"use strict";function b(o){if(typeof o!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(o))}function Z(o,e){for(var t="",s=0,r=-1,a=0,n,i=0;i<=o.length;++i){if(i<o.length)n=o.charCodeAt(i);else{if(n===47)break;n=47}if(n===47){if(!(r===i-1||a===1))if(r!==i-1&&a===2){if(t.length<2||s!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){var l=t.lastIndexOf("/");if(l!==t.length-1){l===-1?(t="",s=0):(t=t.slice(0,l),s=t.length-1-t.lastIndexOf("/")),r=i,a=0;continue}}else if(t.length===2||t.length===1){t="",s=0,r=i,a=0;continue}}e&&(t.length>0?t+="/..":t="..",s=2)}else t.length>0?t+="/"+o.slice(r+1,i):t=o.slice(r+1,i),s=i-r-1;r=i,a=0}else n===46&&a!==-1?++a:a=-1}return t}function Oe(o,e){var t=e.dir||e.root,s=e.base||(e.name||"")+(e.ext||"");return t?t===e.root?t+s:t+o+s:s}var F={resolve:function(){for(var e="",t=!1,s,r=arguments.length-1;r>=-1&&!t;r--){var a;r>=0?a=arguments[r]:(s===void 0&&(s=process.cwd()),a=s),b(a),a.length!==0&&(e=a+"/"+e,t=a.charCodeAt(0)===47)}return e=Z(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(b(e),e.length===0)return".";var t=e.charCodeAt(0)===47,s=e.charCodeAt(e.length-1)===47;return e=Z(e,!t),e.length===0&&!t&&(e="."),e.length>0&&s&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return b(e),e.length>0&&e.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var s=arguments[t];b(s),s.length>0&&(e===void 0?e=s:e+="/"+s)}return e===void 0?".":F.normalize(e)},relative:function(e,t){if(b(e),b(t),e===t||(e=F.resolve(e),t=F.resolve(t),e===t))return"";for(var s=1;s<e.length&&e.charCodeAt(s)===47;++s);for(var r=e.length,a=r-s,n=1;n<t.length&&t.charCodeAt(n)===47;++n);for(var i=t.length,l=i-n,_=a<l?a:l,u=-1,c=0;c<=_;++c){if(c===_){if(l>_){if(t.charCodeAt(n+c)===47)return t.slice(n+c+1);if(c===0)return t.slice(n+c)}else a>_&&(e.charCodeAt(s+c)===47?u=c:c===0&&(u=0));break}var S=e.charCodeAt(s+c),p=t.charCodeAt(n+c);if(S!==p)break;S===47&&(u=c)}var d="";for(c=s+u+1;c<=r;++c)(c===r||e.charCodeAt(c)===47)&&(d.length===0?d+="..":d+="/..");return d.length>0?d+t.slice(n+u):(n+=u,t.charCodeAt(n)===47&&++n,t.slice(n))},_makeLong:function(e){return e},dirname:function(e){if(b(e),e.length===0)return".";for(var t=e.charCodeAt(0),s=t===47,r=-1,a=!0,n=e.length-1;n>=1;--n)if(t=e.charCodeAt(n),t===47){if(!a){r=n;break}}else a=!1;return r===-1?s?"/":".":s&&r===1?"//":e.slice(0,r)},basename:function(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');b(e);var s=0,r=-1,a=!0,n;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var i=t.length-1,l=-1;for(n=e.length-1;n>=0;--n){var _=e.charCodeAt(n);if(_===47){if(!a){s=n+1;break}}else l===-1&&(a=!1,l=n+1),i>=0&&(_===t.charCodeAt(i)?--i===-1&&(r=n):(i=-1,r=l))}return s===r?r=l:r===-1&&(r=e.length),e.slice(s,r)}else{for(n=e.length-1;n>=0;--n)if(e.charCodeAt(n)===47){if(!a){s=n+1;break}}else r===-1&&(a=!1,r=n+1);return r===-1?"":e.slice(s,r)}},extname:function(e){b(e);for(var t=-1,s=0,r=-1,a=!0,n=0,i=e.length-1;i>=0;--i){var l=e.charCodeAt(i);if(l===47){if(!a){s=i+1;break}continue}r===-1&&(a=!1,r=i+1),l===46?t===-1?t=i:n!==1&&(n=1):t!==-1&&(n=-1)}return t===-1||r===-1||n===0||n===1&&t===r-1&&t===s+1?"":e.slice(t,r)},format:function(e){if(e===null||typeof e!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return Oe("/",e)},parse:function(e){b(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var s=e.charCodeAt(0),r=s===47,a;r?(t.root="/",a=1):a=0;for(var n=-1,i=0,l=-1,_=!0,u=e.length-1,c=0;u>=a;--u){if(s=e.charCodeAt(u),s===47){if(!_){i=u+1;break}continue}l===-1&&(_=!1,l=u+1),s===46?n===-1?n=u:c!==1&&(c=1):n!==-1&&(c=-1)}return n===-1||l===-1||c===0||c===1&&n===l-1&&n===i+1?l!==-1&&(i===0&&r?t.base=t.name=e.slice(1,l):t.base=t.name=e.slice(i,l)):(i===0&&r?(t.name=e.slice(1,n),t.base=e.slice(1,l)):(t.name=e.slice(i,n),t.base=e.slice(i,l)),t.ext=e.slice(n,l)),i>0?t.dir=e.slice(0,i-1):r&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};F.posix=F;ee.exports=F});var W=require("node:worker_threads");var ie=V(Y());var U=V(te());function re(o,e){let t=U.default.normalize(e),r=U.default.dirname(t).split("/"),a=[];for(let n of r){a.push(n);let i=a.join("/");if(o.FS.analyzePath(i).exists){if(o.FS.isDir(i))throw new Error(`"${i}" already exists and is not a directory.`);continue}try{o.FS.mkdir(i)}catch(l){throw console.error(`Failed to create a directory "${i}"`),l}}}function $(o,e,t,s){re(o,e),o.FS.writeFile(e,t,s)}function oe(o,e,t){re(o,t),o.FS.rename(e,t)}var Ie="[",Ce="(<=>!~",Ee=";",Le="@",Te=new RegExp(`[${Ie+Ce+Ee+Le}]`);function Ne(o){return o.split(Te)[0].trim()}function H(o){return o.forEach(t=>{let s;try{s=new URL(t)}catch{return}if(s.protocol==="emfs:"||s.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)}),o.filter(t=>Ne(t)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${t}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}function j(o){o.runPython(`
1
+ var me=Object.create;var V=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var M=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ve=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _e(e))!he.call(r,o)&&o!==t&&V(r,o,{get:()=>e[o],enumerable:!(s=pe(e,o))||s.enumerable});return r};var I=(r,e,t)=>(t=r!=null?me(ye(r)):{},ve(e||!r||!r.__esModule?V(t,"default",{value:r,enumerable:!0}):t,r));var X=M(C=>{"use strict";Object.defineProperty(C,"__esModule",{value:!0});C.validateRequirements=void 0;var Pe="[",be="(<=>!~",we=";",Se="@",ke=new RegExp(`[${Pe+be+we+Se}]`);function Ae(r){return r.split(ke)[0].trim()}function Re(r){return r.forEach(t=>{let s;try{s=new URL(t)}catch{return}if(s.protocol==="emfs:"||s.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)}),r.filter(t=>Ae(t)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${t}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}C.validateRequirements=Re});var G=M(T=>{"use strict";Object.defineProperty(T,"__esModule",{value:!0});T.parseRequirementsTxt=void 0;var Fe=/\s#.*$/;function Me(r){return r.split(`
2
+ `).filter(e=>!e.startsWith("#")).map(e=>e.replace(Fe,"")).map(e=>e.trim()).filter(e=>e!=="")}T.parseRequirementsTxt=Me});var Q=M(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.PromiseDelegate=void 0;var U=class{constructor(){this.promise=new Promise((e,t)=>{this.resolveInternal=e,this.rejectInternal=t})}resolve(e){this.resolveInternal(e)}reject(e){this.rejectInternal(e)}};N.PromiseDelegate=U});var Y=M(w=>{"use strict";var Ie=w&&w.__createBinding||(Object.create?function(r,e,t,s){s===void 0&&(s=t);var o=Object.getOwnPropertyDescriptor(e,t);(!o||("get"in o?!e.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(r,s,o)}:function(r,e,t,s){s===void 0&&(s=t),r[s]=e[t]}),q=w&&w.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Ie(e,r,t)};Object.defineProperty(w,"__esModule",{value:!0});q(X(),w);q(G(),w);q(Q(),w)});var te=M((Ke,ee)=>{"use strict";function P(r){if(typeof r!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(r))}function Z(r,e){for(var t="",s=0,o=-1,a=0,n,i=0;i<=r.length;++i){if(i<r.length)n=r.charCodeAt(i);else{if(n===47)break;n=47}if(n===47){if(!(o===i-1||a===1))if(o!==i-1&&a===2){if(t.length<2||s!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){var l=t.lastIndexOf("/");if(l!==t.length-1){l===-1?(t="",s=0):(t=t.slice(0,l),s=t.length-1-t.lastIndexOf("/")),o=i,a=0;continue}}else if(t.length===2||t.length===1){t="",s=0,o=i,a=0;continue}}e&&(t.length>0?t+="/..":t="..",s=2)}else t.length>0?t+="/"+r.slice(o+1,i):t=r.slice(o+1,i),s=i-o-1;o=i,a=0}else n===46&&a!==-1?++a:a=-1}return t}function Oe(r,e){var t=e.dir||e.root,s=e.base||(e.name||"")+(e.ext||"");return t?t===e.root?t+s:t+r+s:s}var R={resolve:function(){for(var e="",t=!1,s,o=arguments.length-1;o>=-1&&!t;o--){var a;o>=0?a=arguments[o]:(s===void 0&&(s=process.cwd()),a=s),P(a),a.length!==0&&(e=a+"/"+e,t=a.charCodeAt(0)===47)}return e=Z(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(P(e),e.length===0)return".";var t=e.charCodeAt(0)===47,s=e.charCodeAt(e.length-1)===47;return e=Z(e,!t),e.length===0&&!t&&(e="."),e.length>0&&s&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return P(e),e.length>0&&e.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var s=arguments[t];P(s),s.length>0&&(e===void 0?e=s:e+="/"+s)}return e===void 0?".":R.normalize(e)},relative:function(e,t){if(P(e),P(t),e===t||(e=R.resolve(e),t=R.resolve(t),e===t))return"";for(var s=1;s<e.length&&e.charCodeAt(s)===47;++s);for(var o=e.length,a=o-s,n=1;n<t.length&&t.charCodeAt(n)===47;++n);for(var i=t.length,l=i-n,_=a<l?a:l,u=-1,c=0;c<=_;++c){if(c===_){if(l>_){if(t.charCodeAt(n+c)===47)return t.slice(n+c+1);if(c===0)return t.slice(n+c)}else a>_&&(e.charCodeAt(s+c)===47?u=c:c===0&&(u=0));break}var S=e.charCodeAt(s+c),p=t.charCodeAt(n+c);if(S!==p)break;S===47&&(u=c)}var d="";for(c=s+u+1;c<=o;++c)(c===o||e.charCodeAt(c)===47)&&(d.length===0?d+="..":d+="/..");return d.length>0?d+t.slice(n+u):(n+=u,t.charCodeAt(n)===47&&++n,t.slice(n))},_makeLong:function(e){return e},dirname:function(e){if(P(e),e.length===0)return".";for(var t=e.charCodeAt(0),s=t===47,o=-1,a=!0,n=e.length-1;n>=1;--n)if(t=e.charCodeAt(n),t===47){if(!a){o=n;break}}else a=!1;return o===-1?s?"/":".":s&&o===1?"//":e.slice(0,o)},basename:function(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');P(e);var s=0,o=-1,a=!0,n;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var i=t.length-1,l=-1;for(n=e.length-1;n>=0;--n){var _=e.charCodeAt(n);if(_===47){if(!a){s=n+1;break}}else l===-1&&(a=!1,l=n+1),i>=0&&(_===t.charCodeAt(i)?--i===-1&&(o=n):(i=-1,o=l))}return s===o?o=l:o===-1&&(o=e.length),e.slice(s,o)}else{for(n=e.length-1;n>=0;--n)if(e.charCodeAt(n)===47){if(!a){s=n+1;break}}else o===-1&&(a=!1,o=n+1);return o===-1?"":e.slice(s,o)}},extname:function(e){P(e);for(var t=-1,s=0,o=-1,a=!0,n=0,i=e.length-1;i>=0;--i){var l=e.charCodeAt(i);if(l===47){if(!a){s=i+1;break}continue}o===-1&&(a=!1,o=i+1),l===46?t===-1?t=i:n!==1&&(n=1):t!==-1&&(n=-1)}return t===-1||o===-1||n===0||n===1&&t===o-1&&t===s+1?"":e.slice(t,o)},format:function(e){if(e===null||typeof e!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return Oe("/",e)},parse:function(e){P(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var s=e.charCodeAt(0),o=s===47,a;o?(t.root="/",a=1):a=0;for(var n=-1,i=0,l=-1,_=!0,u=e.length-1,c=0;u>=a;--u){if(s=e.charCodeAt(u),s===47){if(!_){i=u+1;break}continue}l===-1&&(_=!1,l=u+1),s===46?n===-1?n=u:c!==1&&(c=1):n!==-1&&(c=-1)}return n===-1||l===-1||c===0||c===1&&n===l-1&&n===i+1?l!==-1&&(i===0&&o?t.base=t.name=e.slice(1,l):t.base=t.name=e.slice(i,l)):(i===0&&o?(t.name=e.slice(1,n),t.base=e.slice(1,l)):(t.name=e.slice(i,n),t.base=e.slice(i,l)),t.ext=e.slice(n,l)),i>0?t.dir=e.slice(0,i-1):o&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};R.posix=R;ee.exports=R});var W=require("node:worker_threads");var ae=I(Y());var x=I(te());function re(r,e){let t=x.default.normalize(e),o=x.default.dirname(t).split("/"),a=[];for(let n of o){a.push(n);let i=a.join("/");if(r.FS.analyzePath(i).exists){if(r.FS.isDir(i))throw new Error(`"${i}" already exists and is not a directory.`);continue}try{r.FS.mkdir(i)}catch(l){throw console.error(`Failed to create a directory "${i}"`),l}}}function $(r,e,t,s){re(r,e),r.FS.writeFile(e,t,s)}function oe(r,e,t){re(r,t),r.FS.rename(e,t)}var Le="[",Ee="(<=>!~",Ce=";",Te="@",Ne=new RegExp(`[${Le+Ee+Ce+Te}]`);function De(r){return r.split(Ne)[0].trim()}function H(r){return r.forEach(t=>{let s;try{s=new URL(t)}catch{return}if(s.protocol==="emfs:"||s.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)}),r.filter(t=>De(t)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${t}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}async function Ue(r){let e=typeof process<"u"&&process.versions?.node,t;e?t=(await import("node:path")).sep:t="/";let s=r.slice(0,r.lastIndexOf(t)+1);if(r.endsWith(".mjs")){if(e){let o=await import("node:path"),a=await import("node:url");!r.includes("://")&&o.isAbsolute(r)&&(r=a.pathToFileURL(r).href)}return{scriptURL:r,pyodideIndexURL:s,isESModule:!0}}else return{scriptURL:r,pyodideIndexURL:s,isESModule:!1}}async function se(r,e){let{scriptURL:t,pyodideIndexURL:s,isESModule:o}=await Ue(r),a;return o?a=(await import(t)).loadPyodide:(importScripts(t),a=self.loadPyodide),a({...e,indexURL:s})}function j(r){r.runPython(`
3
3
  import micropip
4
4
  micropip.add_mock_package(
5
5
  "pyarrow", "0.0.1",
@@ -15,24 +15,24 @@ class Table:
15
15
  """
16
16
  }
17
17
  )
18
- `)}function De(o,e){return o.pyodide_py.ffi._pyodide._base.find_imports(e).toJs()}async function se(o,e,t){let s=t.map(l=>De(o,l)),n=Array.from(new Set(s.flat())).filter(l=>!o.runPython(`__import__('importlib').util.find_spec('${l}')`)).map(l=>o._api._import_name_to_package_name.get(l)).filter(l=>l);if(n.length===0)return;let i=new MessageChannel;e({type:"event:moduleAutoLoad",data:{packagesToLoad:n}},i.port2);try{let l=await o.loadPackage(n);i.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:l}}),i.port1.close();return}catch(l){throw i.port1.postMessage({type:"moduleAutoLoad:error",error:l}),i.port1.close(),l}}async function qe(o,e){let t=o.slice(0,o.lastIndexOf("/")+1),s;return o.endsWith(".mjs")?s=(await import(o)).loadPyodide:(importScripts(o),s=O.loadPyodide),s({...e,indexURL:t})}var O=global;function ne(o,e,t){let s=se(o,e,t);O.__moduleAutoLoadPromise__=s,o.runPythonAsync(`
18
+ `)}function qe(r,e){return r.pyodide_py.ffi._pyodide._base.find_imports(e).toJs()}async function ne(r,e,t){let s=t.map(l=>qe(r,l)),n=Array.from(new Set(s.flat())).filter(l=>!r.runPython(`__import__('importlib').util.find_spec('${l}')`)).map(l=>r._api._import_name_to_package_name.get(l)).filter(l=>l);if(n.length===0)return;let i=new MessageChannel;e({type:"event:moduleAutoLoad",data:{packagesToLoad:n}},i.port2);try{let l=await r.loadPackage(n);i.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:l}}),i.port1.close();return}catch(l){throw i.port1.postMessage({type:"moduleAutoLoad:error",error:l}),i.port1.close(),l}}var D=global;function ie(r,e,t){let s=ne(r,e,t);D.__moduleAutoLoadPromise__=s,r.runPythonAsync(`
19
19
  from streamlit.runtime.scriptrunner import script_runner
20
20
  from js import __moduleAutoLoadPromise__
21
21
 
22
22
  script_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__
23
- `)}function ae(o,e,t){function s(u){e({type:"event:progress",data:{message:u}})}let r,a,n=new ie.PromiseDelegate;async function i(){let u=await n.promise,c={...t,...u};console.debug("Initial data",c);let{entrypoint:S,files:p,archives:d,requirements:m,prebuiltPackageNames:y,wheels:h,mountedSitePackagesSnapshotFilePath:v,pyodideUrl:k=o,streamlitConfig:A,idbfsMountpoints:I,nodefsMountpoints:x,moduleAutoLoad:ce}=c,C=H(m);s("Loading Pyodide."),console.debug("Loading Pyodide"),r=await qe(k,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let B=!1;I&&(B=!0,I.forEach(g=>{r.FS.mkdir(g),r.FS.mount(r.FS.filesystems.IDBFS,{},g)}),await new Promise((g,f)=>{r.FS.syncfs(!0,P=>{P?f(P):g()})})),x&&Object.entries(x).forEach(([g,f])=>{r.FS.mkdir(g),r.FS.mount(r.FS.filesystems.NODEFS,{root:f},g)}),s("Mounting files.");let z=[];if(await Promise.all(Object.keys(p).map(async g=>{let f=p[g],P;"url"in f?(console.debug(`Fetch a file from ${f.url}`),P=await fetch(f.url).then(R=>R.arrayBuffer()).then(R=>new Uint8Array(R))):P=f.data;let{opts:E}=p[g];console.debug(`Write a file "${g}"`),$(r,g,P,E),g.endsWith(".py")&&z.push(g)})),s("Unpacking archives."),await Promise.all(d.map(async g=>{let f;"url"in g?(console.debug(`Fetch an archive from ${g.url}`),f=await fetch(g.url).then(R=>R.arrayBuffer())):f=g.buffer;let{format:P,options:E}=g;console.debug("Unpack an archive",{format:P,options:E}),r.unpackArchive(f,P,E)})),!v&&!h)throw new Error("Neither snapshot nor wheel files are provided.");v&&(s("Restoring the snapshot."),await r.runPythonAsync("import tarfile, shutil, site"),await r.runPythonAsync(`
23
+ `)}function le(r,e,t){function s(u){e({type:"event:progress",data:{message:u}})}let o,a,n=new ae.PromiseDelegate;async function i(){let u=await n.promise,c={...t,...u};console.debug("Initial data",c);let{entrypoint:S,files:p,archives:d,requirements:m,prebuiltPackageNames:y,wheels:h,mountedSitePackagesSnapshotFilePath:v,pyodideUrl:k=r,streamlitConfig:A,idbfsMountpoints:O,nodefsMountpoints:B,moduleAutoLoad:de}=c,L=H(m);s("Loading Pyodide."),console.debug("Loading Pyodide"),o=await se(k,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let z=!1;O&&(z=!0,O.forEach(g=>{o.FS.mkdir(g),o.FS.mount(o.FS.filesystems.IDBFS,{},g)}),await new Promise((g,f)=>{o.FS.syncfs(!0,b=>{b?f(b):g()})})),B&&Object.entries(B).forEach(([g,f])=>{o.FS.mkdir(g),o.FS.mount(o.FS.filesystems.NODEFS,{root:f},g)}),s("Mounting files.");let J=[];if(await Promise.all(Object.keys(p).map(async g=>{let f=p[g],b;"url"in f?(console.debug(`Fetch a file from ${f.url}`),b=await fetch(f.url).then(F=>F.arrayBuffer()).then(F=>new Uint8Array(F))):b=f.data;let{opts:E}=p[g];console.debug(`Write a file "${g}"`),$(o,g,b,E),g.endsWith(".py")&&J.push(g)})),s("Unpacking archives."),await Promise.all(d.map(async g=>{let f;"url"in g?(console.debug(`Fetch an archive from ${g.url}`),f=await fetch(g.url).then(F=>F.arrayBuffer())):f=g.buffer;let{format:b,options:E}=g;console.debug("Unpack an archive",{format:b,options:E}),o.unpackArchive(f,b,E)})),!v&&!h)throw new Error("Neither snapshot nor wheel files are provided.");v&&(s("Restoring the snapshot."),await o.runPythonAsync("import tarfile, shutil, site"),await o.runPythonAsync(`
24
24
  site_packages_dirs = site.getsitepackages()
25
25
  for site_packages in site_packages_dirs:
26
26
  shutil.rmtree(site_packages)
27
- `),console.debug(`Unarchive ${v}`),await r.runPythonAsync(`
27
+ `),console.debug(`Unarchive ${v}`),await o.runPythonAsync(`
28
28
  with tarfile.open("${v}", "r") as tar_gz_file:
29
29
  tar_gz_file.extractall("/")
30
- `),console.debug("Restored the snapshot"),s("Mocking some packages."),console.debug("Mock pyarrow"),j(r),console.debug("Mocked pyarrow")),s("Installing packages."),console.debug("Installing the prebuilt packages:",y),await r.loadPackage(y),console.debug("Installed the prebuilt packages"),await r.loadPackage("micropip");let J=r.pyimport("micropip");if(h?(console.debug("Installing the wheels:",h,"and the requirements:",C),await J.install.callKwargs([h.stliteServer,h.streamlit,...C],{keep_going:!0}),console.debug("Installed the wheels and the requirements"),s("Mocking some packages."),console.debug("Mock pyarrow"),j(r),console.debug("Mocked pyarrow")):(console.debug("Installing the requirements:",C),await J.install.callKwargs(C,{keep_going:!0}),console.debug("Installed the requirements")),ce){let g=z.map(f=>r.FS.readFile(f,{encoding:"utf8"}));ne(r,e,g)}await r.runPythonAsync(`
30
+ `),console.debug("Restored the snapshot"),s("Mocking some packages."),console.debug("Mock pyarrow"),j(o),console.debug("Mocked pyarrow")),s("Installing packages."),console.debug("Installing the prebuilt packages:",y),await o.loadPackage(y),console.debug("Installed the prebuilt packages"),await o.loadPackage("micropip");let K=o.pyimport("micropip");if(h?(console.debug("Installing the wheels:",h,"and the requirements:",L),await K.install.callKwargs([h.stliteServer,h.streamlit,...L],{keep_going:!0}),console.debug("Installed the wheels and the requirements"),s("Mocking some packages."),console.debug("Mock pyarrow"),j(o),console.debug("Mocked pyarrow")):(console.debug("Installing the requirements:",L),await K.install.callKwargs(L,{keep_going:!0}),console.debug("Installed the requirements")),de){let g=J.map(f=>o.FS.readFile(f,{encoding:"utf8"}));ie(o,e,g)}await o.runPythonAsync(`
31
31
  import importlib
32
32
  importlib.invalidate_caches()
33
- `),s("Loading streamlit package."),console.debug("Loading the Streamlit package"),await r.runPythonAsync(`
33
+ `),s("Loading streamlit package."),console.debug("Loading the Streamlit package"),await o.runPythonAsync(`
34
34
  import streamlit.runtime
35
- `),console.debug("Loaded the Streamlit package"),s("Setting up the loggers."),console.debug("Setting the loggers"),await r.runPythonAsync(`
35
+ `),console.debug("Loaded the Streamlit package"),s("Setting up the loggers."),console.debug("Setting the loggers"),await o.runPythonAsync(`
36
36
  import logging
37
37
  import streamlit.logger
38
38
 
@@ -50,7 +50,7 @@ for name in streamlit.logger._loggers.keys():
50
50
  logger.setLevel(logging.NOTSET)
51
51
 
52
52
  streamlit.logger._loggers = {}
53
- `);let de=(g,f)=>{g>=40?console.error(f):g>=30?console.warn(f):g>=20?console.info(f):console.debug(f)};O.__logCallback__=de,await r.runPythonAsync(`
53
+ `);let ge=(g,f)=>{g>=40?console.error(f):g>=30?console.warn(f):g>=20?console.info(f):console.debug(f)};D.__logCallback__=ge,await o.runPythonAsync(`
54
54
  def setup_loggers(streamlit_level, streamlit_message_format):
55
55
  from js import __logCallback__
56
56
 
@@ -79,14 +79,14 @@ def setup_loggers(streamlit_level, streamlit_message_format):
79
79
  streamlit_handler.setFormatter(streamlit_formatter)
80
80
  streamlit_logger.addHandler(streamlit_handler)
81
81
  streamlit_logger.setLevel(streamlit_level.upper())
82
- `);let ge=(A?.["logger.level"]??"INFO").toString(),ue=A?.["logger.messageFormat"]??"%(asctime)s %(message)s";if(r.globals.get("setup_loggers")(ge,ue),console.debug("Set the loggers"),s("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await r.runPythonAsync(`
82
+ `);let ue=(A?.["logger.level"]??"INFO").toString(),fe=A?.["logger.messageFormat"]??"%(asctime)s %(message)s";if(o.globals.get("setup_loggers")(ue,fe),console.debug("Set the loggers"),s("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await o.runPythonAsync(`
83
83
  import streamlit
84
84
 
85
85
  def is_cacheable_msg(msg):
86
86
  return False
87
87
 
88
88
  streamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg
89
- `),console.debug("Mocked some Streamlit functions"),B){s("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let g=!1;O.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),g||(g=!0,r.FS.syncfs(!1,f=>{g=!1,f&&console.error(f)}))},await r.runPythonAsync(`
89
+ `),console.debug("Mocked some Streamlit functions"),z){s("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let g=!1;D.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),g||(g=!0,o.FS.syncfs(!1,f=>{g=!1,f&&console.error(f)}))},await o.runPythonAsync(`
90
90
  from streamlit.runtime.app_session import AppSession
91
91
  from streamlit.runtime.scriptrunner import ScriptRunnerEvent
92
92
  from js import __scriptFinishedCallback__
@@ -101,7 +101,7 @@ def wrap_app_session_on_scriptrunner_event(original_method):
101
101
  return wrapped
102
102
 
103
103
  AppSession._on_scriptrunner_event = wrap_app_session_on_scriptrunner_event(AppSession._on_scriptrunner_event)
104
- `),console.debug("Set up the IndexedDB filesystem synchronizer")}return s("Booting up the Streamlit server."),console.debug("Booting up the Streamlit server"),O.__streamlitFlagOptions__={"browser.gatherUsageStats":!1,...A,"runner.fastReruns":!1},await r.runPythonAsync(`
104
+ `),console.debug("Set up the IndexedDB filesystem synchronizer")}return s("Booting up the Streamlit server."),console.debug("Booting up the Streamlit server"),D.__streamlitFlagOptions__={"browser.gatherUsageStats":!1,...A,"runner.fastReruns":!1},await o.runPythonAsync(`
105
105
  from stlite_server.bootstrap import load_config_options, prepare
106
106
  from stlite_server.server import Server
107
107
  from js import __streamlitFlagOptions__
@@ -116,4 +116,4 @@ prepare(main_script_path, args)
116
116
 
117
117
  server = Server(main_script_path)
118
118
  server.start()
119
- `),console.debug("Booted up the Streamlit server"),console.debug("Setting up the HTTP server"),a=r.globals.get("server").copy(),console.debug("Set up the HTTP server"),e({type:"event:loaded"}),c}let l=i().catch(u=>{throw e({type:"event:error",data:{error:u}}),u}),_=async u=>{let c=u.data;if(c.type==="initData"){n.resolve(c.data);return}let{moduleAutoLoad:S}=await l,p=u.ports[0];try{switch(c.type){case"websocket:connect":{console.debug("websocket:connect",c.data);let{path:d}=c.data;a.start_websocket(d,(m,y)=>{if(y){let h=m,v=h.getBuffer("u8");h.destroy();let k=new Uint8ClampedArray(v.data.buffer,v.data.byteOffset,v.data.byteLength);e({type:"websocket:message",data:{payload:new Uint8Array(k)}})}else e({type:"websocket:message",data:{payload:m}})}),p.postMessage({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",c.data);let{payload:d}=c.data;a.receive_websocket_from_js(d);break}case"http:request":{console.debug("http:request",c.data);let{request:d}=c.data,m=(y,h,v)=>{let k=new Map(h.toJs()),A=v.toJs();console.debug({statusCode:y,headers:k,body:A});let I={type:"http:response",data:{response:{statusCode:y,headers:k,body:A}}};p.postMessage(I)};a.receive_http_from_js(d.method,decodeURIComponent(d.path),d.headers,d.body,m);break}case"file:write":{let{path:d,data:m,opts:y}=c.data;S&&typeof m=="string"&&d.endsWith(".py")&&(console.debug(`Auto install the requirements in ${d}`),ne(r,e,[m])),console.debug(`Write a file "${d}"`),$(r,d,m,y),p.postMessage({type:"reply"});break}case"file:rename":{let{oldPath:d,newPath:m}=c.data;console.debug(`Rename "${d}" to ${m}`),oe(r,d,m),p.postMessage({type:"reply"});break}case"file:unlink":{let{path:d}=c.data;console.debug(`Remove "${d}`),r.FS.unlink(d),p.postMessage({type:"reply"});break}case"install":{let{requirements:d}=c.data,m=r.pyimport("micropip"),y=H(d);console.debug("Install the requirements:",y),await m.install.callKwargs(y,{keep_going:!0}).then(()=>{console.debug("Successfully installed"),p.postMessage({type:"reply"})})}}}catch(d){if(console.error(d),!(d instanceof Error))throw d;let m=new Error(d.message);m.name=d.name,m.stack=d.stack,p.postMessage({type:"reply",error:m})}};return e({type:"event:start"}),_}function le(){let o=process.env.NODEFS_MOUNTPOINTS;if(!o)return;let e;try{e=JSON.parse(o)}catch{console.error(`Failed to parse NODEFS_MOUNTPOINTS as JSON: ${o}`);return}if(typeof e!="object"){console.error(`NODEFS_MOUNTPOINTS is not an object: ${o}`);return}if(Array.isArray(e)){console.error(`NODEFS_MOUNTPOINTS is an array: ${o}`);return}if(Object.keys(e).some(t=>typeof t!="string")){console.error(`NODEFS_MOUNTPOINTS has non-string keys: ${o}`);return}if(Object.values(e).some(t=>typeof t!="string")){console.error(`NODEFS_MOUNTPOINTS has non-string values: ${o}`);return}return e}var Ue=o=>{console.debug("[worker thread] postMessage from worker",o),W.parentPort?.postMessage(o)},$e=ae(process.env.PYODIDE_URL,Ue,{nodefsMountpoints:le()});W.parentPort?.on("message",({data:o,port:e})=>{console.debug("[worker thread] parentPort.onMessage",{data:o,port:e}),$e({data:o,ports:[e]})});
119
+ `),console.debug("Booted up the Streamlit server"),console.debug("Setting up the HTTP server"),a=o.globals.get("server").copy(),console.debug("Set up the HTTP server"),e({type:"event:loaded"}),c}let l=i().catch(u=>{throw e({type:"event:error",data:{error:u}}),u}),_=async u=>{let c=u.data;if(c.type==="initData"){n.resolve(c.data);return}let{moduleAutoLoad:S}=await l,p=u.ports[0];try{switch(c.type){case"websocket:connect":{console.debug("websocket:connect",c.data);let{path:d}=c.data;a.start_websocket(d,(m,y)=>{if(y){let h=m,v=h.getBuffer("u8");h.destroy();let k=new Uint8ClampedArray(v.data.buffer,v.data.byteOffset,v.data.byteLength);e({type:"websocket:message",data:{payload:new Uint8Array(k)}})}else e({type:"websocket:message",data:{payload:m}})}),p.postMessage({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",c.data);let{payload:d}=c.data;a.receive_websocket_from_js(d);break}case"http:request":{console.debug("http:request",c.data);let{request:d}=c.data,m=(y,h,v)=>{let k=new Map(h.toJs()),A=v.toJs();console.debug({statusCode:y,headers:k,body:A});let O={type:"http:response",data:{response:{statusCode:y,headers:k,body:A}}};p.postMessage(O)};a.receive_http_from_js(d.method,decodeURIComponent(d.path),d.headers,d.body,m);break}case"file:write":{let{path:d,data:m,opts:y}=c.data;S&&typeof m=="string"&&d.endsWith(".py")&&(console.debug(`Auto install the requirements in ${d}`),ie(o,e,[m])),console.debug(`Write a file "${d}"`),$(o,d,m,y),p.postMessage({type:"reply"});break}case"file:rename":{let{oldPath:d,newPath:m}=c.data;console.debug(`Rename "${d}" to ${m}`),oe(o,d,m),p.postMessage({type:"reply"});break}case"file:unlink":{let{path:d}=c.data;console.debug(`Remove "${d}`),o.FS.unlink(d),p.postMessage({type:"reply"});break}case"install":{let{requirements:d}=c.data,m=o.pyimport("micropip"),y=H(d);console.debug("Install the requirements:",y),await m.install.callKwargs(y,{keep_going:!0}).then(()=>{console.debug("Successfully installed"),p.postMessage({type:"reply"})})}}}catch(d){if(console.error(d),!(d instanceof Error))throw d;let m=new Error(d.message);m.name=d.name,m.stack=d.stack,p.postMessage({type:"reply",error:m})}};return e({type:"event:start"}),_}function ce(){let r=process.env.NODEFS_MOUNTPOINTS;if(!r)return;let e;try{e=JSON.parse(r)}catch{console.error(`Failed to parse NODEFS_MOUNTPOINTS as JSON: ${r}`);return}if(typeof e!="object"){console.error(`NODEFS_MOUNTPOINTS is not an object: ${r}`);return}if(Array.isArray(e)){console.error(`NODEFS_MOUNTPOINTS is an array: ${r}`);return}if(Object.keys(e).some(t=>typeof t!="string")){console.error(`NODEFS_MOUNTPOINTS has non-string keys: ${r}`);return}if(Object.values(e).some(t=>typeof t!="string")){console.error(`NODEFS_MOUNTPOINTS has non-string values: ${r}`);return}return e}var xe=r=>{console.debug("[worker thread] postMessage from worker",r),W.parentPort?.postMessage(r)},$e=le(process.env.PYODIDE_URL,xe,{nodefsMountpoints:ce()});W.parentPort?.on("message",({data:r,port:e})=>{console.debug("[worker thread] parentPort.onMessage",{data:r,port:e}),$e({data:r,ports:[e]})});
package/build/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>stlite</title><script defer="defer" src="/static/js/main.e800a125.js"></script><link href="/static/css/main.6fb7674e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>stlite</title><script defer="defer" src="/static/js/main.0dfc6435.js"></script><link href="/static/css/main.6fb7674e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var e={56977:e=>{function t(e){if("string"!==typeof e)throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function n(e,t){for(var n,r="",o=0,s=-1,i=0,a=0;a<=e.length;++a){if(a<e.length)n=e.charCodeAt(a);else{if(47===n)break;n=47}if(47===n){if(s===a-1||1===i);else if(s!==a-1&&2===i){if(r.length<2||2!==o||46!==r.charCodeAt(r.length-1)||46!==r.charCodeAt(r.length-2))if(r.length>2){var l=r.lastIndexOf("/");if(l!==r.length-1){-1===l?(r="",o=0):o=(r=r.slice(0,l)).length-1-r.lastIndexOf("/"),s=a,i=0;continue}}else if(2===r.length||1===r.length){r="",o=0,s=a,i=0;continue}t&&(r.length>0?r+="/..":r="..",o=2)}else r.length>0?r+="/"+e.slice(s+1,a):r=e.slice(s+1,a),o=a-s-1;s=a,i=0}else 46===n&&-1!==i?++i:i=-1}return r}var r={resolve:function(){for(var e,r="",o=!1,s=arguments.length-1;s>=-1&&!o;s--){var i;s>=0?i=arguments[s]:(void 0===e&&(e=process.cwd()),i=e),t(i),0!==i.length&&(r=i+"/"+r,o=47===i.charCodeAt(0))}return r=n(r,!o),o?r.length>0?"/"+r:"/":r.length>0?r:"."},normalize:function(e){if(t(e),0===e.length)return".";var r=47===e.charCodeAt(0),o=47===e.charCodeAt(e.length-1);return 0!==(e=n(e,!r)).length||r||(e="."),e.length>0&&o&&(e+="/"),r?"/"+e:e},isAbsolute:function(e){return t(e),e.length>0&&47===e.charCodeAt(0)},join:function(){if(0===arguments.length)return".";for(var e,n=0;n<arguments.length;++n){var o=arguments[n];t(o),o.length>0&&(void 0===e?e=o:e+="/"+o)}return void 0===e?".":r.normalize(e)},relative:function(e,n){if(t(e),t(n),e===n)return"";if((e=r.resolve(e))===(n=r.resolve(n)))return"";for(var o=1;o<e.length&&47===e.charCodeAt(o);++o);for(var s=e.length,i=s-o,a=1;a<n.length&&47===n.charCodeAt(a);++a);for(var l=n.length-a,c=i<l?i:l,d=-1,g=0;g<=c;++g){if(g===c){if(l>c){if(47===n.charCodeAt(a+g))return n.slice(a+g+1);if(0===g)return n.slice(a+g)}else i>c&&(47===e.charCodeAt(o+g)?d=g:0===g&&(d=0));break}var u=e.charCodeAt(o+g);if(u!==n.charCodeAt(a+g))break;47===u&&(d=g)}var p="";for(g=o+d+1;g<=s;++g)g!==s&&47!==e.charCodeAt(g)||(0===p.length?p+="..":p+="/..");return p.length>0?p+n.slice(a+d):(a+=d,47===n.charCodeAt(a)&&++a,n.slice(a))},_makeLong:function(e){return e},dirname:function(e){if(t(e),0===e.length)return".";for(var n=e.charCodeAt(0),r=47===n,o=-1,s=!0,i=e.length-1;i>=1;--i)if(47===(n=e.charCodeAt(i))){if(!s){o=i;break}}else s=!1;return-1===o?r?"/":".":r&&1===o?"//":e.slice(0,o)},basename:function(e,n){if(void 0!==n&&"string"!==typeof n)throw new TypeError('"ext" argument must be a string');t(e);var r,o=0,s=-1,i=!0;if(void 0!==n&&n.length>0&&n.length<=e.length){if(n.length===e.length&&n===e)return"";var a=n.length-1,l=-1;for(r=e.length-1;r>=0;--r){var c=e.charCodeAt(r);if(47===c){if(!i){o=r+1;break}}else-1===l&&(i=!1,l=r+1),a>=0&&(c===n.charCodeAt(a)?-1===--a&&(s=r):(a=-1,s=l))}return o===s?s=l:-1===s&&(s=e.length),e.slice(o,s)}for(r=e.length-1;r>=0;--r)if(47===e.charCodeAt(r)){if(!i){o=r+1;break}}else-1===s&&(i=!1,s=r+1);return-1===s?"":e.slice(o,s)},extname:function(e){t(e);for(var n=-1,r=0,o=-1,s=!0,i=0,a=e.length-1;a>=0;--a){var l=e.charCodeAt(a);if(47!==l)-1===o&&(s=!1,o=a+1),46===l?-1===n?n=a:1!==i&&(i=1):-1!==n&&(i=-1);else if(!s){r=a+1;break}}return-1===n||-1===o||0===i||1===i&&n===o-1&&n===r+1?"":e.slice(n,o)},format:function(e){if(null===e||"object"!==typeof e)throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return function(e,t){var n=t.dir||t.root,r=t.base||(t.name||"")+(t.ext||"");return n?n===t.root?n+r:n+e+r:r}("/",e)},parse:function(e){t(e);var n={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return n;var r,o=e.charCodeAt(0),s=47===o;s?(n.root="/",r=1):r=0;for(var i=-1,a=0,l=-1,c=!0,d=e.length-1,g=0;d>=r;--d)if(47!==(o=e.charCodeAt(d)))-1===l&&(c=!1,l=d+1),46===o?-1===i?i=d:1!==g&&(g=1):-1!==i&&(g=-1);else if(!c){a=d+1;break}return-1===i||-1===l||0===g||1===g&&i===l-1&&i===a+1?-1!==l&&(n.base=n.name=0===a&&s?e.slice(1,l):e.slice(a,l)):(0===a&&s?(n.name=e.slice(1,i),n.base=e.slice(1,l)):(n.name=e.slice(a,i),n.base=e.slice(a,l)),n.ext=e.slice(i,l)),a>0?n.dir=e.slice(0,a-1):s&&(n.dir="/"),n},sep:"/",delimiter:":",win32:null,posix:null};r.posix=r,e.exports=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"===typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"===typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{new RegExp("[[(<=>!~;@]");class e{constructor(){this.promise=new Promise(((e,t)=>{this.resolveInternal=e,this.rejectInternal=t}))}resolve(e){this.resolveInternal(e)}reject(e){this.rejectInternal(e)}}var t=n(56977),r=n.n(t);function o(e,t){const n=r().normalize(t),o=r().dirname(n).split("/"),s=[];for(const r of o){s.push(r);const t=s.join("/");if(e.FS.analyzePath(t).exists){if(e.FS.isDir(t))throw new Error(`"${t}" already exists and is not a directory.`)}else try{e.FS.mkdir(t)}catch(i){throw console.error(`Failed to create a directory "${t}"`),i}}}function s(e,t,n,r){o(e,t),e.FS.writeFile(t,n,r)}const i=new RegExp("[[(<=>!~;@]");function a(e){e.forEach((e=>{let t;try{t=new URL(e)}catch{return}if("emfs:"===t.protocol||"file:"===t.protocol)throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${e})`)}));return e.filter((e=>{const t="streamlit"===function(e){return e.split(i)[0].trim()}(e);return!t||(console.warn(`Streamlit is specified in the requirements ("${e}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1)}))}var l=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{l(r.next(e))}catch(t){s(t)}}function a(e){try{l(r.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}l((r=r.apply(e,t||[])).next())}))};function c(e,t){return l(this,void 0,void 0,(function*(){const{scriptURL:n,pyodideIndexURL:r,isESModule:o}=yield function(e){var t;return l(this,void 0,void 0,(function*(){const n="undefined"!==typeof process&&(null===(t=process.versions)||void 0===t?void 0:t.node);let r;r=n?(yield import("node:path")).sep:"/";const o=e.slice(0,e.lastIndexOf(r)+1);if(e.endsWith(".mjs")){if(n){const t=yield import("node:path"),n=yield import("node:url");!e.includes("://")&&t.isAbsolute(e)&&(e=n.pathToFileURL(e).href)}return{scriptURL:e,pyodideIndexURL:o,isESModule:!0}}return{scriptURL:e,pyodideIndexURL:o,isESModule:!1}}))}(e);let s;if(o){s=(yield import(n)).loadPyodide}else importScripts(n),s=self.loadPyodide;return s(Object.assign(Object.assign({},t),{indexURL:r}))}))}function d(e){e.runPython('\nimport micropip\nmicropip.add_mock_package(\n "pyarrow", "0.0.1",\n modules={\n "pyarrow": """\n__version__ = \'0.0.1\' # TODO: Update when releasing\n\n\nclass Table:\n @classmethod\n def from_pandas(*args, **kwargs):\n raise NotImplementedError("stlite is not supporting this method.")\n"""\n }\n)\n')}var g=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{l(r.next(e))}catch(t){s(t)}}function a(e){try{l(r.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}l((r=r.apply(e,t||[])).next())}))};var u=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{l(r.next(e))}catch(t){s(t)}}function a(e){try{l(r.throw(e))}catch(t){s(t)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}l((r=r.apply(e,t||[])).next())}))};const p=n.g;function f(e,t,n){const r=function(e,t,n){return g(this,void 0,void 0,(function*(){const r=n.map((t=>function(e,t){return e.pyodide_py.ffi._pyodide._base.find_imports(t).toJs()}(e,t))),o=Array.from(new Set(r.flat())).filter((t=>!e.runPython(`__import__('importlib').util.find_spec('${t}')`))).map((t=>e._api._import_name_to_package_name.get(t))).filter((e=>e));if(0===o.length)return;const s=new MessageChannel;t({type:"event:moduleAutoLoad",data:{packagesToLoad:o}},s.port2);try{const t=yield e.loadPackage(o);return s.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:t}}),void s.port1.close()}catch(i){throw s.port1.postMessage({type:"moduleAutoLoad:error",error:i}),s.port1.close(),i}}))}(e,t,n);p.__moduleAutoLoadPromise__=r,e.runPythonAsync("\nfrom streamlit.runtime.scriptrunner import script_runner\nfrom js import __moduleAutoLoadPromise__\n\nscript_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__\n")}const m=self.postMessage;self.onmessage=function(t,n,r){function i(e){n({type:"event:progress",data:{message:e}})}let l,g;const m=new e,h=function(){var e,o;return u(this,void 0,void 0,(function*(){const h=yield m.promise,_=Object.assign(Object.assign({},r),h);console.debug("Initial data",_);const{entrypoint:y,files:v,archives:b,requirements:w,prebuiltPackageNames:k,wheels:S,mountedSitePackagesSnapshotFilePath:A,pyodideUrl:P=t,streamlitConfig:F,idbfsMountpoints:C,nodefsMountpoints:L,moduleAutoLoad:x}=_,O=a(w);i("Loading Pyodide."),console.debug("Loading Pyodide"),l=yield c(P,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let j=!1;C&&(j=!0,C.forEach((e=>{l.FS.mkdir(e),l.FS.mount(l.FS.filesystems.IDBFS,{},e)})),yield new Promise(((e,t)=>{l.FS.syncfs(!0,(n=>{n?t(n):e()}))}))),L&&Object.entries(L).forEach((([e,t])=>{l.FS.mkdir(e),l.FS.mount(l.FS.filesystems.NODEFS,{root:t},e)})),i("Mounting files.");const I=[];if(yield Promise.all(Object.keys(v).map((e=>u(this,void 0,void 0,(function*(){const t=v[e];let n;"url"in t?(console.debug(`Fetch a file from ${t.url}`),n=yield fetch(t.url).then((e=>e.arrayBuffer())).then((e=>new Uint8Array(e)))):n=t.data;const{opts:r}=v[e];console.debug(`Write a file "${e}"`),s(l,e,n,r),e.endsWith(".py")&&I.push(e)}))))),i("Unpacking archives."),yield Promise.all(b.map((e=>u(this,void 0,void 0,(function*(){let t;"url"in e?(console.debug(`Fetch an archive from ${e.url}`),t=yield fetch(e.url).then((e=>e.arrayBuffer()))):t=e.buffer;const{format:n,options:r}=e;console.debug("Unpack an archive",{format:n,options:r}),l.unpackArchive(t,n,r)}))))),!A&&!S)throw new Error("Neither snapshot nor wheel files are provided.");A&&(i("Restoring the snapshot."),yield l.runPythonAsync("import tarfile, shutil, site"),yield l.runPythonAsync("\nsite_packages_dirs = site.getsitepackages()\nfor site_packages in site_packages_dirs:\n shutil.rmtree(site_packages)\n"),console.debug(`Unarchive ${A}`),yield l.runPythonAsync(`\nwith tarfile.open("${A}", "r") as tar_gz_file:\n tar_gz_file.extractall("/")\n`),console.debug("Restored the snapshot"),i("Mocking some packages."),console.debug("Mock pyarrow"),d(l),console.debug("Mocked pyarrow")),i("Installing packages."),console.debug("Installing the prebuilt packages:",k),yield l.loadPackage(k),console.debug("Installed the prebuilt packages"),yield l.loadPackage("micropip");const E=l.pyimport("micropip");if(S?(console.debug("Installing the wheels:",S,"and the requirements:",O),yield E.install.callKwargs([S.stliteServer,S.streamlit,...O],{keep_going:!0}),console.debug("Installed the wheels and the requirements"),i("Mocking some packages."),console.debug("Mock pyarrow"),d(l),console.debug("Mocked pyarrow")):(console.debug("Installing the requirements:",O),yield E.install.callKwargs(O,{keep_going:!0}),console.debug("Installed the requirements")),x){const e=I.map((e=>l.FS.readFile(e,{encoding:"utf8"})));f(l,n,e)}yield l.runPythonAsync("\nimport importlib\nimportlib.invalidate_caches()\n"),i("Loading streamlit package."),console.debug("Loading the Streamlit package"),yield l.runPythonAsync("\nimport streamlit.runtime\n "),console.debug("Loaded the Streamlit package"),i("Setting up the loggers."),console.debug("Setting the loggers"),yield l.runPythonAsync('\nimport logging\nimport streamlit.logger\n\nstreamlit.logger.get_logger = logging.getLogger\nstreamlit.logger.setup_formatter = None\nstreamlit.logger.update_formatter = lambda *a, **k: None\nstreamlit.logger.set_log_level = lambda *a, **k: None\n\nfor name in streamlit.logger._loggers.keys():\n if name == "root":\n name = "streamlit"\n logger = logging.getLogger(name)\n logger.propagate = True\n logger.handlers.clear()\n logger.setLevel(logging.NOTSET)\n\nstreamlit.logger._loggers = {}\n');p.__logCallback__=(e,t)=>{e>=40?console.error(t):e>=30?console.warn(t):e>=20?console.info(t):console.debug(t)},yield l.runPythonAsync('\ndef setup_loggers(streamlit_level, streamlit_message_format):\n from js import __logCallback__\n\n\n class JsHandler(logging.Handler):\n def emit(self, record):\n msg = self.format(record)\n __logCallback__(record.levelno, msg)\n\n\n root_message_format = "%(levelname)s:%(name)s:%(message)s"\n\n root_logger = logging.getLogger()\n root_logger.handlers.clear()\n root_formatter = logging.Formatter(root_message_format)\n root_handler = JsHandler()\n root_handler.setFormatter(root_formatter)\n root_logger.addHandler(root_handler)\n root_logger.setLevel(logging.DEBUG)\n\n streamlit_logger = logging.getLogger("streamlit")\n streamlit_logger.propagate = False\n streamlit_logger.handlers.clear()\n streamlit_formatter = logging.Formatter(streamlit_message_format)\n streamlit_handler = JsHandler()\n streamlit_handler.setFormatter(streamlit_formatter)\n streamlit_logger.addHandler(streamlit_handler)\n streamlit_logger.setLevel(streamlit_level.upper())\n');const M=(null!==(e=null===F||void 0===F?void 0:F["logger.level"])&&void 0!==e?e:"INFO").toString(),R=null!==(o=null===F||void 0===F?void 0:F["logger.messageFormat"])&&void 0!==o?o:"%(asctime)s %(message)s";if(l.globals.get("setup_loggers")(M,R),console.debug("Set the loggers"),i("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),yield l.runPythonAsync("\nimport streamlit\n\ndef is_cacheable_msg(msg):\n return False\n\nstreamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg\n"),console.debug("Mocked some Streamlit functions"),j){i("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let e=!1;p.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),e||(e=!0,l.FS.syncfs(!1,(t=>{e=!1,t&&console.error(t)})))},yield l.runPythonAsync('\nfrom streamlit.runtime.app_session import AppSession\nfrom streamlit.runtime.scriptrunner import ScriptRunnerEvent\nfrom js import __scriptFinishedCallback__\n\ndef wrap_app_session_on_scriptrunner_event(original_method):\n def wrapped(self, *args, **kwargs):\n if "event" in kwargs:\n event = kwargs["event"]\n if event == ScriptRunnerEvent.SCRIPT_STOPPED_WITH_SUCCESS or event == ScriptRunnerEvent.SCRIPT_STOPPED_FOR_RERUN or event == ScriptRunnerEvent.SHUTDOWN:\n __scriptFinishedCallback__()\n return original_method(self, *args, **kwargs)\n return wrapped\n\nAppSession._on_scriptrunner_event = wrap_app_session_on_scriptrunner_event(AppSession._on_scriptrunner_event)\n'),console.debug("Set up the IndexedDB filesystem synchronizer")}return i("Booting up the Streamlit server."),console.debug("Booting up the Streamlit server"),p.__streamlitFlagOptions__=Object.assign(Object.assign({"browser.gatherUsageStats":!1},F),{"runner.fastReruns":!1}),yield l.runPythonAsync(`\nfrom stlite_server.bootstrap import load_config_options, prepare\nfrom stlite_server.server import Server\nfrom js import __streamlitFlagOptions__\n\nflag_options = __streamlitFlagOptions__.to_py()\nload_config_options(flag_options)\n\nmain_script_path = "${y}"\nargs = []\n\nprepare(main_script_path, args)\n\nserver = Server(main_script_path)\nserver.start()\n`),console.debug("Booted up the Streamlit server"),console.debug("Setting up the HTTP server"),g=l.globals.get("server").copy(),console.debug("Set up the HTTP server"),n({type:"event:loaded"}),_}))}().catch((e=>{throw n({type:"event:error",data:{error:e}}),e}));return n({type:"event:start"}),e=>u(this,void 0,void 0,(function*(){const t=e.data;if("initData"===t.type)return void m.resolve(t.data);const{moduleAutoLoad:r}=yield h,i=e.ports[0];try{switch(t.type){case"websocket:connect":{console.debug("websocket:connect",t.data);const{path:e}=t.data;g.start_websocket(e,((e,t)=>{if(t){const t=e,r=t.getBuffer("u8");t.destroy();const o=new Uint8ClampedArray(r.data.buffer,r.data.byteOffset,r.data.byteLength);n({type:"websocket:message",data:{payload:new Uint8Array(o)}})}else{n({type:"websocket:message",data:{payload:e}})}})),i.postMessage({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",t.data);const{payload:e}=t.data;g.receive_websocket_from_js(e);break}case"http:request":{console.debug("http:request",t.data);const{request:e}=t.data,n=(e,t,n)=>{const r=new Map(t.toJs()),o=n.toJs();console.debug({statusCode:e,headers:r,body:o});const s={type:"http:response",data:{response:{statusCode:e,headers:r,body:o}}};i.postMessage(s)};g.receive_http_from_js(e.method,decodeURIComponent(e.path),e.headers,e.body,n);break}case"file:write":{const{path:e,data:o,opts:a}=t.data;r&&"string"===typeof o&&e.endsWith(".py")&&(console.debug(`Auto install the requirements in ${e}`),f(l,n,[o])),console.debug(`Write a file "${e}"`),s(l,e,o,a),i.postMessage({type:"reply"});break}case"file:rename":{const{oldPath:e,newPath:n}=t.data;console.debug(`Rename "${e}" to ${n}`),function(e,t,n){o(e,n),e.FS.rename(t,n)}(l,e,n),i.postMessage({type:"reply"});break}case"file:unlink":{const{path:e}=t.data;console.debug(`Remove "${e}`),l.FS.unlink(e),i.postMessage({type:"reply"});break}case"install":{const{requirements:e}=t.data,n=l.pyimport("micropip"),r=a(e);console.debug("Install the requirements:",r),yield n.install.callKwargs(r,{keep_going:!0}).then((()=>{console.debug("Successfully installed"),i.postMessage({type:"reply"})}))}}}catch(c){if(console.error(c),!(c instanceof Error))throw c;const e=new Error(c.message);e.name=c.name,e.stack=c.stack,i.postMessage({type:"reply",error:e})}}))}("https://cdn.jsdelivr.net/pyodide/v0.26.0/full/pyodide.js",((e,t)=>m(e,t?[t]:void 0)))})()})();