@stlite/desktop 0.58.0 → 0.58.2
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.
- package/build/asset-manifest.json +3 -3
- package/build/electron/main.js +1 -1
- package/build/electron/worker.js +36 -13
- package/build/index.html +1 -1
- package/build/static/js/8798.1294d348.chunk.js +1 -0
- package/build/static/js/{main.e800a125.js → main.b1355ae6.js} +3 -3
- package/package.json +4 -4
- package/wheels/streamlit-1.35.0-cp312-none-any.whl +0 -0
- package/build/static/js/2921.32cf8135.chunk.js +0 -1
- /package/build/static/js/{main.e800a125.js.LICENSE.txt → main.b1355ae6.js.LICENSE.txt} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
3
|
"main.css": "/static/css/main.6fb7674e.css",
|
|
4
|
-
"main.js": "/static/js/main.
|
|
5
|
-
"static/js/
|
|
4
|
+
"main.js": "/static/js/main.b1355ae6.js",
|
|
5
|
+
"static/js/8798.1294d348.chunk.js": "/static/js/8798.1294d348.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.
|
|
166
|
+
"static/js/main.b1355ae6.js"
|
|
167
167
|
]
|
|
168
168
|
}
|
package/build/electron/main.js
CHANGED
|
@@ -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,"
|
|
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"}))});
|
package/build/electron/worker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
`).filter(e=>!e.startsWith("#")).map(e=>e.replace(
|
|
1
|
+
var pe=Object.create;var X=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var M=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Pe=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ye(e))!ve.call(r,o)&&o!==t&&X(r,o,{get:()=>e[o],enumerable:!(s=_e(e,o))||s.enumerable});return r};var I=(r,e,t)=>(t=r!=null?pe(he(r)):{},Pe(e||!r||!r.__esModule?X(t,"default",{value:r,enumerable:!0}):t,r));var G=M(C=>{"use strict";Object.defineProperty(C,"__esModule",{value:!0});C.validateRequirements=void 0;var be="[",we="(<=>!~",Se=";",ke="@",Ae=new RegExp(`[${be+we+Se+ke}]`);function Re(r){return r.split(Ae)[0].trim()}function Fe(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=>Re(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=Fe});var Q=M(T=>{"use strict";Object.defineProperty(T,"__esModule",{value:!0});T.parseRequirementsTxt=void 0;var Me=/\s#.*$/;function Ie(r){return r.split(`
|
|
2
|
+
`).filter(e=>!e.startsWith("#")).map(e=>e.replace(Me,"")).map(e=>e.trim()).filter(e=>e!=="")}T.parseRequirementsTxt=Ie});var Y=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 Z=M(w=>{"use strict";var Oe=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]}),x=w&&w.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Oe(e,r,t)};Object.defineProperty(w,"__esModule",{value:!0});x(G(),w);x(Q(),w);x(Y(),w)});var re=M((Xe,te)=>{"use strict";function P(r){if(typeof r!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(r))}function ee(r,e){for(var t="",s=0,o=-1,i=0,n,a=0;a<=r.length;++a){if(a<r.length)n=r.charCodeAt(a);else{if(n===47)break;n=47}if(n===47){if(!(o===a-1||i===1))if(o!==a-1&&i===2){if(t.length<2||s!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){var c=t.lastIndexOf("/");if(c!==t.length-1){c===-1?(t="",s=0):(t=t.slice(0,c),s=t.length-1-t.lastIndexOf("/")),o=a,i=0;continue}}else if(t.length===2||t.length===1){t="",s=0,o=a,i=0;continue}}e&&(t.length>0?t+="/..":t="..",s=2)}else t.length>0?t+="/"+r.slice(o+1,a):t=r.slice(o+1,a),s=a-o-1;o=a,i=0}else n===46&&i!==-1?++i:i=-1}return t}function Le(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 i;o>=0?i=arguments[o]:(s===void 0&&(s=process.cwd()),i=s),P(i),i.length!==0&&(e=i+"/"+e,t=i.charCodeAt(0)===47)}return e=ee(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=ee(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,i=o-s,n=1;n<t.length&&t.charCodeAt(n)===47;++n);for(var a=t.length,c=a-n,g=i<c?i:c,f=-1,l=0;l<=g;++l){if(l===g){if(c>g){if(t.charCodeAt(n+l)===47)return t.slice(n+l+1);if(l===0)return t.slice(n+l)}else i>g&&(e.charCodeAt(s+l)===47?f=l:l===0&&(f=0));break}var S=e.charCodeAt(s+l),_=t.charCodeAt(n+l);if(S!==_)break;S===47&&(f=l)}var d="";for(l=s+f+1;l<=o;++l)(l===o||e.charCodeAt(l)===47)&&(d.length===0?d+="..":d+="/..");return d.length>0?d+t.slice(n+f):(n+=f,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,i=!0,n=e.length-1;n>=1;--n)if(t=e.charCodeAt(n),t===47){if(!i){o=n;break}}else i=!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,i=!0,n;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var a=t.length-1,c=-1;for(n=e.length-1;n>=0;--n){var g=e.charCodeAt(n);if(g===47){if(!i){s=n+1;break}}else c===-1&&(i=!1,c=n+1),a>=0&&(g===t.charCodeAt(a)?--a===-1&&(o=n):(a=-1,o=c))}return s===o?o=c:o===-1&&(o=e.length),e.slice(s,o)}else{for(n=e.length-1;n>=0;--n)if(e.charCodeAt(n)===47){if(!i){s=n+1;break}}else o===-1&&(i=!1,o=n+1);return o===-1?"":e.slice(s,o)}},extname:function(e){P(e);for(var t=-1,s=0,o=-1,i=!0,n=0,a=e.length-1;a>=0;--a){var c=e.charCodeAt(a);if(c===47){if(!i){s=a+1;break}continue}o===-1&&(i=!1,o=a+1),c===46?t===-1?t=a: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 Le("/",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,i;o?(t.root="/",i=1):i=0;for(var n=-1,a=0,c=-1,g=!0,f=e.length-1,l=0;f>=i;--f){if(s=e.charCodeAt(f),s===47){if(!g){a=f+1;break}continue}c===-1&&(g=!1,c=f+1),s===46?n===-1?n=f:l!==1&&(l=1):n!==-1&&(l=-1)}return n===-1||c===-1||l===0||l===1&&n===c-1&&n===a+1?c!==-1&&(a===0&&o?t.base=t.name=e.slice(1,c):t.base=t.name=e.slice(a,c)):(a===0&&o?(t.name=e.slice(1,n),t.base=e.slice(1,c)):(t.name=e.slice(a,n),t.base=e.slice(a,c)),t.ext=e.slice(n,c)),a>0?t.dir=e.slice(0,a-1):o&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};R.posix=R;te.exports=R});var B=require("node:worker_threads");var le=I(Z());var q=I(re());function oe(r,e){let t=q.default.normalize(e),o=q.default.dirname(t).split("/"),i=[];for(let n of o){i.push(n);let a=i.join("/");if(r.FS.analyzePath(a).exists){if(r.FS.isDir(a))throw new Error(`"${a}" already exists and is not a directory.`);continue}try{r.FS.mkdir(a)}catch(c){throw console.error(`Failed to create a directory "${a}"`),c}}}function $(r,e,t,s){oe(r,e),r.FS.writeFile(e,t,s)}function se(r,e,t){oe(r,t),r.FS.rename(e,t)}var Ee="[",Ce="(<=>!~",Te=";",Ne="@",De=new RegExp(`[${Ee+Ce+Te+Ne}]`);function Ue(r){return r.split(De)[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=>Ue(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 xe(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"),i=await import("node:url");!r.includes("://")&&o.isAbsolute(r)&&(r=i.pathToFileURL(r).href)}return{scriptURL:r,pyodideIndexURL:s,isESModule:!0}}else return{scriptURL:r,pyodideIndexURL:s,isESModule:!1}}async function ne(r,e){let{scriptURL:t,pyodideIndexURL:s,isESModule:o}=await xe(r),i;return o?i=(await import(t)).loadPyodide:(importScripts(t),i=self.loadPyodide),i({...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,47 @@ class Table:
|
|
|
15
15
|
"""
|
|
16
16
|
}
|
|
17
17
|
)
|
|
18
|
-
`)}
|
|
18
|
+
`)}var W;function qe(r,e){return W||(r.runPython(`
|
|
19
|
+
import ast
|
|
20
|
+
from textwrap import dedent
|
|
21
|
+
|
|
22
|
+
def find_imports(source: str) -> list[str]:
|
|
23
|
+
source = dedent(source)
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
mod = ast.parse(source)
|
|
27
|
+
except SyntaxError:
|
|
28
|
+
return []
|
|
29
|
+
imports = set()
|
|
30
|
+
for node in mod.body:
|
|
31
|
+
if isinstance(node, ast.Import):
|
|
32
|
+
for name in node.names:
|
|
33
|
+
node_name = name.name
|
|
34
|
+
imports.add(node_name.split(".")[0])
|
|
35
|
+
elif isinstance(node, ast.ImportFrom):
|
|
36
|
+
module_name = node.module
|
|
37
|
+
if module_name is None:
|
|
38
|
+
continue
|
|
39
|
+
imports.add(module_name.split(".")[0])
|
|
40
|
+
return imports
|
|
41
|
+
`),W=r.globals.get("find_imports")),W(e).toJs()}function $e(r){let e=new Set;for(let t of r)for(let s of t)e.add(s);return e}async function ie(r,e,t){let s=t.map(g=>qe(r,g)),o=$e(s),a=Array.from(o).filter(g=>!r.runPython(`__import__('importlib').util.find_spec('${g}')`)).map(g=>r._api._import_name_to_package_name.get(g)).filter(g=>g);if(a.length===0)return;let c=new MessageChannel;e({type:"event:moduleAutoLoad",data:{packagesToLoad:a}},c.port2);try{let g=await r.loadPackage(a);c.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:g}}),c.port1.close();return}catch(g){throw c.port1.postMessage({type:"moduleAutoLoad:error",error:g}),c.port1.close(),g}}var D=global;function ae(r,e,t){let s=ie(r,e,t);D.__moduleAutoLoadPromise__=s,r.runPythonAsync(`
|
|
19
42
|
from streamlit.runtime.scriptrunner import script_runner
|
|
20
43
|
from js import __moduleAutoLoadPromise__
|
|
21
44
|
|
|
22
45
|
script_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__
|
|
23
|
-
`)}function
|
|
46
|
+
`)}function ce(r,e,t){function s(f){e({type:"event:progress",data:{message:f}})}let o,i,n=new le.PromiseDelegate;async function a(){let f=await n.promise,l={...t,...f};console.debug("Initial data",l);let{entrypoint:S,files:_,archives:d,requirements:p,prebuiltPackageNames:y,wheels:h,mountedSitePackagesSnapshotFilePath:v,pyodideUrl:k=r,streamlitConfig:A,idbfsMountpoints:O,nodefsMountpoints:z,moduleAutoLoad:ue}=l,L=H(p);s("Loading Pyodide."),console.debug("Loading Pyodide"),o=await ne(k,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let J=!1;O&&(J=!0,O.forEach(u=>{o.FS.mkdir(u),o.FS.mount(o.FS.filesystems.IDBFS,{},u)}),await new Promise((u,m)=>{o.FS.syncfs(!0,b=>{b?m(b):u()})})),z&&Object.entries(z).forEach(([u,m])=>{o.FS.mkdir(u),o.FS.mount(o.FS.filesystems.NODEFS,{root:m},u)}),s("Mounting files.");let K=[];if(await Promise.all(Object.keys(_).map(async u=>{let m=_[u],b;"url"in m?(console.debug(`Fetch a file from ${m.url}`),b=await fetch(m.url).then(F=>F.arrayBuffer()).then(F=>new Uint8Array(F))):b=m.data;let{opts:E}=_[u];console.debug(`Write a file "${u}"`),$(o,u,b,E),u.endsWith(".py")&&K.push(u)})),s("Unpacking archives."),await Promise.all(d.map(async u=>{let m;"url"in u?(console.debug(`Fetch an archive from ${u.url}`),m=await fetch(u.url).then(F=>F.arrayBuffer())):m=u.buffer;let{format:b,options:E}=u;console.debug("Unpack an archive",{format:b,options:E}),o.unpackArchive(m,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
47
|
site_packages_dirs = site.getsitepackages()
|
|
25
48
|
for site_packages in site_packages_dirs:
|
|
26
49
|
shutil.rmtree(site_packages)
|
|
27
|
-
`),console.debug(`Unarchive ${v}`),await
|
|
50
|
+
`),console.debug(`Unarchive ${v}`),await o.runPythonAsync(`
|
|
28
51
|
with tarfile.open("${v}", "r") as tar_gz_file:
|
|
29
52
|
tar_gz_file.extractall("/")
|
|
30
|
-
`),console.debug("Restored the snapshot"),s("Mocking some packages."),console.debug("Mock pyarrow"),j(
|
|
53
|
+
`),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 V=o.pyimport("micropip");if(h?(console.debug("Installing the wheels:",h,"and the requirements:",L),await V.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 V.install.callKwargs(L,{keep_going:!0}),console.debug("Installed the requirements")),ue){let u=K.map(m=>o.FS.readFile(m,{encoding:"utf8"}));ae(o,e,u)}await o.runPythonAsync(`
|
|
31
54
|
import importlib
|
|
32
55
|
importlib.invalidate_caches()
|
|
33
|
-
`),s("Loading streamlit package."),console.debug("Loading the Streamlit package"),await
|
|
56
|
+
`),s("Loading streamlit package."),console.debug("Loading the Streamlit package"),await o.runPythonAsync(`
|
|
34
57
|
import streamlit.runtime
|
|
35
|
-
`),console.debug("Loaded the Streamlit package"),s("Setting up the loggers."),console.debug("Setting the loggers"),await
|
|
58
|
+
`),console.debug("Loaded the Streamlit package"),s("Setting up the loggers."),console.debug("Setting the loggers"),await o.runPythonAsync(`
|
|
36
59
|
import logging
|
|
37
60
|
import streamlit.logger
|
|
38
61
|
|
|
@@ -50,7 +73,7 @@ for name in streamlit.logger._loggers.keys():
|
|
|
50
73
|
logger.setLevel(logging.NOTSET)
|
|
51
74
|
|
|
52
75
|
streamlit.logger._loggers = {}
|
|
53
|
-
`);let
|
|
76
|
+
`);let ge=(u,m)=>{u>=40?console.error(m):u>=30?console.warn(m):u>=20?console.info(m):console.debug(m)};D.__logCallback__=ge,await o.runPythonAsync(`
|
|
54
77
|
def setup_loggers(streamlit_level, streamlit_message_format):
|
|
55
78
|
from js import __logCallback__
|
|
56
79
|
|
|
@@ -79,14 +102,14 @@ def setup_loggers(streamlit_level, streamlit_message_format):
|
|
|
79
102
|
streamlit_handler.setFormatter(streamlit_formatter)
|
|
80
103
|
streamlit_logger.addHandler(streamlit_handler)
|
|
81
104
|
streamlit_logger.setLevel(streamlit_level.upper())
|
|
82
|
-
`);let
|
|
105
|
+
`);let fe=(A?.["logger.level"]??"INFO").toString(),me=A?.["logger.messageFormat"]??"%(asctime)s %(message)s";if(o.globals.get("setup_loggers")(fe,me),console.debug("Set the loggers"),s("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await o.runPythonAsync(`
|
|
83
106
|
import streamlit
|
|
84
107
|
|
|
85
108
|
def is_cacheable_msg(msg):
|
|
86
109
|
return False
|
|
87
110
|
|
|
88
111
|
streamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg
|
|
89
|
-
`),console.debug("Mocked some Streamlit functions"),
|
|
112
|
+
`),console.debug("Mocked some Streamlit functions"),J){s("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let u=!1;D.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),u||(u=!0,o.FS.syncfs(!1,m=>{u=!1,m&&console.error(m)}))},await o.runPythonAsync(`
|
|
90
113
|
from streamlit.runtime.app_session import AppSession
|
|
91
114
|
from streamlit.runtime.scriptrunner import ScriptRunnerEvent
|
|
92
115
|
from js import __scriptFinishedCallback__
|
|
@@ -101,7 +124,7 @@ def wrap_app_session_on_scriptrunner_event(original_method):
|
|
|
101
124
|
return wrapped
|
|
102
125
|
|
|
103
126
|
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"),
|
|
127
|
+
`),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
128
|
from stlite_server.bootstrap import load_config_options, prepare
|
|
106
129
|
from stlite_server.server import Server
|
|
107
130
|
from js import __streamlitFlagOptions__
|
|
@@ -116,4 +139,4 @@ prepare(main_script_path, args)
|
|
|
116
139
|
|
|
117
140
|
server = Server(main_script_path)
|
|
118
141
|
server.start()
|
|
119
|
-
`),console.debug("Booted up the Streamlit server"),console.debug("Setting up the HTTP server"),
|
|
142
|
+
`),console.debug("Booted up the Streamlit server"),console.debug("Setting up the HTTP server"),i=o.globals.get("server").copy(),console.debug("Set up the HTTP server"),e({type:"event:loaded"}),l}let c=a().catch(f=>{throw e({type:"event:error",data:{error:f}}),f}),g=async f=>{let l=f.data;if(l.type==="initData"){n.resolve(l.data);return}let{moduleAutoLoad:S}=await c,_=f.ports[0];try{switch(l.type){case"websocket:connect":{console.debug("websocket:connect",l.data);let{path:d}=l.data;i.start_websocket(d,(p,y)=>{if(y){let h=p,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:p}})}),_.postMessage({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",l.data);let{payload:d}=l.data;i.receive_websocket_from_js(d);break}case"http:request":{console.debug("http:request",l.data);let{request:d}=l.data,p=(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}}};_.postMessage(O)};i.receive_http_from_js(d.method,decodeURIComponent(d.path),d.headers,d.body,p);break}case"file:write":{let{path:d,data:p,opts:y}=l.data;S&&typeof p=="string"&&d.endsWith(".py")&&(console.debug(`Auto install the requirements in ${d}`),ae(o,e,[p])),console.debug(`Write a file "${d}"`),$(o,d,p,y),_.postMessage({type:"reply"});break}case"file:rename":{let{oldPath:d,newPath:p}=l.data;console.debug(`Rename "${d}" to ${p}`),se(o,d,p),_.postMessage({type:"reply"});break}case"file:unlink":{let{path:d}=l.data;console.debug(`Remove "${d}`),o.FS.unlink(d),_.postMessage({type:"reply"});break}case"install":{let{requirements:d}=l.data,p=o.pyimport("micropip"),y=H(d);console.debug("Install the requirements:",y),await p.install.callKwargs(y,{keep_going:!0}).then(()=>{console.debug("Successfully installed"),_.postMessage({type:"reply"})})}}}catch(d){if(console.error(d),!(d instanceof Error))throw d;let p=new Error(d.message);p.name=d.name,p.stack=d.stack,_.postMessage({type:"reply",error:p})}};return e({type:"event:start"}),g}function de(){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 He=r=>{console.debug("[worker thread] postMessage from worker",r),B.parentPort?.postMessage(r)},je=ce(process.env.PYODIDE_URL,He,{nodefsMountpoints:de()});B.parentPort?.on("message",({data:r,port:e})=>{console.debug("[worker thread] parentPort.onMessage",{data:r,port:e}),je({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.
|
|
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.b1355ae6.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())}))};let u;function p(e,t,n){return g(this,void 0,void 0,(function*(){const r=n.map((t=>function(e,t){if(!u){const t='\nimport ast\nfrom textwrap import dedent\n\ndef find_imports(source: str) -> list[str]:\n source = dedent(source)\n\n try:\n mod = ast.parse(source)\n except SyntaxError:\n return []\n imports = set()\n for node in mod.body:\n if isinstance(node, ast.Import):\n for name in node.names:\n node_name = name.name\n imports.add(node_name.split(".")[0])\n elif isinstance(node, ast.ImportFrom):\n module_name = node.module\n if module_name is None:\n continue\n imports.add(module_name.split(".")[0])\n return imports\n';e.runPython(t),u=e.globals.get("find_imports")}return u(t).toJs()}(e,t))),o=function(e){const t=new Set;for(const n of e)for(const e of n)t.add(e);return t}(r),s=Array.from(o).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===s.length)return;const i=new MessageChannel;t({type:"event:moduleAutoLoad",data:{packagesToLoad:s}},i.port2);try{const t=yield e.loadPackage(s);return i.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:t}}),void i.port1.close()}catch(a){throw i.port1.postMessage({type:"moduleAutoLoad:error",error:a}),i.port1.close(),a}}))}var m=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 f=n.g;function h(e,t,n){const r=p(e,t,n);f.__moduleAutoLoadPromise__=r,e.runPythonAsync("\nfrom streamlit.runtime.scriptrunner import script_runner\nfrom js import __moduleAutoLoadPromise__\n\nscript_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__\n")}const _=self.postMessage;self.onmessage=function(t,n,r){function i(e){n({type:"event:progress",data:{message:e}})}let l,g;const u=new e,p=function(){var e,o;return m(this,void 0,void 0,(function*(){const p=yield u.promise,_=Object.assign(Object.assign({},r),p);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:x,moduleAutoLoad:L}=_,I=a(w);i("Loading Pyodide."),console.debug("Loading Pyodide"),l=yield c(P,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let O=!1;C&&(O=!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()}))}))),x&&Object.entries(x).forEach((([e,t])=>{l.FS.mkdir(e),l.FS.mount(l.FS.filesystems.NODEFS,{root:t},e)})),i("Mounting files.");const j=[];if(yield Promise.all(Object.keys(v).map((e=>m(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")&&j.push(e)}))))),i("Unpacking archives."),yield Promise.all(b.map((e=>m(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:",I),yield E.install.callKwargs([S.stliteServer,S.streamlit,...I],{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:",I),yield E.install.callKwargs(I,{keep_going:!0}),console.debug("Installed the requirements")),L){const e=j.map((e=>l.FS.readFile(e,{encoding:"utf8"})));h(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');f.__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"),O){i("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let e=!1;f.__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"),f.__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=>m(this,void 0,void 0,(function*(){const t=e.data;if("initData"===t.type)return void u.resolve(t.data);const{moduleAutoLoad:r}=yield p,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}`),h(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)=>_(e,t?[t]:void 0)))})()})();
|