@stlite/desktop 0.51.0 → 0.51.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/README.md CHANGED
@@ -24,7 +24,7 @@ Convert your [Streamlit](https://streamlit.io/) application into a desktop app w
24
24
  }
25
25
  },
26
26
  "devDependencies": {
27
- "@stlite/desktop": "^0.48.0",
27
+ "@stlite/desktop": "^0.51.0",
28
28
  "cross-env": "^7.0.3",
29
29
  "electron": "^28.2.1",
30
30
  "electron-builder": "^24.9.1"
@@ -56,7 +56,7 @@ Convert your [Streamlit](https://streamlit.io/) application into a desktop app w
56
56
  To make your app secure, be sure to use the latest version of Electron.
57
57
  This is [announced](https://www.electronjs.org/docs/latest/tutorial/security#16-use-a-current-version-of-electron) as one of the security best practices in the Electron document too.
58
58
 
59
- ## Configure app
59
+ ## Configure the app
60
60
 
61
61
  ### Hide the toolbar, hamburger menu, and the footer
62
62
 
@@ -125,7 +125,7 @@ In the example below, `"."` on the host OS file system is mounted to the `/mnt`
125
125
  }
126
126
  ```
127
127
 
128
- #### NodeJS worker mode
128
+ ### NodeJS worker mode
129
129
 
130
130
  `@stlite/desktop` runs your app on [Electron](https://www.electronjs.org/) as a desktop app.
131
131
  Electron apps have two processes: the main process which is a Node.js process running in the background, and the renderer process which is a Chromium (browser) process running the app's UI.
@@ -1,18 +1,18 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var E=Object.create;var T=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var m=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var A=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of W(t))!J.call(e,a)&&a!==i&&T(e,a,{get:()=>t[a],enumerable:!(r=C(t,a))||r.enumerable});return e};var p=(e,t,i)=>(i=e!=null?E(H(e)):{},A(t||!e||!e.__esModule?T(i,"default",{value:e,enumerable:!0}):i,e));var q=m(g=>{"use strict";Object.defineProperty(g,"__esModule",{value:!0});g.verifyRequirements=void 0;function U(e){e.forEach(t=>{let i;try{i=new URL(t)}catch{return}if(i.protocol==="emfs:"||i.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)})}g.verifyRequirements=U});var O=m(h=>{"use strict";Object.defineProperty(h,"__esModule",{value:!0});h.parseRequirementsTxt=void 0;var L=/\s#.*$/;function z(e){return e.split(`
3
- `).filter(t=>!t.startsWith("#")).map(t=>t.replace(L,"")).map(t=>t.trim()).filter(t=>t!=="")}h.parseRequirementsTxt=z});var B=m(y=>{"use strict";Object.defineProperty(y,"__esModule",{value:!0});y.PromiseDelegate=void 0;var P=class{constructor(){this.promise=new Promise((t,i)=>{this.resolveInternal=t,this.rejectInternal=i})}resolve(t){this.resolveInternal(t)}reject(t){this.rejectInternal(t)}};y.PromiseDelegate=P});var S=m(c=>{"use strict";var N=c&&c.__createBinding||(Object.create?function(e,t,i,r){r===void 0&&(r=i);var a=Object.getOwnPropertyDescriptor(t,i);(!a||("get"in a?!t.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,r,a)}:function(e,t,i,r){r===void 0&&(r=i),e[r]=t[i]}),v=c&&c.__exportStar||function(e,t){for(var i in e)i!=="default"&&!Object.prototype.hasOwnProperty.call(t,i)&&N(t,e,i)};Object.defineProperty(c,"__esModule",{value:!0});v(q(),c);v(O(),c);v(B(),c)});var F=p(require("yargs")),M=require("yargs/helpers"),o=p(require("path")),n=p(require("fs/promises")),_=p(require("fs-extra")),D=p(require("node-fetch")),b=require("pyodide"),w=p(S());var I=require("pyodide");function k(e){return`https://cdn.jsdelivr.net/pyodide/v${I.version}/full/${e}`}var $=p(require("node-fetch"));var f=class e{static _instance;_data=null;constructor(){}static async loadPyodideBuiltinPackageData(){let t=k("pyodide-lock.json");return console.log(`Load the Pyodide pyodide-lock.json from ${t}`),(await(await(0,$.default)(t,void 0)).json()).packages}static async getInstance(){return this._instance==null&&(this._instance=new e,this._instance._data=await this.loadPyodideBuiltinPackageData()),this._instance}getPackageInfoByName(t){if(this._data==null)throw new Error("The package data is not loaded yet.");let i=Object.values(this._data).find(r=>r.name===t);if(i==null)throw new Error(`Package ${t} is not found in the lock file.`);return i}};global.fetch=D.default;var K="../build",V="../wheels";async function R(e,t){let i=[],r=a=>{i.push(a)};if(await e.loadPackage(t,{errorCallback:r}),i.length>0)throw new Error(i.join(`
4
- `))}async function G(e){console.info("Copy the build directory (the bare built app files) to this directory...");let t=o.default.resolve(__dirname,K);if(!(await n.default.stat(t)).isDirectory())throw new Error(`The source ${t} does not exist.`);if(t===e.copyTo){console.warn(`sourceDir == destDir (${t}). Are you in the development environment? Skip copying the directory.`);return}if(e.keepOld)try{await n.default.access(e.copyTo),console.info(`${e.copyTo} already exists. Use it and skip copying.`);return}catch{throw new Error(`${e.copyTo} does not exist even though the \`keepOld\` option is specified`)}console.log(`Copy ${t} to ${e.copyTo}`),await n.default.rm(e.copyTo,{recursive:!0,force:!0}),await _.default.copy(t,e.copyTo)}async function Q(e){if(e.requirements.length===0)return[];let t=await(0,b.loadPyodide)();return await x(t,{requirements:e.requirements}),Object.entries(t.loadedPackages).filter(([,i])=>i==="default channel").map(([i])=>i)}async function j(e,t){console.log(`Preparing the local wheel ${t}`);let i=await n.default.readFile(t),r="/tmp/"+o.default.basename(t);e.FS.writeFile(r,i);let a=`emfs:${r}`;return console.log(`The local wheel ${t} is prepared as ${a}`),a}async function x(e,t){await R(e,"micropip");let i=e.pyimport("micropip"),r=[...t.requirements],a=o.default.join(__dirname,V),s=await j(e,o.default.join(a,"stlite_server-0.1.0-py3-none-any.whl"));r.push(s);let l=await j(e,o.default.join(a,"streamlit-1.32.2-cp311-none-any.whl"));r.push(l),console.log("Install the packages:",r),await i.install.callKwargs(r,{keep_going:!0})}async function X(e){console.info("Create the site-packages snapshot file...");let t=await(0,b.loadPyodide)();await R(t,"micropip");let i=t.pyimport("micropip"),r=await f.getInstance(),a=[];e.usedBuiltinPackages.length>0&&(console.log("Mocking builtin packages so that they will not be included in the site-packages snapshot because these will be installed from the vendored wheel files at runtime..."),e.usedBuiltinPackages.forEach(d=>{let u=r.getPackageInfoByName(d);if(u==null)throw new Error(`Package ${d} is not found in the lock file.`);console.log(`Mock ${u.name} ${u.version}`),i.add_mock_package(u.name,u.version),a.push(u.name)})),console.log(`Install the requirements ${JSON.stringify(e.requirements)}`),await x(t,{requirements:e.requirements}),console.log("Remove the mocked packages",a),a.forEach(d=>i.remove_mock_package(d)),console.log("Archive the site-packages director(y|ies)");let s="/tmp/site-packages-snapshot.tar.gz";await t.runPythonAsync(`
2
+ "use strict";var rt=Object.create;var re=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,at=Object.prototype.hasOwnProperty;var q=(r,o)=>()=>(o||r((o={exports:{}}).exports,o),o.exports);var ct=(r,o,a,c)=>{if(o&&typeof o=="object"||typeof o=="function")for(let f of ot(o))!at.call(r,f)&&f!==a&&re(r,f,{get:()=>o[f],enumerable:!(c=it(o,f))||c.enumerable});return r};var D=(r,o,a)=>(a=r!=null?rt(st(r)):{},ct(o||!r||!r.__esModule?re(a,"default",{value:r,enumerable:!0}):a,r));var ie=q(B=>{"use strict";Object.defineProperty(B,"__esModule",{value:!0});B.verifyRequirements=void 0;function ft(r){r.forEach(o=>{let a;try{a=new URL(o)}catch{return}if(a.protocol==="emfs:"||a.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${o})`)})}B.verifyRequirements=ft});var oe=q(A=>{"use strict";Object.defineProperty(A,"__esModule",{value:!0});A.parseRequirementsTxt=void 0;var ut=/\s#.*$/;function dt(r){return r.split(`
3
+ `).filter(o=>!o.startsWith("#")).map(o=>o.replace(ut,"")).map(o=>o.trim()).filter(o=>o!=="")}A.parseRequirementsTxt=dt});var se=q(F=>{"use strict";Object.defineProperty(F,"__esModule",{value:!0});F.PromiseDelegate=void 0;var U=class{constructor(){this.promise=new Promise((o,a)=>{this.resolveInternal=o,this.rejectInternal=a})}resolve(o){this.resolveInternal(o)}reject(o){this.rejectInternal(o)}};F.PromiseDelegate=U});var ae=q(S=>{"use strict";var lt=S&&S.__createBinding||(Object.create?function(r,o,a,c){c===void 0&&(c=a);var f=Object.getOwnPropertyDescriptor(o,a);(!f||("get"in f?!o.__esModule:f.writable||f.configurable))&&(f={enumerable:!0,get:function(){return o[a]}}),Object.defineProperty(r,c,f)}:function(r,o,a,c){c===void 0&&(c=a),r[c]=o[a]}),L=S&&S.__exportStar||function(r,o){for(var a in r)a!=="default"&&!Object.prototype.hasOwnProperty.call(o,a)&&lt(o,r,a)};Object.defineProperty(S,"__esModule",{value:!0});L(ie(),S);L(oe(),S);L(se(),S)});var K=q((R,ue)=>{(function(r,o){typeof R=="object"&&typeof ue<"u"?o(R):typeof define=="function"&&define.amd?define(["exports"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r.Superstruct={}))})(R,function(r){"use strict";class o extends TypeError{constructor(t,n){let i,{message:s,explanation:u,...l}=t,{path:y}=t,g=y.length===0?s:`At path: ${y.join(".")} -- ${s}`;super(u??g),u!=null&&(this.cause=g),Object.assign(this,l),this.name=this.constructor.name,this.failures=()=>i??(i=[t,...n()])}}function a(e){return c(e)&&typeof e[Symbol.iterator]=="function"}function c(e){return typeof e=="object"&&e!=null}function f(e){if(Object.prototype.toString.call(e)!=="[object Object]")return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function d(e){return typeof e=="symbol"?e.toString():typeof e=="string"?JSON.stringify(e):`${e}`}function $(e){let{done:t,value:n}=e.next();return t?void 0:n}function j(e,t,n,i){if(e===!0)return;e===!1?e={}:typeof e=="string"&&(e={message:e});let{path:s,branch:u}=t,{type:l}=n,{refinement:y,message:g=`Expected a value of type \`${l}\`${y?` with refinement \`${y}\``:""}, but received: \`${d(i)}\``}=e;return{value:i,type:l,refinement:y,key:s[s.length-1],path:s,branch:u,...e,message:g}}function*_(e,t,n,i){a(e)||(e=[e]);for(let s of e){let u=j(s,t,n,i);u&&(yield u)}}function*N(e,t,n={}){let{path:i=[],branch:s=[e],coerce:u=!1,mask:l=!1}=n,y={path:i,branch:s};if(u&&(e=t.coercer(e,y),l&&t.type!=="type"&&c(t.schema)&&c(e)&&!Array.isArray(e)))for(let p in e)t.schema[p]===void 0&&delete e[p];let g="valid";for(let p of t.validator(e,y))p.explanation=n.message,g="not_valid",yield[p,void 0];for(let[p,b,tt]of t.entries(e,y)){let nt=N(b,tt,{path:p===void 0?i:[...i,p],branch:p===void 0?s:[...s,b],coerce:u,mask:l,message:n.message});for(let I of nt)I[0]?(g=I[0].refinement!=null?"not_refined":"not_valid",yield[I[0],void 0]):u&&(b=I[1],p===void 0?e=b:e instanceof Map?e.set(p,b):e instanceof Set?e.add(b):c(e)&&(b!==void 0||p in e)&&(e[p]=b))}if(g!=="not_valid")for(let p of t.refiner(e,y))p.explanation=n.message,g="not_refined",yield[p,void 0];g==="valid"&&(yield[void 0,e])}class m{constructor(t){let{type:n,schema:i,validator:s,refiner:u,coercer:l=g=>g,entries:y=function*(){}}=t;this.type=n,this.schema=i,this.entries=y,this.coercer=l,s?this.validator=(g,p)=>{let b=s(g,p);return _(b,p,this,g)}:this.validator=()=>[],u?this.refiner=(g,p)=>{let b=u(g,p);return _(b,p,this,g)}:this.refiner=()=>[]}assert(t,n){return X(t,this,n)}create(t,n){return Y(t,this,n)}is(t){return W(t,this)}mask(t,n){return Z(t,this,n)}validate(t,n={}){return T(t,this,n)}}function X(e,t,n){let i=T(e,t,{message:n});if(i[0])throw i[0]}function Y(e,t,n){let i=T(e,t,{coerce:!0,message:n});if(i[0])throw i[0];return i[1]}function Z(e,t,n){let i=T(e,t,{coerce:!0,mask:!0,message:n});if(i[0])throw i[0];return i[1]}function W(e,t){return!T(e,t)[0]}function T(e,t,n={}){let i=N(e,t,n),s=$(i);return s[0]?[new o(s[0],function*(){for(let l of i)l[0]&&(yield l[0])}),void 0]:[void 0,s[1]]}function be(...e){let t=e[0].type==="type",n=e.map(s=>s.schema),i=Object.assign({},...n);return t?E(i):v(i)}function w(e,t){return new m({type:e,schema:null,validator:t})}function Pe(e,t){return new m({...e,refiner:(n,i)=>n===void 0||e.refiner(n,i),validator(n,i){return n===void 0?!0:(t(n,i),e.validator(n,i))}})}function $e(e){return new m({type:"dynamic",schema:null,*entries(t,n){yield*e(t,n).entries(t,n)},validator(t,n){return e(t,n).validator(t,n)},coercer(t,n){return e(t,n).coercer(t,n)},refiner(t,n){return e(t,n).refiner(t,n)}})}function _e(e){let t;return new m({type:"lazy",schema:null,*entries(n,i){t??(t=e()),yield*t.entries(n,i)},validator(n,i){return t??(t=e()),t.validator(n,i)},coercer(n,i){return t??(t=e()),t.coercer(n,i)},refiner(n,i){return t??(t=e()),t.refiner(n,i)}})}function De(e,t){let{schema:n}=e,i={...n};for(let s of t)delete i[s];switch(e.type){case"type":return E(i);default:return v(i)}}function Se(e){let t=e instanceof m,n=t?{...e.schema}:{...e};for(let i in n)n[i]=x(n[i]);return t&&e.type==="type"?E(n):v(n)}function je(e,t){let{schema:n}=e,i={};for(let s of t)i[s]=n[s];switch(e.type){case"type":return E(i);default:return v(i)}}function Oe(e,t){return console.warn("superstruct@0.11 - The `struct` helper has been renamed to `define`."),w(e,t)}function Te(){return w("any",()=>!0)}function ve(e){return new m({type:"array",schema:e,*entries(t){if(e&&Array.isArray(t))for(let[n,i]of t.entries())yield[n,i,e]},coercer(t){return Array.isArray(t)?t.slice():t},validator(t){return Array.isArray(t)||`Expected an array value, but received: ${d(t)}`}})}function Ee(){return w("bigint",e=>typeof e=="bigint")}function qe(){return w("boolean",e=>typeof e=="boolean")}function Me(){return w("date",e=>e instanceof Date&&!isNaN(e.getTime())||`Expected a valid \`Date\` object, but received: ${d(e)}`)}function Ie(e){let t={},n=e.map(i=>d(i)).join();for(let i of e)t[i]=i;return new m({type:"enums",schema:t,validator(i){return e.includes(i)||`Expected one of \`${n}\`, but received: ${d(i)}`}})}function Be(){return w("func",e=>typeof e=="function"||`Expected a function, but received: ${d(e)}`)}function Ae(e){return w("instance",t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${d(t)}`)}function Fe(){return w("integer",e=>typeof e=="number"&&!isNaN(e)&&Number.isInteger(e)||`Expected an integer, but received: ${d(e)}`)}function ze(e){return new m({type:"intersection",schema:null,*entries(t,n){for(let i of e)yield*i.entries(t,n)},*validator(t,n){for(let i of e)yield*i.validator(t,n)},*refiner(t,n){for(let i of e)yield*i.refiner(t,n)}})}function Re(e){let t=d(e),n=typeof e;return new m({type:"literal",schema:n==="string"||n==="number"||n==="boolean"?e:null,validator(i){return i===e||`Expected the literal \`${t}\`, but received: ${d(i)}`}})}function Je(e,t){return new m({type:"map",schema:null,*entries(n){if(e&&t&&n instanceof Map)for(let[i,s]of n.entries())yield[i,i,e],yield[i,s,t]},coercer(n){return n instanceof Map?new Map(n):n},validator(n){return n instanceof Map||`Expected a \`Map\` object, but received: ${d(n)}`}})}function C(){return w("never",()=>!1)}function Ne(e){return new m({...e,validator:(t,n)=>t===null||e.validator(t,n),refiner:(t,n)=>t===null||e.refiner(t,n)})}function We(){return w("number",e=>typeof e=="number"&&!isNaN(e)||`Expected a number, but received: ${d(e)}`)}function v(e){let t=e?Object.keys(e):[],n=C();return new m({type:"object",schema:e||null,*entries(i){if(e&&c(i)){let s=new Set(Object.keys(i));for(let u of t)s.delete(u),yield[u,i[u],e[u]];for(let u of s)yield[u,i[u],n]}},validator(i){return c(i)||`Expected an object, but received: ${d(i)}`},coercer(i){return c(i)?{...i}:i}})}function x(e){return new m({...e,validator:(t,n)=>t===void 0||e.validator(t,n),refiner:(t,n)=>t===void 0||e.refiner(t,n)})}function Ce(e,t){return new m({type:"record",schema:null,*entries(n){if(c(n))for(let i in n){let s=n[i];yield[i,i,e],yield[i,s,t]}},validator(n){return c(n)||`Expected an object, but received: ${d(n)}`}})}function He(){return w("regexp",e=>e instanceof RegExp)}function Ue(e){return new m({type:"set",schema:null,*entries(t){if(e&&t instanceof Set)for(let n of t)yield[n,n,e]},coercer(t){return t instanceof Set?new Set(t):t},validator(t){return t instanceof Set||`Expected a \`Set\` object, but received: ${d(t)}`}})}function ee(){return w("string",e=>typeof e=="string"||`Expected a string, but received: ${d(e)}`)}function Le(e){let t=C();return new m({type:"tuple",schema:null,*entries(n){if(Array.isArray(n)){let i=Math.max(e.length,n.length);for(let s=0;s<i;s++)yield[s,n[s],e[s]||t]}},validator(n){return Array.isArray(n)||`Expected an array, but received: ${d(n)}`}})}function E(e){let t=Object.keys(e);return new m({type:"type",schema:e,*entries(n){if(c(n))for(let i of t)yield[i,n[i],e[i]]},validator(n){return c(n)||`Expected an object, but received: ${d(n)}`},coercer(n){return c(n)?{...n}:n}})}function Ke(e){let t=e.map(n=>n.type).join(" | ");return new m({type:"union",schema:null,coercer(n){for(let i of e){let[s,u]=i.validate(n,{coerce:!0});if(!s)return u}return n},validator(n,i){let s=[];for(let u of e){let[...l]=N(n,u,i),[y]=l;if(y[0])for(let[g]of l)g&&s.push(g);else return[]}return[`Expected the value to satisfy a union of \`${t}\`, but received: ${d(n)}`,...s]}})}function te(){return w("unknown",()=>!0)}function H(e,t,n){return new m({...e,coercer:(i,s)=>W(i,t)?e.coercer(n(i,s),s):e.coercer(i,s)})}function Ge(e,t,n={}){return H(e,te(),i=>{let s=typeof t=="function"?t():t;if(i===void 0)return s;if(!n.strict&&f(i)&&f(s)){let u={...i},l=!1;for(let y in s)u[y]===void 0&&(u[y]=s[y],l=!0);if(l)return u}return i})}function Qe(e){return H(e,ee(),t=>t.trim())}function Ve(e){return O(e,"empty",t=>{let n=ne(t);return n===0||`Expected an empty ${e.type} but received one with a size of \`${n}\``})}function ne(e){return e instanceof Map||e instanceof Set?e.size:e.length}function Xe(e,t,n={}){let{exclusive:i}=n;return O(e,"max",s=>i?s<t:s<=t||`Expected a ${e.type} less than ${i?"":"or equal to "}${t} but received \`${s}\``)}function Ye(e,t,n={}){let{exclusive:i}=n;return O(e,"min",s=>i?s>t:s>=t||`Expected a ${e.type} greater than ${i?"":"or equal to "}${t} but received \`${s}\``)}function Ze(e){return O(e,"nonempty",t=>ne(t)>0||`Expected a nonempty ${e.type} but received an empty one`)}function xe(e,t){return O(e,"pattern",n=>t.test(n)||`Expected a ${e.type} matching \`/${t.source}/\` but received "${n}"`)}function et(e,t,n=t){let i=`Expected a ${e.type}`,s=t===n?`of \`${t}\``:`between \`${t}\` and \`${n}\``;return O(e,"size",u=>{if(typeof u=="number"||u instanceof Date)return t<=u&&u<=n||`${i} ${s} but received \`${u}\``;if(u instanceof Map||u instanceof Set){let{size:l}=u;return t<=l&&l<=n||`${i} with a size ${s} but received one with a size of \`${l}\``}else{let{length:l}=u;return t<=l&&l<=n||`${i} with a length ${s} but received one with a length of \`${l}\``}})}function O(e,t,n){return new m({...e,*refiner(i,s){yield*e.refiner(i,s);let u=n(i,s),l=_(u,s,e,i);for(let y of l)yield{...y,refinement:t}}})}r.Struct=m,r.StructError=o,r.any=Te,r.array=ve,r.assert=X,r.assign=be,r.bigint=Ee,r.boolean=qe,r.coerce=H,r.create=Y,r.date=Me,r.defaulted=Ge,r.define=w,r.deprecated=Pe,r.dynamic=$e,r.empty=Ve,r.enums=Ie,r.func=Be,r.instance=Ae,r.integer=Fe,r.intersection=ze,r.is=W,r.lazy=_e,r.literal=Re,r.map=Je,r.mask=Z,r.max=Xe,r.min=Ye,r.never=C,r.nonempty=Ze,r.nullable=Ne,r.number=We,r.object=v,r.omit=De,r.optional=x,r.partial=Se,r.pattern=xe,r.pick=je,r.record=Ce,r.refine=O,r.regexp=He,r.set=Ue,r.size=et,r.string=ee,r.struct=Oe,r.trimmed=Qe,r.tuple=Le,r.type=E,r.union=Ke,r.unknown=te,r.validate=T})});var ge=D(require("yargs")),he=require("yargs/helpers"),k=D(require("path")),P=D(require("fs/promises")),G=D(require("fs-extra")),Q=D(require("node-fetch")),V=require("pyodide"),J=D(ae());var ce=require("pyodide");function z(r){return`https://cdn.jsdelivr.net/pyodide/v${ce.version}/full/${r}`}var fe=D(require("node-fetch"));var M=class r{static _instance;_data=null;constructor(){}static async loadPyodideBuiltinPackageData(){let o=z("pyodide-lock.json");return console.log(`Load the Pyodide pyodide-lock.json from ${o}`),(await(await(0,fe.default)(o,void 0)).json()).packages}static async getInstance(){return this._instance==null&&(this._instance=new r,this._instance._data=await this.loadPyodideBuiltinPackageData()),this._instance}getPackageInfoByName(o){if(this._data==null)throw new Error("The package data is not loaded yet.");let a=Object.values(this._data).find(c=>c.name===o);if(a==null)throw new Error(`Package ${o} is not found in the lock file.`);return a}};var le=D(require("fs/promises")),pe=D(K());var h=D(K()),de=h.object({embed:h.defaulted(h.boolean(),!1),idbfsMountpoints:h.optional(h.array(h.string())),nodeJsWorker:h.defaulted(h.boolean(),!1),nodefsMountpoints:h.optional(h.record(h.string(),h.string()))});function pt(r){let o=pe.create(r??{},de);if(o.nodeJsWorker){if(o.idbfsMountpoints!=null)throw new Error("The `idbfsMountpoints` field is not allowed when `nodeJsWorker` is true.")}else if(o.nodefsMountpoints!=null)throw new Error("The `nodefsMountpoints` field is not allowed when `nodeJsWorker` is false.");return o}async function me(r){let a=require(r.packageJsonPath).stlite?.desktop,c=pt(a),f=JSON.stringify(c,null,2);console.log(`Dump the manifest file -> ${r.manifestFilePath}`),console.log(f),await le.default.writeFile(r.manifestFilePath,f,{encoding:"utf-8"})}global.fetch=Q.default;var mt="../build",yt="../wheels";async function we(r,o){let a=[],c=f=>{a.push(f)};if(await r.loadPackage(o,{errorCallback:c}),a.length>0)throw new Error(a.join(`
4
+ `))}async function gt(r){console.info("Copy the build directory (the bare built app files) to this directory...");let o=k.default.resolve(__dirname,mt);if(!(await P.default.stat(o)).isDirectory())throw new Error(`The source ${o} does not exist.`);if(o===r.copyTo){console.warn(`sourceDir == destDir (${o}). Are you in the development environment? Skip copying the directory.`);return}if(r.keepOld)try{await P.default.access(r.copyTo),console.info(`${r.copyTo} already exists. Use it and skip copying.`);return}catch{throw new Error(`${r.copyTo} does not exist even though the \`keepOld\` option is specified`)}console.log(`Copy ${o} to ${r.copyTo}`),await P.default.rm(r.copyTo,{recursive:!0,force:!0}),await G.default.copy(o,r.copyTo)}async function ht(r){if(r.requirements.length===0)return[];let o=await(0,V.loadPyodide)();return await ke(o,{requirements:r.requirements}),Object.entries(o.loadedPackages).filter(([,a])=>a==="default channel").map(([a])=>a)}async function ye(r,o){console.log(`Preparing the local wheel ${o}`);let a=await P.default.readFile(o),c="/tmp/"+k.default.basename(o);r.FS.writeFile(c,a);let f=`emfs:${c}`;return console.log(`The local wheel ${o} is prepared as ${f}`),f}async function ke(r,o){await we(r,"micropip");let a=r.pyimport("micropip"),c=[...o.requirements],f=k.default.join(__dirname,yt),d=await ye(r,k.default.join(f,"stlite_server-0.1.0-py3-none-any.whl"));c.push(d);let $=await ye(r,k.default.join(f,"streamlit-1.32.2-cp311-none-any.whl"));c.push($),console.log("Install the packages:",c),await a.install.callKwargs(c,{keep_going:!0})}async function wt(r){console.info("Create the site-packages snapshot file...");let o=await(0,V.loadPyodide)();await we(o,"micropip");let a=o.pyimport("micropip"),c=await M.getInstance(),f=[];r.usedBuiltinPackages.length>0&&(console.log("Mocking builtin packages so that they will not be included in the site-packages snapshot because these will be installed from the vendored wheel files at runtime..."),r.usedBuiltinPackages.forEach(j=>{let _=c.getPackageInfoByName(j);if(_==null)throw new Error(`Package ${j} is not found in the lock file.`);console.log(`Mock ${_.name} ${_.version}`),a.add_mock_package(_.name,_.version),f.push(_.name)})),console.log(`Install the requirements ${JSON.stringify(r.requirements)}`),await ke(o,{requirements:r.requirements}),console.log("Remove the mocked packages",f),f.forEach(j=>a.remove_mock_package(j)),console.log("Archive the site-packages director(y|ies)");let d="/tmp/site-packages-snapshot.tar.gz";await o.runPythonAsync(`
5
5
  import os
6
6
  import tarfile
7
7
  import site
8
8
 
9
9
  site_packages_dirs = site.getsitepackages()
10
10
 
11
- tar_file_name = '${s}'
11
+ tar_file_name = '${d}'
12
12
  with tarfile.open(tar_file_name, mode='w:gz') as gzf:
13
13
  for site_packages in site_packages_dirs:
14
14
  print("Add site-package:", site_packages)
15
15
  print(os.listdir(site_packages))
16
16
  gzf.add(site_packages)
17
- `),console.log("Extract the archive file from EMFS");let l=t.FS.readFile(s);console.log(`Save the archive file (${e.saveTo})`),await n.default.writeFile(e.saveTo,l)}async function Y(e){console.info("Copy the Streamlit app directory..."),console.log(`Copy ${e.sourceDir} to ${e.copyTo}`),await n.default.rm(e.copyTo,{recursive:!0,force:!0}),await _.default.copy(e.sourceDir,e.copyTo)}async function Z(e){let t=await n.default.readFile(e,{encoding:"utf-8"});return(0,w.parseRequirementsTxt)(t)}async function ee(e,t){let i=t.join(`
18
- `);await n.default.writeFile(e,i,{encoding:"utf-8"})}async function te(e){let t=await f.getInstance(),r=e.packages.map(a=>t.getPackageInfoByName(a)).map(a=>k(a.file_name));console.log("Downloading the used built-in packages..."),await Promise.all(r.map(async a=>{let s=o.default.resolve(e.destDir,"./pyodide",o.default.basename(a));console.log(`Download ${a} to ${s}`);let l=await(0,D.default)(a);if(!l.ok)throw new Error(`Failed to download ${a}: ${l.status} ${l.statusText}`);let d=await l.arrayBuffer();await n.default.writeFile(s,Buffer.from(d))}))}async function ie(e){let i=require(e.packageJsonPath).stlite?.desktop||{},r={embed:i.embed??!1,idbfsMountpoints:i.idbfsMountpoints,nodeJsWorker:i.nodeJsWorker??!1,nodefsMountpoints:i.nodefsMountpoints},a=JSON.stringify(r,null,2);console.log(`Dump the manifest file -> ${e.manifestFilePath}`),console.log(a),await n.default.writeFile(e.manifestFilePath,a,{encoding:"utf-8"})}(0,F.default)((0,M.hideBin)(process.argv)).command("* <appHomeDirSource> [packages..]","Put the user code and data and the snapshot of the required packages into the build artifact.",()=>{},e=>{console.info(e)}).positional("appHomeDirSource",{describe:"The source directory of the user code and data that will be mounted in the Pyodide file system at app runtime",type:"string",demandOption:!0}).positional("packages",{describe:"Package names to install.",type:"string",array:!0}).options("requirement",{describe:"Install from the given requirements file. This option can be used multiple times.",array:!0,type:"string",alias:"r",default:[]}).options("keepOldBuild",{type:"boolean",default:!1,alias:"k",describe:"Keep the existing build directory contents except appHomeDir."}).parseAsync().then(async e=>{let t=process.cwd(),i=o.default.resolve(t,"./build");try{await n.default.access(e.appHomeDirSource)}catch{throw new Error(`${e.appHomeDirSource} does not exist.`)}let r=e.packages??[];for(let s of e.requirement)r=r.concat(await Z(s));(0,w.verifyRequirements)(r);let a=await Q({requirements:r});console.log("The built-in packages loaded for the given requirements:"),console.log(a),await G({copyTo:i,keepOld:e.keepOldBuild}),await X({requirements:r,usedBuiltinPackages:a,saveTo:o.default.resolve(i,"./site-packages-snapshot.tar.gz")}),await ee(o.default.resolve(i,"./requirements.txt"),a),await Y({sourceDir:e.appHomeDirSource,copyTo:o.default.resolve(i,"./streamlit_app")}),await te({packages:a,destDir:i}),await ie({packageJsonPath:o.default.resolve(t,"./package.json"),manifestFilePath:o.default.resolve(i,"./stlite-manifest.json")})});
17
+ `),console.log("Extract the archive file from EMFS");let $=o.FS.readFile(d);console.log(`Save the archive file (${r.saveTo})`),await P.default.writeFile(r.saveTo,$)}async function kt(r){console.info("Copy the Streamlit app directory..."),console.log(`Copy ${r.sourceDir} to ${r.copyTo}`),await P.default.rm(r.copyTo,{recursive:!0,force:!0}),await G.default.copy(r.sourceDir,r.copyTo)}async function bt(r){let o=await P.default.readFile(r,{encoding:"utf-8"});return(0,J.parseRequirementsTxt)(o)}async function Pt(r,o){let a=o.join(`
18
+ `);await P.default.writeFile(r,a,{encoding:"utf-8"})}async function $t(r){let o=await M.getInstance(),c=r.packages.map(f=>o.getPackageInfoByName(f)).map(f=>z(f.file_name));console.log("Downloading the used built-in packages..."),await Promise.all(c.map(async f=>{let d=k.default.resolve(r.destDir,"./pyodide",k.default.basename(f));console.log(`Download ${f} to ${d}`);let $=await(0,Q.default)(f);if(!$.ok)throw new Error(`Failed to download ${f}: ${$.status} ${$.statusText}`);let j=await $.arrayBuffer();await P.default.writeFile(d,Buffer.from(j))}))}(0,ge.default)((0,he.hideBin)(process.argv)).command("* <appHomeDirSource> [packages..]","Put the user code and data and the snapshot of the required packages into the build artifact.",()=>{},r=>{console.info(r)}).positional("appHomeDirSource",{describe:"The source directory of the user code and data that will be mounted in the Pyodide file system at app runtime",type:"string",demandOption:!0}).positional("packages",{describe:"Package names to install.",type:"string",array:!0}).options("requirement",{describe:"Install from the given requirements file. This option can be used multiple times.",array:!0,type:"string",alias:"r",default:[]}).options("keepOldBuild",{type:"boolean",default:!1,alias:"k",describe:"Keep the existing build directory contents except appHomeDir."}).parseAsync().then(async r=>{let o=process.cwd(),a=k.default.resolve(o,"./build");try{await P.default.access(r.appHomeDirSource)}catch{throw new Error(`${r.appHomeDirSource} does not exist.`)}let c=r.packages??[];for(let d of r.requirement)c=c.concat(await bt(d));(0,J.verifyRequirements)(c);let f=await ht({requirements:c});console.log("The built-in packages loaded for the given requirements:"),console.log(f),await gt({copyTo:a,keepOld:r.keepOldBuild}),await wt({requirements:c,usedBuiltinPackages:f,saveTo:k.default.resolve(a,"./site-packages-snapshot.tar.gz")}),await Pt(k.default.resolve(a,"./requirements.txt"),f),await kt({sourceDir:r.appHomeDirSource,copyTo:k.default.resolve(a,"./streamlit_app")}),await $t({packages:f,destDir:a}),await me({packageJsonPath:k.default.resolve(o,"./package.json"),manifestFilePath:k.default.resolve(a,"./stlite-manifest.json")})});
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "/static/css/main.fb5f4d99.css",
4
- "main.js": "/static/js/main.50eb94c5.js",
4
+ "main.js": "/static/js/main.b686df03.js",
5
5
  "static/js/4681.fc821bbf.chunk.js": "/static/js/4681.fc821bbf.chunk.js",
6
6
  "static/js/4994.37361da4.chunk.js": "/static/js/4994.37361da4.chunk.js",
7
7
  "static/js/3685.39209b63.chunk.js": "/static/js/3685.39209b63.chunk.js",
@@ -162,6 +162,6 @@
162
162
  },
163
163
  "entrypoints": [
164
164
  "static/css/main.fb5f4d99.css",
165
- "static/js/main.50eb94c5.js"
165
+ "static/js/main.b686df03.js"
166
166
  ]
167
167
  }
@@ -1,2 +1,2 @@
1
- var W=Object.create;var P=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var b=(e,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of D(n))!x.call(e,s)&&s!==r&&P(e,s,{get:()=>n[s],enumerable:!(o=R(n,s))||o.enumerable});return e};var w=(e,n,r)=>(r=e!=null?W(S(e)):{},b(n||!e||!e.__esModule?P(r,"default",{value:e,enumerable:!0}):r,e)),I=e=>b(P({},"__esModule",{value:!0}),e);var E={};module.exports=I(E);var t=require("electron"),a=w(require("path")),g=w(require("fs/promises")),v=w(require("node:worker_threads"));var f=w(require("fs/promises")),p=w(require("path"));async function k(e){let n={},r=await f.readdir(e);return await Promise.all(r.map(async o=>{let s=p.join(e,o);if((await f.stat(s)).isDirectory()){let l=await k(s);Object.assign(n,l)}else{let l=await f.readFile(s);n[s]=l}})),n}async function _(e){let n=await k(e),r={};return Object.keys(n).forEach(o=>{let h=p.relative(e,o).split(p.sep).join(p.posix.sep);r[h]=n[o]}),r}async function N(){let e=a.resolve(__dirname,"../stlite-manifest.json"),n=await g.readFile(e,{encoding:"utf-8"}),r=JSON.parse(n);return{embed:r.embed??!1,idbfsMountpoints:r.idbfsMountpoints,nodeJsWorker:r.nodeJsWorker??!1,nodefsMountpoints:r.nodefsMountpoints}}var y=async()=>{let e=await N(),n=[];e.idbfsMountpoints&&n.push(`--idbfs-mountpoints=${JSON.stringify(e.idbfsMountpoints)}`),e.nodeJsWorker&&n.push("--nodejs-worker");let r=new t.BrowserWindow({width:1280,height:720,webPreferences:{preload:a.join(__dirname,"preload.js"),sandbox:!0,additionalArguments:n}}),o=new URL((t.app.isPackaged,"file:///index.html")),s=new URLSearchParams;e.embed&&s.set("embed","true"),o.search=s.toString();let h=o.toString(),l=i=>i.url===h;t.ipcMain.handle("readSitePackagesSnapshot",i=>{if(!l(i.senderFrame))throw new Error("Invalid IPC sender");let m=a.resolve(__dirname,"../site-packages-snapshot.tar.gz");return g.readFile(m)}),t.ipcMain.handle("readRequirements",async i=>{if(!l(i.senderFrame))throw new Error("Invalid IPC sender");let m=a.resolve(__dirname,"../requirements.txt");return(await g.readFile(m,{encoding:"utf-8"})).split(`
2
- `).map(d=>d.trim()).filter(d=>d.length>0)}),t.ipcMain.handle("readStreamlitAppDirectory",async i=>{if(!l(i.senderFrame))throw new Error("Invalid IPC sender");let m=a.resolve(__dirname,"../streamlit_app");return _(m)}),r.on("closed",()=>{t.ipcMain.removeHandler("readSitePackagesSnapshot"),t.ipcMain.removeHandler("readRequirements"),t.ipcMain.removeHandler("readStreamlitAppDirectory")});let c=null;t.ipcMain.handle("initializeNodeJsWorker",i=>{if(!l(i.senderFrame))throw new Error("Invalid IPC sender");let m=a.resolve(__dirname,"../pyodide/pyodide.mjs");function u(d){r.webContents.send("messageFromNodeJsWorker",d)}c=new v.default.Worker(a.resolve(__dirname,"./worker.js"),{env:{PYODIDE_URL:m,NODEFS_MOUNTPOINTS:JSON.stringify(e.nodefsMountpoints)}}),c.on("message",d=>{u(d)})}),t.ipcMain.on("messageToNodeJsWorker",(i,{data:m,portId:u})=>{if(!l(i.senderFrame))throw new Error("Invalid IPC sender");if(c==null)return;let d=new v.default.MessageChannel;d.port1.on("message",F=>{i.reply(`nodeJsWorker-portMessage-${u}`,F)});let M={data:m,port:d.port2};c.postMessage(M,[d.port2])}),t.ipcMain.handle("terminate",(i,{data:m,portId:u})=>{if(!l(i.senderFrame))throw new Error("Invalid IPC sender");c?.terminate(),c=null}),r.on("closed",()=>{t.ipcMain.removeHandler("initializeNodeJsWorker"),t.ipcMain.removeHandler("messageToNodeJsWorker"),t.ipcMain.removeHandler("terminate")}),r.loadURL(h),t.app.isPackaged||r.webContents.openDevTools()};t.app.enableSandbox();t.app.whenReady().then(()=>{let e=a.resolve(__dirname,"..");t.protocol.interceptFileProtocol("file",function(n,r){let o=new URL(n.url).pathname;if(a.isAbsolute(o)){let s=a.join(e,o);r(a.normalize(s))}else r(o)}),y(),t.app.on("activate",()=>{t.BrowserWindow.getAllWindows().length===0&&y()})});t.app.on("window-all-closed",()=>{process.platform!=="darwin"&&t.app.quit()});t.app.on("web-contents-created",(e,n)=>{n.on("will-attach-webview",(r,o,s)=>{r.preventDefault()}),n.on("will-navigate",(r,o)=>{console.debug("will-navigate",o),r.preventDefault()}),n.setWindowOpenHandler(({url:r})=>(console.error("Opening a new window is not allowed."),{action:"deny"}))});
1
+ var Ce=Object.create;var Y=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ue=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty;var He=(i,c)=>()=>(c||i((c={exports:{}}).exports,c),c.exports);var Le=(i,c,f,a)=>{if(c&&typeof c=="object"||typeof c=="function")for(let w of qe(c))!Be.call(i,w)&&w!==f&&Y(i,w,{get:()=>c[w],enumerable:!(a=Je(c,w))||a.enumerable});return i};var M=(i,c,f)=>(f=i!=null?Ce(Ue(i)):{},Le(c||!i||!i.__esModule?Y(f,"default",{value:i,enumerable:!0}):f,i));var Z=He((W,X)=>{(function(i,c){typeof W=="object"&&typeof X<"u"?c(W):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i.Superstruct={}))})(W,function(i){"use strict";class c extends TypeError{constructor(n,t){let r,{message:o,explanation:s,...d}=n,{path:y}=n,h=y.length===0?o:`At path: ${y.join(".")} -- ${o}`;super(s??h),s!=null&&(this.cause=h),Object.assign(this,d),this.name=this.constructor.name,this.failures=()=>r??(r=[n,...t()])}}function f(e){return a(e)&&typeof e[Symbol.iterator]=="function"}function a(e){return typeof e=="object"&&e!=null}function w(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:y,message:h=`Expected a value of type \`${d}\`${y?` with refinement \`${y}\``:""}, but received: \`${p(r)}\``}=e;return{value:r,type:d,refinement:y,key:o[o.length-1],path:o,branch:s,...e,message:h}}function*g(e,n,t,r){f(e)||(e=[e]);for(let o of e){let s=_(o,n,t,r);s&&(yield s)}}function*$(e,n,t={}){let{path:r=[],branch:o=[e],coerce:s=!1,mask:d=!1}=t,y={path:r,branch:o};if(s&&(e=n.coercer(e,y),d&&n.type!=="type"&&a(n.schema)&&a(e)&&!Array.isArray(e)))for(let m in e)n.schema[m]===void 0&&delete e[m];let h="valid";for(let m of n.validator(e,y))m.explanation=t.message,h="not_valid",yield[m,void 0];for(let[m,S,We]of n.entries(e,y)){let ve=$(S,We,{path:m===void 0?r:[...r,m],branch:m===void 0?o:[...o,S],coerce:s,mask:d,message:t.message});for(let T of ve)T[0]?(h=T[0].refinement!=null?"not_refined":"not_valid",yield[T[0],void 0]):s&&(S=T[1],m===void 0?e=S:e instanceof Map?e.set(m,S):e instanceof Set?e.add(S):a(e)&&(S!==void 0||m in e)&&(e[m]=S))}if(h!=="not_valid")for(let m of n.refiner(e,y))m.explanation=t.message,h="not_refined",yield[m,void 0];h==="valid"&&(yield[void 0,e])}class u{constructor(n){let{type:t,schema:r,validator:o,refiner:s,coercer:d=h=>h,entries:y=function*(){}}=n;this.type=t,this.schema=r,this.entries=y,this.coercer=d,o?this.validator=(h,m)=>{let S=o(h,m);return g(S,m,this,h)}:this.validator=()=>[],s?this.refiner=(h,m)=>{let S=s(h,m);return g(S,m,this,h)}:this.refiner=()=>[]}assert(n,t){return k(n,this,t)}create(n,t){return z(n,this,t)}is(n){return v(n,this)}mask(n,t){return R(n,this,t)}validate(n,t={}){return A(n,this,t)}}function k(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 R(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=$(e,n,t),o=E(r);return o[0]?[new c(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 ce(e){let n=e instanceof u,t=n?{...e.schema}:{...e};for(let r in t)t[r]=B(t[r]);return n&&e.type==="type"?I(t):F(t)}function ae(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 we(){return P("integer",e=>typeof e=="number"&&!isNaN(e)&&Number.isInteger(e)||`Expected an integer, but received: ${p(e)}`)}function ge(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 $e(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 ke(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 C(){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=C();return new u({type:"object",schema:e||null,*entries(r){if(e&&a(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 a(r)||`Expected an object, but received: ${p(r)}`},coercer(r){return a(r)?{...r}:r}})}function B(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(a(t))for(let r in t){let o=t[r];yield[r,r,e],yield[r,o,n]}},validator(t){return a(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 H(){return P("string",e=>typeof e=="string"||`Expected a string, but received: ${p(e)}`)}function Me(e){let n=C();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(a(t))for(let r of n)yield[r,t[r],e[r]]},validator(t){return a(t)||`Expected an object, but received: ${p(t)}`},coercer(t){return a(t)?{...t}:t}})}function Oe(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]=$(t,s,r),[y]=d;if(y[0])for(let[h]of d)h&&o.push(h);else return[]}return[`Expected the value to satisfy a union of \`${n}\`, but received: ${p(t)}`,...o]}})}function L(){return P("unknown",()=>!0)}function J(e,n,t){return new u({...e,coercer:(r,o)=>v(r,n)?e.coercer(t(r,o),o):e.coercer(r,o)})}function Ne(e,n,t={}){return J(e,L(),r=>{let o=typeof n=="function"?n():n;if(r===void 0)return o;if(!t.strict&&w(r)&&w(o)){let s={...r},d=!1;for(let y in o)s[y]===void 0&&(s[y]=o[y],d=!0);if(d)return s}return r})}function Ae(e){return J(e,H(),n=>n.trim())}function De(e){return N(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 N(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 N(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 N(e,"nonempty",n=>V(n)>0||`Expected a nonempty ${e.type} but received an empty one`)}function Re(e,n){return N(e,"pattern",t=>n.test(t)||`Expected a ${e.type} matching \`/${n.source}/\` but received "${t}"`)}function Te(e,n,t=n){let r=`Expected a ${e.type}`,o=n===t?`of \`${n}\``:`between \`${n}\` and \`${t}\``;return N(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 N(e,n,t){return new u({...e,*refiner(r,o){yield*e.refiner(r,o);let s=t(r,o),d=g(s,o,e,r);for(let y of d)yield{...y,refinement:n}}})}i.Struct=u,i.StructError=c,i.any=de,i.array=ue,i.assert=k,i.assign=te,i.bigint=le,i.boolean=pe,i.coerce=J,i.create=z,i.date=me,i.defaulted=Ne,i.define=P,i.deprecated=re,i.dynamic=ie,i.empty=De,i.enums=ye,i.func=he,i.instance=be,i.integer=we,i.intersection=ge,i.is=v,i.lazy=oe,i.literal=$e,i.map=ke,i.mask=R,i.max=Fe,i.min=Ie,i.never=C,i.nonempty=ze,i.nullable=Pe,i.number=je,i.object=F,i.omit=se,i.optional=B,i.partial=ce,i.pattern=Re,i.pick=ae,i.record=Ee,i.refine=N,i.regexp=Se,i.set=_e,i.size=Te,i.string=H,i.struct=fe,i.trimmed=Ae,i.tuple=Me,i.type=I,i.union=Oe,i.unknown=L,i.validate=A})});var l=require("electron"),j=M(require("path")),q=M(require("fs/promises")),U=M(require("node:worker_threads"));var D=M(require("fs/promises")),O=M(require("path"));async function G(i){let c={},f=await D.readdir(i);return await Promise.all(f.map(async a=>{let w=O.join(i,a);if((await D.stat(w)).isDirectory()){let E=await G(w);Object.assign(c,E)}else{let E=await D.readFile(w);c[w]=E}})),c}async function Q(i){let c=await G(i),f={};return Object.keys(c).forEach(a=>{let p=O.relative(i,a).split(O.sep).join(O.posix.sep);f[p]=c[a]}),f}var K=M(require("path")),x=M(require("fs/promises")),b=M(Z()),Ve=b.object({embed:b.defaulted(b.boolean(),!1),idbfsMountpoints:b.optional(b.array(b.string())),nodeJsWorker:b.defaulted(b.boolean(),!1),nodefsMountpoints:b.optional(b.record(b.string(),b.string()))});async function ee(){let i=K.resolve(__dirname,"../stlite-manifest.json"),c=await x.readFile(i,{encoding:"utf-8"}),f=JSON.parse(c);return b.assert(f,Ve),f}var ne=async()=>{let i=await ee(),c=[];i.idbfsMountpoints&&c.push(`--idbfs-mountpoints=${JSON.stringify(i.idbfsMountpoints)}`),i.nodeJsWorker&&c.push("--nodejs-worker");let f=new l.BrowserWindow({width:1280,height:720,webPreferences:{preload:j.join(__dirname,"preload.js"),sandbox:!0,additionalArguments:c}}),a=new URL((l.app.isPackaged,"file:///index.html")),w=new URLSearchParams;i.embed&&w.set("embed","true"),a.search=w.toString();let p=a.toString(),E=g=>g.url===p;l.ipcMain.handle("readSitePackagesSnapshot",g=>{if(!E(g.senderFrame))throw new Error("Invalid IPC sender");let $=j.resolve(__dirname,"../site-packages-snapshot.tar.gz");return q.readFile($)}),l.ipcMain.handle("readRequirements",async g=>{if(!E(g.senderFrame))throw new Error("Invalid IPC sender");let $=j.resolve(__dirname,"../requirements.txt");return(await q.readFile($,{encoding:"utf-8"})).split(`
2
+ `).map(k=>k.trim()).filter(k=>k.length>0)}),l.ipcMain.handle("readStreamlitAppDirectory",async g=>{if(!E(g.senderFrame))throw new Error("Invalid IPC sender");let $=j.resolve(__dirname,"../streamlit_app");return Q($)}),f.on("closed",()=>{l.ipcMain.removeHandler("readSitePackagesSnapshot"),l.ipcMain.removeHandler("readRequirements"),l.ipcMain.removeHandler("readStreamlitAppDirectory")});let _=null;l.ipcMain.handle("initializeNodeJsWorker",g=>{if(!E(g.senderFrame))throw new Error("Invalid IPC sender");let $=j.resolve(__dirname,"../pyodide/pyodide.mjs");function u(k){f.webContents.send("messageFromNodeJsWorker",k)}_=new U.default.Worker(j.resolve(__dirname,"./worker.js"),{env:{PYODIDE_URL:$,...i.nodefsMountpoints&&{NODEFS_MOUNTPOINTS:JSON.stringify(i.nodefsMountpoints)}}}),_.on("message",k=>{u(k)})}),l.ipcMain.on("messageToNodeJsWorker",(g,{data:$,portId:u})=>{if(!E(g.senderFrame))throw new Error("Invalid IPC sender");if(_==null)return;let k=new U.default.MessageChannel;k.port1.on("message",R=>{g.reply(`nodeJsWorker-portMessage-${u}`,R)});let z={data:$,port:k.port2};_.postMessage(z,[k.port2])}),l.ipcMain.handle("terminate",(g,{data:$,portId:u})=>{if(!E(g.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(c,f){let a=new URL(c.url).pathname;if(j.isAbsolute(a)){let w=j.join(i,a);f(j.normalize(w))}else f(a)}),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,c)=>{c.on("will-attach-webview",(f,a,w)=>{f.preventDefault()}),c.on("will-navigate",(f,a)=>{console.debug("will-navigate",a),f.preventDefault()}),c.setWindowOpenHandler(({url:f})=>(console.error("Opening a new window is not allowed."),{action:"deny"}))});
@@ -1 +1 @@
1
- var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var k=(o,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of d(r))!g.call(o,s)&&s!==n&&i(o,s,{get:()=>r[s],enumerable:!(t=p(r,s))||t.enumerable});return o};var c=o=>k(i({},"__esModule",{value:!0}),o);var J={};module.exports=c(J);var e=require("electron"),a=process.argv.find(o=>o.startsWith("--idbfs-mountpoints="))?.split("=")[1],W=a&&JSON.parse(a),f={idbfsMountpoints:W};e.contextBridge.exposeInMainWorld("appConfig",f);e.contextBridge.exposeInMainWorld("archives",{readSitePackagesSnapshot:()=>e.ipcRenderer.invoke("readSitePackagesSnapshot"),readRequirements:()=>e.ipcRenderer.invoke("readRequirements"),readStreamlitAppDirectory:()=>e.ipcRenderer.invoke("readStreamlitAppDirectory")});function m(){return Math.floor(Math.random()*1e6)}var l={USE_NODEJS_WORKER:process.argv.includes("--nodejs-worker"),initialize:()=>e.ipcRenderer.invoke("initializeNodeJsWorker"),postMessage:({data:o,onPortMessage:r})=>{console.debug("nodeJsWorkerAPI.postMessage",{data:o,onPortMessage:r});let n=r&&m();e.ipcRenderer.send("messageToNodeJsWorker",{data:o,portId:n}),n&&e.ipcRenderer.on(`nodeJsWorker-portMessage-${n}`,(t,s)=>{r(s)})},onMessage:o=>e.ipcRenderer.on("messageFromNodeJsWorker",(r,n)=>{console.debug("nodeJsWorkerAPI.onMessage",n),o(n)}),terminate:()=>e.ipcRenderer.invoke("terminateNodeJsWorker")};e.contextBridge.exposeInMainWorld("nodeJsWorkerAPI",l);
1
+ var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var g=(o,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of d(r))!c.call(o,s)&&s!==n&&i(o,s,{get:()=>r[s],enumerable:!(t=p(r,s))||t.enumerable});return o};var k=o=>g(i({},"__esModule",{value:!0}),o);var l={};module.exports=k(l);var e=require("electron"),a=process.argv.find(o=>o.startsWith("--idbfs-mountpoints="))?.split("=")[1],W=a&&JSON.parse(a),f={idbfsMountpoints:W};e.contextBridge.exposeInMainWorld("appConfig",f);var A={readSitePackagesSnapshot:()=>e.ipcRenderer.invoke("readSitePackagesSnapshot"),readRequirements:()=>e.ipcRenderer.invoke("readRequirements"),readStreamlitAppDirectory:()=>e.ipcRenderer.invoke("readStreamlitAppDirectory")};e.contextBridge.exposeInMainWorld("archivesAPI",A);function I(){return Math.floor(Math.random()*1e6)}var m={USE_NODEJS_WORKER:process.argv.includes("--nodejs-worker"),initialize:()=>e.ipcRenderer.invoke("initializeNodeJsWorker"),postMessage:({data:o,onPortMessage:r})=>{console.debug("nodeJsWorkerAPI.postMessage",{data:o,onPortMessage:r});let n=r&&I();e.ipcRenderer.send("messageToNodeJsWorker",{data:o,portId:n}),n&&e.ipcRenderer.on(`nodeJsWorker-portMessage-${n}`,(t,s)=>{r(s)})},onMessage:o=>e.ipcRenderer.on("messageFromNodeJsWorker",(r,n)=>{console.debug("nodeJsWorkerAPI.onMessage",n),o(n)}),terminate:()=>e.ipcRenderer.invoke("terminateNodeJsWorker")};e.contextBridge.exposeInMainWorld("nodeJsWorkerAPI",m);
@@ -1,5 +1,5 @@
1
- var ae=Object.create;var z=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var F=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var de=(s,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of le(e))!ge.call(s,t)&&t!==r&&z(s,t,{get:()=>e[t],enumerable:!(o=ie(e,t))||o.enumerable});return s};var H=(s,e,r)=>(r=s!=null?ae(ce(s)):{},de(e||!s||!s.__esModule?z(r,"default",{value:s,enumerable:!0}):r,s));var J=F(I=>{"use strict";Object.defineProperty(I,"__esModule",{value:!0});I.verifyRequirements=void 0;function fe(s){s.forEach(e=>{let r;try{r=new URL(e)}catch{return}if(r.protocol==="emfs:"||r.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${e})`)})}I.verifyRequirements=fe});var K=F(E=>{"use strict";Object.defineProperty(E,"__esModule",{value:!0});E.parseRequirementsTxt=void 0;var ue=/\s#.*$/;function me(s){return s.split(`
2
- `).filter(e=>!e.startsWith("#")).map(e=>e.replace(ue,"")).map(e=>e.trim()).filter(e=>e!=="")}E.parseRequirementsTxt=me});var V=F(O=>{"use strict";Object.defineProperty(O,"__esModule",{value:!0});O.PromiseDelegate=void 0;var L=class{constructor(){this.promise=new Promise((e,r)=>{this.resolveInternal=e,this.rejectInternal=r})}resolve(e){this.resolveInternal(e)}reject(e){this.rejectInternal(e)}};O.PromiseDelegate=L});var G=F(w=>{"use strict";var pe=w&&w.__createBinding||(Object.create?function(s,e,r,o){o===void 0&&(o=r);var t=Object.getOwnPropertyDescriptor(e,r);(!t||("get"in t?!e.__esModule:t.writable||t.configurable))&&(t={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(s,o,t)}:function(s,e,r,o){o===void 0&&(o=r),s[o]=e[r]}),T=w&&w.__exportStar||function(s,e){for(var r in s)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&pe(e,s,r)};Object.defineProperty(w,"__esModule",{value:!0});T(J(),w);T(K(),w);T(V(),w)});var X=F((Ce,Q)=>{"use strict";function v(s){if(typeof s!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(s))}function Y(s,e){for(var r="",o=0,t=-1,i=0,n,a=0;a<=s.length;++a){if(a<s.length)n=s.charCodeAt(a);else{if(n===47)break;n=47}if(n===47){if(!(t===a-1||i===1))if(t!==a-1&&i===2){if(r.length<2||o!==2||r.charCodeAt(r.length-1)!==46||r.charCodeAt(r.length-2)!==46){if(r.length>2){var g=r.lastIndexOf("/");if(g!==r.length-1){g===-1?(r="",o=0):(r=r.slice(0,g),o=r.length-1-r.lastIndexOf("/")),t=a,i=0;continue}}else if(r.length===2||r.length===1){r="",o=0,t=a,i=0;continue}}e&&(r.length>0?r+="/..":r="..",o=2)}else r.length>0?r+="/"+s.slice(t+1,a):r=s.slice(t+1,a),o=a-t-1;t=a,i=0}else n===46&&i!==-1?++i:i=-1}return r}function _e(s,e){var r=e.dir||e.root,o=e.base||(e.name||"")+(e.ext||"");return r?r===e.root?r+o:r+s+o:o}var S={resolve:function(){for(var e="",r=!1,o,t=arguments.length-1;t>=-1&&!r;t--){var i;t>=0?i=arguments[t]:(o===void 0&&(o=process.cwd()),i=o),v(i),i.length!==0&&(e=i+"/"+e,r=i.charCodeAt(0)===47)}return e=Y(e,!r),r?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(v(e),e.length===0)return".";var r=e.charCodeAt(0)===47,o=e.charCodeAt(e.length-1)===47;return e=Y(e,!r),e.length===0&&!r&&(e="."),e.length>0&&o&&(e+="/"),r?"/"+e:e},isAbsolute:function(e){return v(e),e.length>0&&e.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var e,r=0;r<arguments.length;++r){var o=arguments[r];v(o),o.length>0&&(e===void 0?e=o:e+="/"+o)}return e===void 0?".":S.normalize(e)},relative:function(e,r){if(v(e),v(r),e===r||(e=S.resolve(e),r=S.resolve(r),e===r))return"";for(var o=1;o<e.length&&e.charCodeAt(o)===47;++o);for(var t=e.length,i=t-o,n=1;n<r.length&&r.charCodeAt(n)===47;++n);for(var a=r.length,g=a-n,p=i<g?i:g,u=-1,l=0;l<=p;++l){if(l===p){if(g>p){if(r.charCodeAt(n+l)===47)return r.slice(n+l+1);if(l===0)return r.slice(n+l)}else i>p&&(e.charCodeAt(o+l)===47?u=l:l===0&&(u=0));break}var _=e.charCodeAt(o+l),c=r.charCodeAt(n+l);if(_!==c)break;_===47&&(u=l)}var f="";for(l=o+u+1;l<=t;++l)(l===t||e.charCodeAt(l)===47)&&(f.length===0?f+="..":f+="/..");return f.length>0?f+r.slice(n+u):(n+=u,r.charCodeAt(n)===47&&++n,r.slice(n))},_makeLong:function(e){return e},dirname:function(e){if(v(e),e.length===0)return".";for(var r=e.charCodeAt(0),o=r===47,t=-1,i=!0,n=e.length-1;n>=1;--n)if(r=e.charCodeAt(n),r===47){if(!i){t=n;break}}else i=!1;return t===-1?o?"/":".":o&&t===1?"//":e.slice(0,t)},basename:function(e,r){if(r!==void 0&&typeof r!="string")throw new TypeError('"ext" argument must be a string');v(e);var o=0,t=-1,i=!0,n;if(r!==void 0&&r.length>0&&r.length<=e.length){if(r.length===e.length&&r===e)return"";var a=r.length-1,g=-1;for(n=e.length-1;n>=0;--n){var p=e.charCodeAt(n);if(p===47){if(!i){o=n+1;break}}else g===-1&&(i=!1,g=n+1),a>=0&&(p===r.charCodeAt(a)?--a===-1&&(t=n):(a=-1,t=g))}return o===t?t=g:t===-1&&(t=e.length),e.slice(o,t)}else{for(n=e.length-1;n>=0;--n)if(e.charCodeAt(n)===47){if(!i){o=n+1;break}}else t===-1&&(i=!1,t=n+1);return t===-1?"":e.slice(o,t)}},extname:function(e){v(e);for(var r=-1,o=0,t=-1,i=!0,n=0,a=e.length-1;a>=0;--a){var g=e.charCodeAt(a);if(g===47){if(!i){o=a+1;break}continue}t===-1&&(i=!1,t=a+1),g===46?r===-1?r=a:n!==1&&(n=1):r!==-1&&(n=-1)}return r===-1||t===-1||n===0||n===1&&r===t-1&&r===o+1?"":e.slice(r,t)},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 _e("/",e)},parse:function(e){v(e);var r={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return r;var o=e.charCodeAt(0),t=o===47,i;t?(r.root="/",i=1):i=0;for(var n=-1,a=0,g=-1,p=!0,u=e.length-1,l=0;u>=i;--u){if(o=e.charCodeAt(u),o===47){if(!p){a=u+1;break}continue}g===-1&&(p=!1,g=u+1),o===46?n===-1?n=u:l!==1&&(l=1):n!==-1&&(l=-1)}return n===-1||g===-1||l===0||l===1&&n===g-1&&n===a+1?g!==-1&&(a===0&&t?r.base=r.name=e.slice(1,g):r.base=r.name=e.slice(a,g)):(a===0&&t?(r.name=e.slice(1,n),r.base=e.slice(1,g)):(r.name=e.slice(a,n),r.base=e.slice(a,g)),r.ext=e.slice(n,g)),a>0?r.dir=e.slice(0,a-1):t&&(r.dir="/"),r},sep:"/",delimiter:":",win32:null,posix:null};S.posix=S;Q.exports=S});var B=require("node:worker_threads");var re=H(G());var q=H(X());function Z(s,e){let r=q.default.normalize(e),t=q.default.dirname(r).split("/"),i=[];for(let n of t){i.push(n);let a=i.join("/");if(s.FS.analyzePath(a).exists){if(s.FS.isDir(a))throw new Error(`"${a}" already exists and is not a directory.`);continue}try{s.FS.mkdir(a)}catch(g){throw console.error(`Failed to create a directory "${a}"`),g}}}function N(s,e,r,o){Z(s,e),s.FS.writeFile(e,r,o)}function ee(s,e,r){Z(s,r),s.FS.rename(e,r)}function j(s){s.forEach(e=>{let r;try{r=new URL(e)}catch{return}if(r.protocol==="emfs:"||r.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${e})`)})}function U(s){s.runPython(`
1
+ var ie=Object.create;var z=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var F=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var de=(o,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of le(e))!ge.call(o,t)&&t!==r&&z(o,t,{get:()=>e[t],enumerable:!(n=ae(e,t))||n.enumerable});return o};var H=(o,e,r)=>(r=o!=null?ie(ce(o)):{},de(e||!o||!o.__esModule?z(r,"default",{value:o,enumerable:!0}):r,o));var J=F(I=>{"use strict";Object.defineProperty(I,"__esModule",{value:!0});I.verifyRequirements=void 0;function fe(o){o.forEach(e=>{let r;try{r=new URL(e)}catch{return}if(r.protocol==="emfs:"||r.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${e})`)})}I.verifyRequirements=fe});var K=F(R=>{"use strict";Object.defineProperty(R,"__esModule",{value:!0});R.parseRequirementsTxt=void 0;var ue=/\s#.*$/;function me(o){return o.split(`
2
+ `).filter(e=>!e.startsWith("#")).map(e=>e.replace(ue,"")).map(e=>e.trim()).filter(e=>e!=="")}R.parseRequirementsTxt=me});var V=F(E=>{"use strict";Object.defineProperty(E,"__esModule",{value:!0});E.PromiseDelegate=void 0;var T=class{constructor(){this.promise=new Promise((e,r)=>{this.resolveInternal=e,this.rejectInternal=r})}resolve(e){this.resolveInternal(e)}reject(e){this.rejectInternal(e)}};E.PromiseDelegate=T});var G=F(w=>{"use strict";var pe=w&&w.__createBinding||(Object.create?function(o,e,r,n){n===void 0&&(n=r);var t=Object.getOwnPropertyDescriptor(e,r);(!t||("get"in t?!e.__esModule:t.writable||t.configurable))&&(t={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(o,n,t)}:function(o,e,r,n){n===void 0&&(n=r),o[n]=e[r]}),N=w&&w.__exportStar||function(o,e){for(var r in o)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&pe(e,o,r)};Object.defineProperty(w,"__esModule",{value:!0});N(J(),w);N(K(),w);N(V(),w)});var X=F((Oe,Q)=>{"use strict";function v(o){if(typeof o!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(o))}function Y(o,e){for(var r="",n=0,t=-1,a=0,s,i=0;i<=o.length;++i){if(i<o.length)s=o.charCodeAt(i);else{if(s===47)break;s=47}if(s===47){if(!(t===i-1||a===1))if(t!==i-1&&a===2){if(r.length<2||n!==2||r.charCodeAt(r.length-1)!==46||r.charCodeAt(r.length-2)!==46){if(r.length>2){var g=r.lastIndexOf("/");if(g!==r.length-1){g===-1?(r="",n=0):(r=r.slice(0,g),n=r.length-1-r.lastIndexOf("/")),t=i,a=0;continue}}else if(r.length===2||r.length===1){r="",n=0,t=i,a=0;continue}}e&&(r.length>0?r+="/..":r="..",n=2)}else r.length>0?r+="/"+o.slice(t+1,i):r=o.slice(t+1,i),n=i-t-1;t=i,a=0}else s===46&&a!==-1?++a:a=-1}return r}function _e(o,e){var r=e.dir||e.root,n=e.base||(e.name||"")+(e.ext||"");return r?r===e.root?r+n:r+o+n:n}var S={resolve:function(){for(var e="",r=!1,n,t=arguments.length-1;t>=-1&&!r;t--){var a;t>=0?a=arguments[t]:(n===void 0&&(n=process.cwd()),a=n),v(a),a.length!==0&&(e=a+"/"+e,r=a.charCodeAt(0)===47)}return e=Y(e,!r),r?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(v(e),e.length===0)return".";var r=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;return e=Y(e,!r),e.length===0&&!r&&(e="."),e.length>0&&n&&(e+="/"),r?"/"+e:e},isAbsolute:function(e){return v(e),e.length>0&&e.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var e,r=0;r<arguments.length;++r){var n=arguments[r];v(n),n.length>0&&(e===void 0?e=n:e+="/"+n)}return e===void 0?".":S.normalize(e)},relative:function(e,r){if(v(e),v(r),e===r||(e=S.resolve(e),r=S.resolve(r),e===r))return"";for(var n=1;n<e.length&&e.charCodeAt(n)===47;++n);for(var t=e.length,a=t-n,s=1;s<r.length&&r.charCodeAt(s)===47;++s);for(var i=r.length,g=i-s,p=a<g?a:g,u=-1,l=0;l<=p;++l){if(l===p){if(g>p){if(r.charCodeAt(s+l)===47)return r.slice(s+l+1);if(l===0)return r.slice(s+l)}else a>p&&(e.charCodeAt(n+l)===47?u=l:l===0&&(u=0));break}var _=e.charCodeAt(n+l),c=r.charCodeAt(s+l);if(_!==c)break;_===47&&(u=l)}var f="";for(l=n+u+1;l<=t;++l)(l===t||e.charCodeAt(l)===47)&&(f.length===0?f+="..":f+="/..");return f.length>0?f+r.slice(s+u):(s+=u,r.charCodeAt(s)===47&&++s,r.slice(s))},_makeLong:function(e){return e},dirname:function(e){if(v(e),e.length===0)return".";for(var r=e.charCodeAt(0),n=r===47,t=-1,a=!0,s=e.length-1;s>=1;--s)if(r=e.charCodeAt(s),r===47){if(!a){t=s;break}}else a=!1;return t===-1?n?"/":".":n&&t===1?"//":e.slice(0,t)},basename:function(e,r){if(r!==void 0&&typeof r!="string")throw new TypeError('"ext" argument must be a string');v(e);var n=0,t=-1,a=!0,s;if(r!==void 0&&r.length>0&&r.length<=e.length){if(r.length===e.length&&r===e)return"";var i=r.length-1,g=-1;for(s=e.length-1;s>=0;--s){var p=e.charCodeAt(s);if(p===47){if(!a){n=s+1;break}}else g===-1&&(a=!1,g=s+1),i>=0&&(p===r.charCodeAt(i)?--i===-1&&(t=s):(i=-1,t=g))}return n===t?t=g:t===-1&&(t=e.length),e.slice(n,t)}else{for(s=e.length-1;s>=0;--s)if(e.charCodeAt(s)===47){if(!a){n=s+1;break}}else t===-1&&(a=!1,t=s+1);return t===-1?"":e.slice(n,t)}},extname:function(e){v(e);for(var r=-1,n=0,t=-1,a=!0,s=0,i=e.length-1;i>=0;--i){var g=e.charCodeAt(i);if(g===47){if(!a){n=i+1;break}continue}t===-1&&(a=!1,t=i+1),g===46?r===-1?r=i:s!==1&&(s=1):r!==-1&&(s=-1)}return r===-1||t===-1||s===0||s===1&&r===t-1&&r===n+1?"":e.slice(r,t)},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 _e("/",e)},parse:function(e){v(e);var r={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return r;var n=e.charCodeAt(0),t=n===47,a;t?(r.root="/",a=1):a=0;for(var s=-1,i=0,g=-1,p=!0,u=e.length-1,l=0;u>=a;--u){if(n=e.charCodeAt(u),n===47){if(!p){i=u+1;break}continue}g===-1&&(p=!1,g=u+1),n===46?s===-1?s=u:l!==1&&(l=1):s!==-1&&(l=-1)}return s===-1||g===-1||l===0||l===1&&s===g-1&&s===i+1?g!==-1&&(i===0&&t?r.base=r.name=e.slice(1,g):r.base=r.name=e.slice(i,g)):(i===0&&t?(r.name=e.slice(1,s),r.base=e.slice(1,g)):(r.name=e.slice(i,s),r.base=e.slice(i,g)),r.ext=e.slice(s,g)),i>0?r.dir=e.slice(0,i-1):t&&(r.dir="/"),r},sep:"/",delimiter:":",win32:null,posix:null};S.posix=S;Q.exports=S});var $=require("node:worker_threads");var re=H(G());var L=H(X());function Z(o,e){let r=L.default.normalize(e),t=L.default.dirname(r).split("/"),a=[];for(let s of t){a.push(s);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(g){throw console.error(`Failed to create a directory "${i}"`),g}}}function j(o,e,r,n){Z(o,e),o.FS.writeFile(e,r,n)}function ee(o,e,r){Z(o,r),o.FS.rename(e,r)}function q(o){o.forEach(e=>{let r;try{r=new URL(e)}catch{return}if(r.protocol==="emfs:"||r.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${e})`)})}function U(o){o.runPython(`
3
3
  import micropip
4
4
  micropip.add_mock_package(
5
5
  "pyarrow", "0.0.1",
@@ -15,19 +15,19 @@ class Table:
15
15
  """
16
16
  }
17
17
  )
18
- `)}async function he(s,e){let r=s.slice(0,s.lastIndexOf("/")+1),o;return s.endsWith(".mjs")?o=(await import(s)).loadPyodide:(importScripts(s),o=D.loadPyodide),o({...e,indexURL:r})}var D=global;function te(s,e,r){function o(u){e({type:"event:progress",data:{message:u}})}let t,i,n=new re.PromiseDelegate;async function a(){let u=await n.promise,l={...r,...u};console.debug("Initial data",l);let{entrypoint:_,files:c,archives:f,requirements:h,wheels:y,mountedSitePackagesSnapshotFilePath:P,pyodideUrl:C=s,streamlitConfig:k,idbfsMountpoints:M,nodefsMountpoints:W}=l;o("Loading Pyodide."),console.debug("Loading Pyodide"),t=await he(C,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let $=!1;if(M&&($=!0,M.forEach(d=>{t.FS.mkdir(d),t.FS.mount(t.FS.filesystems.IDBFS,{},d)}),await new Promise((d,m)=>{t.FS.syncfs(!0,b=>{b?m(b):d()})})),W&&Object.entries(W).forEach(([d,m])=>{t.FS.mkdir(d),t.FS.mount(t.FS.filesystems.NODEFS,{root:m},d)}),o("Mounting files."),await Promise.all(Object.keys(c).map(async d=>{let m=c[d],b;"url"in m?(console.debug(`Fetch a file from ${m.url}`),b=await fetch(m.url).then(A=>A.arrayBuffer()).then(A=>new Uint8Array(A))):b=m.data;let{opts:R}=c[d];console.debug(`Write a file "${d}"`),N(t,d,b,R)})),o("Unpacking archives."),await Promise.all(f.map(async d=>{let m;"url"in d?(console.debug(`Fetch an archive from ${d.url}`),m=await fetch(d.url).then(A=>A.arrayBuffer())):m=d.buffer;let{format:b,options:R}=d;console.debug("Unpack an archive",{format:b,options:R}),t.unpackArchive(m,b,R)})),!P&&!y)throw new Error("Neither snapshot nor wheel files are provided.");P&&(o("Restoring the snapshot."),await t.runPythonAsync("import tarfile, shutil, site"),await t.runPythonAsync(`
18
+ `)}async function ye(o,e){let r=o.slice(0,o.lastIndexOf("/")+1),n;return o.endsWith(".mjs")?n=(await import(o)).loadPyodide:(importScripts(o),n=D.loadPyodide),n({...e,indexURL:r})}var D=global;function te(o,e,r){function n(u){e({type:"event:progress",data:{message:u}})}let t,a,s=new re.PromiseDelegate;async function i(){let u=await s.promise,l={...r,...u};console.debug("Initial data",l);let{entrypoint:_,files:c,archives:f,requirements:y,wheels:h,mountedSitePackagesSnapshotFilePath:P,pyodideUrl:O=o,streamlitConfig:k,idbfsMountpoints:M,nodefsMountpoints:B}=l;n("Loading Pyodide."),console.debug("Loading Pyodide"),t=await ye(O,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let W=!1;if(M&&(W=!0,M.forEach(d=>{t.FS.mkdir(d),t.FS.mount(t.FS.filesystems.IDBFS,{},d)}),await new Promise((d,m)=>{t.FS.syncfs(!0,b=>{b?m(b):d()})})),B&&Object.entries(B).forEach(([d,m])=>{t.FS.mkdir(d),t.FS.mount(t.FS.filesystems.NODEFS,{root:m},d)}),n("Mounting files."),await Promise.all(Object.keys(c).map(async d=>{let m=c[d],b;"url"in m?(console.debug(`Fetch a file from ${m.url}`),b=await fetch(m.url).then(A=>A.arrayBuffer()).then(A=>new Uint8Array(A))):b=m.data;let{opts:C}=c[d];console.debug(`Write a file "${d}"`),j(t,d,b,C)})),n("Unpacking archives."),await Promise.all(f.map(async d=>{let m;"url"in d?(console.debug(`Fetch an archive from ${d.url}`),m=await fetch(d.url).then(A=>A.arrayBuffer())):m=d.buffer;let{format:b,options:C}=d;console.debug("Unpack an archive",{format:b,options:C}),t.unpackArchive(m,b,C)})),!P&&!h)throw new Error("Neither snapshot nor wheel files are provided.");P&&(n("Restoring the snapshot."),await t.runPythonAsync("import tarfile, shutil, site"),await t.runPythonAsync(`
19
19
  site_packages_dirs = site.getsitepackages()
20
20
  for site_packages in site_packages_dirs:
21
21
  shutil.rmtree(site_packages)
22
22
  `),console.debug(`Unarchive ${P}`),await t.runPythonAsync(`
23
23
  with tarfile.open("${P}", "r") as tar_gz_file:
24
24
  tar_gz_file.extractall("/")
25
- `),console.debug("Restored the snapshot"),o("Mocking some packages."),console.debug("Mock pyarrow"),U(t),console.debug("Mocked pyarrow")),j(h),o("Installing packages."),await t.loadPackage("micropip");let x=t.pyimport("micropip");y?(console.debug("Installing the wheels:",y,"and the requirements:",h),await x.install.callKwargs([y.stliteServer,y.streamlit,...h],{keep_going:!0}),console.debug("Installed the wheels and the requirements"),o("Mocking some packages."),console.debug("Mock pyarrow"),U(t),console.debug("Mocked pyarrow")):(console.debug("Installing the requirements:",h),await x.install.callKwargs(h,{keep_going:!0}),console.debug("Installed the requirements")),await t.runPythonAsync(`
25
+ `),console.debug("Restored the snapshot"),n("Mocking some packages."),console.debug("Mock pyarrow"),U(t),console.debug("Mocked pyarrow")),q(y),n("Installing packages."),await t.loadPackage("micropip");let x=t.pyimport("micropip");h?(console.debug("Installing the wheels:",h,"and the requirements:",y),await x.install.callKwargs([h.stliteServer,h.streamlit,...y],{keep_going:!0}),console.debug("Installed the wheels and the requirements"),n("Mocking some packages."),console.debug("Mock pyarrow"),U(t),console.debug("Mocked pyarrow")):(console.debug("Installing the requirements:",y),await x.install.callKwargs(y,{keep_going:!0}),console.debug("Installed the requirements")),await t.runPythonAsync(`
26
26
  import importlib
27
27
  importlib.invalidate_caches()
28
- `),o("Loading streamlit package."),console.debug("Loading the Streamlit package"),await t.runPythonAsync(`
28
+ `),n("Loading streamlit package."),console.debug("Loading the Streamlit package"),await t.runPythonAsync(`
29
29
  import streamlit.runtime
30
- `),console.debug("Loaded the Streamlit package"),o("Setting up the loggers."),console.debug("Setting the loggers"),await t.runPythonAsync(`
30
+ `),console.debug("Loaded the Streamlit package"),n("Setting up the loggers."),console.debug("Setting the loggers"),await t.runPythonAsync(`
31
31
  import logging
32
32
  import streamlit.logger
33
33
 
@@ -74,14 +74,14 @@ def setup_loggers(streamlit_level, streamlit_message_format):
74
74
  streamlit_handler.setFormatter(streamlit_formatter)
75
75
  streamlit_logger.addHandler(streamlit_handler)
76
76
  streamlit_logger.setLevel(streamlit_level.upper())
77
- `);let se=(k?.["logger.level"]??"INFO").toString(),ne=k?.["logger.messageFormat"]??"%(asctime)s %(message)s";if(t.globals.get("setup_loggers")(se,ne),console.debug("Set the loggers"),o("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await t.runPythonAsync(`
77
+ `);let ne=(k?.["logger.level"]??"INFO").toString(),se=k?.["logger.messageFormat"]??"%(asctime)s %(message)s";if(t.globals.get("setup_loggers")(ne,se),console.debug("Set the loggers"),n("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await t.runPythonAsync(`
78
78
  import streamlit
79
79
 
80
80
  def is_cacheable_msg(msg):
81
81
  return False
82
82
 
83
83
  streamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg
84
- `),console.debug("Mocked some Streamlit functions"),$){o("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let d=!1;D.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),d||(d=!0,t.FS.syncfs(!1,m=>{d=!1,m&&console.error(m)}))},await t.runPythonAsync(`
84
+ `),console.debug("Mocked some Streamlit functions"),W){n("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let d=!1;D.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),d||(d=!0,t.FS.syncfs(!1,m=>{d=!1,m&&console.error(m)}))},await t.runPythonAsync(`
85
85
  from streamlit.runtime.app_session import AppSession
86
86
  from streamlit.runtime.scriptrunner import ScriptRunnerEvent
87
87
  from js import __scriptFinishedCallback__
@@ -96,7 +96,7 @@ def wrap_app_session_on_scriptrunner_event(original_method):
96
96
  return wrapped
97
97
 
98
98
  AppSession._on_scriptrunner_event = wrap_app_session_on_scriptrunner_event(AppSession._on_scriptrunner_event)
99
- `),console.debug("Set up the IndexedDB filesystem synchronizer")}o("Booting up the Streamlit server."),console.debug("Booting up the Streamlit server"),D.__streamlitFlagOptions__={"browser.gatherUsageStats":!1,...k,"runner.fastReruns":!1},await t.runPythonAsync(`
99
+ `),console.debug("Set up the IndexedDB filesystem synchronizer")}n("Booting up the Streamlit server."),console.debug("Booting up the Streamlit server"),D.__streamlitFlagOptions__={"browser.gatherUsageStats":!1,...k,"runner.fastReruns":!1},await t.runPythonAsync(`
100
100
  from stlite_server.bootstrap import load_config_options, prepare
101
101
  from stlite_server.server import Server
102
102
  from js import __streamlitFlagOptions__
@@ -112,7 +112,7 @@ prepare(main_script_path, args)
112
112
 
113
113
  server = Server(main_script_path, command_line)
114
114
  server.start()
115
- `),console.debug("Booted up the Streamlit server"),console.debug("Setting up the HTTP server"),i=t.globals.get("server").copy(),console.debug("Set up the HTTP server"),e({type:"event:loaded"})}let g=a().catch(u=>{throw e({type:"event:error",data:{error:u}}),u}),p=async u=>{let l=u.data;if(l.type==="initData"){n.resolve(l.data);return}await g;let _=u.ports[0];try{switch(l.type){case"websocket:connect":{console.debug("websocket:connect",l.data);let{path:c}=l.data;i.start_websocket(c,(f,h)=>{if(h){let y=f.getBuffer("u8");f.destroy();let P=new Uint8ClampedArray(y.data.buffer,y.data.byteOffset,y.data.byteLength);e({type:"websocket:message",data:{payload:new Uint8Array(P)}})}else e({type:"websocket:message",data:{payload:f}})}),_.postMessage({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",l.data);let{payload:c}=l.data;i.receive_websocket_from_js(c);break}case"http:request":{console.debug("http:request",l.data);let{request:c}=l.data,f=(h,y,P)=>{let C=y.toJs(),k=P.toJs();console.debug({statusCode:h,headers:C,body:k});let M={type:"http:response",data:{response:{statusCode:h,headers:C,body:k}}};_.postMessage(M)};i.receive_http_from_js(c.method,decodeURIComponent(c.path),c.headers,c.body,f);break}case"file:write":{let{path:c,data:f,opts:h}=l.data;console.debug(`Write a file "${c}"`),N(t,c,f,h),_.postMessage({type:"reply"});break}case"file:rename":{let{oldPath:c,newPath:f}=l.data;console.debug(`Rename "${c}" to ${f}`),ee(t,c,f),_.postMessage({type:"reply"});break}case"file:unlink":{let{path:c}=l.data;console.debug(`Remove "${c}`),t.FS.unlink(c),_.postMessage({type:"reply"});break}case"install":{let{requirements:c}=l.data,f=t.pyimport("micropip");console.debug("Install the requirements:",c),j(c),await f.install.callKwargs(c,{keep_going:!0}).then(()=>{if(c.includes("matplotlib"))return t.runPythonAsync(`
115
+ `),console.debug("Booted up the Streamlit server"),console.debug("Setting up the HTTP server"),a=t.globals.get("server").copy(),console.debug("Set up the HTTP server"),e({type:"event:loaded"})}let g=i().catch(u=>{throw e({type:"event:error",data:{error:u}}),u}),p=async u=>{let l=u.data;if(l.type==="initData"){s.resolve(l.data);return}await g;let _=u.ports[0];try{switch(l.type){case"websocket:connect":{console.debug("websocket:connect",l.data);let{path:c}=l.data;a.start_websocket(c,(f,y)=>{if(y){let h=f.getBuffer("u8");f.destroy();let P=new Uint8ClampedArray(h.data.buffer,h.data.byteOffset,h.data.byteLength);e({type:"websocket:message",data:{payload:new Uint8Array(P)}})}else e({type:"websocket:message",data:{payload:f}})}),_.postMessage({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",l.data);let{payload:c}=l.data;a.receive_websocket_from_js(c);break}case"http:request":{console.debug("http:request",l.data);let{request:c}=l.data,f=(y,h,P)=>{let O=h.toJs(),k=P.toJs();console.debug({statusCode:y,headers:O,body:k});let M={type:"http:response",data:{response:{statusCode:y,headers:O,body:k}}};_.postMessage(M)};a.receive_http_from_js(c.method,decodeURIComponent(c.path),c.headers,c.body,f);break}case"file:write":{let{path:c,data:f,opts:y}=l.data;console.debug(`Write a file "${c}"`),j(t,c,f,y),_.postMessage({type:"reply"});break}case"file:rename":{let{oldPath:c,newPath:f}=l.data;console.debug(`Rename "${c}" to ${f}`),ee(t,c,f),_.postMessage({type:"reply"});break}case"file:unlink":{let{path:c}=l.data;console.debug(`Remove "${c}`),t.FS.unlink(c),_.postMessage({type:"reply"});break}case"install":{let{requirements:c}=l.data,f=t.pyimport("micropip");console.debug("Install the requirements:",c),q(c),await f.install.callKwargs(c,{keep_going:!0}).then(()=>{if(c.includes("matplotlib"))return t.runPythonAsync(`
116
116
  from stlite_server.bootstrap import _fix_matplotlib_crash
117
117
  _fix_matplotlib_crash()
118
- `)}).then(()=>{console.debug("Successfully installed"),_.postMessage({type:"reply"})})}}}catch(c){if(console.error(c),!(c instanceof Error))throw c;let f=new Error(c.message);f.name=c.name,f.stack=c.stack,_.postMessage({type:"reply",error:f})}};return e({type:"event:start"}),p}function ye(s){console.debug("[worker thread] postMessage from worker",s),B.parentPort?.postMessage(s)}var ve=process.env.NODEFS_MOUNTPOINTS&&JSON.parse(process.env.NODEFS_MOUNTPOINTS),be=te(process.env.PYODIDE_URL,ye,{nodefsMountpoints:ve});B.parentPort?.on("message",({data:s,port:e})=>{console.debug("[worker thread] parentPort.onMessage",{data:s,port:e}),be({data:s,ports:[e]})});
118
+ `)}).then(()=>{console.debug("Successfully installed"),_.postMessage({type:"reply"})})}}}catch(c){if(console.error(c),!(c instanceof Error))throw c;let f=new Error(c.message);f.name=c.name,f.stack=c.stack,_.postMessage({type:"reply",error:f})}};return e({type:"event:start"}),p}function he(){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(Object.keys(e).some(r=>typeof r!="string")){console.error(`NODEFS_MOUNTPOINTS has non-string keys: ${o}`);return}if(Object.values(e).some(r=>typeof r!="string")){console.error(`NODEFS_MOUNTPOINTS has non-string values: ${o}`);return}}function ve(o){console.debug("[worker thread] postMessage from worker",o),$.parentPort?.postMessage(o)}var be=te(process.env.PYODIDE_URL,ve,{nodefsMountpoints:he()});$.parentPort?.on("message",({data:o,port:e})=>{console.debug("[worker thread] parentPort.onMessage",{data:o,port:e}),be({data:o,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.50eb94c5.js"></script><link href="/static/css/main.fb5f4d99.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.b686df03.js"></script><link href="/static/css/main.fb5f4d99.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>