From 484f86abca764a264636d478bf1689c448594654 Mon Sep 17 00:00:00 2001 From: dmitry-vsl Date: Wed, 24 Sep 2025 00:44:06 +0000 Subject: [PATCH] deploy: leporello-js/app@485bad078fac2bd307df437557fe4d9b19d6852d --- docs/examples/todos-preact/index.js | 2 +- src/launch.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/examples/todos-preact/index.js b/docs/examples/todos-preact/index.js index 53eb3ca..64ee27b 100644 --- a/docs/examples/todos-preact/index.js +++ b/docs/examples/todos-preact/index.js @@ -2,7 +2,7 @@ Example of a TODO app built using the Preact library */ -import React from "preact/compat" +import * as React from "preact/compat" // Core diff --git a/src/launch.js b/src/launch.js index 8c728b5..af28c86 100644 --- a/src/launch.js +++ b/src/launch.js @@ -51476,7 +51476,7 @@ Path: `+gv(this.current_file);if(confirm(P))if(this.current_file.startsWith("loc (__await_state = __rt.await_start(__cxt, ${Oe.expression}), await __await_state.promise, __rt.await_finish(__cxt, __await_state)) - `),Oe}),cW(function ae(Ee){return Ee.kind==$e.SyntaxKind.DebuggerStatement?null:$e.visitEachChild(Ee,ae)})]).transformed[0]},j3e=(x,P,Q,ae,Ee,Oe,dt,Mt,Ut,Wt,gr)=>{let ti=globalThis.app_window.Function,qr=globalThis.app_window.eval("(async function(){})").constructor,Lr=x.sorted.map(gs=>{let Za=x.modules[gs],md={module:gs,toplevel:Za,breakpoint:Wt,current_function:Za,should_collect_footprints:Ut};Za=mvt(Za,md);let Gd=Gm`"use strict";let __obj, __fn, __tmp;`;Za=$e.factory.updateSourceFile(Za,[...Gd,...Cte(Za,md),...Za.statements]);let by=$e.transformNodes(x.program.getTypeChecker().getEmitResolver(),void 0,$e.factory,DC,[Za],[$e.transformJsx],!1).transformed;if(by.length!=1)throw new Error("illegal state");Za=by[0];let kC=pvt.printFile(Za),Ol=vG(Za)?qr:ti,ki;try{ki=new Ol("__cxt","__rt",kC)}catch(nu){throw new Error(nu.message,{cause:nu})}return{module:gs,fn:ki}}),oa={logs:[],deferred_calls:[],modules:P==null?{}:Z4e(P,(gs,{module:Za})=>Za),call_counter:0,version_counter:0,children:null,stack:new Array,is_recording_deferred_calls:!1,on_deferred_call:(gs,Za,md)=>Q(O3e(x.modules,gs),Za,md),execution_id:ae,is_toplevel_call:!0,window:globalThis.app_window,storage:dt,canvas_ops:{ops:[],contexts:new Set},snapshots:Mt,footprints:new Map,breakpoint:Wt,selected_call_id:Wt.selected_call_id,io_trace:Ee,io_trace_is_recording:Oe},Zo=w3e(Lr,oa);Zo?.[Symbol.toStringTag]=="Promise"&&(Zo=new Promise((gs,Za)=>{Promise.prototype.then.call(Zo,gs,Za)})),gr||(Zo=Promise.resolve(Zo));let fs=gs=>{let Za=O3e(x.modules,dte(gs.calltree,oa.deferred_calls.length==0?null:oa.deferred_calls));return{...gs,breakpoint:Wt,calltree:Za}};return Zo?.[Symbol.toStringTag]=="Promise"?Promise.all([Zo,new Promise(gs=>setTimeout(gs,0))]).then(([gs])=>fs(gs)):fs(Zo)},_vt=(x,P)=>{let Q=$e.forEachChildRecursively(x,ae=>{if(ae.index==P.index&&ae.length==P.length&&(lp(ae)||Jp(ae)))return ae});if(Q==null)throw new Error("illegal state");return Q},O3e=(x,P)=>{let Q=new Map;function ae(Ee){if(Ee.toplevel)return{...Ee,code:x[Ee.module],children:Ee.children&&Ee.children.map(ae)};{let Oe;if(Ee.fn==null||Ee.fn.__location==null)Oe=null;else if(Oe=Q.get(Ee.fn.__location),Oe==null){let dt=JSON.parse(Ee.fn.__location);Oe=_vt(x[dt.module],dt),Q.set(Ee.fn.__location,Oe)}return{...Ee,code:Oe,children:Ee.children&&Ee.children.map(ae)}}}return ae(P)},tEe=(x,P,Q)=>x.kind==$e.SyntaxKind.AwaitExpression&&!Q&&!P.toplevel&&P.value.status==null,Qbe=class extends Map{get(P){return P=CC(P)?P.original:P,super.get(P)}},nEe=(x,P,Q,ae,Ee)=>{Ee??=new Qbe;let Oe=hvt(x,P,Q,ae,Ee);return Ee.set(x,Oe.result),Ee},hvt=(x,P,Q,ae,Ee)=>{let Oe=qr=>nEe(qr,P,Q,x,Ee),dt=qr=>Q.get(qr.index+"_"+qr.length),Mt=dt(x);if(x.kind==$e.SyntaxKind.VariableDeclarationList&&x.parent.kind==$e.SyntaxKind.VariableStatement&&(Mt=dt(x.parent)),ae?.kind==$e.SyntaxKind.PropertyAccessExpression&&ae.name==x&&(Ee.get(ae.expression)?.ok?Mt=!0:Mt=void 0),(ae?.kind==$e.SyntaxKind.PropertyAssignment||ae?.kind==$e.SyntaxKind.ShorthandPropertyAssignment)&&ae.name==x&&dt(ae.parent)!=null&&(Mt=!0),tEe(x,P,Mt)&&(Mt=void 0),lp(x)){if(ae!=null)return{result:Mt==null?void 0:{ok:Mt}};{let[qr,Lr]=Kb(x);return dt(qr)?(Ee.set(qr.original,{ok:!0}),Oe(Lr)):Ee.set(qr.original,{ok:!1,is_error_origin:!0}),{result:{ok:Ee.get(Lr)?.ok}}}}if(Jp(x)&&ae!=null)return(x.kind==$e.SyntaxKind.ForOfStatement||x.kind==$e.SyntaxKind.ForInStatement)&&Oe(x.expression),x.kind==$e.SyntaxKind.ForStatement&&Oe(x.initializer),Mt==null?{result:void 0}:{result:{ok:Mt,is_error_origin:!Mt}};if(G3e(x)&&!(x.kind==$e.SyntaxKind.Block||x.kind==$e.SyntaxKind.SourceFile)&&ae!=null&&Mt==null)return{result:void 0};if(ae!=null&&bG(x,ae))if(x.kind==$e.SyntaxKind.PropertyAccessExpression||x.kind==$e.SyntaxKind.ElementAccessExpression){let qr=Kb(x);return qr.map(oa=>Oe(oa)),{result:{ok:qr.every(oa=>Ee.get(oa)?.ok)}}}else Mt=!0;if(x.kind==$e.SyntaxKind.VariableDeclaration){let[qr,Lr]=[x.name,x.initializer];return Lr!=null&&Oe(Lr),(Lr==null||Ee.get(Lr)?.ok)&&Oe(qr),{result:{ok:Mt,is_error_origin:Mt?void 0:Ee.get(Lr)?.ok}}}let Ut=Kb(x);Ut&&Ut.map(qr=>Oe(qr));let Wt=Ut==null||Ut.every(qr=>Ee.get(qr)?.ok),gr=!Mt&&Wt;if((x.kind==$e.SyntaxKind.Block||x.kind==$e.SyntaxKind.SourceFile)&&(Ut.length!=0&&(Mt=Ut.reduce((qr,Lr)=>qr&&Ee.get(Lr)?.ok,!0)),gr=!1),x.kind==$e.SyntaxKind.PartiallyEmittedExpression||x.kind==$e.SyntaxKind.ExpressionStatement||x.kind==$e.SyntaxKind.ParenthesizedExpression||x.kind==$e.SyntaxKind.JsxExpression){if(Ut.length!=1)throw new Error("illegal state");let qr=Ee.get(x.expression);return{result:qr==null?null:{...qr,is_error_origin:!1}}}if(x.kind==$e.SyntaxKind.IfStatement&&(Mt=dt(x.expression),Ut.some(qr=>Ee.get(qr)?.ok===!1)&&(Mt=!1)),Jp(x)&&ae==null){if(x.kind==$e.SyntaxKind.ForOfStatement||x.kind==$e.SyntaxKind.ForInStatement){let qr=x.statement;Oe(qr);let Lr=Ee.get(qr)!=null;Ee.set(x.initializer,{ok:Lr,is_error_origin:!Lr})}return{result:void 0}}return[$e.SyntaxKind.ReturnStatement,$e.SyntaxKind.BreakStatement,$e.SyntaxKind.ContinueStatement].includes(x.kind)&&(Mt!=null&&(Mt=Wt),gr=!1),x.kind==$e.SyntaxKind.PropertyAssignment||x.kind==$e.SyntaxKind.ShorthandPropertyAssignment||x.kind==$e.SyntaxKind.SpreadElement||x.kind==$e.SyntaxKind.SpreadAssignment||x.kind==$e.SyntaxKind.JsxSpreadAttribute?{result:{ok:Wt}}:{result:Mt===void 0?void 0:{ok:Mt,is_error_origin:Mt?void 0:gr}}};function U3e(x){return new Map([...x.entries()].map(([P,Q])=>[P,structuredClone(Q)]))}var EG=class extends Map{set(P,Q){if(structuredClone(Q),typeof P!="string")throw new Error("key must be a string");super.set(P,Q)}};var dW=class extends Map{get_by_module_and_node(P,Q){if(Q.index==null||Q.length==null)throw new Error("illegal state");return this.get(`${P}_${Q.index}_${Q.length}`)}set_by_module_and_node(P,Q,ae){if(Q.index==null||Q.length==null)throw new Error("illegal state");return this.set(`${P}_${Q.index}_${Q.length}`,ae)}};var H3e=x=>x.kind==$e.SyntaxKind.ExpressionStatement?x.expression:x.kind==$e.SyntaxKind.NotEmittedStatement||x.kind==$e.SyntaxKind.EmptyStatement?null:x.kind==$e.SyntaxKind.ReturnStatement?x.expression==null?x:x.expression:x.kind=="export"?H3e(x.children[0]):x,Pte=(x,P)=>{let Q=lp(x);if(Q){let Ut=Kb(x)[0];if(fL(Ut,P))return x.parameters.length>0?Ut:null}let ae=XS(x,P),Ee=ae==null||(ae.kind==$e.SyntaxKind.Block||ae.kind==$e.SyntaxKind.SourceFile)&&P>ae.index?XS(x,P-1):ae;if(Ee==null||Ee.kind==$e.SyntaxKind.Block||x==Ee||x.name==Ee)return null;let Oe=aW(Ee,x);for(let Ut of Oe){if(lp(Ut))break;if(Ut.kind==$e.SyntaxKind.JsxExpression||Ut.kind==$e.SyntaxKind.JsxSpreadAttribute)return Ut.expression;if(Gbe(Ut))return Ut}if(Q&&x.body.kind!=$e.SyntaxKind.Block)return x.body;if(Oe.find(Ut=>Ut!=x&&Ut!=Ee&&(lp(Ut)||Jp(Ut)))!=null)return null;if(Jp(x)&&Oe.includes(x.expression))return x.expression;if(x.kind==$e.SyntaxKind.ForStatement&&Oe.includes(x.incrementor))return x.incrementor;if(x.kind==$e.SyntaxKind.ForStatement&&Oe.includes(x.condition))return x.condition;let Mt=$e.forEachAncestor(Ee,Ut=>{if(Ut.parent.kind==$e.SyntaxKind.IfStatement&&Ut.parent.expression==Ut||$e.isStatement(Ut))return Ut});return H3e(Mt)};var tu={parse:"parse",reload_app_window:"reload_app_window",reload_app_window_finished:"reload_app_window_finished",load_external_imports:"load_external_imports",eval_modules:"eval_modules",eval_modules_finished:"eval_modules_finished"},q3e=(x,P)=>{let Q=new Set(x),ae=new Map,Ee=(Oe,dt)=>{if(Oe.children!=null)for(let Mt of Oe.children)Ee(Mt,Oe.code!=null&&Jp(Oe.code)?dt:Oe);Q.has(Oe.id)&&ae.set(Oe.id,{id:Oe.id,version_number:Oe.version_number,toplevel:dt.toplevel,module:vy(dt)?.module,parent_name:dt.fn?.name,args:Oe.args,log_fn_name:Oe.fn.name})};return Ee(P,null),x.map(Oe=>ae.get(Oe))},gvt=x=>x.run_state?.status!=tu.reload_app_window?_L({...x,run_state:{status:tu.reload_app_window_finished}},!1):x.run_state.on_reload_app_window_finished(x),Lte=(x,P,Q)=>({function_node:P,module:x,selected_node:Q}),X3e=x=>{let P=hL(x),Q=Bte(x,x.current_module,P),ae=Pte(Q,P);return Lte(x.current_module,Q,ae)},kte=x=>{if(x.parse_result.modules[x.current_module]==null)return Lte(x.current_module,x.parse_result.modules[x.entrypoint],null);let P=X3e(x);return Y3e(x,P)},Y3e=(x,P)=>{let Q;return P.function_node==x.active_calltree_node?.code?Q=x.active_calltree_node:x.calltree!=null&&x.deepest_calltree_node_id!=null&&(Q=aEe(x.calltree,x.deepest_calltree_node_id).findLast(ae=>ae.code==P.function_node&&(!Jp(ae.code)||ae.fn.__type=="loop_iteration"))),Q==null?x.active_calltree_node!=null&&(P={...P,parent_calltree_node:x.active_calltree_node}):P={...P,selected_call_id:Q.id},P},_L=(x,P,Q)=>{let ae=x.active_calltree_node;if(x={...x,calltree:null,modules:null,execution_id:x.execution_id+1,rt_cxt:null,logs:null,current_calltree_node:null,active_calltree_node:null,deepest_calltree_node_id:null,calltree_node_is_expanded:null,collected_footprints_functions:new Set,frames:new Map,colored_frames:null,frame_coloring:new Map,selection_state:null,value_explorer:null,snapshots:new dW,subcalls:new Map,footprints:null},P){let Ee={status:tu.parse,prev_status:x.run_state?.status};return Q&&(Ee={...Ee,prev_active_calltree_node:ae}),{...x,run_state:Ee}}return $3e(x,P)},$3e=(x,P,Q)=>{P&&(x={...x,parse_result:h3e(x.entrypoint,Q)});let ae=P?{status:x.run_state.prev_status,prev_active_calltree_node:x.run_state.prev_active_calltree_node}:x.run_state;return x={...x,run_state:ae},x.parse_result.ok?x.run_state?.status==tu.reload_app_window_finished?K3e(x):{...x,run_state:{status:tu.reload_app_window,on_reload_app_window_finished:K3e,reload_counter:x.run_state?.reload_counter,prev_active_calltree_node:x.run_state.prev_active_calltree_node}}:x},K3e=x=>{let P=kte(x),Q=x.run_state.prev_active_calltree_node;if(Q!=null&&Q.kind!=$e.SyntaxKind.SourceFile&&P.function_node.kind!=$e.SyntaxKind.SourceFile){let ae=Q.code.getSourceFile().text,Ee=x.run_state.prev_active_calltree_node.code,Oe=x.files[x.current_module],dt=P.function_node;ae.slice(0,Ee.index)==Oe.slice(0,dt.index)&&ae.slice(Ee.index+Ee.length)==Oe.slice(dt.index+dt.length)&&(P={...P,selected_call_id:Q.id})}return x={...x,run_state:{breakpoint:P,on_eval_modules_finished:eze}},TG(x)},TG=x=>{let P=t3e(jbe(x.parse_result.modules).map(Q=>Q.url));return P.length!=0?{...x,run_state:{...x.run_state,status:tu.load_external_imports,external_imports:P}}:Q3e(x,x)},Q3e=(x,P,Q)=>{if(x.run_state!=P.run_state)return x;if(Q!=null){let Mt=new Set(Object.entries(Q).filter(([Ut,Wt])=>!Wt.ok).map(([Ut,Wt])=>Ut));if(Mt.size!=0){let Ut=jbe(x.parse_result.modules).filter(({url:Wt})=>Mt.has(Wt)).map(({node:Wt,module_name:gr,url:ti})=>({index:Wt.index,length:Wt.length,message:Q[ti].error.message,module:gr}));return{...x,parse_result:{...x.parse_result,ok:!1,problems:Ut,is_external_imports_problems:!0},run_state:{status:tu.eval_modules_finished}}}}let ae=new dW([...x.snapshots.entries()].map(([Mt,Ut])=>[Mt,Ut==null?Ut:new Map(Ut)])),Ee=x.run_state.on_eval_modules_finished!=eze;!Ee&&x.is_open_app_window&&(x={...x,io_trace:[]});let Oe=x.io_trace.length==0&&!Ee,dt=j3e(x.parse_result,Q,x.on_deferred_call,x.execution_id,x.io_trace,Oe,U3e(Ee?x.prev_storage:x.storage),ae,!x.collected_footprints_functions.has(x.run_state.breakpoint.function_node),x.run_state.breakpoint,x.allow_sync_execution);return dt.then==null&&x.allow_sync_execution?Z3e(x,x.execution_id,dt):{...x,run_state:{...x.run_state,status:tu.eval_modules,promise:dt}}},Z3e=(x,P,Q)=>{if(x.execution_id!=P)return x;if(x.calltree!=null){if(Q.rt_cxt.io_trace_is_replay_aborted)throw new Error("illegal state");if(Q.rt_cxt.call_counter!=x.rt_cxt.call_counter)throw new Error("illegal state: bad replay, call_counter do not match");x={...x,calltree:mze(x.calltree,Q.calltree)}}let ae=Q.rt_cxt.snapshots,Ee=Q.breakpoint,Oe=Ee.function_node.kind==$e.SyntaxKind.SourceFile?[Ee.selected_node]:[Ee.selected_node,Ee.function_node];for(let Mt of Oe){let Ut=[Ee.module,Mt];Mt!=null&&ae.get_by_module_and_node(...Ut)===void 0&&ae.set_by_module_and_node(...Ut,null)}for(let Mt of[Q.rt_cxt.selected_call_id,Q.rt_cxt.first_call_id])if(Ee.selected_node!=null&&Mt!=null){let Ut=ae.get_by_module_and_node(Ee.module,Ee.selected_node);Ut!=null&&Ut.get(Mt)===void 0&&Ut.set(Mt,null)}if(Ee.parent_calltree_node!=null){let Mt=x.subcalls.get(Ee.parent_calltree_node.id);Mt==null&&(Mt=new Map,x.subcalls.set(Ee.parent_calltree_node.id,Mt)),Mt.set(Ee.function_node,Q.rt_cxt.selected_call_id??null)}let dt={...x,snapshots:ae,footprints:new Map([...x.footprints??[],...Q.rt_cxt.footprints]),rt_cxt:Q.rt_cxt,run_state:{status:tu.eval_modules_finished}};if(x.run_state.breakpoint.function_node==null)throw new Error("illegal state");return x.collected_footprints_functions.add(x.run_state.breakpoint.function_node),x.run_state.on_eval_modules_finished(dt,Q,x.run_state.breakpoint)},eze=(x,P,Q)=>{if(P.rt_cxt.io_trace_is_replay_aborted)return cze(x);if(x={...x,calltree:P.calltree,rt_cxt:P.rt_cxt,logs:{logs:q3e(P.logs,P.calltree),log_position:null},modules:P.modules,prev_storage:x.storage,storage:P.rt_cxt.storage},x=lze(x,P,Q),x.active_calltree_node==null){let{node:ae,state:Ee}=zte(x);x=uW(Ee,null,ae)}else x=_ze(LC(x,x.active_calltree_node));if(x.run_state.status==tu.reload_app_window)return x;if(x.run_state.status!=tu.eval_modules_finished)throw new Error("illegal state");return x},yvt=(x,P,Q)=>{let ae={...x.files,[x.current_module]:P};x={...x,files:ae},x=Fte(x,Q);let Ee={type:"write",args:[x.current_module,x.files[x.current_module]]};return{state:_L(x,!0,!0),effects:[Ee]}},oEe=(x,P)=>{if(!x.parse_result.ok)return{state:x,effects:{type:"set_status",args:["invalid syntax"]}};if(x.calltree==null)return{state:x,effects:{type:"set_status",args:["code is executing"]}};let Q=Bte(x,x.current_module,P);if(Q==null||Q.kind==$e.SyntaxKind.SourceFile&&Q!=mL(x)||lp(Q)&&x.snapshots.get_by_module_and_node(x.current_module,Q)===null)return{state:x,effects:{type:"set_status",args:["code was not reached during program execution"]}}},vvt=(x,P)=>{let Q=x.parse_result.modules[x.current_module],ae=XS(Q,P);if(ae==null)return null;let Ee=aW(ae,Q).find(Oe=>Oe.kind==$e.SyntaxKind.CallExpression||Oe.kind==$e.SyntaxKind.NewExpression||lp(Oe));return Ee==null||lp(Ee)?null:Ee},bvt=x=>{let P=hL(x),Q=oEe(x,P);if(Q!=null)return Q;let ae=vvt(x,P);if(ae==null)return{state:x,effects:{type:"set_status",args:["no function call to step into"]}};if(x.run_state.status!=tu.eval_modules_finished)return{state:x,effects:{type:"set_status",args:["code is not executed yet"]}};let Ee=sEe(x.active_calltree_node,ae);if(Ee==null){let Oe=cte(x),dt;return Oe.get(ae)==null?dt="call was not reached during program execution":dt="Cannot step into: function is either builtin or from external lib",{state:x,effects:{type:"set_status",args:[dt]}}}return AG(x,!0,Ee)},tze=x=>{if(x.kind==$e.SyntaxKind.SourceFile)return!1;if(x.parent==null)throw new Error("illegal state");let P=x.parent;return $e.isExpression(x)&&x.kind!=$e.SyntaxKind.SpreadAssignment&&x.kind!=$e.SyntaxKind.SpreadElement&&P?.kind!=$e.SyntaxKind.ShorthandPropertyAssignment&&P?.kind!=$e.SyntaxKind.ImportDeclaration&&P?.kind!=$e.SyntaxKind.ImportClause&&P?.kind!=$e.SyntaxKind.ImportSpecifier&&P?.kind!=$e.SyntaxKind.NamespaceImport&&(P==null||!bG(x,P))&&!(P!=null&&P.kind==$e.SyntaxKind.PropertyAccessExpression&&P.name==x)&&!(P!=null&&P.kind==$e.SyntaxKind.PropertyAssignment&&x==P.name)&&P?.kind!=$e.SyntaxKind.JsxAttribute&&!(P!=null&&(P.kind==$e.SyntaxKind.JsxOpeningElement||P.kind==$e.SyntaxKind.JsxClosingElement)&&x.kind==$e.SyntaxKind.Identifier&&$e.isIntrinsicJsxName(x.escapedText))&&!(P!=null&&oW(P)&&oW(x))},J3e=x=>x.find(P=>tze(P)),Evt=(x,P,Q,ae)=>{if(XS(P,ae)==null)return{ok:!1,message:"out of scope"};if(x!=null&&x.index==ae){let Oe;if(x.initial_is_expand==Q)x.node==P?Oe=x.node:(Oe=J3e(Ube(x.node,P)),(Oe==null||!$e.isExpression(Oe))&&(Oe=x.node));else{let Mt=XS(x.node,ae);Mt!=x.node?(Oe=aW(Mt,x.node).findLast(Wt=>Wt!=x.node&&tze(Wt)),Oe==null&&(Oe=x.node)):Oe=x.node}return{ok:!0,initial_is_expand:x.initial_is_expand,node:Oe,function_node:x.function_node,index:ae}}else{let Oe=XS(P,ae),dt=J3e(aW(Oe,P));return dt==null||!$e.isExpression(dt)?{ok:!1,message:"can only evaluate expression, not statement"}:{ok:!0,index:ae,function_node:P,node:dt,initial_is_expand:Q}}},Svt=(x,P,Q)=>{let ae=oEe(x,P);if(ae!=null)return ae;let Ee=Bte(x,x.current_module,P);if(Ee==null)throw new Error("not implemented");let Oe=Evt(x.selection_state,Ee,Q,P),dt={...x,selection_state:Oe,value_explorer:null};if(!Oe.ok)return{state:dt,effects:{type:"set_status",args:[Oe.message]}};let Mt=Y3e(x,Lte(x.current_module,Ee,Oe.node));return nze(dt,Mt,!0)},SG=(x,P,Q,ae)=>{let Ee=x.snapshots.get_by_module_and_node(P,Q);if(Ee===null)return{has_snapshot:!0,node_snapshot:null};if(Ee===void 0)return{has_snapshot:!1};let Oe=Ee.get(ae);return{has_snapshot:Oe!==void 0,node_snapshot:Oe}},rEe=(x,P,Q,ae=void 0)=>{let Ee=x.snapshots.get_by_module_and_node(P,Q);if(Ee===null)return{has_snapshot:!0,node_snapshot:null};if(Ee===void 0)return{has_snapshot:!1};if(ae!=null){let Mt=Ee.get(ae);if(Mt!=null)return{has_snapshot:!0,node_snapshot:Mt};if(Mt===void 0)return{has_snapshot:!1}}let[Oe,dt]=[...Ee.entries()].sort((Mt,Ut)=>Mt[0]-Ut[0]).find(([Mt,Ut])=>Ut!=null);if(Oe==null)throw new Error("illegal state");return{has_snapshot:!0,node_snapshot:dt}},nze=(x,P)=>(x=sze(x,P),x.run_state.status==tu.reload_app_window?{...x,run_state:{...x.run_state,on_eval_modules_finished:Tvt}}:x.value_explorer!=null?x:{state:x,effects:{type:"set_status",args:["expression was not reached during program execution"]}}),Tvt=(x,P,Q)=>x.selection_state==null||x.value_explorer!=null?x:nze(x,Q,!1),Avt=(x,P)=>x.files[P]==null?{state:x,effects:{type:"set_status",args:["File not found"]}}:{...x,current_module:P,selection_state:null,value_explorer:null},Ivt=(x,P,Q=P)=>_L({...x,entrypoint:P,current_module:Q},!0),xvt=(x,P)=>_L({...x,html_file:P},!0),Rvt=(x,P)=>({state:rze(PC(x,P),P.index),effects:{type:"set_focus"}}),Dvt=(x,P)=>({state:PC(x,P),effects:{type:"set_focus"}}),rze=(x,P)=>(x=Fte(x,P),x={...x,selection_state:null,value_explorer:null},oEe(x,P)!=null?x:Ote(x,kte(x),ize,!0)),wte=(x,P,Q,ae)=>{let Ee=ae.call_id;if(Ee==null)throw new Error("illegal state");let Oe=f0(x.calltree,Mt=>Mt.id==Ee);if(tEe(Q,Oe,ae.ok)||[$e.SyntaxKind.BreakStatement,$e.SyntaxKind.ContinueStatement].includes(Q.kind))return null;let dt;if(ae.ok)dt=void 0;else{let Mt=MC(Oe);if(Mt==null)return null;dt=Mt.error}return{call_id:Ee,index:Q.index,length:Q.length,result:{ok:ae.ok,value:ae.value,error:dt}}},iEe=(x,P)=>f0(x,Q=>MC(Q)?.ok==!1&&Q.code==P&&(!Jp(Q.code)||Q.fn.__type=="loop_iteration")),ize=(x,P)=>{function Q(){return{...x,run_state:{status:tu.reload_app_window,reload_counter:(x.run_state.reload_counter??0)+1,on_reload_app_window_finished:TG,on_eval_modules_finished:Nvt,breakpoint:P}}}let ae;if(P.selected_call_id!=null)ae=P.selected_call_id;else{if(P.parent_calltree_node!=null){let Mt=iEe(P.parent_calltree_node,P.function_node),Ut;if(Mt!=null?Ut=Mt.id:Ut=x.subcalls.get(P.parent_calltree_node.id)?.get(P.function_node),Ut===void 0)return Q();Ut!=null&&(ae=Ut)}if(ae==null){let Mt=iEe(x.calltree,P.function_node);if(Mt!=null)ae=Mt.id;else{let Ut;if(P.function_node==mL(x))ae=yy(x).id,Ut=x.footprints.get(ae)==null;else{let{has_snapshot:Wt,node_snapshot:gr}=rEe(x,P.module,P.function_node);if(Ut=!Wt,Wt)if(gr!=null)ae=gr.call_id;else return Mte({...x,value_explorer:null},P.function_node,null)}if(Ut&&P.parent_calltree_node!=null)throw new Error("illegal state: replay cannot be required here");if(Ut)return Q()}}}if(ae==null)throw new Error("illegal state: selected_call_id is null");let Ee;if(P.function_node==mL(x))Ee=x.footprints.get(ae)==null;else{let{has_snapshot:Mt}=SG(x,P.module,P.function_node,ae);Ee=!Mt}if(Ee)return P={...P,selected_call_id:ae},Q();let Oe,dt=P.selected_node;if(dt!=null){let{has_snapshot:Mt,node_snapshot:Ut}=SG(x,P.module,CC(P.selected_node)?P.function_node:P.selected_node,ae);if(Mt)Ut==null?Oe={is_jump_here:!0,index:dt.index,length:dt.length}:Oe=wte(x,P.function_node,dt,Ut);else return Q()}else Oe=null;return Mte({...x,value_explorer:Oe},P.function_node,ae)},oze=x=>{if(!x.value_explorer?.is_jump_here)return x;let P;return x.selection_state==null?P=X3e(x):P=Lte(x.current_module,x.selection_state.function_node,x.selection_state.node),Ote(x,P,Cvt,!0)},Cvt=(x,P)=>{if(P.selected_node==null)throw new Error("illegal state");let Q=x;return x=aze(x,P,!0),Q==x?{state:x,effects:{type:"set_status",args:["code was not reached during program execution"]}}:x.run_state.status==tu.reload_app_window?{...x,run_state:{...x.run_state,on_eval_modules_finished:oze}}:x},Ote=(x,P,Q)=>{if(P.function_node.kind==$e.SyntaxKind.SourceFile&&P.function_node!=mL(x)||(x=Q(x,P),x.effects!=null)||x.run_state.status==tu.reload_app_window||x.value_explorer==null||x.value_explorer.is_jump_here||!x.value_explorer.result.ok)return x;let ae=P.selected_node;if(ae.kind!=$e.SyntaxKind.CallExpression)return x;let Ee=sEe(x.active_calltree_node,P.selected_node);if(Ee==null||!Ee.is_log)return x;let{has_snapshot:Oe,node_snapshot:dt}=SG(x,P.module,eEe(ae),x.value_explorer.call_id);if(!Oe)throw console.error({state:x,breakpoint:P,calltree_node:Ee,has_snapshot:Oe,node_snapshot:dt}),new Error("illegal state: no node snapshot for log fn args");if(!dt.ok)throw console.error({state:x,breakpoint:P,calltree_node:Ee,has_snapshot:Oe,node_snapshot:dt}),new Error("illegal state: node snapshot with ok: false for log fn args");let Mt={...x.value_explorer,result:{ok:!0,value:dt.value}};return{...x,value_explorer:Mt}},aze=(x,P,Q)=>{if(Q||P.selected_call_id==null){let dt=iEe(x.calltree,P.function_node);dt!=null&&(P={...P,selected_call_id:dt.id})}let ae=P.selected_node,{has_snapshot:Ee,node_snapshot:Oe}=ae==null?{has_snapshot:!0,node_snapshot:null}:rEe(x,P.module,CC(P.selected_node)?P.function_node:P.selected_node,P.selected_call_id);if(Ee){let dt=!1,Mt,Ut;if(Oe==null){if(Q)return x;if(Mt=null,P.function_node==mL(x))Ut=yy(x).id,dt=x.footprints.get(Ut)==null;else{let{has_snapshot:Wt,node_snapshot:gr}=rEe(x,P.module,P.function_node,P.selected_call_id);dt=!Wt,Ut=gr?.call_id}}else Ut=Oe.call_id,Mt=wte(x,P.function_node,ae,Oe);if(!dt)return Mte({...x,value_explorer:Mt},P.function_node,Ut)}return{...x,run_state:{status:tu.reload_app_window,reload_counter:(x.run_state.reload_counter??0)+1,on_reload_app_window_finished:TG,breakpoint:P}}},sze=(x,P)=>(x=aze(x,P,!1),x.run_state.status==tu.reload_app_window?{...x,run_state:{...x.run_state,on_eval_modules_finished:lze}}:x),lze=(x,P,Q)=>{let ae=kte(x);return Q.selected_call_id!=null&&ae.function_node==Q.function_node&&(ae={...Q,selected_call_id:Q.selected_call_id}),Ote(x,ae,sze,!0)},Nvt=x=>x.selection_state!=null||x.value_explorer!=null?x:Ote(x,kte(x),ize,!0),Pvt=(x,P,Q,ae)=>x.execution_id!=Q||(x={...x,snapshots:new dW,footprints:new Map,collected_footprints_functions:new Set,calltree:dte(yy(x),[...rI(x)??[],P]),logs:{...x.logs,logs:x.logs.logs.concat(q3e(ae,P))}},P.ok)?x:zte(x,P).state,cze=x=>_L({...x,io_trace:[],run_state:{...x.run_state,reload_counter:(x.run_state.reload_counter??0)+1}},!1),dze=(x,P)=>{let Q=Ee=>Ee.kind=="file"?[Ee]:Ee.children.map(Q).flat(),ae=Object.fromEntries([...Q(P.scratch_files),...P.local_files==null?[]:Q(P.local_files)].map(Ee=>[Ee.path,Ee.contents]));return{...x,project_dir:P,files:ae}},uze=(x,P)=>(x=dze(x,P),x=pze(x),_L(x,!0)),Mvt=(x,P,Q)=>{let ae={...x.project_dir,scratch_files:P};return x={...x,current_module:Q,entrypoint:Q},uze(x,ae)},pze=x=>{let P=x.project_dir.scratch_files.children[0];return{...x,current_module:x.files[x.current_module]==null?P.path:x.current_module,entrypoint:x.files[x.entrypoint]==null?P.path:x.entrypoint,html_file:x.files[x.html_file]==null?null:x.html_file}},fze=(x,P)=>{let Q={...x.project_dir,local_files:P};return uze(x,Q)},Lvt=(x,P,Q)=>fze({...x,current_module:Q,entrypoint:Q},P),kvt=(x,P)=>({...x,storage:new EG,is_open_app_window:P}),wvt=(x,P=0)=>(x=dze(x,x.project_dir),x=pze(x),_L({...x,execution_id:0,storage:new EG,io_trace:[],is_open_app_window:!1,cursor_position_by_file:{[x.current_module]:P}},!0)),Wte={get_initial_state:wvt,parse_finished:$3e,input:yvt,open_app_window:kvt,load_local_dir:fze,create_local_file:Lvt,load_scratch_dir:Mvt,step_into:bvt,change_current_module:Avt,change_entrypoint:Ivt,change_html_file:xvt,goto_location:Rvt,goto_problem:Dvt,move_cursor:rze,jump_here:oze,eval_selection:Svt,reload_app_window_finished:gvt,external_imports_loaded:Q3e,eval_modules_finished:Z3e,on_deferred_call:Pvt,clear_io_trace:cze};var hL=x=>x.cursor_position_by_file[x.current_module]??0,Fte=(x,P)=>({...x,cursor_position_by_file:{...x.cursor_position_by_file,[x.current_module]:P}});var PC=(x,P)=>Fte({...x,current_module:P.module},P.index),Ovt=x=>x.error?.constructor==lW.constructor&&x.error?.message==lW.message,gL=x=>!x.ok||x.value?.[Symbol.toStringTag]=="Promise"&&x.value.status!=null&&!x.value.status.ok,MC=x=>x.value?.[Symbol.toStringTag]=="Promise"?x.value.status:x,vy=x=>x.toplevel?{module:x.module}:x.fn.__location&&JSON.parse(x.fn.__location),Wvt=x=>yy(x).module,mL=x=>x.parse_result.modules[Wvt(x)],Vte=x=>!x.toplevel&&!x.fn.is_hosted,Fvt=(x,P)=>x?.[P.module]?.[P.index??-1],zvt=(x,P,Q)=>({...x,[P.module]:{...x?.[P.module],[P.index??-1]:Q}}),aEe=(x,P)=>{let Q=[{node:x,child_index:0}];for(;;){if(Q.length==0)return null;let ae=Q.at(-1);if(ae.node.id==P)return Q.map(Ee=>Ee.node);if(ae.node.children==null||ae.child_index>=ae.node.children.length){Q.pop();continue}Q.push({node:ae.node.children[ae.child_index],child_index:0}),ae.child_index++}},uW=(x,P,Q=x.current_calltree_node)=>{let ae=x.deepest_calltree_node_id;return ae==null?ae=Q?.id:aEe(x.calltree,ae).includes(Q)||(ae=Q.id),{...x,active_calltree_node:P,current_calltree_node:Q,deepest_calltree_node_id:ae}},lEe=(x,P,Q=P)=>{let ae=vy(P);if(Fvt(x.colored_frames,ae)!=P.id){x={...x,colored_frames:zvt(x.colored_frames,ae,P.id)};let Oe=x.frames.get(P.id);if(Oe==null){let dt=x.footprints.get(P.id);if(dt==null)throw new Error("illegal state");if(P.code!=null&&Jp(P.code)&&P.fn?.__type!="loop_iteration")throw new Error("illegal state");Oe=nEe(P.code,P,dt);let Mt=y3e(P.code,Oe);x.frames.set(P.id,Oe),x.frame_coloring.set(P.id,Mt)}}return uW(x,P,Q)},mze=(x,P)=>Gte(x,P)[1],Gte=(x,P)=>{if(x.id!=P.id)throw new Error("illegal state: merge_calltree");if(x.callsite_location==null&&P.callsite_location!=null)return[!0,Gte({...x,callsite_location:P.callsite_location},P)[1]];if(x.snapshot==null&&P.snapshot!=null)return[!0,Gte({...x,snapshot:P.snapshot},P)[1]];if(x.has_more_children){if(P.has_more_children)return[!1,x];if(x.id!=P.id)throw new Error("illegal state");return[!0,P]}if(x.children==null)return[!1,x];if(P.has_more_children)return[!1,x];if(x.children.length!=(P.children?.length??0))throw new Error("illegal state");let[Q,ae]=e3e((Ee,Oe,dt)=>{let[Mt,Ut]=Gte(Oe,P.children[dt]);return[Ee||Mt,Ut]},!1,x.children);return Q?[!0,{...x,children:ae}]:[!1,x]},sEe=(x,P)=>(x.children??[]).find(Q=>{if(Q.callsite_location==null)return!1;let ae=JSON.parse(Q.callsite_location);return ae.index==P.index&&ae.length==P.length}),gze=(x,P)=>{let Q=x.callsite_location;if(Q==null)return null;Q=JSON.parse(Q);let ae=Ate(P.code,Ee=>Ee.index==Q.index&&Ee.length==Q.length&&(Ee.kind==$e.SyntaxKind.CallExpression||Ee.kind==$e.SyntaxKind.NewExpression||Jp(Ee)));if(ae==null)throw new Error("illegal state");return ae},hze=(x,P,Q)=>{let{has_snapshot:ae,node_snapshot:Ee}=SG(x,vy(x.current_calltree_node).module,P,Q);if(ae){let Oe;return Ee==null?Oe=null:Oe=wte(x,x.current_calltree_node.code,P,Ee),{should_replay:!1,value_explorer:Oe}}else return{should_replay:!0}},$S=(x,P,Q=Oe=>Oe,ae=!1,Ee=!1)=>{function Oe(Lr){if(Ee)throw new Error("illegal state");let oa=Wt.code;return{...x,value_explorer:null,run_state:{status:tu.reload_app_window,on_reload_app_window_finished:TG,on_eval_modules_finished:dt,breakpoint:{module:vy(Wt).module,function_node:oa,selected_call_id:Wt.id,current_calltree_node_id:P.id,selected_node:Lr}}}}function dt(Lr,oa,Zo){if(Zo.current_calltree_node_id!=Lr.current_calltree_node.id)return Lr;let fs=f0(Lr.calltree,gs=>gs.id==P.id);return $S(Lr,fs,Q,ae,!0)}let[Mt]=IG(x.calltree,P);if(!P.toplevel&&!P.fn.is_hosted&&!Mt.toplevel&&!Mt.fn.is_hosted)return Q({...uW(x,null,P),value_explorer:null,selection_state:null});let Ut;P.toplevel||P.fn.__type=="loop_iteration"?Ut=!0:P.code!=null&&Jp(P.code)?Ut=!1:Mt.id=="deferred_calls"?Ut=!0:Vte(P)?Ut=!1:Vte(Mt)?Ut=!0:Ut=x.calltree_node_is_expanded[P.id];let Wt=Ut?P:Mt;x=uW(x,Wt,P);let gr,ti,qr;if(P.toplevel){if(x.footprints.get(yy(x).id)==null)return Oe();ti=null,qr=null,gr=vy(Wt)}else if(P.fn.__type=="loop_iteration"){let Lr=vy(P).module,oa=hL(x),Zo=!1;if(x.current_module==Lr&&fL(P.code,oa)&&oa!=P.code.index)gr={module:Lr,index:oa};else{let md=P.code,Gd=md.kind;if(Gd==$e.SyntaxKind.WhileStatement||Gd==$e.SyntaxKind.DoStatement||Gd==$e.SyntaxKind.ForStatement){let by=md.statement.kind==$e.SyntaxKind.Block?md.statement.statements.length==0?Gd==$e.SyntaxKind.ForStatement?md.initializer:md.expression:md.statement.statements[0]:md.statement;gr={module:Lr,index:by.index}}else gr={module:Lr,index:md.initializer.index},Zo=!0}let fs=x.selection_state?.node,gs=fs!=null&&!(fs==P.code.expression&&(P.code.kind==$e.SyntaxKind.ForOfStatement||P.code.kind==$e.SyntaxKind.ForInStatement))&&fs!=P.code.initializer&&fL(P.code,fs.index),Za;if((P.code.kind==$e.SyntaxKind.ForOfStatement||P.code.kind==$e.SyntaxKind.ForInStatement)&&(fs==P.code.initializer||Zo)?(qr={node:P.code.initializer},Za=P.code):gs?(qr=x.selection_state,Za=x.selection_state.node):(Za=Pte(P.code,gr.index),qr=null),Za==null)ti=null,qr=null;else{let md;if({value_explorer:ti,should_replay:md}=hze(x,Za,P.id),md)return Oe(Za)}}else if(P.code!=null&&Jp(P.code)){let Lr=P.code.kind;if(Lr==$e.SyntaxKind.WhileStatement||Lr==$e.SyntaxKind.DoStatement)ti=null,qr=null;else{let oa;Lr==$e.SyntaxKind.ForStatement?oa=P.code.initializer:oa=P.code.expression,qr={node:oa};let Zo;if({value_explorer:ti,should_replay:Zo}=hze(x,oa,Hbe(x.calltree,P).id),Zo)return Oe(oa)}if(gr={module:vy(P).module,index:P.code.index},P.has_more_children)return Oe()}else{if(P.snapshot==null)return Oe();let Lr;if(Ut){gr=vy(P),qr=null;let Zo=x.snapshots.get_by_module_and_node(vy(Wt).module,Wt.code)?.get(Wt.id);if(Zo==null)return Oe();Zo.ok?Lr=Zo.value:Lr=P.snapshot.args}else{let Zo=gze(P,Wt);if(Zo==null)return Oe();gr={module:vy(Wt).module,index:Zo.index},Lr=P.snapshot.args,qr={node:Zo}}if(Lr==null)throw new Error("illegal state");let oa=P.ok?{args:Lr,return_value:P.snapshot.value}:{args:Lr,throws:P.snapshot.error};P.context!=null&&(oa={...oa,context_before:P.snapshot.context_before,context_after:P.snapshot.context_after}),ti={call_id:P.id,index:gr.index,result:{ok:!0,is_calltree_node_explorer:!0,value:oa}}}return x=ae?x:P.toplevel?{...x,current_module:gr.module}:PC(x,gr),x.footprints.get(Wt.id)==null?Oe():Q({...lEe(x,Wt,P),value_explorer:ti,selection_state:qr})},Bvt=x=>$S(x,x.current_calltree_node,void 0,!0),IG=(x,P)=>{let Q=Ee=>Ee.id==P.id?[]:Ee.children==null?null:Ee.children.reduce((Oe,dt)=>{if(Oe!=null)return Oe;let Mt=Q(dt);return Mt==null?null:[...Mt,Ee]},null),ae=Q(x);if(ae==null)throw new Error("illegal state");return ae},yL=x=>Vte(x)||Jp(x.code)?x.children!=null&&x.children.length!=0||x.has_more_children:x.toplevel?x.children!=null&&x.children.length!=0:!0,Gvt=x=>{let P=x.current_calltree_node,Q;if(yL(P)&&x.calltree_node_is_expanded[P.id]&&P.children!=null)Q=P.children[0];else{let ae=(Ee,Oe)=>{if(Ee.id=="calltree")return null;let[dt,...Mt]=Oe,Ut=dt.children.findIndex(gr=>gr==Ee),Wt=dt.children[Ut+1];return Wt??ae(dt,Mt)};Q=ae(P,IG(x.calltree,P))}return Q?.id=="deferred_calls"&&(Q.children==null?Q=null:Q=Q.children[0]),Q==null?x:$S(x,Q)},Vvt=x=>{let P=x.current_calltree_node;if(P.toplevel)return x;let[Q]=IG(x.calltree,P),ae=Q.children.findIndex(Mt=>Mt==P),Ee=Q.children[ae-1],Oe=Mt=>!yL(Mt)||!x.calltree_node_is_expanded[Mt.id]||Mt.children==null?Mt:Oe(Mt.children[Mt.children.length-1]),dt;return Ee==null?dt=Q.id=="deferred_calls"?Oe(yy(x)):Q:dt=Oe(Ee),$S(x,dt)},jvt=x=>{let P=x.current_calltree_node,Q=x.calltree_node_is_expanded[P.id];if(!yL(P)||!Q){let[ae]=IG(x.calltree,P);return ae.id=="calltree"||ae.id=="deferred_calls"?x:$S(x,ae)}else return AG(x)},Uvt=x=>{let P=x.current_calltree_node;return yL(P)?x.calltree_node_is_expanded[P.id]?P.children!=null?$S(x,P.children[0]):x:AG(x):x},AG=(x,P,Q=x.current_calltree_node)=>{let ae=Q.id,Ee=x.calltree_node_is_expanded[ae],Oe=P??!Ee,dt={...x,calltree_node_is_expanded:{...x.calltree_node_is_expanded,[ae]:Oe}};return $S(dt,Q)},Hvt=(x,P)=>{let Q=f0(x.calltree,ae=>ae.id==P);return $S(x,Q)},Kvt=(x,P)=>{let Q=f0(x.calltree,ae=>ae.id==P);return yL(Q)?AG(x,void 0,Q):$S(x,Q)},LC=(x,P)=>x.calltree_node_is_expanded?.[P.id]?x:{...x,calltree_node_is_expanded:{...x.calltree_node_is_expanded,...Object.fromEntries(IG(x.calltree,P).map(Q=>[Q.id,!0])),[P.id]:!0}},zte=(x,P)=>{if(P??=yy(x),P.ok||Ovt(P))return{state:LC(x,P),node:P};{let Q=f0(P,ae=>!MC(ae).ok&&(ae.children==null||ae.children.find(Ee=>!MC(Ee).ok)==null));return{state:LC(x,Q),node:Q}}},_ze=x=>zte(x).state,Bte=(x,P,Q)=>{let ae=x.parse_result.modules[P];if(ae==null)return null;if(fL(ae,Q)){let Ee=XS(ae,Q),Oe=$e.forEachAncestor(Ee,dt=>{let Mt=Ste(dt);if(Mt!=null)return Mt;if(lp(dt)||Jp(dt))return dt});return Oe??ae}else return ae},Mte=(x,P,Q)=>{if(P==mL(x)){let Ee=yy(x);return lEe(LC(x,Ee),Ee)}if(P.kind==$e.SyntaxKind.SourceFile)return x;if(Q==null)return uW(x,null);let ae=f0(x.calltree,Ee=>Ee.id==Q);if(ae==null)throw new Error("illegal state");return lEe(LC(x,ae),ae)},Jvt=x=>{if(x.current_calltree_node.toplevel)return{state:x};if(x.current_calltree_node.code!=null&&Jp(x.current_calltree_node.code))return{state:x};let P=vy(x.active_calltree_node),Q;if(x.current_calltree_node==x.active_calltree_node){let ae=x.frames.get(x.active_calltree_node.id),Ee=x.active_calltree_node.code;if(x.active_calltree_node.ok)if(Ee.body.kind==$e.SyntaxKind.Block){let Oe=Ate(Ee,dt=>dt.kind==$e.SyntaxKind.ReturnStatement&&ae.get(dt)?.ok);if(Oe==null)return{state:PC(x,{module:P.module,index:Ee.body.index}),effects:{type:"set_focus"}};Q=Oe.expression}else Q=Ee.body;else Q=Kbe(Ee,ae)}else{let ae=x.current_calltree_node.callsite_location;ae=JSON.parse(ae),Q=Ate(x.active_calltree_node.code,Ee=>Ee.index==ae.index&&Ee.length==ae.length)}return{state:{...PC(x,{module:P.module,index:Q.index}),selection_state:{node:Q},value_explorer:{call_id:x.current_calltree_node.id,index:Q.index,length:Q.length,result:x.current_calltree_node.snapshot}},effects:{type:"set_focus"}}},qvt=(x,P=!0)=>{if(x.current_calltree_node.toplevel)return{state:x};if(x.current_calltree_node.code!=null&&Jp(x.current_calltree_node.code))return{state:x};let Q=vy(x.active_calltree_node),ae,Ee;if(x.current_calltree_node==x.active_calltree_node){if(x.active_calltree_node.toplevel)return{state:x};let Oe=x.active_calltree_node.code;ae=Kb(Oe)[0];let dt=x.snapshots.get_by_module_and_node(vy(x.active_calltree_node).module,Oe)?.get(x.active_calltree_node.id);if(dt==null)return{state:x};Ee=dt.ok?dt:{ok:!1,error:x.active_calltree_node.error}}else{let Oe=gze(x.current_calltree_node,x.active_calltree_node);if(Oe==null)return{state:x};Ee={ok:!0,value:x.current_calltree_node.snapshot.args},ae=[...Oe.arguments];let dt=Oe.getChildren();ae.index=dt.find(Mt=>Mt.kind==$e.SyntaxKind.OpenParenToken).pos,ae.length=dt.find(Mt=>Mt.kind==$e.SyntaxKind.CloseParenToken).pos-ae.index+1}return{state:{...PC(x,{module:Q.module,index:ae.index}),selection_state:{node:ae},value_explorer:{call_id:x.current_calltree_node.id,index:ae.index,length:ae.length,result:Ee}},effects:P?{type:"set_focus"}:null}},Xvt=x=>{let P=[x.current_calltree_node,x.active_calltree_node,yy(x)].find(ae=>gL(ae));if(P==null)return{state:x,effects:[{type:"set_status",args:["no error found"]}]};let Q=f0(P,ae=>gL(ae)&&(ae.children==null||ae.children.every(Ee=>!gL(Ee)||Vte(Ee)&&Ee.children==null)));if(Q==null)throw new Error("illegal state: error origin not found");return $S(LC(x,Q),Q,ae=>{let Ee=cte(ae),Oe=Kbe(ae.active_calltree_node.code,Ee);return{state:PC(ae,{module:vy(Q).module,index:Oe.index}),effects:{type:"set_focus"}}})},Yvt=(x,P)=>{if(x.logs.logs.length==0)return{state:x};let Q=Math.max(Math.min(x.logs.log_position==null?0:x.logs.log_position+P,x.logs.logs.length-1),0);return yze(x,Q)},yze=(x,P)=>{x={...x,logs:{...x.logs,log_position:P}};let Q=f0(x.calltree,ae=>ae.id==x.logs.logs[P].id);return $S(LC(x,Q),Q,ae=>ae.active_calltree_node==null?ae:{...ae,value_explorer:{...ae.value_explorer,result:{...ae.value_explorer.result,is_calltree_node_explorer:!1,value:ae.value_explorer.result.value.args}}})};Wte.calltree={arrow_down:Gvt,arrow_up:Vvt,arrow_left:jvt,arrow_right:Uvt,select_node:Hvt,select_and_toggle_expanded:Kvt,select_return_value:Jvt,select_arguments:qvt,select_error:Xvt,navigate_logs_position:yze,navigate_logs_increment:Yvt,show_value_explorer:Bvt};var jte=class{constructor(P,Q){this.ui=P,this.container=Q,this.container.addEventListener("keydown",ae=>{ae.key=="r"&&(ae.ctrlKey||ae.metaKey)||ae.preventDefault(),ae.key=="Escape"&&this.ui.editor.focus(),ae.key=="F1"&&this.ui.editor.focus_value_explorer(this.container),ae.key=="F2"&&this.ui.editor.focus(),ae.key=="a"&&Ws("calltree.select_arguments"),ae.key=="e"&&Ws("calltree.select_error"),(ae.key=="r"||ae.key=="Enter")&&Ws("calltree.select_return_value"),(ae.key=="ArrowDown"||ae.key=="j")&&Ws("calltree.arrow_down"),(ae.key=="ArrowUp"||ae.key=="k")&&Ws("calltree.arrow_up"),(ae.key=="ArrowLeft"||ae.key=="h")&&Ws("calltree.arrow_left"),(ae.key=="ArrowRight"||ae.key=="l")&&Ws("calltree.arrow_right")})}on_click_node(P,Q){P.target.classList.contains("expand_icon")?Ws("calltree.select_and_toggle_expanded",Q):Ws("calltree.select_node",Q)}clear_calltree(){this.container.innerHTML="",this.node_to_el=new Map,this.state=null}render_loop(P){let{ok:Q,error:ae}=MC(P),Ee;P.code.kind==$e.SyntaxKind.WhileStatement&&(Ee="while"),P.code.kind==$e.SyntaxKind.DoStatement&&(Ee="do while"),(P.code.kind==$e.SyntaxKind.ForInStatement||P.code.kind==$e.SyntaxKind.ForOfStatement||P.code.kind==$e.SyntaxKind.ForStatement)&&(Ee="for");let Oe=P.has_more_children?P.children_count:P.children?.length??0;return Pr("span","call_header "+(Q?"":"error"),Ee+" loop("+Oe+")",Q?null:[": ",Ag(ae)])}render_loop_iteration(P,Q){let{ok:ae,error:Ee}=MC(P),Oe=Q.children.indexOf(P),dt=null;(P.code.kind==$e.SyntaxKind.ForOfStatement||P.code.kind==$e.SyntaxKind.ForInStatement)&&(dt=P.code.initializer.getText()+" = "+Ag(P.args[0]));let Mt=Tte(P.code);return Mt!=null&&(dt=Mt.getText()+" = "+Ag(P.args[0])),Pr("span","call_header "+(ae?"":"error"),Pr("span","loop_step","step "+Oe,(dt!=null||!ae)&&":"),dt,ae?"":Pr("span","call_header error",dt!=null&&":\xA0",Ag(Ee)))}render_node(P,Q){let ae=this.state.calltree_node_is_expanded[P.id],Ee=Pr("div","callnode",Pr("div",{class:"call_el",click:Oe=>this.on_click_node(Oe,P.id)},yL(P)?ae&&P.has_more_children?Pr("div","spinner"):Pr("span","expand_icon",ae?"\u25BC":"\u25B6"):Pr("span","expand_icon_placeholder","\xA0"),P.toplevel?Pr("span",P.ok?"":"call_header error",Pr("i","","toplevel: "+gv(P.module)),P.ok?"":Pr("span","",":\xA0",Ag(P.error))):P.fn.__type=="loop_iteration"?this.render_loop_iteration(P,Q):P.code!=null&&Jp(P.code)?this.render_loop(P):Pr("span","call_header "+(gL(P)?"error":"")+(P.fn.is_hosted?"":" native"),P.is_new?"new ":"",P.context==null||P.is_new?"":Pr("span","",typeof P.context=="object"?P.context.constructor?.name||"":Ag(P.context),"."),P.fn.name==""?"anonymous":P.fn.name,"(",...dL(P.args.map(Oe=>Ag(Oe))),")",": ",P.ok?Ag(P.value):Ag(P.error))),P.children==null||!ae?null:P.children.map(Oe=>this.render_node(Oe,P)));return this.node_to_el.set(P.id,Ee),Ee.is_expanded=ae,Ee}render_active(P,Q){let ae=this.node_to_el.get(P.id).getElementsByClassName("call_el")[0];Q?ae.classList.add("active"):ae.classList.remove("active")}reveal_current_calltree_node(){tW(this.container,this.node_to_el.get(this.state.current_calltree_node.id).getElementsByClassName("call_el")[0])}render_select_node(P,Q){if(P!=null&&this.render_active(P.current_calltree_node,!1),this.state=Q,this.render_active(this.state.current_calltree_node,!0),P?.current_calltree_node!=Q.current_calltree_node){let ae=this.container.scrollLeft;this.reveal_current_calltree_node(),this.container.scrollLeft=ae}}render_expand_node(P,Q){this.state=Q,this.do_render_expand_node(P.calltree_node_is_expanded,Q.calltree_node_is_expanded,yy(P),yy(Q));let ae=rI(P),Ee=rI(Q);if(ae!=null){for(let Oe=0;Oethis.render_node(Q))))))}};var Ute=class{constructor(P,Q){this.el=Q,this.ui=P,this.el.addEventListener("keydown",ae=>{ae.key=="Escape"&&this.ui.editor.focus(),ae.key=="Enter"&&this.ui.editor.focus(),ae.key=="F1"&&this.ui.editor.focus_value_explorer(this.el),ae.key=="F3"&&this.ui.editor.focus(),(ae.key=="ArrowDown"||ae.key=="j")&&(ae.preventDefault(),Ws("calltree.navigate_logs_increment",1)),(ae.key=="ArrowUp"||ae.key=="k")&&(ae.preventDefault(),Ws("calltree.navigate_logs_increment",-1))})}rerender_logs(P,Q){this.el.innerHTML="",this.render_logs(P,null,Q)}render_logs(P,Q,ae){for(let Ee=Q==null?0:Q.logs.length;EeWs("calltree.navigate_logs_position",Ee)},Pr("a",{href:"javascript: void(0)"},dt+": "+(Oe.toplevel?"toplevel":"fn "+(Oe.parent_name==""?"anonymous":Oe.parent_name))+":")," ",...dL(Oe.args.map(Ut=>Ag(Ut)))))}if(Q?.log_position!=ae.log_position&&(Q?.logs==ae.logs&&Q?.log_position!=null&&this.el.children[Q.log_position].classList.remove("active"),ae.log_position!=null)){let Ee=this.el.children[ae.log_position];Ee.classList.add("active"),tW(this.el,Ee)}}};var Hte=class{constructor(P,Q){this.el=Q,this.ui=P,this.el.addEventListener("keydown",ae=>{ae.key=="Escape"&&this.ui.editor.focus(),ae.key=="F4"&&this.ui.editor.focus()})}clear(){this.is_rendered&&(this.el.innerHTML="",this.is_rendered=!1,this.io_trace_length=0,this.io_trace_index=void 0)}render_io_trace(P,Q){if(Q&&(this.is_rendered=!1),this.is_rendered)return;this.is_rendered=!0,this.el.innerHTML="",this.io_trace_length=P.io_trace.length,this.io_trace_index=P.rt_cxt.io_trace_index;let ae=P.io_trace,Ee=P.rt_cxt.io_trace_index??ae.length;for(let Oe=0;Oe ")));else if(dt.type=="call")this.el.appendChild(Pr("div","call_header "+(gL(dt)?"error ":"")+(Mt?"":"native "),dt.name,"(",...dL(dt.args.map(Ut=>Ag(Ut))),"): ",dt.ok?Ag(dt.value):Ag(dt.error)));else throw new Error("unknown item type")}}};var $vt="leporello-js",vze=`https://firebasestorage.googleapis.com/v0/b/${$vt}.appspot.com/o/`;async function Qvt(x){let P=new TextEncoder().encode(x),Q=await crypto.subtle.digest("SHA-256",P);return Array.from(new Uint8Array(Q)).map(Oe=>Oe.toString(16).padStart(2,"0")).join("")}async function bze(x,P){let Q=(await Qvt(P)).slice(0,40),ae=new Blob([P],{type:"text/plain"}),Ee=new FormData;Ee.append("file",ae);let Oe=await fetch(vze+Q,{method:"POST",body:Ee});if(!Oe.ok){let Ut=(await Oe.json())?.error?.message;throw new Error("Failed to upload: "+Ut)}let dt=new URL(window.location);return dt.searchParams.set("share_id",Q),dt.searchParams.set("share_name",x),dt.toString()}async function Zvt(x){let P=await fetch(vze+x+"?alt=media");if(!P.ok){let ae=(await P.json())?.error?.message;throw new Error("Failed to fetch: "+ae)}return P.text()}async function Eze(){let x=new URLSearchParams(window.location.search),P=x.get("share_id");if(P==null)return null;let Q=x.get("share_name")??"";Q.trim()==""&&(Q="Share");let ae=new URL(window.location);ae.searchParams.delete("share_id"),ae.searchParams.delete("share_name"),history.replaceState(null,null,ae.href);try{let Ee=await Zvt(P);return{name:Q,contents:Ee}}catch(Ee){return alert(Ee.message),null}}var Kte=class{constructor(){let Q=yv().current_module.split("/").at(-1);this.el=Pr("dialog","share_dialog",this.upload_begin=Pr("p","",Pr("p","","Uploads your file to the cloud so you can share it with others."),Pr("ul","",Pr("li","","Please ensure that no personal data or confidential information is included."),Pr("li","","Avoid including copyrighted materials.")),Pr("span",{style:"color: red"},"Caution: Once shared, files cannot be deleted."),Pr("div","share_name",Pr("label","","Public file name"),this.share_name=Pr("input",{type:"text",value:Q})),this.upload_buttons=Pr("p",{style:"text-align: center"},Pr("button",{class:"upload_button",click:()=>this.upload()},"Upload"),this.cancel_button=Pr("button",{style:"margin-left: 1em",click:()=>this.el.close()},"Cancel"))),this.uploading=Pr("span",{style:"display: none"},"Uploading..."),this.upload_finish=Pr("p",{style:"display: none"},Pr("p","",Pr("p",{style:` + `),Oe}),cW(function ae(Ee){return Ee.kind==$e.SyntaxKind.DebuggerStatement?null:$e.visitEachChild(Ee,ae)})]).transformed[0]},j3e=(x,P,Q,ae,Ee,Oe,dt,Mt,Ut,Wt,gr)=>{let ti=globalThis.app_window.Function,qr=globalThis.app_window.eval("(async function(){})").constructor,Lr=x.sorted.map(gs=>{let Za=x.modules[gs],md={module:gs,toplevel:Za,breakpoint:Wt,current_function:Za,should_collect_footprints:Ut};Za=mvt(Za,md);let Gd=Gm`"use strict";let __obj, __fn, __tmp;`;Za=$e.factory.updateSourceFile(Za,[...Gd,...Cte(Za,md),...Za.statements]);let by=$e.transformNodes(x.program.getTypeChecker().getEmitResolver(),void 0,$e.factory,DC,[Za],[$e.transformJsx],!1).transformed;if(by.length!=1)throw new Error("illegal state");Za=by[0];let kC=pvt.printFile(Za),Ol=vG(Za)?qr:ti,ki;try{ki=new Ol("__cxt","__rt",kC)}catch(nu){throw new Error(nu.message,{cause:nu})}return{module:gs,fn:ki}}),oa={logs:[],deferred_calls:[],modules:P==null?{}:Z4e(P,(gs,{module:Za})=>Za),call_counter:0,version_counter:0,children:null,stack:new Array,is_recording_deferred_calls:!1,on_deferred_call:(gs,Za,md)=>Q(O3e(x.modules,gs),Za,md),execution_id:ae,is_toplevel_call:!0,window:globalThis.app_window,storage:dt,canvas_ops:{ops:[],contexts:new Set},snapshots:Mt,footprints:new Map,breakpoint:Wt,selected_call_id:Wt.selected_call_id,io_trace:Ee,io_trace_is_recording:Oe},Zo=w3e(Lr,oa);Zo?.[Symbol.toStringTag]=="Promise"&&(Zo=new Promise((gs,Za)=>{Promise.prototype.then.call(Zo,gs,Za)})),gr||(Zo=Promise.resolve(Zo));let fs=gs=>{let Za=O3e(x.modules,dte(gs.calltree,oa.deferred_calls.length==0?null:oa.deferred_calls));return{...gs,breakpoint:Wt,calltree:Za}};return Zo?.[Symbol.toStringTag]=="Promise"?Promise.all([Zo,new Promise(gs=>setTimeout(gs,0))]).then(([gs])=>fs(gs)):fs(Zo)},_vt=(x,P)=>{let Q=$e.forEachChildRecursively(x,ae=>{if(ae.index==P.index&&ae.length==P.length&&(lp(ae)||Jp(ae)))return ae});if(Q==null)throw new Error("illegal state");return Q},O3e=(x,P)=>{let Q=new Map;function ae(Ee){if(Ee.toplevel)return{...Ee,code:x[Ee.module],children:Ee.children&&Ee.children.map(ae)};{let Oe;if(Ee.fn==null||Ee.fn.__location==null)Oe=null;else if(Oe=Q.get(Ee.fn.__location),Oe==null){let dt=JSON.parse(Ee.fn.__location);Oe=_vt(x[dt.module],dt),Q.set(Ee.fn.__location,Oe)}return{...Ee,code:Oe,children:Ee.children&&Ee.children.map(ae)}}}return ae(P)},tEe=(x,P,Q)=>x.kind==$e.SyntaxKind.AwaitExpression&&!Q&&!P.toplevel&&P.value.status==null,Qbe=class extends Map{get(P){return P=CC(P)?P.original:P,super.get(P)}},nEe=(x,P,Q,ae,Ee)=>{Ee??=new Qbe;let Oe=hvt(x,P,Q,ae,Ee);return Ee.set(x,Oe.result),Ee},hvt=(x,P,Q,ae,Ee)=>{let Oe=qr=>nEe(qr,P,Q,x,Ee),dt=qr=>Q.get(qr.index+"_"+qr.length),Mt=dt(x);if(x.kind==$e.SyntaxKind.VariableDeclarationList&&x.parent.kind==$e.SyntaxKind.VariableStatement&&(Mt=dt(x.parent)),ae?.kind==$e.SyntaxKind.PropertyAccessExpression&&ae.name==x&&(Ee.get(ae.expression)?.ok?Mt=!0:Mt=void 0),(ae?.kind==$e.SyntaxKind.PropertyAssignment||ae?.kind==$e.SyntaxKind.ShorthandPropertyAssignment)&&ae.name==x&&dt(ae.parent)!=null&&(Mt=!0),tEe(x,P,Mt)&&(Mt=void 0),lp(x)){if(ae!=null)return{result:Mt==null?void 0:{ok:Mt}};{let[qr,Lr]=Kb(x);return dt(qr)?(Ee.set(qr.original,{ok:!0}),Oe(Lr)):Ee.set(qr.original,{ok:!1,is_error_origin:!0}),{result:{ok:Ee.get(Lr)?.ok}}}}if(Jp(x)&&ae!=null)return(x.kind==$e.SyntaxKind.ForOfStatement||x.kind==$e.SyntaxKind.ForInStatement)&&Oe(x.expression),x.kind==$e.SyntaxKind.ForStatement&&Oe(x.initializer),Mt==null?{result:void 0}:{result:{ok:Mt,is_error_origin:!Mt}};if(G3e(x)&&!(x.kind==$e.SyntaxKind.Block||x.kind==$e.SyntaxKind.SourceFile)&&ae!=null&&Mt==null)return{result:void 0};if(ae!=null&&bG(x,ae))if(x.kind==$e.SyntaxKind.PropertyAccessExpression||x.kind==$e.SyntaxKind.ElementAccessExpression){let qr=Kb(x);return qr.map(oa=>Oe(oa)),{result:{ok:qr.every(oa=>Ee.get(oa)?.ok)}}}else Mt=!0;if(x.kind==$e.SyntaxKind.VariableDeclaration){let[qr,Lr]=[x.name,x.initializer];return Lr!=null&&Oe(Lr),(Lr==null||Ee.get(Lr)?.ok)&&Oe(qr),{result:{ok:Mt,is_error_origin:Mt?void 0:Ee.get(Lr)?.ok}}}let Ut=Kb(x);Ut&&Ut.map(qr=>Oe(qr));let Wt=Ut==null||Ut.every(qr=>Ee.get(qr)?.ok),gr=!Mt&&Wt;if((x.kind==$e.SyntaxKind.Block||x.kind==$e.SyntaxKind.SourceFile)&&(Ut.length!=0&&(Mt=Ut.reduce((qr,Lr)=>qr&&Ee.get(Lr)?.ok,!0)),gr=!1),x.kind==$e.SyntaxKind.PartiallyEmittedExpression||x.kind==$e.SyntaxKind.ExpressionStatement||x.kind==$e.SyntaxKind.ParenthesizedExpression||x.kind==$e.SyntaxKind.JsxExpression){if(Ut.length!=1)throw new Error("illegal state");let qr=Ee.get(x.expression);return{result:qr==null?null:{...qr,is_error_origin:!1}}}if(x.kind==$e.SyntaxKind.IfStatement&&(Mt=dt(x.expression),Ut.some(qr=>Ee.get(qr)?.ok===!1)&&(Mt=!1)),Jp(x)&&ae==null){if(x.kind==$e.SyntaxKind.ForOfStatement||x.kind==$e.SyntaxKind.ForInStatement){let qr=x.statement;Oe(qr);let Lr=Ee.get(qr)!=null;Ee.set(x.initializer,{ok:Lr,is_error_origin:!Lr})}return{result:void 0}}return[$e.SyntaxKind.ReturnStatement,$e.SyntaxKind.BreakStatement,$e.SyntaxKind.ContinueStatement].includes(x.kind)&&(Mt!=null&&(Mt=Wt),gr=!1),x.kind==$e.SyntaxKind.PropertyAssignment||x.kind==$e.SyntaxKind.ShorthandPropertyAssignment||x.kind==$e.SyntaxKind.SpreadElement||x.kind==$e.SyntaxKind.SpreadAssignment||x.kind==$e.SyntaxKind.JsxSpreadAttribute?{result:{ok:Wt}}:{result:Mt===void 0?void 0:{ok:Mt,is_error_origin:Mt?void 0:gr}}};function U3e(x){return new Map([...x.entries()].map(([P,Q])=>[P,structuredClone(Q)]))}var EG=class extends Map{set(P,Q){if(structuredClone(Q),typeof P!="string")throw new Error("key must be a string");super.set(P,Q)}};var dW=class extends Map{get_by_module_and_node(P,Q){if(Q.index==null||Q.length==null)throw new Error("illegal state");return this.get(`${P}_${Q.index}_${Q.length}`)}set_by_module_and_node(P,Q,ae){if(Q.index==null||Q.length==null)throw new Error("illegal state");return this.set(`${P}_${Q.index}_${Q.length}`,ae)}};var H3e=x=>x.kind==$e.SyntaxKind.ExpressionStatement?x.expression:x.kind==$e.SyntaxKind.NotEmittedStatement||x.kind==$e.SyntaxKind.EmptyStatement?null:x.kind==$e.SyntaxKind.ReturnStatement?x.expression==null?x:x.expression:x.kind=="export"?H3e(x.children[0]):x,Pte=(x,P)=>{let Q=lp(x);if(Q){let Ut=Kb(x)[0];if(fL(Ut,P))return x.parameters.length>0?Ut:null}let ae=XS(x,P),Ee=ae==null||(ae.kind==$e.SyntaxKind.Block||ae.kind==$e.SyntaxKind.SourceFile)&&P>ae.index?XS(x,P-1):ae;if(Ee==null||Ee.kind==$e.SyntaxKind.Block||x==Ee||x.name==Ee)return null;let Oe=aW(Ee,x);for(let Ut of Oe){if(lp(Ut))break;if(Ut.kind==$e.SyntaxKind.JsxExpression||Ut.kind==$e.SyntaxKind.JsxSpreadAttribute)return Ut.expression;if(Gbe(Ut))return Ut}if(Q&&x.body.kind!=$e.SyntaxKind.Block)return x.body;if(Oe.find(Ut=>Ut!=x&&Ut!=Ee&&(lp(Ut)||Jp(Ut)))!=null)return null;if(Jp(x)&&Oe.includes(x.expression))return x.expression;if(x.kind==$e.SyntaxKind.ForStatement&&Oe.includes(x.incrementor))return x.incrementor;if(x.kind==$e.SyntaxKind.ForStatement&&Oe.includes(x.condition))return x.condition;let Mt=$e.forEachAncestor(Ee,Ut=>{if(Ut.parent.kind==$e.SyntaxKind.IfStatement&&Ut.parent.expression==Ut||$e.isStatement(Ut))return Ut});return H3e(Mt)};var tu={parse:"parse",reload_app_window:"reload_app_window",reload_app_window_finished:"reload_app_window_finished",load_external_imports:"load_external_imports",eval_modules:"eval_modules",eval_modules_finished:"eval_modules_finished"},q3e=(x,P)=>{let Q=new Set(x),ae=new Map,Ee=(Oe,dt)=>{if(Oe.children!=null)for(let Mt of Oe.children)Ee(Mt,Oe.code!=null&&Jp(Oe.code)?dt:Oe);Q.has(Oe.id)&&ae.set(Oe.id,{id:Oe.id,version_number:Oe.version_number,toplevel:dt.toplevel,module:vy(dt)?.module,parent_name:dt.fn?.name,args:Oe.args,log_fn_name:Oe.fn.name})};return Ee(P,null),x.map(Oe=>ae.get(Oe))},gvt=x=>x.run_state?.status!=tu.reload_app_window?_L({...x,run_state:{status:tu.reload_app_window_finished}},!1):x.run_state.on_reload_app_window_finished(x),Lte=(x,P,Q)=>({function_node:P,module:x,selected_node:Q}),X3e=x=>{let P=hL(x),Q=Bte(x,x.current_module,P),ae=Pte(Q,P);return Lte(x.current_module,Q,ae)},kte=x=>{if(x.parse_result.modules[x.current_module]==null)return Lte(x.current_module,x.parse_result.modules[x.entrypoint],null);let P=X3e(x);return Y3e(x,P)},Y3e=(x,P)=>{let Q;return P.function_node==x.active_calltree_node?.code?Q=x.active_calltree_node:x.calltree!=null&&x.deepest_calltree_node_id!=null&&(Q=aEe(x.calltree,x.deepest_calltree_node_id).findLast(ae=>ae.code==P.function_node&&(!Jp(ae.code)||ae.fn.__type=="loop_iteration"))),Q==null?x.active_calltree_node!=null&&(P={...P,parent_calltree_node:x.active_calltree_node}):P={...P,selected_call_id:Q.id},P},_L=(x,P,Q)=>{let ae=x.active_calltree_node;if(x={...x,calltree:null,modules:null,execution_id:x.execution_id+1,rt_cxt:null,logs:null,current_calltree_node:null,active_calltree_node:null,deepest_calltree_node_id:null,calltree_node_is_expanded:null,collected_footprints_functions:new Set,frames:new Map,colored_frames:null,frame_coloring:new Map,selection_state:null,value_explorer:null,snapshots:new dW,subcalls:new Map,footprints:null},P){let Ee={status:tu.parse,prev_status:x.run_state?.status};return Q&&(Ee={...Ee,prev_active_calltree_node:ae}),{...x,run_state:Ee}}return $3e(x,P)},$3e=(x,P,Q)=>{P&&(x={...x,parse_result:h3e(x.entrypoint,Q)});let ae=P?{status:x.run_state.prev_status,prev_active_calltree_node:x.run_state.prev_active_calltree_node}:x.run_state;return x={...x,run_state:ae},x.parse_result.ok?x.run_state?.status==tu.reload_app_window_finished?K3e(x):{...x,run_state:{status:tu.reload_app_window,on_reload_app_window_finished:K3e,reload_counter:x.run_state?.reload_counter,prev_active_calltree_node:x.run_state.prev_active_calltree_node}}:x},K3e=x=>{let P=kte(x),Q=x.run_state.prev_active_calltree_node;if(Q!=null&&Q.kind!=$e.SyntaxKind.SourceFile&&P.function_node.kind!=$e.SyntaxKind.SourceFile){let ae=Q.code.getSourceFile().text,Ee=x.run_state.prev_active_calltree_node.code,Oe=x.files[x.current_module],dt=P.function_node;ae.slice(0,Ee.index)==Oe.slice(0,dt.index)&&ae.slice(Ee.index+Ee.length)==Oe.slice(dt.index+dt.length)&&(P={...P,selected_call_id:Q.id})}return x={...x,run_state:{breakpoint:P,on_eval_modules_finished:eze}},TG(x)},TG=x=>{let P=t3e(jbe(x.parse_result.modules).map(Q=>Q.url));return P.length!=0?{...x,run_state:{...x.run_state,status:tu.load_external_imports,external_imports:P}}:Q3e(x,x)},Q3e=(x,P,Q)=>{if(x.run_state!=P.run_state)return x;if(Q!=null){let Mt=new Set(Object.entries(Q).filter(([Ut,Wt])=>!Wt.ok).map(([Ut,Wt])=>Ut));if(Mt.size!=0){let Ut=jbe(x.parse_result.modules).filter(({url:Wt})=>Mt.has(Wt)).map(({node:Wt,module_name:gr,url:ti})=>({index:Wt.index,length:Wt.length,message:Q[ti].error.message,module:gr}));return{...x,parse_result:{...x.parse_result,ok:!1,problems:Ut,is_external_imports_problems:!0},run_state:{status:tu.eval_modules_finished}}}}let ae=new dW([...x.snapshots.entries()].map(([Mt,Ut])=>[Mt,Ut==null?Ut:new Map(Ut)])),Ee=x.run_state.on_eval_modules_finished!=eze;!Ee&&x.is_open_app_window&&(x={...x,io_trace:[]});let Oe=x.io_trace.length==0&&!Ee,dt=j3e(x.parse_result,Q,x.on_deferred_call,x.execution_id,x.io_trace,Oe,U3e(Ee?x.prev_storage:x.storage),ae,!x.collected_footprints_functions.has(x.run_state.breakpoint.function_node),x.run_state.breakpoint,x.allow_sync_execution);return dt.then==null&&x.allow_sync_execution?Z3e(x,x.execution_id,dt):{...x,run_state:{...x.run_state,status:tu.eval_modules,promise:dt}}},Z3e=(x,P,Q)=>{if(x.execution_id!=P)return x;if(x.calltree!=null){if(Q.rt_cxt.io_trace_is_replay_aborted)throw new Error("illegal state");if(Q.rt_cxt.call_counter!=x.rt_cxt.call_counter)throw new Error("illegal state: bad replay, call_counter do not match");x={...x,calltree:mze(x.calltree,Q.calltree)}}let ae=Q.rt_cxt.snapshots,Ee=Q.breakpoint,Oe=Ee.function_node.kind==$e.SyntaxKind.SourceFile?[Ee.selected_node]:[Ee.selected_node,Ee.function_node];for(let Mt of Oe){let Ut=[Ee.module,Mt];Mt!=null&&ae.get_by_module_and_node(...Ut)===void 0&&ae.set_by_module_and_node(...Ut,null)}for(let Mt of[Q.rt_cxt.selected_call_id,Q.rt_cxt.first_call_id])if(Ee.selected_node!=null&&Mt!=null){let Ut=ae.get_by_module_and_node(Ee.module,Ee.selected_node);Ut!=null&&Ut.get(Mt)===void 0&&Ut.set(Mt,null)}if(Ee.parent_calltree_node!=null){let Mt=x.subcalls.get(Ee.parent_calltree_node.id);Mt==null&&(Mt=new Map,x.subcalls.set(Ee.parent_calltree_node.id,Mt)),Mt.set(Ee.function_node,Q.rt_cxt.selected_call_id??null)}let dt={...x,snapshots:ae,footprints:new Map([...x.footprints??[],...Q.rt_cxt.footprints]),rt_cxt:Q.rt_cxt,run_state:{status:tu.eval_modules_finished}};if(x.run_state.breakpoint.function_node==null)throw new Error("illegal state");return x.collected_footprints_functions.add(x.run_state.breakpoint.function_node),x.run_state.on_eval_modules_finished(dt,Q,x.run_state.breakpoint)},eze=(x,P,Q)=>{if(P.rt_cxt.io_trace_is_replay_aborted)return cze(x);if(x={...x,calltree:P.calltree,rt_cxt:P.rt_cxt,logs:{logs:q3e(P.logs,P.calltree),log_position:null},modules:P.modules,prev_storage:x.storage,storage:P.rt_cxt.storage},x=lze(x,P,Q),x.active_calltree_node==null){let{node:ae,state:Ee}=zte(x);x=uW(Ee,null,ae)}else x=_ze(LC(x,x.active_calltree_node));if(x.run_state.status==tu.reload_app_window)return x;if(x.run_state.status!=tu.eval_modules_finished)throw new Error("illegal state");return x},yvt=(x,P,Q)=>{let ae={...x.files,[x.current_module]:P};x={...x,files:ae},x=Fte(x,Q);let Ee={type:"write",args:[x.current_module,x.files[x.current_module]]};return{state:_L(x,!0,!0),effects:[Ee]}},oEe=(x,P)=>{if(!x.parse_result.ok)return{state:x,effects:{type:"set_status",args:["invalid syntax"]}};if(x.calltree==null)return{state:x,effects:{type:"set_status",args:["code is executing"]}};let Q=Bte(x,x.current_module,P);if(Q==null||Q.kind==$e.SyntaxKind.SourceFile&&Q!=mL(x)||lp(Q)&&x.snapshots.get_by_module_and_node(x.current_module,Q)===null)return{state:x,effects:{type:"set_status",args:["code was not reached during program execution"]}}},vvt=(x,P)=>{let Q=x.parse_result.modules[x.current_module],ae=XS(Q,P);if(ae==null)return null;let Ee=aW(ae,Q).find(Oe=>Oe.kind==$e.SyntaxKind.CallExpression||Oe.kind==$e.SyntaxKind.NewExpression||lp(Oe));return Ee==null||lp(Ee)?null:Ee},bvt=x=>{let P=hL(x),Q=oEe(x,P);if(Q!=null)return Q;let ae=vvt(x,P);if(ae==null)return{state:x,effects:{type:"set_status",args:["no function call to step into"]}};if(x.run_state.status!=tu.eval_modules_finished)return{state:x,effects:{type:"set_status",args:["code is not executed yet"]}};let Ee=sEe(x.active_calltree_node,ae);if(Ee==null){let Oe=cte(x),dt;return Oe.get(ae)==null?dt="call was not reached during program execution":dt="Cannot step into: function is either builtin or from external lib",{state:x,effects:{type:"set_status",args:[dt]}}}return AG(x,!0,Ee)},tze=x=>{if(x.kind==$e.SyntaxKind.SourceFile)return!1;if(x.parent==null)throw new Error("illegal state");let P=x.parent;return $e.isExpression(x)&&x.kind!=$e.SyntaxKind.SpreadAssignment&&x.kind!=$e.SyntaxKind.SpreadElement&&P?.kind!=$e.SyntaxKind.ShorthandPropertyAssignment&&P?.kind!=$e.SyntaxKind.ImportDeclaration&&P?.kind!=$e.SyntaxKind.ImportClause&&P?.kind!=$e.SyntaxKind.ImportSpecifier&&P?.kind!=$e.SyntaxKind.NamespaceImport&&(P==null||!bG(x,P))&&!(P!=null&&P.kind==$e.SyntaxKind.PropertyAccessExpression&&P.name==x)&&!(P!=null&&P.kind==$e.SyntaxKind.PropertyAssignment&&x==P.name)&&P?.kind!=$e.SyntaxKind.JsxAttribute&&!(P!=null&&(P.kind==$e.SyntaxKind.JsxOpeningElement||P.kind==$e.SyntaxKind.JsxClosingElement)&&x.kind==$e.SyntaxKind.Identifier&&$e.isIntrinsicJsxName(x.escapedText))&&!(P!=null&&oW(P)&&oW(x))},J3e=x=>x.find(P=>tze(P)),Evt=(x,P,Q,ae)=>{if(XS(P,ae)==null)return{ok:!1,message:"out of scope"};if(x!=null&&x.index==ae){let Oe;if(x.initial_is_expand==Q)x.node==P?Oe=x.node:(Oe=J3e(Ube(x.node,P)),(Oe==null||!$e.isExpression(Oe))&&(Oe=x.node));else{let Mt=XS(x.node,ae);Mt!=x.node?(Oe=aW(Mt,x.node).findLast(Wt=>Wt!=x.node&&tze(Wt)),Oe==null&&(Oe=x.node)):Oe=x.node}return{ok:!0,initial_is_expand:x.initial_is_expand,node:Oe,function_node:x.function_node,index:ae}}else{let Oe=XS(P,ae),dt=J3e(aW(Oe,P));return dt==null||!$e.isExpression(dt)?{ok:!1,message:"can only evaluate expression, not statement"}:{ok:!0,index:ae,function_node:P,node:dt,initial_is_expand:Q}}},Svt=(x,P,Q)=>{let ae=oEe(x,P);if(ae!=null)return ae;let Ee=Bte(x,x.current_module,P);if(Ee==null)throw new Error("not implemented");let Oe=Evt(x.selection_state,Ee,Q,P),dt={...x,selection_state:Oe,value_explorer:null};if(!Oe.ok)return{state:dt,effects:{type:"set_status",args:[Oe.message]}};let Mt=Y3e(x,Lte(x.current_module,Ee,Oe.node));return nze(dt,Mt,!0)},SG=(x,P,Q,ae)=>{let Ee=x.snapshots.get_by_module_and_node(P,Q);if(Ee===null)return{has_snapshot:!0,node_snapshot:null};if(Ee===void 0)return{has_snapshot:!1};let Oe=Ee.get(ae);return{has_snapshot:Oe!==void 0,node_snapshot:Oe}},rEe=(x,P,Q,ae=void 0)=>{let Ee=x.snapshots.get_by_module_and_node(P,Q);if(Ee===null)return{has_snapshot:!0,node_snapshot:null};if(Ee===void 0)return{has_snapshot:!1};if(ae!=null){let Mt=Ee.get(ae);if(Mt!=null)return{has_snapshot:!0,node_snapshot:Mt};if(Mt===void 0)return{has_snapshot:!1}}let[Oe,dt]=[...Ee.entries()].sort((Mt,Ut)=>Mt[0]-Ut[0]).find(([Mt,Ut])=>Ut!=null);if(Oe==null)throw new Error("illegal state");return{has_snapshot:!0,node_snapshot:dt}},nze=(x,P)=>(x=sze(x,P),x.run_state.status==tu.reload_app_window?{...x,run_state:{...x.run_state,on_eval_modules_finished:Tvt}}:x.value_explorer!=null?x:{state:x,effects:{type:"set_status",args:["expression was not reached during program execution"]}}),Tvt=(x,P,Q)=>x.selection_state==null||x.value_explorer!=null?x:nze(x,Q,!1),Avt=(x,P)=>x.files[P]==null?{state:x,effects:{type:"set_status",args:["File not found"]}}:{...x,current_module:P,selection_state:null,value_explorer:null},Ivt=(x,P,Q=P)=>_L({...x,entrypoint:P,current_module:Q},!0),xvt=(x,P)=>_L({...x,html_file:P},!0),Rvt=(x,P)=>({state:rze(PC(x,P),P.index),effects:{type:"set_focus"}}),Dvt=(x,P)=>({state:PC(x,P),effects:{type:"set_focus"}}),rze=(x,P)=>(x=Fte(x,P),x={...x,selection_state:null,value_explorer:null},oEe(x,P)!=null?x:Ote(x,kte(x),ize,!0)),wte=(x,P,Q,ae)=>{let Ee=ae.call_id;if(Ee==null)throw new Error("illegal state");let Oe=f0(x.calltree,Mt=>Mt.id==Ee);if(tEe(Q,Oe,ae.ok)||[$e.SyntaxKind.BreakStatement,$e.SyntaxKind.ContinueStatement].includes(Q.kind))return null;let dt;if(ae.ok)dt=void 0;else{let Mt=MC(Oe);if(Mt==null)return null;dt=Mt.error}return{call_id:Ee,index:Q.index,length:Q.length,result:{ok:ae.ok,value:ae.value,error:dt}}},iEe=(x,P)=>f0(x,Q=>MC(Q)?.ok==!1&&Q.code==P&&(!Jp(Q.code)||Q.fn.__type=="loop_iteration")),ize=(x,P)=>{function Q(){return{...x,run_state:{status:tu.reload_app_window,reload_counter:(x.run_state.reload_counter??0)+1,on_reload_app_window_finished:TG,on_eval_modules_finished:Nvt,breakpoint:P}}}let ae;if(P.selected_call_id!=null)ae=P.selected_call_id;else{if(P.parent_calltree_node!=null){let Mt=iEe(P.parent_calltree_node,P.function_node),Ut;if(Mt!=null?Ut=Mt.id:Ut=x.subcalls.get(P.parent_calltree_node.id)?.get(P.function_node),Ut===void 0)return Q();Ut!=null&&(ae=Ut)}if(ae==null){let Mt=iEe(x.calltree,P.function_node);if(Mt!=null)ae=Mt.id;else{let Ut;if(P.function_node==mL(x))ae=yy(x).id,Ut=x.footprints.get(ae)==null;else{let{has_snapshot:Wt,node_snapshot:gr}=rEe(x,P.module,P.function_node);if(Ut=!Wt,Wt)if(gr!=null)ae=gr.call_id;else return Mte({...x,value_explorer:null},P.function_node,null)}if(Ut&&P.parent_calltree_node!=null)throw new Error("illegal state: replay cannot be required here");if(Ut)return Q()}}}if(ae==null)throw new Error("illegal state: selected_call_id is null");let Ee;if(P.function_node==mL(x))Ee=x.footprints.get(ae)==null;else{let{has_snapshot:Mt}=SG(x,P.module,P.function_node,ae);Ee=!Mt}if(Ee)return P={...P,selected_call_id:ae},Q();let Oe,dt=P.selected_node;if(dt!=null){let{has_snapshot:Mt,node_snapshot:Ut}=SG(x,P.module,CC(P.selected_node)?P.function_node:P.selected_node,ae);if(Mt)Ut==null?Oe={is_jump_here:!0,index:dt.index,length:dt.length}:Oe=wte(x,P.function_node,dt,Ut);else return Q()}else Oe=null;return Mte({...x,value_explorer:Oe},P.function_node,ae)},oze=x=>{if(!x.value_explorer?.is_jump_here)return x;let P;return x.selection_state==null?P=X3e(x):P=Lte(x.current_module,x.selection_state.function_node,x.selection_state.node),Ote(x,P,Cvt,!0)},Cvt=(x,P)=>{if(P.selected_node==null)throw new Error("illegal state");let Q=x;return x=aze(x,P,!0),Q==x?{state:x,effects:{type:"set_status",args:["code was not reached during program execution"]}}:x.run_state.status==tu.reload_app_window?{...x,run_state:{...x.run_state,on_eval_modules_finished:oze}}:x},Ote=(x,P,Q)=>{if(P.function_node.kind==$e.SyntaxKind.SourceFile&&P.function_node!=mL(x)||(x=Q(x,P),x.effects!=null)||x.run_state.status==tu.reload_app_window||x.value_explorer==null||x.value_explorer.is_jump_here||!x.value_explorer.result.ok)return x;let ae=P.selected_node;if(ae.kind!=$e.SyntaxKind.CallExpression)return x;let Ee=sEe(x.active_calltree_node,P.selected_node);if(Ee==null||!Ee.is_log)return x;let{has_snapshot:Oe,node_snapshot:dt}=SG(x,P.module,eEe(ae),x.value_explorer.call_id);if(!Oe)throw console.error({state:x,breakpoint:P,calltree_node:Ee,has_snapshot:Oe,node_snapshot:dt}),new Error("illegal state: no node snapshot for log fn args");if(!dt.ok)throw console.error({state:x,breakpoint:P,calltree_node:Ee,has_snapshot:Oe,node_snapshot:dt}),new Error("illegal state: node snapshot with ok: false for log fn args");let Mt={...x.value_explorer,result:{ok:!0,value:dt.value}};return{...x,value_explorer:Mt}},aze=(x,P,Q)=>{if(Q||P.selected_call_id==null){let dt=iEe(x.calltree,P.function_node);dt!=null&&(P={...P,selected_call_id:dt.id})}let ae=P.selected_node,{has_snapshot:Ee,node_snapshot:Oe}=ae==null?{has_snapshot:!0,node_snapshot:null}:rEe(x,P.module,CC(P.selected_node)?P.function_node:P.selected_node,P.selected_call_id);if(Ee){let dt=!1,Mt,Ut;if(Oe==null){if(Q)return x;if(Mt=null,P.function_node==mL(x))Ut=yy(x).id,dt=x.footprints.get(Ut)==null;else{let{has_snapshot:Wt,node_snapshot:gr}=rEe(x,P.module,P.function_node,P.selected_call_id);dt=!Wt,Ut=gr?.call_id}}else Ut=Oe.call_id,Mt=wte(x,P.function_node,ae,Oe);if(!dt)return Mte({...x,value_explorer:Mt},P.function_node,Ut)}return{...x,run_state:{status:tu.reload_app_window,reload_counter:(x.run_state.reload_counter??0)+1,on_reload_app_window_finished:TG,breakpoint:P}}},sze=(x,P)=>(x=aze(x,P,!1),x.run_state.status==tu.reload_app_window?{...x,run_state:{...x.run_state,on_eval_modules_finished:lze}}:x),lze=(x,P,Q)=>{let ae=kte(x);return Q.selected_call_id!=null&&ae.function_node==Q.function_node&&(ae={...Q,selected_call_id:Q.selected_call_id}),Ote(x,ae,sze,!0)},Nvt=x=>x.selection_state!=null||x.value_explorer!=null?x:Ote(x,kte(x),ize,!0),Pvt=(x,P,Q,ae)=>x.execution_id!=Q||(x={...x,snapshots:new dW,footprints:new Map,collected_footprints_functions:new Set,calltree:dte(yy(x),[...rI(x)??[],P]),logs:{...x.logs,logs:x.logs.logs.concat(q3e(ae,P))}},P.ok)?x:zte(x,P).state,cze=x=>_L({...x,io_trace:[],run_state:{...x.run_state,reload_counter:(x.run_state.reload_counter??0)+1}},!1),dze=(x,P)=>{let Q=Ee=>Ee.kind=="file"?[Ee]:Ee.children.map(Q).flat(),ae=Object.fromEntries([...Q(P.scratch_files),...P.local_files==null?[]:Q(P.local_files)].map(Ee=>[Ee.path,Ee.contents]));return{...x,project_dir:P,files:ae}},uze=(x,P)=>(x=dze(x,P),x=pze(x),_L(x,!0)),Mvt=(x,P,Q)=>{let ae={...x.project_dir,scratch_files:P};return x={...x,current_module:Q,entrypoint:Q},uze(x,ae)},pze=x=>{let P=x.project_dir.scratch_files.children[0];return{...x,current_module:x.files[x.current_module]==null?P.path:x.current_module,entrypoint:x.files[x.entrypoint]==null?P.path:x.entrypoint,html_file:x.files[x.html_file]==null?null:x.html_file}},fze=(x,P)=>{let Q={...x.project_dir,local_files:P};return uze(x,Q)},Lvt=(x,P,Q)=>fze({...x,current_module:Q,entrypoint:Q},P),kvt=(x,P)=>({...x,storage:new EG,is_open_app_window:P}),wvt=(x,P=0)=>(x=dze(x,x.project_dir),x=pze(x),_L({...x,execution_id:0,storage:new EG,io_trace:[],is_open_app_window:!1,cursor_position_by_file:{[x.current_module]:P}},!0)),Wte={get_initial_state:wvt,parse_finished:$3e,input:yvt,open_app_window:kvt,load_local_dir:fze,create_local_file:Lvt,load_scratch_dir:Mvt,step_into:bvt,change_current_module:Avt,change_entrypoint:Ivt,change_html_file:xvt,goto_location:Rvt,goto_problem:Dvt,move_cursor:rze,jump_here:oze,eval_selection:Svt,reload_app_window_finished:gvt,external_imports_loaded:Q3e,eval_modules_finished:Z3e,on_deferred_call:Pvt,clear_io_trace:cze};var hL=x=>x.cursor_position_by_file[x.current_module]??0,Fte=(x,P)=>({...x,cursor_position_by_file:{...x.cursor_position_by_file,[x.current_module]:P}});var PC=(x,P)=>Fte({...x,current_module:P.module},P.index),Ovt=x=>x.error?.constructor==lW.constructor&&x.error?.message==lW.message,gL=x=>!x.ok||x.value?.[Symbol.toStringTag]=="Promise"&&x.value.status!=null&&!x.value.status.ok,MC=x=>x.value?.[Symbol.toStringTag]=="Promise"?x.value.status:x,vy=x=>x.toplevel?{module:x.module}:x.fn.__location&&JSON.parse(x.fn.__location),Wvt=x=>yy(x).module,mL=x=>x.parse_result.modules[Wvt(x)],Vte=x=>!x.toplevel&&!x.fn.is_hosted,Fvt=(x,P)=>x?.[P.module]?.[P.index??-1],zvt=(x,P,Q)=>({...x,[P.module]:{...x?.[P.module],[P.index??-1]:Q}}),aEe=(x,P)=>{let Q=[{node:x,child_index:0}];for(;;){if(Q.length==0)return null;let ae=Q.at(-1);if(ae.node.id==P)return Q.map(Ee=>Ee.node);if(ae.node.children==null||ae.child_index>=ae.node.children.length){Q.pop();continue}Q.push({node:ae.node.children[ae.child_index],child_index:0}),ae.child_index++}},uW=(x,P,Q=x.current_calltree_node)=>{let ae=x.deepest_calltree_node_id;return ae==null?ae=Q?.id:aEe(x.calltree,ae).includes(Q)||(ae=Q.id),{...x,active_calltree_node:P,current_calltree_node:Q,deepest_calltree_node_id:ae}},lEe=(x,P,Q=P)=>{let ae=vy(P);if(Fvt(x.colored_frames,ae)!=P.id){x={...x,colored_frames:zvt(x.colored_frames,ae,P.id)};let Oe=x.frames.get(P.id);if(Oe==null){let dt=x.footprints.get(P.id);if(dt==null)throw new Error("illegal state");if(P.code!=null&&Jp(P.code)&&P.fn?.__type!="loop_iteration")throw new Error("illegal state");Oe=nEe(P.code,P,dt);let Mt=y3e(P.code,Oe);x.frames.set(P.id,Oe),x.frame_coloring.set(P.id,Mt)}}return uW(x,P,Q)},mze=(x,P)=>Gte(x,P)[1],Gte=(x,P)=>{if(x.id!=P.id)throw new Error("illegal state: merge_calltree");if(x.callsite_location==null&&P.callsite_location!=null)return[!0,Gte({...x,callsite_location:P.callsite_location},P)[1]];if(x.snapshot==null&&P.snapshot!=null)return[!0,Gte({...x,snapshot:P.snapshot},P)[1]];if(x.has_more_children){if(P.has_more_children)return[!1,x];if(x.id!=P.id)throw new Error("illegal state");return[!0,P]}if(x.children==null)return[!1,x];if(P.has_more_children)return[!1,x];if(x.children.length!=(P.children?.length??0))throw new Error("illegal state");let[Q,ae]=e3e((Ee,Oe,dt)=>{let[Mt,Ut]=Gte(Oe,P.children[dt]);return[Ee||Mt,Ut]},!1,x.children);return Q?[!0,{...x,children:ae}]:[!1,x]},sEe=(x,P)=>(x.children??[]).find(Q=>{if(Q.callsite_location==null)return!1;let ae=JSON.parse(Q.callsite_location);return ae.index==P.index&&ae.length==P.length}),gze=(x,P)=>{let Q=x.callsite_location;if(Q==null)return null;Q=JSON.parse(Q);let ae=Ate(P.code,Ee=>Ee.index==Q.index&&Ee.length==Q.length&&(Ee.kind==$e.SyntaxKind.CallExpression||Ee.kind==$e.SyntaxKind.NewExpression||Jp(Ee)));if(ae==null)throw new Error("illegal state");return ae},hze=(x,P,Q)=>{let{has_snapshot:ae,node_snapshot:Ee}=SG(x,vy(x.current_calltree_node).module,P,Q);if(ae){let Oe;return Ee==null?Oe=null:Oe=wte(x,x.current_calltree_node.code,P,Ee),{should_replay:!1,value_explorer:Oe}}else return{should_replay:!0}},$S=(x,P,Q=Oe=>Oe,ae=!1,Ee=!1)=>{function Oe(Lr){if(Ee)throw new Error("illegal state");let oa=Wt.code;return{...x,value_explorer:null,run_state:{status:tu.reload_app_window,on_reload_app_window_finished:TG,on_eval_modules_finished:dt,breakpoint:{module:vy(Wt).module,function_node:oa,selected_call_id:Wt.id,current_calltree_node_id:P.id,selected_node:Lr}}}}function dt(Lr,oa,Zo){if(Zo.current_calltree_node_id!=Lr.current_calltree_node.id)return Lr;let fs=f0(Lr.calltree,gs=>gs.id==P.id);return $S(Lr,fs,Q,ae,!0)}let[Mt]=IG(x.calltree,P);if(!P.toplevel&&!P.fn.is_hosted&&!Mt.toplevel&&!Mt.fn.is_hosted)return Q({...uW(x,null,P),value_explorer:null,selection_state:null});let Ut;P.toplevel||P.fn.__type=="loop_iteration"?Ut=!0:P.code!=null&&Jp(P.code)?Ut=!1:Mt.id=="deferred_calls"?Ut=!0:Vte(P)?Ut=!1:Vte(Mt)?Ut=!0:Ut=x.calltree_node_is_expanded[P.id];let Wt=Ut?P:Mt;x=uW(x,Wt,P);let gr,ti,qr;if(P.toplevel){if(x.footprints.get(yy(x).id)==null)return Oe();ti=null,qr=null,gr=vy(Wt)}else if(P.fn.__type=="loop_iteration"){let Lr=vy(P).module,oa=hL(x),Zo=!1;if(x.current_module==Lr&&fL(P.code,oa)&&oa!=P.code.index)gr={module:Lr,index:oa};else{let md=P.code,Gd=md.kind;if(Gd==$e.SyntaxKind.WhileStatement||Gd==$e.SyntaxKind.DoStatement||Gd==$e.SyntaxKind.ForStatement){let by=md.statement.kind==$e.SyntaxKind.Block?md.statement.statements.length==0?Gd==$e.SyntaxKind.ForStatement?md.initializer:md.expression:md.statement.statements[0]:md.statement;gr={module:Lr,index:by.index}}else gr={module:Lr,index:md.initializer.index},Zo=!0}let fs=x.selection_state?.node,gs=fs!=null&&!(fs==P.code.expression&&(P.code.kind==$e.SyntaxKind.ForOfStatement||P.code.kind==$e.SyntaxKind.ForInStatement))&&fs!=P.code.initializer&&fL(P.code,fs.index),Za;if((P.code.kind==$e.SyntaxKind.ForOfStatement||P.code.kind==$e.SyntaxKind.ForInStatement)&&(fs==P.code.initializer||Zo)?(qr={node:P.code.initializer},Za=P.code):gs?(qr=x.selection_state,Za=x.selection_state.node):(Za=Pte(P.code,gr.index),qr=null),Za==null)ti=null,qr=null;else{let md;if({value_explorer:ti,should_replay:md}=hze(x,Za,P.id),md)return Oe(Za)}}else if(P.code!=null&&Jp(P.code)){let Lr=P.code.kind;if(Lr==$e.SyntaxKind.WhileStatement||Lr==$e.SyntaxKind.DoStatement)ti=null,qr=null;else{let oa;Lr==$e.SyntaxKind.ForStatement?oa=P.code.initializer:oa=P.code.expression,qr={node:oa};let Zo;if({value_explorer:ti,should_replay:Zo}=hze(x,oa,Hbe(x.calltree,P).id),Zo)return Oe(oa)}if(gr={module:vy(P).module,index:P.code.index},P.has_more_children)return Oe()}else{if(P.snapshot==null)return Oe();let Lr;if(Ut){gr=vy(P),qr=null;let Zo=x.snapshots.get_by_module_and_node(vy(Wt).module,Wt.code)?.get(Wt.id);if(Zo==null)return Oe();Zo.ok?Lr=Zo.value:Lr=P.snapshot.args}else{let Zo=gze(P,Wt);if(Zo==null)return Oe();gr={module:vy(Wt).module,index:Zo.index},Lr=P.snapshot.args,qr={node:Zo}}if(Lr==null)throw new Error("illegal state");let oa=P.ok?{args:Lr,return_value:P.snapshot.value}:{args:Lr,throws:P.snapshot.error};P.context!=null&&(oa={...oa,context_before:P.snapshot.context_before,context_after:P.snapshot.context_after}),ti={call_id:P.id,index:gr.index,result:{ok:!0,is_calltree_node_explorer:!0,value:oa}}}return x=ae?x:P.toplevel?{...x,current_module:gr.module}:PC(x,gr),x.footprints.get(Wt.id)==null?Oe():Q({...lEe(x,Wt,P),value_explorer:ti,selection_state:qr})},Bvt=x=>$S(x,x.current_calltree_node,void 0,!0),IG=(x,P)=>{let Q=Ee=>Ee.id==P.id?[]:Ee.children==null?null:Ee.children.reduce((Oe,dt)=>{if(Oe!=null)return Oe;let Mt=Q(dt);return Mt==null?null:[...Mt,Ee]},null),ae=Q(x);if(ae==null)throw new Error("illegal state");return ae},yL=x=>Vte(x)||Jp(x.code)?x.children!=null&&x.children.length!=0||x.has_more_children:x.toplevel?x.children!=null&&x.children.length!=0:!0,Gvt=x=>{let P=x.current_calltree_node,Q;if(yL(P)&&x.calltree_node_is_expanded[P.id]&&P.children!=null)Q=P.children[0];else{let ae=(Ee,Oe)=>{if(Ee.id=="calltree")return null;let[dt,...Mt]=Oe,Ut=dt.children.findIndex(gr=>gr==Ee),Wt=dt.children[Ut+1];return Wt??ae(dt,Mt)};Q=ae(P,IG(x.calltree,P))}return Q?.id=="deferred_calls"&&(Q.children==null?Q=null:Q=Q.children[0]),Q==null?x:$S(x,Q)},Vvt=x=>{let P=x.current_calltree_node;if(P.toplevel)return x;let[Q]=IG(x.calltree,P),ae=Q.children.findIndex(Mt=>Mt==P),Ee=Q.children[ae-1],Oe=Mt=>!yL(Mt)||!x.calltree_node_is_expanded[Mt.id]||Mt.children==null?Mt:Oe(Mt.children[Mt.children.length-1]),dt;return Ee==null?dt=Q.id=="deferred_calls"?Oe(yy(x)):Q:dt=Oe(Ee),$S(x,dt)},jvt=x=>{let P=x.current_calltree_node,Q=x.calltree_node_is_expanded[P.id];if(!yL(P)||!Q){let[ae]=IG(x.calltree,P);return ae.id=="calltree"||ae.id=="deferred_calls"?x:$S(x,ae)}else return AG(x)},Uvt=x=>{let P=x.current_calltree_node;return yL(P)?x.calltree_node_is_expanded[P.id]?P.children!=null?$S(x,P.children[0]):x:AG(x):x},AG=(x,P,Q=x.current_calltree_node)=>{let ae=Q.id,Ee=x.calltree_node_is_expanded[ae],Oe=P??!Ee,dt={...x,calltree_node_is_expanded:{...x.calltree_node_is_expanded,[ae]:Oe}};return $S(dt,Q)},Hvt=(x,P)=>{let Q=f0(x.calltree,ae=>ae.id==P);return $S(x,Q)},Kvt=(x,P)=>{let Q=f0(x.calltree,ae=>ae.id==P);return yL(Q)?AG(x,void 0,Q):$S(x,Q)},LC=(x,P)=>x.calltree_node_is_expanded?.[P.id]?x:{...x,calltree_node_is_expanded:{...x.calltree_node_is_expanded,...Object.fromEntries(IG(x.calltree,P).map(Q=>[Q.id,!0])),[P.id]:!0}},zte=(x,P)=>{if(P??=yy(x),P.ok||Ovt(P))return{state:LC(x,P),node:P};{let Q=f0(P,ae=>!MC(ae).ok&&(ae.children==null||ae.children.find(Ee=>!MC(Ee).ok)==null));return{state:LC(x,Q),node:Q}}},_ze=x=>zte(x).state,Bte=(x,P,Q)=>{let ae=x.parse_result.modules[P];if(ae==null)return null;if(fL(ae,Q)){let Ee=XS(ae,Q),Oe=$e.forEachAncestor(Ee,dt=>{let Mt=Ste(dt);if(Mt!=null)return Mt;if(lp(dt)||Jp(dt))return dt});return Oe??ae}else return ae},Mte=(x,P,Q)=>{if(P==mL(x)){let Ee=yy(x);return lEe(LC(x,Ee),Ee)}if(P.kind==$e.SyntaxKind.SourceFile)return x;if(Q==null)return uW(x,null);let ae=f0(x.calltree,Ee=>Ee.id==Q);if(ae==null)throw new Error("illegal state");return lEe(LC(x,ae),ae)},Jvt=x=>{if(x.current_calltree_node.toplevel)return{state:x};if(x.current_calltree_node.code!=null&&Jp(x.current_calltree_node.code))return{state:x};let P=vy(x.active_calltree_node),Q;if(x.current_calltree_node==x.active_calltree_node){let ae=x.frames.get(x.active_calltree_node.id),Ee=x.active_calltree_node.code;if(x.active_calltree_node.ok)if(Ee.body.kind==$e.SyntaxKind.Block){let Oe=Ate(Ee,dt=>dt.kind==$e.SyntaxKind.ReturnStatement&&ae.get(dt)?.ok);if(Oe==null)return{state:PC(x,{module:P.module,index:Ee.body.index}),effects:{type:"set_focus"}};Q=Oe.expression}else Q=Ee.body;else Q=Kbe(Ee,ae)}else{let ae=x.current_calltree_node.callsite_location;ae=JSON.parse(ae),Q=Ate(x.active_calltree_node.code,Ee=>Ee.index==ae.index&&Ee.length==ae.length)}return{state:{...PC(x,{module:P.module,index:Q.index}),selection_state:{node:Q},value_explorer:{call_id:x.current_calltree_node.id,index:Q.index,length:Q.length,result:x.current_calltree_node.snapshot}},effects:{type:"set_focus"}}},qvt=(x,P=!0)=>{if(x.current_calltree_node.toplevel)return{state:x};if(x.current_calltree_node.code!=null&&Jp(x.current_calltree_node.code))return{state:x};let Q=vy(x.active_calltree_node),ae,Ee;if(x.current_calltree_node==x.active_calltree_node){if(x.active_calltree_node.toplevel)return{state:x};let Oe=x.active_calltree_node.code;ae=Kb(Oe)[0];let dt=x.snapshots.get_by_module_and_node(vy(x.active_calltree_node).module,Oe)?.get(x.active_calltree_node.id);if(dt==null)return{state:x};Ee=dt.ok?dt:{ok:!1,error:x.active_calltree_node.error}}else{let Oe=gze(x.current_calltree_node,x.active_calltree_node);if(Oe==null)return{state:x};Ee={ok:!0,value:x.current_calltree_node.snapshot.args},ae=[...Oe.arguments];let dt=Oe.getChildren();ae.index=dt.find(Mt=>Mt.kind==$e.SyntaxKind.OpenParenToken).pos,ae.length=dt.find(Mt=>Mt.kind==$e.SyntaxKind.CloseParenToken).pos-ae.index+1}return{state:{...PC(x,{module:Q.module,index:ae.index}),selection_state:{node:ae},value_explorer:{call_id:x.current_calltree_node.id,index:ae.index,length:ae.length,result:Ee}},effects:P?{type:"set_focus"}:null}},Xvt=x=>{let P=[x.current_calltree_node,x.active_calltree_node,yy(x)].find(ae=>gL(ae));if(P==null)return{state:x,effects:[{type:"set_status",args:["no error found"]}]};let Q=f0(P,ae=>gL(ae)&&(ae.children==null||ae.children.every(Ee=>!gL(Ee)||Vte(Ee)&&Ee.children==null)));if(Q==null)throw new Error("illegal state: error origin not found");return $S(LC(x,Q),Q,ae=>{let Ee=cte(ae),Oe=Kbe(ae.active_calltree_node.code,Ee);return{state:PC(ae,{module:vy(Q).module,index:Oe.index}),effects:{type:"set_focus"}}})},Yvt=(x,P)=>{if(x.logs.logs.length==0)return{state:x};let Q=Math.max(Math.min(x.logs.log_position==null?0:x.logs.log_position+P,x.logs.logs.length-1),0);return yze(x,Q)},yze=(x,P)=>{x={...x,logs:{...x.logs,log_position:P}};let Q=f0(x.calltree,ae=>ae.id==x.logs.logs[P].id);return $S(LC(x,Q),Q,ae=>ae.active_calltree_node==null?ae:{...ae,value_explorer:{...ae.value_explorer,result:{...ae.value_explorer.result,is_calltree_node_explorer:!1,value:ae.value_explorer.result.value.args}}})};Wte.calltree={arrow_down:Gvt,arrow_up:Vvt,arrow_left:jvt,arrow_right:Uvt,select_node:Hvt,select_and_toggle_expanded:Kvt,select_return_value:Jvt,select_arguments:qvt,select_error:Xvt,navigate_logs_position:yze,navigate_logs_increment:Yvt,show_value_explorer:Bvt};var jte=class{constructor(P,Q){this.ui=P,this.container=Q,this.container.addEventListener("keydown",ae=>{ae.key=="r"&&(ae.ctrlKey||ae.metaKey)||ae.preventDefault(),ae.key=="Escape"&&this.ui.editor.focus(),ae.key=="F1"&&this.ui.editor.focus_value_explorer(this.container),ae.key=="F2"&&this.ui.editor.focus(),ae.key=="a"&&Ws("calltree.select_arguments"),ae.key=="e"&&Ws("calltree.select_error"),(ae.key=="r"||ae.key=="Enter")&&Ws("calltree.select_return_value"),(ae.key=="ArrowDown"||ae.key=="j")&&Ws("calltree.arrow_down"),(ae.key=="ArrowUp"||ae.key=="k")&&Ws("calltree.arrow_up"),(ae.key=="ArrowLeft"||ae.key=="h")&&Ws("calltree.arrow_left"),(ae.key=="ArrowRight"||ae.key=="l")&&Ws("calltree.arrow_right")})}on_click_node(P,Q){P.target.classList.contains("expand_icon")?Ws("calltree.select_and_toggle_expanded",Q):Ws("calltree.select_node",Q)}clear_calltree(){this.container.innerHTML="",this.node_to_el=new Map,this.state=null}render_loop(P){let{ok:Q,error:ae}=MC(P),Ee;P.code.kind==$e.SyntaxKind.WhileStatement&&(Ee="while"),P.code.kind==$e.SyntaxKind.DoStatement&&(Ee="do while"),(P.code.kind==$e.SyntaxKind.ForInStatement||P.code.kind==$e.SyntaxKind.ForOfStatement||P.code.kind==$e.SyntaxKind.ForStatement)&&(Ee="for");let Oe=P.has_more_children?P.children_count:P.children?.length??0;return Pr("span","call_header "+(Q?"":"error"),Ee+" loop("+Oe+")",Q?null:[": ",Ag(ae)])}render_loop_iteration(P,Q){let{ok:ae,error:Ee}=MC(P),Oe=Q.children.indexOf(P),dt=null;(P.code.kind==$e.SyntaxKind.ForOfStatement||P.code.kind==$e.SyntaxKind.ForInStatement)&&(dt=P.code.initializer.getText()+" = "+Ag(P.args[0]));let Mt=Tte(P.code);return Mt!=null&&(dt=Mt.getText()+" = "+Ag(P.args[0])),Pr("span","call_header "+(ae?"":"error"),Pr("span","loop_step","step "+Oe,(dt!=null||!ae)&&":"),dt,ae?"":Pr("span","call_header error",dt!=null&&":\xA0",Ag(Ee)))}render_node(P,Q){let ae=this.state.calltree_node_is_expanded[P.id],Ee=Pr("div","callnode",Pr("div",{class:"call_el",click:Oe=>this.on_click_node(Oe,P.id)},yL(P)?ae&&P.has_more_children?Pr("div","spinner"):Pr("span","expand_icon",ae?"\u25BC":"\u25B6"):Pr("span","expand_icon_placeholder","\xA0"),P.toplevel?Pr("span",P.ok?"":"call_header error",Pr("i","","toplevel: "+gv(P.module)),P.ok?"":Pr("span","",":\xA0",Ag(P.error))):P.fn.__type=="loop_iteration"?this.render_loop_iteration(P,Q):P.code!=null&&Jp(P.code)?this.render_loop(P):Pr("span","call_header "+(gL(P)?"error":"")+(P.fn.is_hosted?"":" native"),P.is_new?"new ":"",P.context==null||P.is_new?"":Pr("span","",typeof P.context=="object"?P.context.constructor?.name||"":Ag(P.context),"."),P.fn.name==""?"anonymous":P.fn.name,"(",...dL(P.args.map(Oe=>Ag(Oe))),")",": ",P.ok?Ag(P.value):Ag(P.error))),P.children==null||!ae?null:P.children.map(Oe=>this.render_node(Oe,P)));return this.node_to_el.set(P.id,Ee),Ee.is_expanded=ae,Ee}render_active(P,Q){let ae=this.node_to_el.get(P.id).getElementsByClassName("call_el")[0];Q?ae.classList.add("active"):ae.classList.remove("active")}reveal_current_calltree_node(){tW(this.container,this.node_to_el.get(this.state.current_calltree_node.id).getElementsByClassName("call_el")[0])}render_select_node(P,Q){if(P!=null&&this.render_active(P.current_calltree_node,!1),this.state=Q,this.render_active(this.state.current_calltree_node,!0),P?.current_calltree_node!=Q.current_calltree_node){let ae=this.container.scrollLeft;this.reveal_current_calltree_node(),this.container.scrollLeft=ae}}render_expand_node(P,Q){this.state=Q,this.do_render_expand_node(P.calltree_node_is_expanded,Q.calltree_node_is_expanded,yy(P),yy(Q));let ae=rI(P),Ee=rI(Q);if(ae!=null){for(let Oe=0;Oethis.render_node(Q))))))}};var Ute=class{constructor(P,Q){this.el=Q,this.ui=P,this.el.addEventListener("keydown",ae=>{ae.key=="Escape"&&this.ui.editor.focus(),ae.key=="Enter"&&this.ui.editor.focus(),ae.key=="F1"&&this.ui.editor.focus_value_explorer(this.el),ae.key=="F3"&&this.ui.editor.focus(),(ae.key=="ArrowDown"||ae.key=="j")&&(ae.preventDefault(),Ws("calltree.navigate_logs_increment",1)),(ae.key=="ArrowUp"||ae.key=="k")&&(ae.preventDefault(),Ws("calltree.navigate_logs_increment",-1))})}rerender_logs(P,Q){this.el.innerHTML="",this.render_logs(P,null,Q)}render_logs(P,Q,ae){for(let Ee=Q==null?0:Q.logs.length;EeWs("calltree.navigate_logs_position",Ee)},Pr("a",{href:"javascript: void(0)"},dt+": "+(Oe.toplevel?"toplevel":"fn "+(Oe.parent_name==""?"anonymous":Oe.parent_name))+":")," ",...dL(Oe.args.map(Ut=>Ag(Ut)))))}if(Q?.log_position!=ae.log_position&&(Q?.logs==ae.logs&&Q?.log_position!=null&&this.el.children[Q.log_position].classList.remove("active"),ae.log_position!=null)){let Ee=this.el.children[ae.log_position];Ee.classList.add("active"),tW(this.el,Ee)}}};var Hte=class{constructor(P,Q){this.el=Q,this.ui=P,this.el.addEventListener("keydown",ae=>{ae.key=="Escape"&&this.ui.editor.focus(),ae.key=="F4"&&this.ui.editor.focus()})}clear(){this.is_rendered&&(this.el.innerHTML="",this.is_rendered=!1,this.io_trace_length=0,this.io_trace_index=void 0)}render_io_trace(P,Q){if(Q&&(this.is_rendered=!1),this.is_rendered)return;this.is_rendered=!0,this.el.innerHTML="",this.io_trace_length=P.io_trace.length,this.io_trace_index=P.rt_cxt.io_trace_index;let ae=P.io_trace,Ee=P.rt_cxt.io_trace_index??ae.length;for(let Oe=0;Oe ")));else if(dt.type=="call")this.el.appendChild(Pr("div","call_header "+(gL(dt)?"error ":"")+(Mt?"":"native "),dt.name,"(",...dL(dt.args.map(Ut=>Ag(Ut))),"): ",dt.ok?Ag(dt.value):Ag(dt.error)));else throw new Error("unknown item type")}}};var $vt="leporello-js",vze=`https://firebasestorage.googleapis.com/v0/b/${$vt}.appspot.com/o/`;async function Qvt(x){let P=new TextEncoder().encode(x),Q=await crypto.subtle.digest("SHA-256",P);return Array.from(new Uint8Array(Q)).map(Oe=>Oe.toString(16).padStart(2,"0")).join("")}async function bze(x,P){let Q=(await Qvt(P)).slice(0,40),ae=new Blob([P],{type:"text/plain"}),Ee=new FormData;Ee.append("file",ae);let Oe=await fetch(vze+Q,{method:"POST",body:Ee});if(!Oe.ok){let Ut=(await Oe.json())?.error?.message;throw new Error("Failed to upload: "+Ut)}let dt=new URL(window.location);return dt.searchParams.set("share_id",Q),dt.searchParams.set("share_name",x),dt.toString()}async function Zvt(x){let P=await fetch(vze+x+"?alt=media");if(!P.ok){let ae=(await P.json())?.error?.message;throw new Error("Failed to fetch: "+ae)}return P.text()}async function Eze(){let x=new URLSearchParams(window.location.search),P=x.get("share_id");if(P==null)return null;let Q=x.get("share_name")??"";Q.trim()==""&&(Q="Share");let ae=new URL(window.location);ae.searchParams.delete("share_id"),ae.searchParams.delete("share_name"),history.replaceState(null,null,ae.href);try{let Ee=await Zvt(P);return{name:Q,contents:Ee}}catch(Ee){return alert(Ee.message),null}}var Kte=class{constructor(){let Q=yv().current_module.split("/").at(-1);this.el=Pr("dialog","share_dialog",this.upload_begin=Pr("p","",Pr("p","","Uploads your file to the cloud so you can share it with others."),Pr("ul","",Pr("li","","Please ensure that no personal data or confidential information is included."),Pr("li","","Avoid including copyrighted materials.")),Pr("span",{style:"color: red"},"Caution: Once shared, files cannot be deleted."),Pr("div","share_name",Pr("label","","Public file name"),this.share_name=Pr("input",{type:"text",value:Q})),this.upload_buttons=Pr("p",{style:"text-align: center"},Pr("button",{class:"upload_button",click:()=>this.upload()},"Upload"),this.cancel_button=Pr("button",{style:"margin-left: 1em",click:()=>this.el.close()},"Cancel"))),this.uploading=Pr("span",{style:"display: none"},"Uploading..."),this.upload_finish=Pr("p",{style:"display: none"},Pr("p","",Pr("p",{style:` text-align: center; margin-bottom: 1em; font-size: 1.2em