@stlite/desktop 0.91.0 → 0.91.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/CHANGELOG.md +12 -0
- package/bin/dump_artifacts.js +1 -1
- package/build/assets/{ErrorOutline.esm-5cmZjQRC-icYL4BM5.js → ErrorOutline.esm-CBPRrcCq-C9-TIHiy.js} +1 -1
- package/build/assets/{FileDownload.esm-rDRR6AEq-DjpuiBZc.js → FileDownload.esm-zztsCQgv-C5piFaVt.js} +1 -1
- package/build/assets/{FileHelper-DDgj8qUb-DZYWXyeE.js → FileHelper-D9iak492-B1kwMP-N.js} +1 -1
- package/build/assets/{FormClearHelper-Bi1RDDCw-CUfvtGEu.js → FormClearHelper-B-0AN2KG-drNJ-Zdq.js} +1 -1
- package/build/assets/{Hooks-BLb3umpI-D_n25nUE.js → Hooks-BLb3umpI-CC08A2wx.js} +1 -1
- package/build/assets/{InputInstructions-DK4vKQJt-CxHQuxCq.js → InputInstructions-w5hPdqFC-DnPj3I4S.js} +1 -1
- package/build/assets/{Particles-CVTDiAXz-DxW9qGxs.js → Particles-DQoPZNo9-BWmBxXhd.js} +1 -1
- package/build/assets/{ProgressBar-DBzTytnw-KD3bOGNH.js → ProgressBar-DlHaaa-z-DdC3oXz0.js} +1 -1
- package/build/assets/{Toolbar-C79vGzHM-4gREjS-R.js → Toolbar-Cau3SOTY-cJ6wtM04.js} +1 -1
- package/build/assets/{base-input-DqwZ6cLM-CfKARdZH.js → base-input-D-Fvddky-3QuAUeGB.js} +1 -1
- package/build/assets/{checkbox-DSLjv1hz-C5dTTEJn.js → checkbox-CjcIG3na-LB8a9-d7.js} +1 -1
- package/build/assets/{createSuper-B3kpwht8-vR1ZxlfE.js → createSuper-B81LEHTk-DVB4ulOX.js} +1 -1
- package/build/assets/data-grid-overlay-editor-C7-8Z8CC-CmhK1L1G.js +1 -0
- package/build/assets/{downloader-DcCTL3Wz-B8zcxQVm.js → downloader-DcCTL3Wz-DfHnsO-D.js} +1 -1
- package/build/assets/{es6--XPcqeHG-Ct8fR_QW.js → es6--XPcqeHG-CU-P5RWV.js} +2 -2
- package/build/assets/{iframeResizer.contentWindow-BYeUxEkG-BGHgpKaO.js → iframeResizer.contentWindow-vAQsQkcx-DjDgPkx5.js} +1 -1
- package/build/assets/{index-DDzvi540-BP83xTE8.js → index--hiX6Uwv-DtKO9Hld.js} +1 -1
- package/build/assets/{index-CqUzXpnq-BkRqyTZ-.js → index-6t9Tq-Ab-Cc_ees8I.js} +1 -1
- package/build/assets/{index-zCpSIFXF-CNWD8XSX.js → index-B5h0Xgw3-CNFqm9ip.js} +1 -1
- package/build/assets/{index-fUOYudAa-DwvNVa4q.js → index-BDD6ManL-XC9-hEWd.js} +1 -1
- package/build/assets/{index-0V3zFawH-dk2qSnUj.js → index-BDtR3I-m-C6v_enzF.js} +1 -1
- package/build/assets/{index-B77TIzH--_sfHBOLj.js → index-BNeCf0z6-eizg-dFz.js} +1 -1
- package/build/assets/{index-BPsr3GBY-CJGmhZ4p.js → index-BXbsmcnm-D0BJVs7R.js} +1 -1
- package/build/assets/index-Bt2pmgaJ-ymksNLCl.js +198 -0
- package/build/assets/{index-DdN7bQv1-B-kAc3Ut.js → index-Bx1YyC6x-bUWv5Yyf.js} +1 -1
- package/build/assets/{index-BUGX2TMK.js → index-BxpEVUJq.js} +45 -45
- package/build/assets/{index-BFxpMDN6-DR2ES9VX.js → index-C5FPtYYS-BTTgdUI2.js} +1 -1
- package/build/assets/{index-CKLXnSph-0c1m_tEn.js → index-CL9VPrGG-DvzaBWYj.js} +1 -1
- package/build/assets/{index-DpgEDPmz-DJh9zWZb.js → index-COXlYbHo-B2m8urCs.js} +1 -1
- package/build/assets/{index-xHja9EuR-BJAq-yTR.js → index-CR_1rzEZ-DaqWZNME.js} +1 -1
- package/build/assets/{index-CK3GkxeH-D2XBcs5n.js → index-CUH8SI0g-CgCG3Tq7.js} +1 -1
- package/build/assets/{index-D6seXbqB-BPSqxK2r.js → index-CeUKVR_x-6fYziq6X.js} +1 -1
- package/build/assets/{index-p30tlBB--Bny4OpXe.js → index-D4OS_mB9-BwMU_oxN.js} +1 -1
- package/build/assets/{index-DUxsAr3N-YOYvjsWo.js → index-D5GvvN8r-CL05rAIV.js} +1 -1
- package/build/assets/{index-DJv86VV6-BxF_m0zQ.js → index-D6OV4wQy-CQIpYALu.js} +1 -1
- package/build/assets/{index-fJZU9fvL-CKGTaTkl.js → index-D8AcUh2z-BvmWAicd.js} +1 -1
- package/build/assets/index-D9Ww6wIM-CODTYNKi.js +1 -0
- package/build/assets/{index-j0zTFwH2-B6bjwCqo.js → index-D9xjkRNt-CFe8X0f3.js} +1 -1
- package/build/assets/{index-BkEF79ga-BDywftDb.js → index-DBM8Q3zu-1UaS0Le1.js} +1 -1
- package/build/assets/{index-pBZdYFXV-CISZ02sQ.js → index-DEKI5kx7-B8lK1On8.js} +1 -1
- package/build/assets/{index-CZG1F3wS-BFc-W9r-.js → index-DVo6TdD5-Cigl7ucs.js} +1 -1
- package/build/assets/{index-CFJPpmiv-DJLEtKZ0.js → index-DYssp6us-ss1M0SKX.js} +1 -1
- package/build/assets/{index-BV9PPylv-DWAKeZC_.js → index-Da8BucgM-CDMzLZMq.js} +1 -1
- package/build/assets/{index-Hwxwzkvz-BrKybKu3.js → index-DbIPIRRU-UJS7GIgX.js} +1 -1
- package/build/assets/{index-D--Ibtdf-DP7qoXbQ.js → index-DqAvSOqr-BCGTFud5.js} +1 -1
- package/build/assets/{index-BQabGVla-C_9TU-y1.js → index-Ds3R2kL1-CFh_Kz3Y.js} +1 -1
- package/build/assets/{index-Ng0C2pop-CzH2RCjT.js → index-FbSORAjW-Lthz52ML.js} +1 -1
- package/build/assets/{index-B7QM9sAr-BJJ9a1xS.js → index-JJq6JoHy-CX1Omp_x.js} +1 -1
- package/build/assets/{index-DlIOBmG6-fWsA1K6o.js → index-OAJkEMe--vGYqEFkN.js} +1 -1
- package/build/assets/{index-CxQBvv94-C1cgCYzN.js → index-PfjJDWy5-DkldmeJ8.js} +1 -1
- package/build/assets/{index-CQ0SOKgT-K7zOmyHq.js → index-kgY8PEpO-BUILDAe7.js} +1 -1
- package/build/assets/{index-BacWTAj2-C6QHLACm.js → index-oFRA4JRK-kx0e_3zA.js} +1 -1
- package/build/assets/{index-DfmwwL-F-BtkRVq0J.js → index-vdN_5NIh-CyyygayY.js} +1 -1
- package/build/assets/{inherits-V2B09WF6-BfQai87E.js → inherits-DIXnBNlu-DQhXiByk.js} +1 -1
- package/build/assets/{input-0QG8D109-QEdIPUBc.js → input-D3V-zfyu-Ca751_uU.js} +1 -1
- package/build/assets/{memory-B3L1Fctl-DNNZq00W.js → memory-B3L1Fctl-DNb7NEQl.js} +1 -1
- package/build/assets/{number-overlay-editor-CQf9AWEA-RmKnGQqj.js → number-overlay-editor-ChRMsdOl-C6ThLwiC.js} +1 -1
- package/build/assets/{sandbox-ChAzL-i--Bt92ucFR.js → sandbox-ChAzL-i--FikCfyDW.js} +1 -1
- package/build/assets/{slicedToArray-bXF_q2D_-C8JYb8qs.js → slicedToArray-BPQXLGHq-C21Y2TxO.js} +1 -1
- package/build/assets/{timepicker-BaiGCRZ1-Sm9ehMNI.js → timepicker-B0aGGgzd-sxFvpbfo.js} +1 -1
- package/build/assets/{uniqueId-DEZw4fCm-ChV-p6H5.js → uniqueId-MHj2wT7u-DPxsodx6.js} +1 -1
- package/build/assets/{useBasicWidgetState-gAw0WJ0t-BlUmDiku.js → useBasicWidgetState-zjZCXhqV-BNiFnFun.js} +1 -1
- package/build/assets/{useTextInputAutoExpand-CrQdinCr-BiEwhNXe.js → useTextInputAutoExpand-ox95UJrD-CZJQOtsK.js} +1 -1
- package/build/assets/{useUpdateUiValue-Bz-Z5Int-0QBs3uQx.js → useUpdateUiValue-Yj1mvLxf-DIZzUp3u.js} +1 -1
- package/build/assets/{withFullScreenWrapper-BKnfDWJg-dLKoL1-0.js → withFullScreenWrapper-Ca0mIjWH-ClODS1xe.js} +1 -1
- package/build/assets/worker-B65uO5d3-CuVvmm9s.js +106 -0
- package/build/electron/worker.js +9 -9
- package/build/index.html +1 -1
- package/package.json +12 -11
- package/wheels/stlite_lib-0.1.0-py3-none-any.whl +0 -0
- package/wheels/streamlit-1.50.0-cp313-none-any.whl +0 -0
- package/build/assets/data-grid-overlay-editor-DlwBF2tR-B5qTFESv.js +0 -1
- package/build/assets/index-BaDPYxKb-eLNjgO02.js +0 -1
- package/build/assets/index-Cwu3avS4-DiDBV46w.js +0 -188
- package/build/assets/worker-BOuMG9lT-DqkGm1hg.js +0 -106
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
(function(){"use strict";function X(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var M,$;function Q(){if($)return M;$=1;function o(i){if(typeof i!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(i))}function c(i,e){for(var t="",s=0,a=-1,d=0,r,l=0;l<=i.length;++l){if(l<i.length)r=i.charCodeAt(l);else{if(r===47)break;r=47}if(r===47){if(!(a===l-1||d===1))if(a!==l-1&&d===2){if(t.length<2||s!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){var u=t.lastIndexOf("/");if(u!==t.length-1){u===-1?(t="",s=0):(t=t.slice(0,u),s=t.length-1-t.lastIndexOf("/")),a=l,d=0;continue}}else if(t.length===2||t.length===1){t="",s=0,a=l,d=0;continue}}e&&(t.length>0?t+="/..":t="..",s=2)}else t.length>0?t+="/"+i.slice(a+1,l):t=i.slice(a+1,l),s=l-a-1;a=l,d=0}else r===46&&d!==-1?++d:d=-1}return t}function m(i,e){var t=e.dir||e.root,s=e.base||(e.name||"")+(e.ext||"");return t?t===e.root?t+s:t+i+s:s}var g={resolve:function(){for(var e="",t=!1,s,a=arguments.length-1;a>=-1&&!t;a--){var d;a>=0?d=arguments[a]:(s===void 0&&(s=process.cwd()),d=s),o(d),d.length!==0&&(e=d+"/"+e,t=d.charCodeAt(0)===47)}return e=c(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(o(e),e.length===0)return".";var t=e.charCodeAt(0)===47,s=e.charCodeAt(e.length-1)===47;return e=c(e,!t),e.length===0&&!t&&(e="."),e.length>0&&s&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return o(e),e.length>0&&e.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var e,t=0;t<arguments.length;++t){var s=arguments[t];o(s),s.length>0&&(e===void 0?e=s:e+="/"+s)}return e===void 0?".":g.normalize(e)},relative:function(e,t){if(o(e),o(t),e===t||(e=g.resolve(e),t=g.resolve(t),e===t))return"";for(var s=1;s<e.length&&e.charCodeAt(s)===47;++s);for(var a=e.length,d=a-s,r=1;r<t.length&&t.charCodeAt(r)===47;++r);for(var l=t.length,u=l-r,k=d<u?d:u,w=-1,_=0;_<=k;++_){if(_===k){if(u>k){if(t.charCodeAt(r+_)===47)return t.slice(r+_+1);if(_===0)return t.slice(r+_)}else d>k&&(e.charCodeAt(s+_)===47?w=_:_===0&&(w=0));break}var P=e.charCodeAt(s+_),C=t.charCodeAt(r+_);if(P!==C)break;P===47&&(w=_)}var b="";for(_=s+w+1;_<=a;++_)(_===a||e.charCodeAt(_)===47)&&(b.length===0?b+="..":b+="/..");return b.length>0?b+t.slice(r+w):(r+=w,t.charCodeAt(r)===47&&++r,t.slice(r))},_makeLong:function(e){return e},dirname:function(e){if(o(e),e.length===0)return".";for(var t=e.charCodeAt(0),s=t===47,a=-1,d=!0,r=e.length-1;r>=1;--r)if(t=e.charCodeAt(r),t===47){if(!d){a=r;break}}else d=!1;return a===-1?s?"/":".":s&&a===1?"//":e.slice(0,a)},basename:function(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');o(e);var s=0,a=-1,d=!0,r;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var l=t.length-1,u=-1;for(r=e.length-1;r>=0;--r){var k=e.charCodeAt(r);if(k===47){if(!d){s=r+1;break}}else u===-1&&(d=!1,u=r+1),l>=0&&(k===t.charCodeAt(l)?--l===-1&&(a=r):(l=-1,a=u))}return s===a?a=u:a===-1&&(a=e.length),e.slice(s,a)}else{for(r=e.length-1;r>=0;--r)if(e.charCodeAt(r)===47){if(!d){s=r+1;break}}else a===-1&&(d=!1,a=r+1);return a===-1?"":e.slice(s,a)}},extname:function(e){o(e);for(var t=-1,s=0,a=-1,d=!0,r=0,l=e.length-1;l>=0;--l){var u=e.charCodeAt(l);if(u===47){if(!d){s=l+1;break}continue}a===-1&&(d=!1,a=l+1),u===46?t===-1?t=l:r!==1&&(r=1):t!==-1&&(r=-1)}return t===-1||a===-1||r===0||r===1&&t===a-1&&t===s+1?"":e.slice(t,a)},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 m("/",e)},parse:function(e){o(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var s=e.charCodeAt(0),a=s===47,d;a?(t.root="/",d=1):d=0;for(var r=-1,l=0,u=-1,k=!0,w=e.length-1,_=0;w>=d;--w){if(s=e.charCodeAt(w),s===47){if(!k){l=w+1;break}continue}u===-1&&(k=!1,u=w+1),s===46?r===-1?r=w:_!==1&&(_=1):r!==-1&&(_=-1)}return r===-1||u===-1||_===0||_===1&&r===u-1&&r===l+1?u!==-1&&(l===0&&a?t.base=t.name=e.slice(1,u):t.base=t.name=e.slice(l,u)):(l===0&&a?(t.name=e.slice(1,r),t.base=e.slice(1,u)):(t.name=e.slice(l,r),t.base=e.slice(l,u)),t.ext=e.slice(r,u)),l>0?t.dir=e.slice(0,l-1):a&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};return g.posix=g,M=g,M}var V=Q(),E=X(V);const B="/home/pyodide",U=o=>`${B}/${o}`,R=(o,c)=>o==null?E.resolve(B,c):E.resolve(U(o),c);function z(o,c){const m=E.normalize(c),i=E.dirname(m).split(/(?=\/)/);let e="";for(const t of i){e+=t;const s=o.FS.analyzePath(e);if(s.exists&&s.object){if(!o.FS.isDir(s.object.mode))throw new Error(`"${e}" already exists and is not a directory.`);continue}try{o.FS.mkdir(e)}catch(a){throw console.error(`Failed to create a directory "${e}"`),a}}}function H(o,c,m,g){z(o,c),o.FS.writeFile(c,m,g)}function Y(o,c,m){z(o,m),o.FS.rename(c,m)}const Z="[",ee="(<=>!~",te=";",re="@",oe=new RegExp(`[${Z+ee+te+re}]`);function ne(o){return o.split(oe)[0].trim()}function T(o){return o.forEach(m=>{let g;try{g=new URL(m)}catch{return}if(g.protocol==="emfs:"||g.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${m})`)}),o.filter(m=>ne(m)==="streamlit"?(console.warn(`Streamlit is specified in the requirements ("${m}"), but it will be ignored. A built-in version of Streamlit will be used.`),!1):!0)}async function se(o){const c=typeof process<"u"&&process.versions?.node;let m;c?m=(await Promise.resolve().then(function(){return j})).sep:m="/";const g=o.slice(0,o.lastIndexOf(m)+1);if(o.endsWith(".mjs")){if(c){const i=await Promise.resolve().then(function(){return j}),e=await Promise.resolve().then(function(){return j});!o.includes("://")&&i.isAbsolute(o)&&(o=e.pathToFileURL(o).href)}return{scriptURL:o,pyodideIndexURL:g,isESModule:!0}}else return{scriptURL:o,pyodideIndexURL:g,isESModule:!1}}async function ae(o,c){const{scriptURL:m,pyodideIndexURL:g,isESModule:i}=await se(o);let e;return i?e=(await import(m)).loadPyodide:(importScripts(m),e=self.loadPyodide),e({...c,indexURL:g})}function ie(o){o.runPython(`
|
|
2
|
+
import micropip
|
|
3
|
+
micropip.add_mock_package(
|
|
4
|
+
"pyarrow", "0.0.1",
|
|
5
|
+
modules={
|
|
6
|
+
"pyarrow": """
|
|
7
|
+
__version__ = '0.0.1' # TODO: Update when releasing
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Table:
|
|
11
|
+
@classmethod
|
|
12
|
+
def from_pandas(*args, **kwargs):
|
|
13
|
+
raise NotImplementedError("stlite is not supporting this method.")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Array:
|
|
17
|
+
def __init__(self, *args, **kwargs):
|
|
18
|
+
raise NotImplementedError("stlite is not supporting PyArrow.Array")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ChunkedArray:
|
|
22
|
+
def __init__(self, *args, **kwargs):
|
|
23
|
+
raise NotImplementedError("stlite is not supporting PyArrow.ChunkedArray")
|
|
24
|
+
"""
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
`)}function le(o,c,m){const g=o.pyimport("pyodide"),i=r=>g.code.find_imports(r).toJs(),e=m.map(r=>i(r)),a=Array.from(new Set(e.flat())).filter(r=>!o.runPython(`__import__('importlib').util.find_spec('${r}')`)).map(r=>o._api._import_name_to_package_name.get(r)).filter(r=>r);if(a.length===0)return Promise.resolve();const d=o.loadPackage(a);return c(a,d),d.then()}function J(o,c,m){const g=le(o,c,m);o.runPython(`
|
|
28
|
+
def __set_module_auto_load_promise__(promise):
|
|
29
|
+
from streamlit.runtime.scriptrunner import script_runner
|
|
30
|
+
script_runner.moduleAutoLoadPromise = promise
|
|
31
|
+
|
|
32
|
+
__set_module_auto_load_promise__`)(g)}async function ce(o,c,m){const{line:g,column:i}=m,e=o.Script(c);if(g>e._code_lines.length)return[];const t=e.complete.callKwargs({line:g,column:i,fuzzy:!1}),s=[];for(const a of t.toJs())s.push({name:a.name,type:a.$type,docstring:a.docstring.callKwargs({raw:!0}),complete:a.complete}),a.destroy();return s}let O=null,N=Promise.resolve(),D=!1;async function de(o,c,m,g,i){const{files:e,archives:t,requirements:s,prebuiltPackageNames:a,wheels:d,installs:r,pyodideUrl:l=o,streamlitConfig:u,idbfsMountpoints:k,nodefsMountpoints:w,moduleAutoLoad:_,env:P,languageServer:C}=m,b=T(s);O?(i("Pyodide is already loaded."),console.debug("Pyodide is already loaded.")):(i("Loading Pyodide."),console.debug("Loading Pyodide."),O=ae(l,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide"));const n=await O;if(P){console.debug("Setting environment variables",P);const f=n.pyimport("os");f.environ.update(n.toPy(P)),console.debug("Set environment variables",f.environ)}let p=!1;k&&(p=!0,k.forEach(f=>{n.FS.mkdir(f),n.FS.mount(n.FS.filesystems.IDBFS,{},f)}),await new Promise((f,y)=>{n.FS.syncfs(!0,S=>{S?y(S):f()})})),w&&Object.entries(w).forEach(([f,y])=>{n.FS.mkdir(f),n.FS.mount(n.FS.filesystems.NODEFS,{root:y},f)}),i("Mounting files.");const h=[];await Promise.all(Object.keys(e).map(async f=>{const y=e[f];f=R(c,f);let S;"url"in y?(console.debug(`Fetch a file from ${y.url}`),S=await fetch(y.url).then(A=>A.arrayBuffer()).then(A=>new Uint8Array(A))):S=y.data,console.debug(`Write a file "${f}"`),H(n,f,S,e.opts),f.endsWith(".py")&&h.push(f)})),i("Unpacking archives."),await Promise.all(t.map(async f=>{let y;"url"in f?(console.debug(`Fetch an archive from ${f.url}`),y=await fetch(f.url).then(be=>be.arrayBuffer())):y=f.buffer;const{format:S,options:A}=f;console.debug("Unpack an archive",{format:S,options:A}),n.unpackArchive(y,S,A)})),await n.loadPackage("micropip");const v=n.pyimport("micropip");i("Mocking some packages."),console.debug("Mock pyarrow"),ie(n),console.debug("Mocked pyarrow"),i("Installing packages."),console.debug("Installing the prebuilt packages:",a),await n.loadPackage(a),console.debug("Installed the prebuilt packages");const F=async()=>{console.debug("Installing the packages:",{requirements:b,systemPackagesInstalled:D});const f=[];D||(console.debug("System packages will be installed"),d&&(f.push(d.streamlit),f.push(d.stliteLib)),C&&f.push("jedi"));const y=[...f,...b];console.debug("Installing the packages:",y),await v.install.callKwargs(y,{keep_going:!0}),f.length>0&&(console.debug("Installed the system packages"),D=!0),console.debug("Installed the packages")},L=N.then(()=>F());if(N=L.catch(f=>{console.error("Package installation failed:",f)}),await L,r&&(console.debug("Installing the additional requirements"),await Promise.all(r.map(({requirements:f,options:y})=>{const S=T(f);return console.debug("Installing the requirements:",S),v.install.callKwargs(S,y??{})}))),_){const f=h.map(y=>n.FS.readFile(y,{encoding:"utf8"}));J(n,g,f)}await n.runPythonAsync(`
|
|
33
|
+
import importlib
|
|
34
|
+
importlib.invalidate_caches()
|
|
35
|
+
`),i("Loading streamlit package."),console.debug("Loading the Streamlit package"),await n.runPythonAsync(`
|
|
36
|
+
import streamlit.runtime
|
|
37
|
+
`),console.debug("Loaded the Streamlit package"),i("Setting up the loggers."),console.debug("Setting the loggers"),await n.runPythonAsync(`
|
|
38
|
+
import logging
|
|
39
|
+
import streamlit.logger
|
|
40
|
+
|
|
41
|
+
streamlit.logger.get_logger = logging.getLogger
|
|
42
|
+
streamlit.logger.setup_formatter = None
|
|
43
|
+
streamlit.logger.update_formatter = lambda *a, **k: None
|
|
44
|
+
streamlit.logger.set_log_level = lambda *a, **k: None
|
|
45
|
+
|
|
46
|
+
for name in streamlit.logger._loggers.keys():
|
|
47
|
+
if name == "root":
|
|
48
|
+
name = "streamlit"
|
|
49
|
+
logger = logging.getLogger(name)
|
|
50
|
+
logger.propagate = True
|
|
51
|
+
logger.handlers.clear()
|
|
52
|
+
logger.setLevel(logging.NOTSET)
|
|
53
|
+
|
|
54
|
+
streamlit.logger._loggers = {}
|
|
55
|
+
`);const I=(f,y)=>{f>=40?console.error(y):f>=30?console.warn(y):f>=20?console.info(y):console.debug(y)},fe=n.runPython(`
|
|
56
|
+
def __setup_loggers__(streamlit_level, streamlit_message_format, callback):
|
|
57
|
+
class JsHandler(logging.Handler):
|
|
58
|
+
def emit(self, record):
|
|
59
|
+
msg = self.format(record)
|
|
60
|
+
callback(record.levelno, msg)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
root_message_format = "%(levelname)s:%(name)s:%(message)s"
|
|
64
|
+
|
|
65
|
+
root_logger = logging.getLogger()
|
|
66
|
+
root_logger.handlers.clear()
|
|
67
|
+
root_formatter = logging.Formatter(root_message_format)
|
|
68
|
+
root_handler = JsHandler()
|
|
69
|
+
root_handler.setFormatter(root_formatter)
|
|
70
|
+
root_logger.addHandler(root_handler)
|
|
71
|
+
root_logger.setLevel(logging.DEBUG)
|
|
72
|
+
|
|
73
|
+
streamlit_logger = logging.getLogger("streamlit")
|
|
74
|
+
streamlit_logger.propagate = False
|
|
75
|
+
streamlit_logger.handlers.clear()
|
|
76
|
+
streamlit_formatter = logging.Formatter(streamlit_message_format)
|
|
77
|
+
streamlit_handler = JsHandler()
|
|
78
|
+
streamlit_handler.setFormatter(streamlit_formatter)
|
|
79
|
+
streamlit_logger.addHandler(streamlit_handler)
|
|
80
|
+
streamlit_logger.setLevel(streamlit_level.upper())
|
|
81
|
+
|
|
82
|
+
__setup_loggers__`),me=(u?.["logger.level"]??"INFO").toString(),pe=u?.["logger.messageFormat"]??"%(asctime)s %(message)s";if(fe(me,pe,I),console.debug("Set the loggers"),i("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await n.runPythonAsync(`
|
|
83
|
+
import streamlit
|
|
84
|
+
|
|
85
|
+
def is_cacheable_msg(msg):
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
streamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg
|
|
89
|
+
`),console.debug("Mocked some Streamlit functions"),p){i("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let f=!1;const y=()=>{console.debug("The script has finished. Syncing the filesystem."),f||(f=!0,n.FS.syncfs(!1,A=>{f=!1,A&&console.error(A)}))};(await n.runPython(`
|
|
90
|
+
def __setup_script_finished_callback__(callback):
|
|
91
|
+
from streamlit.runtime.app_session import AppSession
|
|
92
|
+
from streamlit.runtime.scriptrunner import ScriptRunnerEvent
|
|
93
|
+
|
|
94
|
+
def wrap_app_session_on_scriptrunner_event(original_method):
|
|
95
|
+
def wrapped(self, *args, **kwargs):
|
|
96
|
+
if "event" in kwargs:
|
|
97
|
+
event = kwargs["event"]
|
|
98
|
+
if event == ScriptRunnerEvent.SCRIPT_STOPPED_WITH_SUCCESS or event == ScriptRunnerEvent.SCRIPT_STOPPED_FOR_RERUN or event == ScriptRunnerEvent.SHUTDOWN:
|
|
99
|
+
callback()
|
|
100
|
+
return original_method(self, *args, **kwargs)
|
|
101
|
+
return wrapped
|
|
102
|
+
|
|
103
|
+
AppSession._on_scriptrunner_event = wrap_app_session_on_scriptrunner_event(AppSession._on_scriptrunner_event)
|
|
104
|
+
|
|
105
|
+
__setup_script_finished_callback__`))(y),console.debug("Set up the IndexedDB filesystem synchronizer")}console.debug("Setting up the Streamlit configuration");const{load_config_options:he}=n.pyimport("stlite_lib.bootstrap"),_e={"browser.gatherUsageStats":!1,...u,"runner.fastReruns":!1},ye=c!=null;he(n.toPy(_e),ye),console.debug("Set up the Streamlit configuration");let q;if(C){i("Loading auto-completion engine."),console.debug("Loading Jedi");try{q=await n.pyimport("jedi"),console.debug("Loaded Jedi")}catch(f){console.error("Failed to load Jedi:",f),q=void 0}}return{pyodide:n,micropip:v,jedi:q,initData:m}}async function W(o,c,m){const g=R(c,m);console.debug("Preparing the Streamlit environment");const{prepare:i}=o.pyimport("stlite_lib.bootstrap");i(g,[]),console.debug("Prepared the Streamlit environment"),console.debug("Booting up the Streamlit server");const t=o.pyimport("stlite_lib.server.Server")(g,c?U(c):void 0);return await t.start(),console.debug("Booted up the Streamlit server"),t}function x(o,c,m,g){function i(d){c({type:"event:loadProgress",data:{message:d}})}const e=(d,r)=>{const l=new MessageChannel;c({type:"event:moduleAutoLoad",data:{packagesToLoad:d}},[l.port2]),r.then(u=>{l.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:u}}),l.port1.close()}).catch(u=>{throw l.port1.postMessage({type:"moduleAutoLoad:error",error:u}),l.port1.close(),u})};let t=null,s=null;const a=async d=>{const r=d.data;if(r.type==="initData"){const n=r.data,p={...m,...n};console.debug("Initial data",p),t=de(o,g,p,e,i),t.then(({pyodide:h})=>(i("Booting up the Streamlit server."),s=W(h,g,p.entrypoint),s)).then(()=>{c({type:"event:loadFinished"})}).catch(h=>{console.error(h),c({type:"event:loadError",data:{error:h}})});return}if(!t)throw new Error("Pyodide initialization has not been started yet.");if(!s)throw new Error("Streamlit server has not been started yet.");const l=await t,u=l.pyodide,k=l.micropip,w=l.jedi,{moduleAutoLoad:_}=l.initData,P=await s,C=d.ports[0];function b(n){C.postMessage(n)}try{switch(r.type){case"reboot":{console.debug("Reboot the Streamlit server",r.data);const{entrypoint:n}=r.data;P.stop(),console.debug("Booting up the Streamlit server"),s=W(u,g,n),await s,console.debug("Booted up the Streamlit server"),b({type:"reply"});break}case"websocket:connect":{console.debug("websocket:connect",r.data);const{path:n}=r.data;P.start_websocket(n,(p,h)=>{if(h){const v=p;try{const F=v.toJs(),L=F.buffer.slice(F.byteOffset,F.byteOffset+F.byteLength);c({type:"websocket:message",data:{payload:L}},[L])}finally{v.destroy()}}else c({type:"websocket:message",data:{payload:p}})}),b({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",r.data);const{payload:n}=r.data;P.receive_websocket_from_js(n);break}case"http:request":{console.debug("http:request",r.data);const{request:n}=r.data,p=(h,v,F)=>{const L=new Map(v.toJs()),I=F.toJs();console.debug({statusCode:h,headers:L,body:I}),b({type:"http:response",data:{response:{statusCode:h,headers:L,body:I}}})};P.receive_http_from_js(n.method,decodeURIComponent(n.path),n.headers,n.body,p);break}case"file:write":{const{path:n,data:p,opts:h}=r.data,v=R(g,n);_&&typeof p=="string"&&v.endsWith(".py")&&(console.debug(`Auto install the requirements in ${v}`),J(u,e,[p])),console.debug(`Write a file "${v}"`),H(u,v,p,h),b({type:"reply"});break}case"file:rename":{const{oldPath:n,newPath:p}=r.data,h=R(g,n),v=R(g,p);console.debug(`Rename "${h}" to ${v}`),Y(u,h,v),b({type:"reply"});break}case"file:unlink":{const{path:n}=r.data,p=R(g,n);console.debug(`Remove "${p}`),u.FS.unlink(p),b({type:"reply"});break}case"file:read":{const{path:n,opts:p}=r.data;console.debug(`Read "${n}"`);const h=u.FS.readFile(n,p);b({type:"reply:file:read",data:{content:h}});break}case"install":{const{requirements:n,options:p}=r.data,h=T(n);console.debug("Install the requirements:",h),await k.install.callKwargs(h,p??{}).then(()=>{console.debug("Successfully installed"),b({type:"reply"})});break}case"setEnv":{const{env:n}=r.data;u.pyimport("os").environ.update(u.toPy(n)),console.debug("Successfully set the environment variables",n),b({type:"reply"});break}case"code_completion":{if(!w)throw new Error("Jedi is not installed");const{code:n,line:p,column:h}=r.data,v=await ce(w,n,{line:p,column:h});b({type:"reply:code_completion",data:{codeCompletions:v}});break}case"run_python":{const{code:n}=r.data;console.debug("Run python code",n);const p=await u.runPythonAsync(n);let h;p instanceof u.ffi.PyProxy?(console.debug("The result is a PyProxy object"),h=p.toJs(),p.destroy(),console.debug("Converted the result to a JS object",h)):(h=p,console.debug("The result is a JS primitive",h)),b({type:"reply:run_python",data:{result:h}});break}case"add_mock_package":{const{name:n,version:p,modules:h,persistent:v}=r.data;console.debug("Add a mock package:",{name:n,version:p,modules:h,persistent:v}),k.add_mock_package.callKwargs({name:n,version:p,modules:u.toPy(h),persistent:v}),b({type:"reply"});break}}}catch(n){if(console.error(n),!(n instanceof Error))throw n;const p=new Error(n.message);p.name=n.name,p.stack=n.stack,b({type:"reply",error:p})}};return c({type:"event:envSetup"}),a}const K="abcdefghijklmnopqrstuvwxyz",ue=K.length;function ge(o){let c="";for(let m=0;m<o;m++){const g=Math.floor(Math.random()*ue);c+=K[g]}return c}const G="https://cdn.jsdelivr.net/pyodide/v0.28.2/full/pyodide.mjs";if("postMessage"in self)self.onmessage=x(G,(o,c)=>c?self.postMessage(o,c):self.postMessage(o));else{const o=[];self.onconnect=c=>{let m;do m=ge(4);while(o.includes(m));o.push(m),console.debug("SharedWorker mode.",{appId:m});const g=c.ports[0];g.onmessage=x(G,(i,e)=>e?g.postMessage(i,e):g.postMessage(i),void 0,m),g.start()}}var j=Object.freeze({__proto__:null})})();
|
|
106
|
+
//# sourceMappingURL=worker-B65uO5d3.js.map
|
package/build/electron/worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var de=Object.create;var J=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var me=Object.getPrototypeOf,fe=Object.prototype.hasOwnProperty;var pe=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var he=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ge(e))!fe.call(r,n)&&n!==t&&J(r,n,{get:()=>e[n],enumerable:!(o=ue(e,n))||o.enumerable});return r};var I=(r,e,t)=>(t=r!=null?de(me(r)):{},he(e||!r||!r.__esModule?J(t,"default",{value:r,enumerable:!0}):t,r));var B=pe((Re,z)=>{"use strict";function w(r){if(typeof r!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(r))}function W(r,e){for(var t="",o=0,n=-1,i=0,a,l=0;l<=r.length;++l){if(l<r.length)a=r.charCodeAt(l);else{if(a===47)break;a=47}if(a===47){if(!(n===l-1||i===1))if(n!==l-1&&i===2){if(t.length<2||o!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){var u=t.lastIndexOf("/");if(u!==t.length-1){u===-1?(t="",o=0):(t=t.slice(0,u),o=t.length-1-t.lastIndexOf("/")),n=l,i=0;continue}}else if(t.length===2||t.length===1){t="",o=0,n=l,i=0;continue}}e&&(t.length>0?t+="/..":t="..",o=2)}else t.length>0?t+="/"+r.slice(n+1,l):t=r.slice(n+1,l),o=l-n-1;n=l,i=0}else a===46&&i!==-1?++i:i=-1}return t}function _e(r,e){var t=e.dir||e.root,o=e.base||(e.name||"")+(e.ext||"");return t?t===e.root?t+o:t+r+o:o}var L={resolve:function(){for(var e="",t=!1,o,n=arguments.length-1;n>=-1&&!t;n--){var i;n>=0?i=arguments[n]:(o===void 0&&(o=process.cwd()),i=o),w(i),i.length!==0&&(e=i+"/"+e,t=i.charCodeAt(0)===47)}return e=W(e,!t),t?e.length>0?"/"+e:"/":e.length>0?e:"."},normalize:function(e){if(w(e),e.length===0)return".";var t=e.charCodeAt(0)===47,o=e.charCodeAt(e.length-1)===47;return e=W(e,!t),e.length===0&&!t&&(e="."),e.length>0&&o&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return w(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 o=arguments[t];w(o),o.length>0&&(e===void 0?e=o:e+="/"+o)}return e===void 0?".":L.normalize(e)},relative:function(e,t){if(w(e),w(t),e===t||(e=L.resolve(e),t=L.resolve(t),e===t))return"";for(var o=1;o<e.length&&e.charCodeAt(o)===47;++o);for(var n=e.length,i=n-o,a=1;a<t.length&&t.charCodeAt(a)===47;++a);for(var l=t.length,u=l-a,h=i<u?i:u,c=-1,m=0;m<=h;++m){if(m===h){if(u>h){if(t.charCodeAt(a+m)===47)return t.slice(a+m+1);if(m===0)return t.slice(a+m)}else i>h&&(e.charCodeAt(o+m)===47?c=m:m===0&&(c=0));break}var _=e.charCodeAt(o+m),R=t.charCodeAt(a+m);if(_!==R)break;_===47&&(c=m)}var S="";for(m=o+c+1;m<=n;++m)(m===n||e.charCodeAt(m)===47)&&(S.length===0?S+="..":S+="/..");return S.length>0?S+t.slice(a+c):(a+=c,t.charCodeAt(a)===47&&++a,t.slice(a))},_makeLong:function(e){return e},dirname:function(e){if(w(e),e.length===0)return".";for(var t=e.charCodeAt(0),o=t===47,n=-1,i=!0,a=e.length-1;a>=1;--a)if(t=e.charCodeAt(a),t===47){if(!i){n=a;break}}else i=!1;return n===-1?o?"/":".":o&&n===1?"//":e.slice(0,n)},basename:function(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');w(e);var o=0,n=-1,i=!0,a;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var l=t.length-1,u=-1;for(a=e.length-1;a>=0;--a){var h=e.charCodeAt(a);if(h===47){if(!i){o=a+1;break}}else u===-1&&(i=!1,u=a+1),l>=0&&(h===t.charCodeAt(l)?--l===-1&&(n=a):(l=-1,n=u))}return o===n?n=u:n===-1&&(n=e.length),e.slice(o,n)}else{for(a=e.length-1;a>=0;--a)if(e.charCodeAt(a)===47){if(!i){o=a+1;break}}else n===-1&&(i=!1,n=a+1);return n===-1?"":e.slice(o,n)}},extname:function(e){w(e);for(var t=-1,o=0,n=-1,i=!0,a=0,l=e.length-1;l>=0;--l){var u=e.charCodeAt(l);if(u===47){if(!i){o=l+1;break}continue}n===-1&&(i=!1,n=l+1),u===46?t===-1?t=l:a!==1&&(a=1):t!==-1&&(a=-1)}return t===-1||n===-1||a===0||a===1&&t===n-1&&t===o+1?"":e.slice(t,n)},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){w(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(e.length===0)return t;var o=e.charCodeAt(0),n=o===47,i;n?(t.root="/",i=1):i=0;for(var a=-1,l=0,u=-1,h=!0,c=e.length-1,m=0;c>=i;--c){if(o=e.charCodeAt(c),o===47){if(!h){l=c+1;break}continue}u===-1&&(h=!1,u=c+1),o===46?a===-1?a=c:m!==1&&(m=1):a!==-1&&(m=-1)}return a===-1||u===-1||m===0||m===1&&a===u-1&&a===l+1?u!==-1&&(l===0&&n?t.base=t.name=e.slice(1,u):t.base=t.name=e.slice(l,u)):(l===0&&n?(t.name=e.slice(1,a),t.base=e.slice(1,u)):(t.name=e.slice(l,a),t.base=e.slice(l,u)),t.ext=e.slice(a,u)),l>0?t.dir=e.slice(0,l-1):n&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};L.posix=L;z.exports=L});var q=require("node:worker_threads");var C=I(B(),1),K="/home/pyodide",x=r=>`${K}/${r}`,E=(r,e)=>r==null?C.default.resolve(K,e):C.default.resolve(x(r),e);function X(r,e){let t=C.default.normalize(e),n=C.default.dirname(t).split(/(?=\/)/),i="";for(let a of n){i+=a;let l=r.FS.analyzePath(i);if(l.exists&&l.object){if(!r.FS.isDir(l.object.mode))throw new Error(`"${i}" already exists and is not a directory.`);continue}try{r.FS.mkdir(i)}catch(u){throw console.error(`Failed to create a directory "${i}"`),u}}}function U(r,e,t,o){X(r,e),r.FS.writeFile(e,t,o)}function G(r,e,t){X(r,t),r.FS.rename(e,t)}var ye="(<=>!~";var be=new RegExp(`[${"["+ye+";@"}]`);function ve(r){return r.split(be)[0].trim()}function M(r){return r.forEach(t=>{let o;try{o=new URL(t)}catch{return}if(o.protocol==="emfs:"||o.protocol==="file:")throw new Error(`"emfs:" and "file:" protocols are not allowed for the requirement (${t})`)}),r.filter(t=>ve(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 Se(r){let e=typeof process<"u"&&process.versions?.node,t;e?t=(await import("node:path")).sep:t="/";let o=r.slice(0,r.lastIndexOf(t)+1);if(r.endsWith(".mjs")){if(e){let n=await import("node:path"),i=await import("node:url");!r.includes("://")&&n.isAbsolute(r)&&(r=i.pathToFileURL(r).href)}return{scriptURL:r,pyodideIndexURL:o,isESModule:!0}}else return{scriptURL:r,pyodideIndexURL:o,isESModule:!1}}async function Q(r,e){let{scriptURL:t,pyodideIndexURL:o,isESModule:n}=await Se(r),i;return n?i=(await import(t)).loadPyodide:(importScripts(t),i=self.loadPyodide),i({...e,indexURL:o})}function V(r){r.runPython(`
|
|
2
2
|
import micropip
|
|
3
3
|
micropip.add_mock_package(
|
|
4
4
|
"pyarrow", "0.0.1",
|
|
@@ -24,17 +24,17 @@ class ChunkedArray:
|
|
|
24
24
|
"""
|
|
25
25
|
}
|
|
26
26
|
)
|
|
27
|
-
`)}function
|
|
27
|
+
`)}function we(r,e,t){let o=r.pyimport("pyodide"),n=c=>o.code.find_imports(c).toJs(),i=t.map(c=>n(c)),u=Array.from(new Set(i.flat())).filter(c=>!r.runPython(`__import__('importlib').util.find_spec('${c}')`)).map(c=>r._api._import_name_to_package_name.get(c)).filter(c=>c);if(u.length===0)return Promise.resolve();let h=r.loadPackage(u);return e(u,h),h.then()}function $(r,e,t){let o=we(r,e,t);r.runPython(`
|
|
28
28
|
def __set_module_auto_load_promise__(promise):
|
|
29
29
|
from streamlit.runtime.scriptrunner import script_runner
|
|
30
30
|
script_runner.moduleAutoLoadPromise = promise
|
|
31
31
|
|
|
32
|
-
__set_module_auto_load_promise__`)(o)}async function
|
|
32
|
+
__set_module_auto_load_promise__`)(o)}async function Y(r,e,t){let{line:o,column:n}=t,i=r.Script(e);if(o>i._code_lines.length)return[];let a=i.complete.callKwargs({line:o,column:n,fuzzy:!1}),l=[];for(let u of a.toJs())l.push({name:u.name,type:u.$type,docstring:u.docstring.callKwargs({raw:!0}),complete:u.complete}),u.destroy();return l}var j=null,Z=Promise.resolve(),H=!1;async function ke(r,e,t,o,n){let{files:i,archives:a,requirements:l,prebuiltPackageNames:u,wheels:h,installs:c,pyodideUrl:m=r,streamlitConfig:_,idbfsMountpoints:R,nodefsMountpoints:S,moduleAutoLoad:N,env:P,languageServer:O}=t,b=M(l);j?(n("Pyodide is already loaded."),console.debug("Pyodide is already loaded.")):(n("Loading Pyodide."),console.debug("Loading Pyodide."),j=Q(m,{stdout:console.log,stderr:console.error}),console.debug("Loaded Pyodide"));let s=await j;if(P){console.debug("Setting environment variables",P);let d=s.pyimport("os");d.environ.update(s.toPy(P)),console.debug("Set environment variables",d.environ)}let g=!1;R&&(g=!0,R.forEach(d=>{s.FS.mkdir(d),s.FS.mount(s.FS.filesystems.IDBFS,{},d)}),await new Promise((d,p)=>{s.FS.syncfs(!0,v=>{v?p(v):d()})})),S&&Object.entries(S).forEach(([d,p])=>{s.FS.mkdir(d),s.FS.mount(s.FS.filesystems.NODEFS,{root:p},d)}),n("Mounting files.");let f=[];await Promise.all(Object.keys(i).map(async d=>{let p=i[d];d=E(e,d);let v;"url"in p?(console.debug(`Fetch a file from ${p.url}`),v=await fetch(p.url).then(k=>k.arrayBuffer()).then(k=>new Uint8Array(k))):v=p.data,console.debug(`Write a file "${d}"`),U(s,d,v,i.opts),d.endsWith(".py")&&f.push(d)})),n("Unpacking archives."),await Promise.all(a.map(async d=>{let p;"url"in d?(console.debug(`Fetch an archive from ${d.url}`),p=await fetch(d.url).then(ce=>ce.arrayBuffer())):p=d.buffer;let{format:v,options:k}=d;console.debug("Unpack an archive",{format:v,options:k}),s.unpackArchive(p,v,k)})),await s.loadPackage("micropip");let y=s.pyimport("micropip");n("Mocking some packages."),console.debug("Mock pyarrow"),V(s),console.debug("Mocked pyarrow"),n("Installing packages."),console.debug("Installing the prebuilt packages:",u),await s.loadPackage(u),console.debug("Installed the prebuilt packages");let A=async()=>{console.debug("Installing the packages:",{requirements:b,systemPackagesInstalled:H});let d=[];H||(console.debug("System packages will be installed"),h&&(d.push(h.streamlit),d.push(h.stliteLib)),O&&d.push("jedi"));let p=[...d,...b];console.debug("Installing the packages:",p),await y.install.callKwargs(p,{keep_going:!0}),d.length>0&&(console.debug("Installed the system packages"),H=!0),console.debug("Installed the packages")},F=Z.then(()=>A());if(Z=F.catch(d=>{console.error("Package installation failed:",d)}),await F,c&&(console.debug("Installing the additional requirements"),await Promise.all(c.map(({requirements:d,options:p})=>{let v=M(d);return console.debug("Installing the requirements:",v),y.install.callKwargs(v,p??{})}))),N){let d=f.map(p=>s.FS.readFile(p,{encoding:"utf8"}));$(s,o,d)}await s.runPythonAsync(`
|
|
33
33
|
import importlib
|
|
34
34
|
importlib.invalidate_caches()
|
|
35
|
-
`),n("Loading streamlit package."),console.debug("Loading the Streamlit package"),await
|
|
35
|
+
`),n("Loading streamlit package."),console.debug("Loading the Streamlit package"),await s.runPythonAsync(`
|
|
36
36
|
import streamlit.runtime
|
|
37
|
-
`),console.debug("Loaded the Streamlit package"),n("Setting up the loggers."),console.debug("Setting the loggers"),await
|
|
37
|
+
`),console.debug("Loaded the Streamlit package"),n("Setting up the loggers."),console.debug("Setting the loggers"),await s.runPythonAsync(`
|
|
38
38
|
import logging
|
|
39
39
|
import streamlit.logger
|
|
40
40
|
|
|
@@ -52,7 +52,7 @@ for name in streamlit.logger._loggers.keys():
|
|
|
52
52
|
logger.setLevel(logging.NOTSET)
|
|
53
53
|
|
|
54
54
|
streamlit.logger._loggers = {}
|
|
55
|
-
`);let
|
|
55
|
+
`);let T=(d,p)=>{d>=40?console.error(p):d>=30?console.warn(p):d>=20?console.info(p):console.debug(p)},oe=s.runPython(`
|
|
56
56
|
def __setup_loggers__(streamlit_level, streamlit_message_format, callback):
|
|
57
57
|
class JsHandler(logging.Handler):
|
|
58
58
|
def emit(self, record):
|
|
@@ -79,14 +79,14 @@ def __setup_loggers__(streamlit_level, streamlit_message_format, callback):
|
|
|
79
79
|
streamlit_logger.addHandler(streamlit_handler)
|
|
80
80
|
streamlit_logger.setLevel(streamlit_level.upper())
|
|
81
81
|
|
|
82
|
-
__setup_loggers__`),
|
|
82
|
+
__setup_loggers__`),ne=(_?.["logger.level"]??"INFO").toString(),se=_?.["logger.messageFormat"]??"%(asctime)s %(message)s";if(oe(ne,se,T),console.debug("Set the loggers"),n("Mocking some Streamlit functions for the browser environment."),console.debug("Mocking some Streamlit functions"),await s.runPythonAsync(`
|
|
83
83
|
import streamlit
|
|
84
84
|
|
|
85
85
|
def is_cacheable_msg(msg):
|
|
86
86
|
return False
|
|
87
87
|
|
|
88
88
|
streamlit.runtime.runtime.is_cacheable_msg = is_cacheable_msg
|
|
89
|
-
`),console.debug("Mocked some Streamlit functions"),g){n("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let
|
|
89
|
+
`),console.debug("Mocked some Streamlit functions"),g){n("Setting up the IndexedDB filesystem synchronizer."),console.debug("Setting up the IndexedDB filesystem synchronizer");let d=!1,p=()=>{console.debug("The script has finished. Syncing the filesystem."),d||(d=!0,s.FS.syncfs(!1,k=>{d=!1,k&&console.error(k)}))};(await s.runPython(`
|
|
90
90
|
def __setup_script_finished_callback__(callback):
|
|
91
91
|
from streamlit.runtime.app_session import AppSession
|
|
92
92
|
from streamlit.runtime.scriptrunner import ScriptRunnerEvent
|
|
@@ -102,4 +102,4 @@ def __setup_script_finished_callback__(callback):
|
|
|
102
102
|
|
|
103
103
|
AppSession._on_scriptrunner_event = wrap_app_session_on_scriptrunner_event(AppSession._on_scriptrunner_event)
|
|
104
104
|
|
|
105
|
-
__setup_script_finished_callback__`))(
|
|
105
|
+
__setup_script_finished_callback__`))(p),console.debug("Set up the IndexedDB filesystem synchronizer")}console.debug("Setting up the Streamlit configuration");let{load_config_options:ae}=s.pyimport("stlite_lib.bootstrap"),ie={"browser.gatherUsageStats":!1,..._,"runner.fastReruns":!1},le=e!=null;ae(s.toPy(ie),le),console.debug("Set up the Streamlit configuration");let D;if(O){n("Loading auto-completion engine."),console.debug("Loading Jedi");try{D=await s.pyimport("jedi"),console.debug("Loaded Jedi")}catch(d){console.error("Failed to load Jedi:",d),D=void 0}}return{pyodide:s,micropip:y,jedi:D,initData:t}}async function ee(r,e,t){let o=E(e,t);console.debug("Preparing the Streamlit environment");let{prepare:n}=r.pyimport("stlite_lib.bootstrap");n(o,[]),console.debug("Prepared the Streamlit environment"),console.debug("Booting up the Streamlit server");let a=r.pyimport("stlite_lib.server.Server")(o,e?x(e):void 0);return await a.start(),console.debug("Booted up the Streamlit server"),a}function te(r,e,t,o){function n(h){e({type:"event:loadProgress",data:{message:h}})}let i=(h,c)=>{let m=new MessageChannel;e({type:"event:moduleAutoLoad",data:{packagesToLoad:h}},[m.port2]),c.then(_=>{m.port1.postMessage({type:"moduleAutoLoad:success",data:{loadedPackages:_}}),m.port1.close()}).catch(_=>{throw m.port1.postMessage({type:"moduleAutoLoad:error",error:_}),m.port1.close(),_})},a=null,l=null,u=async h=>{let c=h.data;if(c.type==="initData"){let s=c.data,g={...t,...s};console.debug("Initial data",g),a=ke(r,o,g,i,n),a.then(({pyodide:f})=>(n("Booting up the Streamlit server."),l=ee(f,o,g.entrypoint),l)).then(()=>{e({type:"event:loadFinished"})}).catch(f=>{console.error(f),e({type:"event:loadError",data:{error:f}})});return}if(!a)throw new Error("Pyodide initialization has not been started yet.");if(!l)throw new Error("Streamlit server has not been started yet.");let m=await a,_=m.pyodide,R=m.micropip,S=m.jedi,{moduleAutoLoad:N}=m.initData,P=await l,O=h.ports[0];function b(s){O.postMessage(s)}try{switch(c.type){case"reboot":{console.debug("Reboot the Streamlit server",c.data);let{entrypoint:s}=c.data;P.stop(),console.debug("Booting up the Streamlit server"),l=ee(_,o,s),await l,console.debug("Booted up the Streamlit server"),b({type:"reply"});break}case"websocket:connect":{console.debug("websocket:connect",c.data);let{path:s}=c.data;P.start_websocket(s,(g,f)=>{if(f){let y=g;try{let A=y.toJs(),F=A.buffer.slice(A.byteOffset,A.byteOffset+A.byteLength);e({type:"websocket:message",data:{payload:F}},[F])}finally{y.destroy()}}else e({type:"websocket:message",data:{payload:g}})}),b({type:"reply"});break}case"websocket:send":{console.debug("websocket:send",c.data);let{payload:s}=c.data;P.receive_websocket_from_js(s);break}case"http:request":{console.debug("http:request",c.data);let{request:s}=c.data,g=(f,y,A)=>{let F=new Map(y.toJs()),T=A.toJs();console.debug({statusCode:f,headers:F,body:T}),b({type:"http:response",data:{response:{statusCode:f,headers:F,body:T}}})};P.receive_http_from_js(s.method,decodeURIComponent(s.path),s.headers,s.body,g);break}case"file:write":{let{path:s,data:g,opts:f}=c.data,y=E(o,s);N&&typeof g=="string"&&y.endsWith(".py")&&(console.debug(`Auto install the requirements in ${y}`),$(_,i,[g])),console.debug(`Write a file "${y}"`),U(_,y,g,f),b({type:"reply"});break}case"file:rename":{let{oldPath:s,newPath:g}=c.data,f=E(o,s),y=E(o,g);console.debug(`Rename "${f}" to ${y}`),G(_,f,y),b({type:"reply"});break}case"file:unlink":{let{path:s}=c.data,g=E(o,s);console.debug(`Remove "${g}`),_.FS.unlink(g),b({type:"reply"});break}case"file:read":{let{path:s,opts:g}=c.data;console.debug(`Read "${s}"`);let f=_.FS.readFile(s,g);b({type:"reply:file:read",data:{content:f}});break}case"install":{let{requirements:s,options:g}=c.data,f=M(s);console.debug("Install the requirements:",f),await R.install.callKwargs(f,g??{}).then(()=>{console.debug("Successfully installed"),b({type:"reply"})});break}case"setEnv":{let{env:s}=c.data;_.pyimport("os").environ.update(_.toPy(s)),console.debug("Successfully set the environment variables",s),b({type:"reply"});break}case"code_completion":{if(!S)throw new Error("Jedi is not installed");let{code:s,line:g,column:f}=c.data,y=await Y(S,s,{line:g,column:f});b({type:"reply:code_completion",data:{codeCompletions:y}});break}case"run_python":{let{code:s}=c.data;console.debug("Run python code",s);let g=await _.runPythonAsync(s),f;g instanceof _.ffi.PyProxy?(console.debug("The result is a PyProxy object"),f=g.toJs(),g.destroy(),console.debug("Converted the result to a JS object",f)):(f=g,console.debug("The result is a JS primitive",f)),b({type:"reply:run_python",data:{result:f}});break}case"add_mock_package":{let{name:s,version:g,modules:f,persistent:y}=c.data;console.debug("Add a mock package:",{name:s,version:g,modules:f,persistent:y}),R.add_mock_package.callKwargs({name:s,version:g,modules:_.toPy(f),persistent:y}),b({type:"reply"});break}}}catch(s){if(console.error(s),!(s instanceof Error))throw s;let g=new Error(s.message);g.name=s.name,g.stack=s.stack,b({type:"reply",error:g})}};return e({type:"event:envSetup"}),u}function re(){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 Pe=r=>{console.debug("[worker thread] postMessage from worker",r),q.parentPort?.postMessage(r)},Ae=te(process.env.PYODIDE_URL,Pe,{nodefsMountpoints:re()});q.parentPort?.on("message",({data:r,port:e})=>{console.debug("[worker thread] parentPort.onMessage",{data:r,port:e}),Ae({data:r,ports:[e]})});
|
package/build/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
7
|
<title>Stlite Desktop</title>
|
|
8
8
|
<!-- The Content-Security-Policy setting will be injected at build time. See vite.config.js. -->
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-BxpEVUJq.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-Bjs8n_uU.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stlite/desktop",
|
|
3
|
-
"version": "0.91.
|
|
3
|
+
"version": "0.91.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -63,11 +63,11 @@
|
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@emotion/babel-plugin": "^11.13.5",
|
|
66
|
-
"@eslint/js": "^9.
|
|
66
|
+
"@eslint/js": "^9.39.1",
|
|
67
67
|
"@stlite/common": "^0.90.1",
|
|
68
68
|
"@stlite/devutils": "^0.90.0",
|
|
69
|
-
"@stlite/kernel": "^0.
|
|
70
|
-
"@stlite/react": "^0.1.
|
|
69
|
+
"@stlite/kernel": "^0.97.1",
|
|
70
|
+
"@stlite/react": "^0.1.1",
|
|
71
71
|
"@types/react": "^18.2.0",
|
|
72
72
|
"@types/react-dom": "^18.2.0",
|
|
73
73
|
"@types/yargs": "^17.0.35",
|
|
@@ -76,26 +76,27 @@
|
|
|
76
76
|
"cross-env": "^10.1.0",
|
|
77
77
|
"electron": "34.3.0",
|
|
78
78
|
"electron-reload": "^2.0.0-alpha.1",
|
|
79
|
-
"esbuild": "^0.27.
|
|
80
|
-
"eslint": "^9.
|
|
81
|
-
"eslint-
|
|
79
|
+
"esbuild": "^0.27.1",
|
|
80
|
+
"eslint": "^9.39.1",
|
|
81
|
+
"eslint-config-prettier": "^10.1.8",
|
|
82
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
82
83
|
"eslint-plugin-react": "^7.37.5",
|
|
83
84
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
84
|
-
"glob": "^
|
|
85
|
+
"glob": "^13.0.0",
|
|
85
86
|
"node-html-parser": "^7.0.1",
|
|
86
87
|
"prettier": "^3.6.2",
|
|
87
88
|
"react": "^18.2.0",
|
|
88
89
|
"react-dom": "^18.2.0",
|
|
89
|
-
"rimraf": "^6.
|
|
90
|
+
"rimraf": "^6.1.2",
|
|
90
91
|
"rollup-plugin-visualizer": "^5.12.0",
|
|
91
92
|
"sass": "^1.90.0",
|
|
92
93
|
"superstruct": "^2.0.2",
|
|
93
94
|
"ts-node": "^10.9.1",
|
|
94
95
|
"tsx": "^4.19.2",
|
|
95
96
|
"typescript": "^5.9.2",
|
|
96
|
-
"typescript-eslint": "^8.
|
|
97
|
+
"typescript-eslint": "^8.46.2",
|
|
97
98
|
"vite": "^7.1.5",
|
|
98
|
-
"vitest": "^4.0.
|
|
99
|
+
"vitest": "^4.0.15",
|
|
99
100
|
"wait-on": "^8.0.1",
|
|
100
101
|
"winston": "^3.13.0"
|
|
101
102
|
},
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r,b as J}from"./index-BUGX2TMK.js";import{V as R,E as Q,m as U,G as Z,c as ee,k as te,a as re}from"./index-Cwu3avS4-DiDBV46w.js";import"./withFullScreenWrapper-BKnfDWJg-dLKoL1-0.js";import"./Toolbar-C79vGzHM-4gREjS-R.js";import"./FormClearHelper-Bi1RDDCw-CUfvtGEu.js";import"./sprintf-D5E86llw-6tzWM3a-.js";import"./checkbox-DSLjv1hz-C5dTTEJn.js";import"./createDownloadLinkElement-CbRjLJ8e-NbV49OP9.js";import"./slicedToArray-bXF_q2D_-C8JYb8qs.js";import"./inherits-V2B09WF6-BfQai87E.js";import"./createSuper-B3kpwht8-vR1ZxlfE.js";import"./FileDownload.esm-rDRR6AEq-DjpuiBZc.js";const ie=()=>t=>t.targetX,ae=()=>t=>t.targetY,oe=()=>t=>t.targetWidth,ne=()=>t=>t.targetHeight,se=()=>t=>t.targetY+10,le=()=>t=>Math.max(0,(t.targetHeight-28)/2),de=re("div")({name:"DataGridOverlayEditorStyle",class:"gdg-d19meir1",propsAsIs:!1,vars:{"d19meir1-0":[ae(),"px"],"d19meir1-1":[ie(),"px"],"d19meir1-2":[oe(),"px"],"d19meir1-3":[ne(),"px"],"d19meir1-4":[se(),"px"],"d19meir1-5":[le(),"px"]}});function ce(){const[t,o]=r.useState();return[t??void 0,o]}function ue(){const[t,o]=ce(),[a,f]=r.useState(0),[m,b]=r.useState(!0);r.useLayoutEffect(()=>{if(t===void 0||!("IntersectionObserver"in window))return;const n=new IntersectionObserver(s=>{s.length!==0&&b(s[0].isIntersecting)},{threshold:1});return n.observe(t),()=>n.disconnect()},[t]),r.useEffect(()=>{if(m||t===void 0)return;let n;const s=()=>{const{right:k}=t.getBoundingClientRect();f(g=>Math.min(g+window.innerWidth-k-10,0)),n=requestAnimationFrame(s)};return n=requestAnimationFrame(s),()=>{n!==void 0&&cancelAnimationFrame(n)}},[t,m]);const C=r.useMemo(()=>({transform:`translateX(${a}px)`}),[a]);return{ref:o,style:C}}const we=t=>{const{target:o,content:a,onFinishEditing:f,forceEditMode:m,initialValue:b,imageEditorOverride:C,markdownDivCreateNode:n,highlight:s,className:k,theme:g,id:K,cell:p,bloom:S,portalElementRef:P,validateCell:v,getCellRenderer:M,provideEditor:N,isOutsideClick:W,customEventTarget:X,activation:x}=t,[l,Y]=r.useState(m?a:void 0),w=r.useRef(l??a);w.current=l??a;const[h,F]=r.useState(()=>v===void 0?!0:!(R(a)&&v?.(p,a,w.current)===!1)),c=r.useCallback((e,i)=>{f(h?e:void 0,i)},[h,f]),q=r.useCallback(e=>{if(v!==void 0&&e!==void 0&&R(e)){const i=v(p,e,w.current);i===!1?F(!1):(typeof i=="object"&&(e=i),F(!0))}Y(e)},[p,v]),E=r.useRef(!1),u=r.useRef(void 0),B=r.useCallback(()=>{c(l,[0,0]),E.current=!0},[l,c]),j=r.useCallback((e,i)=>{c(e,i??u.current??[0,0]),E.current=!0},[c]),L=r.useCallback(async e=>{let i=!1;e.key==="Escape"?(e.stopPropagation(),e.preventDefault(),u.current=[0,0]):e.key==="Enter"&&!e.shiftKey?(e.stopPropagation(),e.preventDefault(),u.current=[0,1],i=!0):e.key==="Tab"&&(e.stopPropagation(),e.preventDefault(),u.current=[e.shiftKey?-1:1,0],i=!0),window.setTimeout(()=>{!E.current&&u.current!==void 0&&(c(i?l:void 0,u.current),E.current=!0)},0)},[c,l]),O=l??a,[d,$]=r.useMemo(()=>{if(Q(a))return[];const e={...a,location:p,activation:x},i=N?.(e);return i!==void 0?[i,!1]:[M(a)?.provideEditor?.(e),!1]},[p,a,M,N,x]),{ref:z,style:_}=ue();let I=!0,V,A=!0,y;if(d!==void 0){I=d.disablePadding!==!0,A=d.disableStyling!==!0;const e=U(d);e&&(y=d.styleOverride);const i=e?d.editor:d;V=r.createElement(i,{portalElementRef:P,isHighlighted:s,activation:x,onChange:q,value:O,initialValue:b,onFinishedEditing:j,validatedSelection:R(O)?O.selectionRange:void 0,forceEditMode:m,target:o,imageEditorOverride:C,markdownDivCreateNode:n,isValid:h,theme:g})}y={...y,..._};const G=P?.current??document.getElementById("portal");if(G===null)return console.error('Cannot open Data Grid overlay editor, because portal not found. Please, either provide a portalElementRef or add `<div id="portal" />` as the last child of your `<body>`.'),null;let D=A?"gdg-style":"gdg-unstyle";h||(D+=" gdg-invalid"),I&&(D+=" gdg-pad");const H=S?.[0]??1,T=S?.[1]??1;return J.createPortal(r.createElement(Z.Provider,{value:g},r.createElement(ee,{style:te(g),className:k,onClickOutside:B,isOutsideClick:W,customEventTarget:X},r.createElement(de,{ref:z,id:K,className:D,style:y,as:$===!0?"label":void 0,targetX:o.x-H,targetY:o.y-T,targetWidth:o.width+H*2,targetHeight:o.height+T*2},r.createElement("div",{className:"gdg-clip-region",onKeyDown:L},V)))),G)};export{we as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as u,L as A,ai as h,a_ as C,j as d,ak as E,aQ as R,al as T,am as B}from"./index-BUGX2TMK.js";import{a as v}from"./createDownloadLinkElement-CbRjLJ8e-NbV49OP9.js";const L=/%([0-9A-Fa-f]{2})/g,$=/[^\x20-\x7e\xa0-\xff]/g,z=/\\([\u0000-\u007f])/g,w=/;[\x09\x20]*([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*=[\x09\x20]*("(?:[\x20!\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*/g,k=/^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/,I=/^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/,U=r=>String(r).replace($,"?");class j{constructor(e,t){this.type=e,this.parameters=t}}const D=(r,e)=>String.fromCharCode(Number.parseInt(e,16));function Z(r){const e=k.exec(r);if(!e)throw new TypeError("invalid extended field value");const t=e[1].toLowerCase(),a=e[2];let n;switch(t){case"iso-8859-1":n=U(a.replace(L,D));break;case"utf-8":try{n=decodeURIComponent(a)}catch{throw new TypeError("invalid encoded utf-8")}break;default:throw new TypeError("unsupported charset in extended field")}return n}function S(r){let e=I.exec(r);if(!e)throw new TypeError("invalid type format");let t=e[0].length;const a=e[1].toLowerCase();let n;const l=[],i={};let o;for(t=w.lastIndex=e[0].slice(-1)===";"?t-1:t;e=w.exec(r);){if(e.index!==t)throw new TypeError("invalid parameter format");if(t+=e[0].length,n=e[1].toLowerCase(),o=e[2],l.indexOf(n)!==-1)throw new TypeError("invalid duplicate parameter");if(l.push(n),n.indexOf("*")+1===n.length){n=n.slice(0,-1),o=Z(o),i[n]=o;continue}typeof i[n]!="string"&&(o[0]==='"'&&(o=o.slice(1,o.length-1).replace(z,"$1")),i[n]=o)}if(t!==-1&&t!==r.length)throw new TypeError("invalid parameter format");return new j(a,i)}function _(r){const e=S(r);if(e.type!=="attachment")return;const t=e.parameters.filename;if(typeof t=="string")return t}function N(r,e){r.sendHttpRequest({method:"GET",path:`${e}?title=${encodeURIComponent(document.title)}`,headers:{},body:""}).then(({statusCode:t,headers:a,body:n})=>{if(t!==200)return;const l=a.get("Content-Disposition"),i=(l&&_(l))??"",o=a.get("Content-Type"),f=new Blob([n],o?{type:o}:void 0),c=URL.createObjectURL(f),s=document.createElement("a");s.setAttribute("href",c),s.setAttribute("target","_blank"),s.setAttribute("download",i),s.click(),URL.revokeObjectURL(c),s.remove()})}function O(r){const{disabled:e,element:t,widgetMgr:a,endpoints:n,fragmentId:l}=r,{help:i,label:o,icon:f,ignoreRerun:c,type:s,url:m}=t,{libConfig:{enforceDownloadInNewTab:g=!1}}=u.useContext(A);let p=h.SECONDARY;s==="primary"?p=h.PRIMARY:s==="tertiary"&&(p=h.TERTIARY);const x=u.useMemo(()=>n.buildDownloadUrl(m),[n,m]);u.useEffect(()=>{n.checkSourceUrlResponse(x,"Download Button")},[x,n]);const b=C(),y=()=>{if(c||a.setTriggerValue(t,{fromUi:!0},l),t.url.startsWith("/media")){N(b,t.url);return}v({filename:"",url:x,enforceDownloadInNewTab:g}).click()};return d.jsx("div",{className:"stDownloadButton","data-testid":"stDownloadButton",children:d.jsx(E,{help:i,containerWidth:!0,children:d.jsx(R,{kind:p,size:T.SMALL,disabled:e,onClick:y,containerWidth:!0,children:d.jsx(B,{icon:f,label:o})})})})}const K=u.memo(O);export{K as default};
|