@stlite/desktop 0.67.1 → 0.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "/static/css/main.43acb583.css",
4
- "main.js": "/static/js/main.099ed3b9.js",
5
- "static/js/8798.a9a59610.chunk.js": "/static/js/8798.a9a59610.chunk.js",
4
+ "main.js": "/static/js/main.02fd259c.js",
5
+ "static/js/8798.140e4c63.chunk.js": "/static/js/8798.140e4c63.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.98dbde84.chunk.js": "/static/js/4785.98dbde84.chunk.js",
@@ -167,6 +167,6 @@
167
167
  },
168
168
  "entrypoints": [
169
169
  "static/css/main.43acb583.css",
170
- "static/js/main.099ed3b9.js"
170
+ "static/js/main.02fd259c.js"
171
171
  ]
172
172
  }
@@ -1,5 +1,5 @@
1
1
  var me=Object.create;var K=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty;var O=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ve=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _e(e))!he.call(r,o)&&o!==t&&K(r,o,{get:()=>e[o],enumerable:!(n=pe(e,o))||n.enumerable});return r};var M=(r,e,t)=>(t=r!=null?me(ye(r)):{},ve(e||!r||!r.__esModule?K(t,"default",{value:r,enumerable:!0}):t,r));var V=O(C=>{"use strict";Object.defineProperty(C,"__esModule",{value:!0});C.validateRequirements=void 0;var Pe="[",be="(<=>!~",Se=";",we="@",ke=new RegExp(`[${Pe+be+Se+we}]`);function Ae(r){return r.split(ke)[0].trim()}function Re(r){return r.forEach(t=>{let n;try{n=new URL(t)}catch{return}if(n.protocol==="emfs:"||n.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)}),r.filter(t=>Ae(t)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${t}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}C.validateRequirements=Re});var X=O(T=>{"use strict";Object.defineProperty(T,"__esModule",{value:!0});T.parseRequirementsTxt=void 0;var Fe=/\s#.*$/;function Ie(r){return r.split(`
2
- `).filter(e=>!e.startsWith("#")).map(e=>e.replace(Fe,"")).map(e=>e.trim()).filter(e=>e!=="")}T.parseRequirementsTxt=Ie});var G=O(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.PromiseDelegate=void 0;var U=class{promise;resolveInternal;rejectInternal;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 Q=O(b=>{"use strict";var Oe=b&&b.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=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,n,o)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),x=b&&b.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Oe(e,r,t)};Object.defineProperty(b,"__esModule",{value:!0});x(V(),b);x(X(),b);x(G(),b)});var ee=O((Xe,Z)=>{"use strict";function h(r){if(typeof r!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(r))}function Y(r,e){for(var t="",n=0,o=-1,i=0,s,a=0;a<=r.length;++a){if(a<r.length)s=r.charCodeAt(a);else{if(s===47)break;s=47}if(s===47){if(!(o===a-1||i===1))if(o!==a-1&&i===2){if(t.length<2||n!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){var d=t.lastIndexOf("/");if(d!==t.length-1){d===-1?(t="",n=0):(t=t.slice(0,d),n=t.length-1-t.lastIndexOf("/")),o=a,i=0;continue}}else if(t.length===2||t.length===1){t="",n=0,o=a,i=0;continue}}e&&(t.length>0?t+="/..":t="..",n=2)}else t.length>0?t+="/"+r.slice(o+1,a):t=r.slice(o+1,a),n=a-o-1;o=a,i=0}else s===46&&i!==-1?++i:i=-1}return t}function Me(r,e){var t=e.dir||e.root,n=e.base||(e.name||"")+(e.ext||"");return t?t===e.root?t+n:t+r+n:n}var R={resolve:function(){for(var e="",t=!1,n,o=arguments.length-1;o>=-1&&!t;o--){var i;o>=0?i=arguments[o]:(n===void 0&&(n=process.cwd()),i=n),h(i),i.length!==0&&(e=i+"/"+e,t=i.charCodeAt(0)===47)}return e=Y(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(h(e),e.length===0)return".";var t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;return e=Y(e,!t),e.length===0&&!t&&(e="."),e.length>0&&n&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return h(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 n=arguments[t];h(n),n.length>0&&(e===void 0?e=n:e+="/"+n)}return e===void 0?".":R.normalize(e)},relative:function(e,t){if(h(e),h(t),e===t||(e=R.resolve(e),t=R.resolve(t),e===t))return"";for(var n=1;n<e.length&&e.charCodeAt(n)===47;++n);for(var o=e.length,i=o-n,s=1;s<t.length&&t.charCodeAt(s)===47;++s);for(var a=t.length,d=a-s,f=i<d?i:d,g=-1,l=0;l<=f;++l){if(l===f){if(d>f){if(t.charCodeAt(s+l)===47)return t.slice(s+l+1);if(l===0)return t.slice(s+l)}else i>f&&(e.charCodeAt(n+l)===47?g=l:l===0&&(g=0));break}var S=e.charCodeAt(n+l),w=t.charCodeAt(s+l);if(S!==w)break;S===47&&(g=l)}var _="";for(l=n+g+1;l<=o;++l)(l===o||e.charCodeAt(l)===47)&&(_.length===0?_+="..":_+="/..");return _.length>0?_+t.slice(s+g):(s+=g,t.charCodeAt(s)===47&&++s,t.slice(s))},_makeLong:function(e){return e},dirname:function(e){if(h(e),e.length===0)return".";for(var t=e.charCodeAt(0),n=t===47,o=-1,i=!0,s=e.length-1;s>=1;--s)if(t=e.charCodeAt(s),t===47){if(!i){o=s;break}}else i=!1;return o===-1?n?"/":".":n&&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');h(e);var n=0,o=-1,i=!0,s;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var a=t.length-1,d=-1;for(s=e.length-1;s>=0;--s){var f=e.charCodeAt(s);if(f===47){if(!i){n=s+1;break}}else d===-1&&(i=!1,d=s+1),a>=0&&(f===t.charCodeAt(a)?--a===-1&&(o=s):(a=-1,o=d))}return n===o?o=d:o===-1&&(o=e.length),e.slice(n,o)}else{for(s=e.length-1;s>=0;--s)if(e.charCodeAt(s)===47){if(!i){n=s+1;break}}else o===-1&&(i=!1,o=s+1);return o===-1?"":e.slice(n,o)}},extname:function(e){h(e);for(var t=-1,n=0,o=-1,i=!0,s=0,a=e.length-1;a>=0;--a){var d=e.charCodeAt(a);if(d===47){if(!i){n=a+1;break}continue}o===-1&&(i=!1,o=a+1),d===46?t===-1?t=a:s!==1&&(s=1):t!==-1&&(s=-1)}return t===-1||o===-1||s===0||s===1&&t===o-1&&t===n+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 Me("/",e)},parse:function(e){h(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var n=e.charCodeAt(0),o=n===47,i;o?(t.root="/",i=1):i=0;for(var s=-1,a=0,d=-1,f=!0,g=e.length-1,l=0;g>=i;--g){if(n=e.charCodeAt(g),n===47){if(!f){a=g+1;break}continue}d===-1&&(f=!1,d=g+1),n===46?s===-1?s=g:l!==1&&(l=1):s!==-1&&(l=-1)}return s===-1||d===-1||l===0||l===1&&s===d-1&&s===a+1?d!==-1&&(a===0&&o?t.base=t.name=e.slice(1,d):t.base=t.name=e.slice(a,d)):(a===0&&o?(t.name=e.slice(1,s),t.base=e.slice(1,d)):(t.name=e.slice(a,s),t.base=e.slice(a,d)),t.ext=e.slice(s,d)),a>0?t.dir=e.slice(0,a-1):o&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};R.posix=R;Z.exports=R});var B=require("node:worker_threads");var ae=M(Q());var q=M(ee());function te(r,e){let t=q.default.normalize(e),o=q.default.dirname(t).split("/"),i=[];for(let s of o){i.push(s);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(d){throw console.error(`Failed to create a directory "${a}"`),d}}}function j(r,e,t,n){te(r,e),r.FS.writeFile(e,t,n)}function re(r,e,t){te(r,t),r.FS.rename(e,t)}var Le="[",Ee="(<=>!~",Ce=";",Te="@",Ne=new RegExp(`[${Le+Ee+Ce+Te}]`);function De(r){return r.split(Ne)[0].trim()}function $(r){return r.forEach(t=>{let n;try{n=new URL(t)}catch{return}if(n.protocol==="emfs:"||n.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)}),r.filter(t=>De(t)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${t}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}async function Ue(r){let e=typeof process<"u"&&process.versions?.node,t;e?t=(await import("node:path")).sep:t="/";let n=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:n,isESModule:!0}}else return{scriptURL:r,pyodideIndexURL:n,isESModule:!1}}async function oe(r,e){let{scriptURL:t,pyodideIndexURL:n,isESModule:o}=await Ue(r),i;return o?i=(await import(t)).loadPyodide:(importScripts(t),i=self.loadPyodide),i({...e,indexURL:n})}function ne(r){r.runPython(`
2
+ `).filter(e=>!e.startsWith("#")).map(e=>e.replace(Fe,"")).map(e=>e.trim()).filter(e=>e!=="")}T.parseRequirementsTxt=Ie});var G=O(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.PromiseDelegate=void 0;var U=class{promise;resolveInternal;rejectInternal;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 Q=O(b=>{"use strict";var Oe=b&&b.__createBinding||(Object.create?function(r,e,t,n){n===void 0&&(n=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,n,o)}:function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]}),x=b&&b.__exportStar||function(r,e){for(var t in r)t!=="default"&&!Object.prototype.hasOwnProperty.call(e,t)&&Oe(e,r,t)};Object.defineProperty(b,"__esModule",{value:!0});x(V(),b);x(X(),b);x(G(),b)});var ee=O((Xe,Z)=>{"use strict";function h(r){if(typeof r!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(r))}function Y(r,e){for(var t="",n=0,o=-1,i=0,s,a=0;a<=r.length;++a){if(a<r.length)s=r.charCodeAt(a);else{if(s===47)break;s=47}if(s===47){if(!(o===a-1||i===1))if(o!==a-1&&i===2){if(t.length<2||n!==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="",n=0):(t=t.slice(0,c),n=t.length-1-t.lastIndexOf("/")),o=a,i=0;continue}}else if(t.length===2||t.length===1){t="",n=0,o=a,i=0;continue}}e&&(t.length>0?t+="/..":t="..",n=2)}else t.length>0?t+="/"+r.slice(o+1,a):t=r.slice(o+1,a),n=a-o-1;o=a,i=0}else s===46&&i!==-1?++i:i=-1}return t}function Me(r,e){var t=e.dir||e.root,n=e.base||(e.name||"")+(e.ext||"");return t?t===e.root?t+n:t+r+n:n}var R={resolve:function(){for(var e="",t=!1,n,o=arguments.length-1;o>=-1&&!t;o--){var i;o>=0?i=arguments[o]:(n===void 0&&(n=process.cwd()),i=n),h(i),i.length!==0&&(e=i+"/"+e,t=i.charCodeAt(0)===47)}return e=Y(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(h(e),e.length===0)return".";var t=e.charCodeAt(0)===47,n=e.charCodeAt(e.length-1)===47;return e=Y(e,!t),e.length===0&&!t&&(e="."),e.length>0&&n&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return h(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 n=arguments[t];h(n),n.length>0&&(e===void 0?e=n:e+="/"+n)}return e===void 0?".":R.normalize(e)},relative:function(e,t){if(h(e),h(t),e===t||(e=R.resolve(e),t=R.resolve(t),e===t))return"";for(var n=1;n<e.length&&e.charCodeAt(n)===47;++n);for(var o=e.length,i=o-n,s=1;s<t.length&&t.charCodeAt(s)===47;++s);for(var a=t.length,c=a-s,f=i<c?i:c,g=-1,l=0;l<=f;++l){if(l===f){if(c>f){if(t.charCodeAt(s+l)===47)return t.slice(s+l+1);if(l===0)return t.slice(s+l)}else i>f&&(e.charCodeAt(n+l)===47?g=l:l===0&&(g=0));break}var S=e.charCodeAt(n+l),w=t.charCodeAt(s+l);if(S!==w)break;S===47&&(g=l)}var _="";for(l=n+g+1;l<=o;++l)(l===o||e.charCodeAt(l)===47)&&(_.length===0?_+="..":_+="/..");return _.length>0?_+t.slice(s+g):(s+=g,t.charCodeAt(s)===47&&++s,t.slice(s))},_makeLong:function(e){return e},dirname:function(e){if(h(e),e.length===0)return".";for(var t=e.charCodeAt(0),n=t===47,o=-1,i=!0,s=e.length-1;s>=1;--s)if(t=e.charCodeAt(s),t===47){if(!i){o=s;break}}else i=!1;return o===-1?n?"/":".":n&&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');h(e);var n=0,o=-1,i=!0,s;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(s=e.length-1;s>=0;--s){var f=e.charCodeAt(s);if(f===47){if(!i){n=s+1;break}}else c===-1&&(i=!1,c=s+1),a>=0&&(f===t.charCodeAt(a)?--a===-1&&(o=s):(a=-1,o=c))}return n===o?o=c:o===-1&&(o=e.length),e.slice(n,o)}else{for(s=e.length-1;s>=0;--s)if(e.charCodeAt(s)===47){if(!i){n=s+1;break}}else o===-1&&(i=!1,o=s+1);return o===-1?"":e.slice(n,o)}},extname:function(e){h(e);for(var t=-1,n=0,o=-1,i=!0,s=0,a=e.length-1;a>=0;--a){var c=e.charCodeAt(a);if(c===47){if(!i){n=a+1;break}continue}o===-1&&(i=!1,o=a+1),c===46?t===-1?t=a:s!==1&&(s=1):t!==-1&&(s=-1)}return t===-1||o===-1||s===0||s===1&&t===o-1&&t===n+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 Me("/",e)},parse:function(e){h(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var n=e.charCodeAt(0),o=n===47,i;o?(t.root="/",i=1):i=0;for(var s=-1,a=0,c=-1,f=!0,g=e.length-1,l=0;g>=i;--g){if(n=e.charCodeAt(g),n===47){if(!f){a=g+1;break}continue}c===-1&&(f=!1,c=g+1),n===46?s===-1?s=g:l!==1&&(l=1):s!==-1&&(l=-1)}return s===-1||c===-1||l===0||l===1&&s===c-1&&s===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,s),t.base=e.slice(1,c)):(t.name=e.slice(a,s),t.base=e.slice(a,c)),t.ext=e.slice(s,c)),a>0?t.dir=e.slice(0,a-1):o&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};R.posix=R;Z.exports=R});var B=require("node:worker_threads");var ae=M(Q());var q=M(ee());function te(r,e){let t=q.default.normalize(e),o=q.default.dirname(t).split("/"),i=[];for(let s of o){i.push(s);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,n){te(r,e),r.FS.writeFile(e,t,n)}function re(r,e,t){te(r,t),r.FS.rename(e,t)}var Le="[",Ee="(<=>!~",Ce=";",Te="@",Ne=new RegExp(`[${Le+Ee+Ce+Te}]`);function De(r){return r.split(Ne)[0].trim()}function j(r){return r.forEach(t=>{let n;try{n=new URL(t)}catch{return}if(n.protocol==="emfs:"||n.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)}),r.filter(t=>De(t)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${t}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}async function Ue(r){let e=typeof process<"u"&&process.versions?.node,t;e?t=(await import("node:path")).sep:t="/";let n=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:n,isESModule:!0}}else return{scriptURL:r,pyodideIndexURL:n,isESModule:!1}}async function oe(r,e){let{scriptURL:t,pyodideIndexURL:n,isESModule:o}=await Ue(r),i;return o?i=(await import(t)).loadPyodide:(importScripts(t),i=self.loadPyodide),i({...e,indexURL:n})}function ne(r){r.runPython(`
3
3
  import micropip
4
4
  micropip.add_mock_package(
5
5
  "pyarrow", "0.0.1",
@@ -48,12 +48,12 @@ def find_imports(source: str) -> list[str]:
48
48
  continue
49
49
  imports.add(module_name.split(".")[0])
50
50
  return imports
51
- `),W=r.globals.get("find_imports")),W(e).toJs()}function qe(r){let e=new Set;for(let t of r)for(let n of t)e.add(n);return e}async function se(r,e,t){let n=t.map(f=>xe(r,f)),o=qe(n),a=Array.from(o).filter(f=>!r.runPython(`__import__('importlib').util.find_spec('${f}')`)).map(f=>r._api._import_name_to_package_name.get(f)).filter(f=>f);if(a.length===0)return;let d=new MessageChannel;e({type:"event:moduleAutoLoad",data:{packagesToLoad:a}},d.port2);try{let f=await r.loadPackage(a);d.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:f}}),d.port1.close();return}catch(f){throw d.port1.postMessage({type:"moduleAutoLoad:error",error:f}),d.port1.close(),f}}var D=global;function ie(r,e,t){let n=se(r,e,t);D.__moduleAutoLoadPromise__=n,r.runPythonAsync(`
51
+ `),W=r.globals.get("find_imports")),W(e).toJs()}function qe(r){let e=new Set;for(let t of r)for(let n of t)e.add(n);return e}async function se(r,e,t){let n=t.map(f=>xe(r,f)),o=qe(n),a=Array.from(o).filter(f=>!r.runPython(`__import__('importlib').util.find_spec('${f}')`)).map(f=>r._api._import_name_to_package_name.get(f)).filter(f=>f);if(a.length===0)return;let c=new MessageChannel;e({type:"event:moduleAutoLoad",data:{packagesToLoad:a}},c.port2);try{let f=await r.loadPackage(a);c.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:f}}),c.port1.close();return}catch(f){throw c.port1.postMessage({type:"moduleAutoLoad:error",error:f}),c.port1.close(),f}}var D=global;function ie(r,e,t){let n=se(r,e,t);D.__moduleAutoLoadPromise__=n,r.runPythonAsync(`
52
52
  from streamlit.runtime.scriptrunner import script_runner
53
53
  from js import __moduleAutoLoadPromise__
54
54
 
55
55
  script_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__
56
- `)}function le(r,e,t){function n(g){e({type:"event:progress",data:{message:g}})}let o,i,s=new ae.PromiseDelegate;async function a(){let g=await s.promise,l={...t,...g};console.debug("Initial data",l);let{entrypoint:S,files:w,archives:_,requirements:c,prebuiltPackageNames:p,wheels:y,pyodideUrl:k=r,streamlitConfig:v,idbfsMountpoints:A,nodefsMountpoints:F,moduleAutoLoad:ce}=l,L=$(c);n("Loading Pyodide."),console.debug("Loading Pyodide"),o=await oe(k,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let H=!1;A&&(H=!0,A.forEach(u=>{o.FS.mkdir(u),o.FS.mount(o.FS.filesystems.IDBFS,{},u)}),await new Promise((u,m)=>{o.FS.syncfs(!0,P=>{P?m(P):u()})})),F&&Object.entries(F).forEach(([u,m])=>{o.FS.mkdir(u),o.FS.mount(o.FS.filesystems.NODEFS,{root:m},u)}),n("Mounting files.");let z=[];await Promise.all(Object.keys(w).map(async u=>{let m=w[u],P;"url"in m?(console.debug(`Fetch a file from ${m.url}`),P=await fetch(m.url).then(I=>I.arrayBuffer()).then(I=>new Uint8Array(I))):P=m.data;let{opts:E}=w[u];console.debug(`Write a file "${u}"`),j(o,u,P,E),u.endsWith(".py")&&z.push(u)})),n("Unpacking archives."),await Promise.all(_.map(async u=>{let m;"url"in u?(console.debug(`Fetch an archive from ${u.url}`),m=await fetch(u.url).then(I=>I.arrayBuffer())):m=u.buffer;let{format:P,options:E}=u;console.debug("Unpack an archive",{format:P,options:E}),o.unpackArchive(m,P,E)})),await o.loadPackage("micropip");let J=o.pyimport("micropip");if(n("Mocking some packages."),console.debug("Mock pyarrow"),ne(o),console.debug("Mocked pyarrow"),n("Installing packages."),console.debug("Installing the prebuilt packages:",p),await o.loadPackage(p),console.debug("Installed the prebuilt packages"),y?(console.debug("Installing the wheels:",y,"and the requirements:",L),await J.install.callKwargs([y.stliteLib,y.streamlit,...L],{keep_going:!0}),console.debug("Installed the wheels and the requirements")):(console.debug("Installing the requirements:",L),await J.install.callKwargs(L,{keep_going:!0}),console.debug("Installed the requirements")),ce){let u=z.map(m=>o.FS.readFile(m,{encoding:"utf8"}));ie(o,e,u)}await o.runPythonAsync(`
56
+ `)}function le(r,e,t){function n(g){e({type:"event:progress",data:{message:g}})}let o,i,s=new ae.PromiseDelegate;async function a(){let g=await s.promise,l={...t,...g};console.debug("Initial data",l);let{entrypoint:S,files:w,archives:_,requirements:d,prebuiltPackageNames:m,wheels:y,pyodideUrl:k=r,streamlitConfig:v,idbfsMountpoints:A,nodefsMountpoints:F,moduleAutoLoad:ce}=l,L=j(d);n("Loading Pyodide."),console.debug("Loading Pyodide"),o=await oe(k,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let H=!1;A&&(H=!0,A.forEach(u=>{o.FS.mkdir(u),o.FS.mount(o.FS.filesystems.IDBFS,{},u)}),await new Promise((u,p)=>{o.FS.syncfs(!0,P=>{P?p(P):u()})})),F&&Object.entries(F).forEach(([u,p])=>{o.FS.mkdir(u),o.FS.mount(o.FS.filesystems.NODEFS,{root:p},u)}),n("Mounting files.");let z=[];await Promise.all(Object.keys(w).map(async u=>{let p=w[u],P;"url"in p?(console.debug(`Fetch a file from ${p.url}`),P=await fetch(p.url).then(I=>I.arrayBuffer()).then(I=>new Uint8Array(I))):P=p.data;let{opts:E}=w[u];console.debug(`Write a file "${u}"`),$(o,u,P,E),u.endsWith(".py")&&z.push(u)})),n("Unpacking archives."),await Promise.all(_.map(async u=>{let p;"url"in u?(console.debug(`Fetch an archive from ${u.url}`),p=await fetch(u.url).then(I=>I.arrayBuffer())):p=u.buffer;let{format:P,options:E}=u;console.debug("Unpack an archive",{format:P,options:E}),o.unpackArchive(p,P,E)})),await o.loadPackage("micropip");let J=o.pyimport("micropip");if(n("Mocking some packages."),console.debug("Mock pyarrow"),ne(o),console.debug("Mocked pyarrow"),n("Installing packages."),console.debug("Installing the prebuilt packages:",m),await o.loadPackage(m),console.debug("Installed the prebuilt packages"),y?(console.debug("Installing the wheels:",y,"and the requirements:",L),await J.install.callKwargs([y.stliteLib,y.streamlit,...L],{keep_going:!0}),console.debug("Installed the wheels and the requirements")):(console.debug("Installing the requirements:",L),await J.install.callKwargs(L,{keep_going:!0}),console.debug("Installed the requirements")),ce){let u=z.map(p=>o.FS.readFile(p,{encoding:"utf8"}));ie(o,e,u)}await o.runPythonAsync(`
57
57
  import importlib
58
58
  importlib.invalidate_caches()
59
59
  `),n("Loading streamlit package."),console.debug("Loading the Streamlit package"),await o.runPythonAsync(`
@@ -76,7 +76,7 @@ for name in streamlit.logger._loggers.keys():
76
76
  logger.setLevel(logging.NOTSET)
77
77
 
78
78
  streamlit.logger._loggers = {}
79
- `);let ue=(u,m)=>{u>=40?console.error(m):u>=30?console.warn(m):u>=20?console.info(m):console.debug(m)};D.__logCallback__=ue,await o.runPythonAsync(`
79
+ `);let ue=(u,p)=>{u>=40?console.error(p):u>=30?console.warn(p):u>=20?console.info(p):console.debug(p)};D.__logCallback__=ue,await o.runPythonAsync(`
80
80
  def setup_loggers(streamlit_level, streamlit_message_format):
81
81
  from js import __logCallback__
82
82
 
@@ -112,7 +112,7 @@ def is_cacheable_msg(msg):
112
112
  return False
113
113
 
114
114
  streamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg
115
- `),console.debug("Mocked some Streamlit functions"),H){n("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(`
115
+ `),console.debug("Mocked some Streamlit functions"),H){n("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,p=>{u=!1,p&&console.error(p)}))},await o.runPythonAsync(`
116
116
  from streamlit.runtime.app_session import AppSession
117
117
  from streamlit.runtime.scriptrunner import ScriptRunnerEvent
118
118
  from js import __scriptFinishedCallback__
@@ -138,4 +138,4 @@ main_script_path = "${S}"
138
138
  args = []
139
139
 
140
140
  prepare(main_script_path, args)
141
- `),console.debug("Set up the Streamlit configuration"),console.debug("Booting up the Streamlit server"),i=o.pyimport("stlite_lib.server.Server")(S),await i.start(),console.debug("Booted up the Streamlit server"),e({type:"event:loaded"}),l}let d=a().catch(g=>{throw e({type:"event:error",data:{error:g}}),g}),f=async g=>{let l=g.data;if(l.type==="initData"){s.resolve(l.data);return}let{moduleAutoLoad:S}=await d,w=g.ports[0];function _(c){w.postMessage(c)}try{switch(l.type){case"reboot":{console.debug("Reboot the Streamlit server",l.data);let{entrypoint:c}=l.data;i.stop(),console.debug("Booting up the Streamlit server"),i=o.pyimport("stlite_lib.server.Server")(c),i.start(),console.debug("Booted up the Streamlit server"),_({type:"reply"});break}case"websocket:connect":{console.debug("websocket:connect",l.data);let{path:c}=l.data;i.start_websocket(c,(p,y)=>{if(y){let k=p,v=k.getBuffer("u8");k.destroy();let A=new Uint8ClampedArray(v.data.buffer,v.data.byteOffset,v.data.byteLength);e({type:"websocket:message",data:{payload:new Uint8Array(A)}})}else e({type:"websocket:message",data:{payload:p}})}),_({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,p=(y,k,v)=>{let A=new Map(k.toJs()),F=v.toJs();console.debug({statusCode:y,headers:A,body:F}),_({type:"http:response",data:{response:{statusCode:y,headers:A,body:F}}})};i.receive_http_from_js(c.method,decodeURIComponent(c.path),c.headers,c.body,p);break}case"file:write":{let{path:c,data:p,opts:y}=l.data;S&&typeof p=="string"&&c.endsWith(".py")&&(console.debug(`Auto install the requirements in ${c}`),ie(o,e,[p])),console.debug(`Write a file "${c}"`),j(o,c,p,y),_({type:"reply"});break}case"file:rename":{let{oldPath:c,newPath:p}=l.data;console.debug(`Rename "${c}" to ${p}`),re(o,c,p),_({type:"reply"});break}case"file:unlink":{let{path:c}=l.data;console.debug(`Remove "${c}`),o.FS.unlink(c),_({type:"reply"});break}case"install":{let{requirements:c}=l.data,p=o.pyimport("micropip"),y=$(c);console.debug("Install the requirements:",y),await p.install.callKwargs(y,{keep_going:!0}).then(()=>{console.debug("Successfully installed"),_({type:"reply"})})}}}catch(c){if(console.error(c),!(c instanceof Error))throw c;let p=new Error(c.message);p.name=c.name,p.stack=c.stack,_({type:"reply",error:p})}};return e({type:"event:start"}),f}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 je=r=>{console.debug("[worker thread] postMessage from worker",r),B.parentPort?.postMessage(r)},$e=le(process.env.PYODIDE_URL,je,{nodefsMountpoints:de()});B.parentPort?.on("message",({data:r,port:e})=>{console.debug("[worker thread] parentPort.onMessage",{data:r,port:e}),$e({data:r,ports:[e]})});
141
+ `),console.debug("Set up the Streamlit configuration"),console.debug("Booting up the Streamlit server"),i=o.pyimport("stlite_lib.server.Server")(S),await i.start(),console.debug("Booted up the Streamlit server"),e({type:"event:loaded"}),l}let c=a().catch(g=>{throw e({type:"event:error",data:{error:g}}),g}),f=async g=>{let l=g.data;if(l.type==="initData"){s.resolve(l.data);return}let{moduleAutoLoad:S}=await c,w=g.ports[0];function _(d){w.postMessage(d)}try{switch(l.type){case"reboot":{console.debug("Reboot the Streamlit server",l.data);let{entrypoint:d}=l.data;i.stop(),console.debug("Booting up the Streamlit server"),i=o.pyimport("stlite_lib.server.Server")(d),i.start(),console.debug("Booted up the Streamlit server"),_({type:"reply"});break}case"websocket:connect":{console.debug("websocket:connect",l.data);let{path:d}=l.data;i.start_websocket(d,(m,y)=>{if(y){let k=m,v=k.getBuffer("u8");k.destroy();let A=new Uint8ClampedArray(v.data.buffer,v.data.byteOffset,v.data.byteLength);e({type:"websocket:message",data:{payload:new Uint8Array(A)}})}else e({type:"websocket:message",data:{payload:m}})}),_({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,m=(y,k,v)=>{let A=new Map(k.toJs()),F=v.toJs();console.debug({statusCode:y,headers:A,body:F}),_({type:"http:response",data:{response:{statusCode:y,headers:A,body:F}}})};i.receive_http_from_js(d.method,decodeURIComponent(d.path),d.headers,d.body,m);break}case"file:write":{let{path:d,data:m,opts:y}=l.data;S&&typeof m=="string"&&d.endsWith(".py")&&(console.debug(`Auto install the requirements in ${d}`),ie(o,e,[m])),console.debug(`Write a file "${d}"`),$(o,d,m,y),_({type:"reply"});break}case"file:rename":{let{oldPath:d,newPath:m}=l.data;console.debug(`Rename "${d}" to ${m}`),re(o,d,m),_({type:"reply"});break}case"file:unlink":{let{path:d}=l.data;console.debug(`Remove "${d}`),o.FS.unlink(d),_({type:"reply"});break}case"file:read":{let{path:d,opts:m}=l.data;console.debug(`Read "${d}"`);let y=o.FS.readFile(d,m);_({type:"reply:file:read",data:{content:y}});break}case"install":{let{requirements:d}=l.data,m=o.pyimport("micropip"),y=j(d);console.debug("Install the requirements:",y),await m.install.callKwargs(y,{keep_going:!0}).then(()=>{console.debug("Successfully installed"),_({type:"reply"})})}}}catch(d){if(console.error(d),!(d instanceof Error))throw d;let m=new Error(d.message);m.name=d.name,m.stack=d.stack,_({type:"reply",error:m})}};return e({type:"event:start"}),f}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 $e=r=>{console.debug("[worker thread] postMessage from worker",r),B.parentPort?.postMessage(r)},je=le(process.env.PYODIDE_URL,$e,{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.099ed3b9.js"></script><link href="/static/css/main.43acb583.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.02fd259c.js"></script><link href="/static/css/main.43acb583.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
@@ -1 +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,a=0,i=0;i<=e.length;++i){if(i<e.length)n=e.charCodeAt(i);else{if(47===n)break;n=47}if(47===n){if(s===i-1||1===a);else if(s!==i-1&&2===a){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=i,a=0;continue}}else if(2===r.length||1===r.length){r="",o=0,s=i,a=0;continue}t&&(r.length>0?r+="/..":r="..",o=2)}else r.length>0?r+="/"+e.slice(s+1,i):r=e.slice(s+1,i),o=i-s-1;s=i,a=0}else 46===n&&-1!==a?++a:a=-1}return r}var r={resolve:function(){for(var e,r="",o=!1,s=arguments.length-1;s>=-1&&!o;s--){var a;s>=0?a=arguments[s]:(void 0===e&&(e=process.cwd()),a=e),t(a),0!==a.length&&(r=a+"/"+r,o=47===a.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,a=s-o,i=1;i<n.length&&47===n.charCodeAt(i);++i);for(var l=n.length-i,c=a<l?a:l,d=-1,g=0;g<=c;++g){if(g===c){if(l>c){if(47===n.charCodeAt(i+g))return n.slice(i+g+1);if(0===g)return n.slice(i+g)}else a>c&&(47===e.charCodeAt(o+g)?d=g:0===g&&(d=0));break}var p=e.charCodeAt(o+g);if(p!==n.charCodeAt(i+g))break;47===p&&(d=g)}var u="";for(g=o+d+1;g<=s;++g)g!==s&&47!==e.charCodeAt(g)||(0===u.length?u+="..":u+="/..");return u.length>0?u+n.slice(i+d):(i+=d,47===n.charCodeAt(i)&&++i,n.slice(i))},_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,a=e.length-1;a>=1;--a)if(47===(n=e.charCodeAt(a))){if(!s){o=a;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,a=!0;if(void 0!==n&&n.length>0&&n.length<=e.length){if(n.length===e.length&&n===e)return"";var i=n.length-1,l=-1;for(r=e.length-1;r>=0;--r){var c=e.charCodeAt(r);if(47===c){if(!a){o=r+1;break}}else-1===l&&(a=!1,l=r+1),i>=0&&(c===n.charCodeAt(i)?-1===--i&&(s=r):(i=-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(!a){o=r+1;break}}else-1===s&&(a=!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,a=0,i=e.length-1;i>=0;--i){var l=e.charCodeAt(i);if(47!==l)-1===o&&(s=!1,o=i+1),46===l?-1===n?n=i:1!==a&&(a=1):-1!==n&&(a=-1);else if(!s){r=i+1;break}}return-1===n||-1===o||0===a||1===a&&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 a=-1,i=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===a?a=d:1!==g&&(g=1):-1!==a&&(g=-1);else if(!c){i=d+1;break}return-1===a||-1===l||0===g||1===g&&a===l-1&&a===i+1?-1!==l&&(n.base=n.name=0===i&&s?e.slice(1,l):e.slice(i,l)):(0===i&&s?(n.name=e.slice(1,a),n.base=e.slice(1,l)):(n.name=e.slice(i,a),n.base=e.slice(i,l)),n.ext=e.slice(a,l)),i>0?n.dir=e.slice(0,i-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(a){throw console.error(`Failed to create a directory "${t}"`),a}}}function s(e,t,n,r){o(e,t),e.FS.writeFile(t,n,r)}const a=new RegExp("[[(<=>!~;@]");function i(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(a)[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)}))}async function l(e,t){const{scriptURL:n,pyodideIndexURL:r,isESModule:o}=await async function(e){var t;const n="undefined"!==typeof process&&(null===(t=process.versions)||void 0===t?void 0:t.node);let r;r=n?(await import("node:path")).sep:"/";const o=e.slice(0,e.lastIndexOf(r)+1);if(e.endsWith(".mjs")){if(n){const t=await import("node:path"),n=await 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=(await import(n)).loadPyodide}else importScripts(n),s=self.loadPyodide;return s({...t,indexURL:r})}let c;async function d(e,t,n){const r=n.map((t=>function(e,t){if(!c){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),c=e.globals.get("find_imports")}return c(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 a=new MessageChannel;t({type:"event:moduleAutoLoad",data:{packagesToLoad:s}},a.port2);try{const t=await e.loadPackage(s);return a.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:t}}),void a.port1.close()}catch(i){throw a.port1.postMessage({type:"moduleAutoLoad:error",error:i}),a.port1.close(),i}}const g=n.g;function p(e,t,n){const r=d(e,t,n);g.__moduleAutoLoadPromise__=r,e.runPythonAsync("\nfrom streamlit.runtime.scriptrunner import script_runner\nfrom js import __moduleAutoLoadPromise__\n\nscript_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__\n")}const u=self.postMessage;self.onmessage=function(t,n,r){function a(e){n({type:"event:progress",data:{message:e}})}let c,d;const u=new e,m=async function(){var e,o;const m=await u.promise,f={...r,...m};console.debug("Initial data",f);const{entrypoint:h,files:_,archives:y,requirements:b,prebuiltPackageNames:v,wheels:w,pyodideUrl:k=t,streamlitConfig:S,idbfsMountpoints:A,nodefsMountpoints:P,moduleAutoLoad:C}=f,F=i(b);a("Loading Pyodide."),console.debug("Loading Pyodide"),c=await l(k,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let L=!1;A&&(L=!0,A.forEach((e=>{c.FS.mkdir(e),c.FS.mount(c.FS.filesystems.IDBFS,{},e)})),await new Promise(((e,t)=>{c.FS.syncfs(!0,(n=>{n?t(n):e()}))}))),P&&Object.entries(P).forEach((([e,t])=>{c.FS.mkdir(e),c.FS.mount(c.FS.filesystems.NODEFS,{root:t},e)})),a("Mounting files.");const I=[];await Promise.all(Object.keys(_).map((async e=>{const t=_[e];let n;"url"in t?(console.debug(`Fetch a file from ${t.url}`),n=await fetch(t.url).then((e=>e.arrayBuffer())).then((e=>new Uint8Array(e)))):n=t.data;const{opts:r}=_[e];console.debug(`Write a file "${e}"`),s(c,e,n,r),e.endsWith(".py")&&I.push(e)}))),a("Unpacking archives."),await Promise.all(y.map((async e=>{let t;"url"in e?(console.debug(`Fetch an archive from ${e.url}`),t=await 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}),c.unpackArchive(t,n,r)}))),await c.loadPackage("micropip");const E=c.pyimport("micropip");if(a("Mocking some packages."),console.debug("Mock pyarrow"),function(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\nclass Array:\n def __init__(self, *args, **kwargs):\n raise NotImplementedError("stlite is not supporting PyArrow.Array")\n\n\nclass ChunkedArray:\n def __init__(self, *args, **kwargs):\n raise NotImplementedError("stlite is not supporting PyArrow.ChunkedArray")\n"""\n }\n)\n')}(c),console.debug("Mocked pyarrow"),a("Installing packages."),console.debug("Installing the prebuilt packages:",v),await c.loadPackage(v),console.debug("Installed the prebuilt packages"),w?(console.debug("Installing the wheels:",w,"and the requirements:",F),await E.install.callKwargs([w.stliteLib,w.streamlit,...F],{keep_going:!0}),console.debug("Installed the wheels and the requirements")):(console.debug("Installing the requirements:",F),await E.install.callKwargs(F,{keep_going:!0}),console.debug("Installed the requirements")),C){const e=I.map((e=>c.FS.readFile(e,{encoding:"utf8"})));p(c,n,e)}await c.runPythonAsync("\nimport importlib\nimportlib.invalidate_caches()\n"),a("Loading streamlit package."),console.debug("Loading the Streamlit package"),await c.runPythonAsync("\nimport streamlit.runtime\n "),console.debug("Loaded the Streamlit package"),a("Setting up the loggers."),console.debug("Setting the loggers"),await c.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'),g.__logCallback__=(e,t)=>{e>=40?console.error(t):e>=30?console.warn(t):e>=20?console.info(t):console.debug(t)},await c.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 x=(null!==(e=null===S||void 0===S?void 0:S["logger.level"])&&void 0!==e?e:"INFO").toString(),R=null!==(o=null===S||void 0===S?void 0:S["logger.messageFormat"])&&void 0!==o?o:"%(asctime)s %(message)s";if(c.globals.get("setup_loggers")(x,R),console.debug("Set the loggers"),a("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await c.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"),L){a("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let e=!1;g.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),e||(e=!0,c.FS.syncfs(!1,(t=>{e=!1,t&&console.error(t)})))},await c.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")}a("Booting up the Streamlit server."),console.debug("Setting up the Streamlit configuration"),g.__streamlitFlagOptions__={"browser.gatherUsageStats":!1,...S,"runner.fastReruns":!1},await c.runPythonAsync(`\nfrom stlite_lib.bootstrap import load_config_options, prepare\nfrom js import __streamlitFlagOptions__\n\nflag_options = __streamlitFlagOptions__.to_py()\nload_config_options(flag_options)\n\nmain_script_path = "${h}"\nargs = []\n\nprepare(main_script_path, args)\n`),console.debug("Set up the Streamlit configuration"),console.debug("Booting up the Streamlit server");const O=c.pyimport("stlite_lib.server.Server");return d=O(h),await d.start(),console.debug("Booted up the Streamlit server"),n({type:"event:loaded"}),f}().catch((e=>{throw n({type:"event:error",data:{error:e}}),e}));return n({type:"event:start"}),async e=>{const t=e.data;if("initData"===t.type)return void u.resolve(t.data);const{moduleAutoLoad:r}=await m,a=e.ports[0];function l(e){a.postMessage(e)}try{switch(t.type){case"reboot":{console.debug("Reboot the Streamlit server",t.data);const{entrypoint:e}=t.data;d.stop(),console.debug("Booting up the Streamlit server");const n=c.pyimport("stlite_lib.server.Server");d=n(e),d.start(),console.debug("Booted up the Streamlit server"),l({type:"reply"});break}case"websocket:connect":{console.debug("websocket:connect",t.data);const{path:e}=t.data;d.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}})}})),l({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",t.data);const{payload:e}=t.data;d.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}),l({type:"http:response",data:{response:{statusCode:e,headers:r,body:o}}})};d.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}`),p(c,n,[o])),console.debug(`Write a file "${e}"`),s(c,e,o,a),l({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)}(c,e,n),l({type:"reply"});break}case"file:unlink":{const{path:e}=t.data;console.debug(`Remove "${e}`),c.FS.unlink(e),l({type:"reply"});break}case"install":{const{requirements:e}=t.data,n=c.pyimport("micropip"),r=i(e);console.debug("Install the requirements:",r),await n.install.callKwargs(r,{keep_going:!0}).then((()=>{console.debug("Successfully installed"),l({type:"reply"})}))}}}catch(g){if(console.error(g),!(g instanceof Error))throw g;const e=new Error(g.message);e.name=g.name,e.stack=g.stack,l({type:"reply",error:e})}}}("https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js",((e,t)=>u(e,t?[t]:void 0)))})()})();
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,a=-1,s=0,i=0;i<=e.length;++i){if(i<e.length)n=e.charCodeAt(i);else{if(47===n)break;n=47}if(47===n){if(a===i-1||1===s);else if(a!==i-1&&2===s){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("/"),a=i,s=0;continue}}else if(2===r.length||1===r.length){r="",o=0,a=i,s=0;continue}t&&(r.length>0?r+="/..":r="..",o=2)}else r.length>0?r+="/"+e.slice(a+1,i):r=e.slice(a+1,i),o=i-a-1;a=i,s=0}else 46===n&&-1!==s?++s:s=-1}return r}var r={resolve:function(){for(var e,r="",o=!1,a=arguments.length-1;a>=-1&&!o;a--){var s;a>=0?s=arguments[a]:(void 0===e&&(e=process.cwd()),s=e),t(s),0!==s.length&&(r=s+"/"+r,o=47===s.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 a=e.length,s=a-o,i=1;i<n.length&&47===n.charCodeAt(i);++i);for(var l=n.length-i,c=s<l?s:l,d=-1,g=0;g<=c;++g){if(g===c){if(l>c){if(47===n.charCodeAt(i+g))return n.slice(i+g+1);if(0===g)return n.slice(i+g)}else s>c&&(47===e.charCodeAt(o+g)?d=g:0===g&&(d=0));break}var p=e.charCodeAt(o+g);if(p!==n.charCodeAt(i+g))break;47===p&&(d=g)}var u="";for(g=o+d+1;g<=a;++g)g!==a&&47!==e.charCodeAt(g)||(0===u.length?u+="..":u+="/..");return u.length>0?u+n.slice(i+d):(i+=d,47===n.charCodeAt(i)&&++i,n.slice(i))},_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,a=!0,s=e.length-1;s>=1;--s)if(47===(n=e.charCodeAt(s))){if(!a){o=s;break}}else a=!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,a=-1,s=!0;if(void 0!==n&&n.length>0&&n.length<=e.length){if(n.length===e.length&&n===e)return"";var i=n.length-1,l=-1;for(r=e.length-1;r>=0;--r){var c=e.charCodeAt(r);if(47===c){if(!s){o=r+1;break}}else-1===l&&(s=!1,l=r+1),i>=0&&(c===n.charCodeAt(i)?-1===--i&&(a=r):(i=-1,a=l))}return o===a?a=l:-1===a&&(a=e.length),e.slice(o,a)}for(r=e.length-1;r>=0;--r)if(47===e.charCodeAt(r)){if(!s){o=r+1;break}}else-1===a&&(s=!1,a=r+1);return-1===a?"":e.slice(o,a)},extname:function(e){t(e);for(var n=-1,r=0,o=-1,a=!0,s=0,i=e.length-1;i>=0;--i){var l=e.charCodeAt(i);if(47!==l)-1===o&&(a=!1,o=i+1),46===l?-1===n?n=i:1!==s&&(s=1):-1!==n&&(s=-1);else if(!a){r=i+1;break}}return-1===n||-1===o||0===s||1===s&&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),a=47===o;a?(n.root="/",r=1):r=0;for(var s=-1,i=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===s?s=d:1!==g&&(g=1):-1!==s&&(g=-1);else if(!c){i=d+1;break}return-1===s||-1===l||0===g||1===g&&s===l-1&&s===i+1?-1!==l&&(n.base=n.name=0===i&&a?e.slice(1,l):e.slice(i,l)):(0===i&&a?(n.name=e.slice(1,s),n.base=e.slice(1,l)):(n.name=e.slice(i,s),n.base=e.slice(i,l)),n.ext=e.slice(s,l)),i>0?n.dir=e.slice(0,i-1):a&&(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 a=t[r]={exports:{}};return e[r](a,a.exports,n),a.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("/"),a=[];for(const r of o){a.push(r);const t=a.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(s){throw console.error(`Failed to create a directory "${t}"`),s}}}function a(e,t,n,r){o(e,t),e.FS.writeFile(t,n,r)}const s=new RegExp("[[(<=>!~;@]");function i(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(s)[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)}))}async function l(e,t){const{scriptURL:n,pyodideIndexURL:r,isESModule:o}=await async function(e){var t;const n="undefined"!==typeof process&&(null===(t=process.versions)||void 0===t?void 0:t.node);let r;r=n?(await import("node:path")).sep:"/";const o=e.slice(0,e.lastIndexOf(r)+1);if(e.endsWith(".mjs")){if(n){const t=await import("node:path"),n=await 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 a;if(o){a=(await import(n)).loadPyodide}else importScripts(n),a=self.loadPyodide;return a({...t,indexURL:r})}let c;async function d(e,t,n){const r=n.map((t=>function(e,t){if(!c){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),c=e.globals.get("find_imports")}return c(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),a=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===a.length)return;const s=new MessageChannel;t({type:"event:moduleAutoLoad",data:{packagesToLoad:a}},s.port2);try{const t=await e.loadPackage(a);return s.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:t}}),void s.port1.close()}catch(i){throw s.port1.postMessage({type:"moduleAutoLoad:error",error:i}),s.port1.close(),i}}const g=n.g;function p(e,t,n){const r=d(e,t,n);g.__moduleAutoLoadPromise__=r,e.runPythonAsync("\nfrom streamlit.runtime.scriptrunner import script_runner\nfrom js import __moduleAutoLoadPromise__\n\nscript_runner.moduleAutoLoadPromise = __moduleAutoLoadPromise__\n")}const u=self.postMessage;self.onmessage=function(t,n,r){function s(e){n({type:"event:progress",data:{message:e}})}let c,d;const u=new e,m=async function(){var e,o;const m=await u.promise,f={...r,...m};console.debug("Initial data",f);const{entrypoint:h,files:_,archives:y,requirements:b,prebuiltPackageNames:v,wheels:w,pyodideUrl:k=t,streamlitConfig:S,idbfsMountpoints:A,nodefsMountpoints:P,moduleAutoLoad:F}=f,C=i(b);s("Loading Pyodide."),console.debug("Loading Pyodide"),c=await l(k,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide");let L=!1;A&&(L=!0,A.forEach((e=>{c.FS.mkdir(e),c.FS.mount(c.FS.filesystems.IDBFS,{},e)})),await new Promise(((e,t)=>{c.FS.syncfs(!0,(n=>{n?t(n):e()}))}))),P&&Object.entries(P).forEach((([e,t])=>{c.FS.mkdir(e),c.FS.mount(c.FS.filesystems.NODEFS,{root:t},e)})),s("Mounting files.");const I=[];await Promise.all(Object.keys(_).map((async e=>{const t=_[e];let n;"url"in t?(console.debug(`Fetch a file from ${t.url}`),n=await fetch(t.url).then((e=>e.arrayBuffer())).then((e=>new Uint8Array(e)))):n=t.data;const{opts:r}=_[e];console.debug(`Write a file "${e}"`),a(c,e,n,r),e.endsWith(".py")&&I.push(e)}))),s("Unpacking archives."),await Promise.all(y.map((async e=>{let t;"url"in e?(console.debug(`Fetch an archive from ${e.url}`),t=await 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}),c.unpackArchive(t,n,r)}))),await c.loadPackage("micropip");const E=c.pyimport("micropip");if(s("Mocking some packages."),console.debug("Mock pyarrow"),function(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\nclass Array:\n def __init__(self, *args, **kwargs):\n raise NotImplementedError("stlite is not supporting PyArrow.Array")\n\n\nclass ChunkedArray:\n def __init__(self, *args, **kwargs):\n raise NotImplementedError("stlite is not supporting PyArrow.ChunkedArray")\n"""\n }\n)\n')}(c),console.debug("Mocked pyarrow"),s("Installing packages."),console.debug("Installing the prebuilt packages:",v),await c.loadPackage(v),console.debug("Installed the prebuilt packages"),w?(console.debug("Installing the wheels:",w,"and the requirements:",C),await E.install.callKwargs([w.stliteLib,w.streamlit,...C],{keep_going:!0}),console.debug("Installed the wheels and the requirements")):(console.debug("Installing the requirements:",C),await E.install.callKwargs(C,{keep_going:!0}),console.debug("Installed the requirements")),F){const e=I.map((e=>c.FS.readFile(e,{encoding:"utf8"})));p(c,n,e)}await c.runPythonAsync("\nimport importlib\nimportlib.invalidate_caches()\n"),s("Loading streamlit package."),console.debug("Loading the Streamlit package"),await c.runPythonAsync("\nimport streamlit.runtime\n "),console.debug("Loaded the Streamlit package"),s("Setting up the loggers."),console.debug("Setting the loggers"),await c.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'),g.__logCallback__=(e,t)=>{e>=40?console.error(t):e>=30?console.warn(t):e>=20?console.info(t):console.debug(t)},await c.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 x=(null!==(e=null===S||void 0===S?void 0:S["logger.level"])&&void 0!==e?e:"INFO").toString(),R=null!==(o=null===S||void 0===S?void 0:S["logger.messageFormat"])&&void 0!==o?o:"%(asctime)s %(message)s";if(c.globals.get("setup_loggers")(x,R),console.debug("Set the loggers"),s("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await c.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"),L){s("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let e=!1;g.__scriptFinishedCallback__=()=>{console.debug("The script has finished. Syncing the filesystem."),e||(e=!0,c.FS.syncfs(!1,(t=>{e=!1,t&&console.error(t)})))},await c.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")}s("Booting up the Streamlit server."),console.debug("Setting up the Streamlit configuration"),g.__streamlitFlagOptions__={"browser.gatherUsageStats":!1,...S,"runner.fastReruns":!1},await c.runPythonAsync(`\nfrom stlite_lib.bootstrap import load_config_options, prepare\nfrom js import __streamlitFlagOptions__\n\nflag_options = __streamlitFlagOptions__.to_py()\nload_config_options(flag_options)\n\nmain_script_path = "${h}"\nargs = []\n\nprepare(main_script_path, args)\n`),console.debug("Set up the Streamlit configuration"),console.debug("Booting up the Streamlit server");const O=c.pyimport("stlite_lib.server.Server");return d=O(h),await d.start(),console.debug("Booted up the Streamlit server"),n({type:"event:loaded"}),f}().catch((e=>{throw n({type:"event:error",data:{error:e}}),e}));return n({type:"event:start"}),async e=>{const t=e.data;if("initData"===t.type)return void u.resolve(t.data);const{moduleAutoLoad:r}=await m,s=e.ports[0];function l(e){s.postMessage(e)}try{switch(t.type){case"reboot":{console.debug("Reboot the Streamlit server",t.data);const{entrypoint:e}=t.data;d.stop(),console.debug("Booting up the Streamlit server");const n=c.pyimport("stlite_lib.server.Server");d=n(e),d.start(),console.debug("Booted up the Streamlit server"),l({type:"reply"});break}case"websocket:connect":{console.debug("websocket:connect",t.data);const{path:e}=t.data;d.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}})}})),l({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",t.data);const{payload:e}=t.data;d.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}),l({type:"http:response",data:{response:{statusCode:e,headers:r,body:o}}})};d.receive_http_from_js(e.method,decodeURIComponent(e.path),e.headers,e.body,n);break}case"file:write":{const{path:e,data:o,opts:s}=t.data;r&&"string"===typeof o&&e.endsWith(".py")&&(console.debug(`Auto install the requirements in ${e}`),p(c,n,[o])),console.debug(`Write a file "${e}"`),a(c,e,o,s),l({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)}(c,e,n),l({type:"reply"});break}case"file:unlink":{const{path:e}=t.data;console.debug(`Remove "${e}`),c.FS.unlink(e),l({type:"reply"});break}case"file:read":{const{path:e,opts:n}=t.data;console.debug(`Read "${e}"`);l({type:"reply:file:read",data:{content:c.FS.readFile(e,n)}});break}case"install":{const{requirements:e}=t.data,n=c.pyimport("micropip"),r=i(e);console.debug("Install the requirements:",r),await n.install.callKwargs(r,{keep_going:!0}).then((()=>{console.debug("Successfully installed"),l({type:"reply"})}))}}}catch(g){if(console.error(g),!(g instanceof Error))throw g;const e=new Error(g.message);e.name=g.name,e.stack=g.stack,l({type:"reply",error:e})}}}("https://cdn.jsdelivr.net/pyodide/v0.26.2/full/pyodide.js",((e,t)=>u(e,t?[t]:void 0)))})()})();