export function work_last_created(){window.interpreter.Work()}export function last_needs_memory(){return 0===window.interpreter.view.buffer.byteLength}export function update_last_memory(e){window.interpreter.UpdateMemory(e)}let parent,len,children,node,ns,attr,text,i,name,value,element,ptr;export class JsInterpreter{constructor(e,t,s,i,r,o){this.root=e,this.lastNode=e,this.nodes=[e],this.parents=[],this.view=new DataView(t.buffer),this.idSize=1,this.last_start_pos,this.ptr_updated_ptr=s,this.ptr_ptr=i,this.str_ptr_ptr=r,this.str_len_ptr=o,this.strings="",this.strPos=0,this.decoder=new TextDecoder,window.interpreter=this,this.updateDecodeIdFn()}NeedsMemory(){return 0===this.view.buffer.byteLength}UpdateMemory(e){this.view=new DataView(e.buffer)}Work(){for(1===this.view.getUint8(this.ptr_updated_ptr)&&(this.last_start_pos=this.view.getUint32(this.ptr_ptr,!0)),this.u8BufPos=this.last_start_pos,len=this.view.getUint32(this.str_len_ptr,!0),len>0&&(ptr=this.view.getUint32(this.str_ptr_ptr,!0),this.strings=len<25?this.utf8Decode(ptr,len):this.decoder.decode(new DataView(this.view.buffer,ptr,len)),this.strPos=0);;)switch(this.view.getUint8(this.u8BufPos++)){case 0:for(parent=this.decodeNode(),len=this.decodeU32(),i=0;i<len;i++)parent.appendChild(this.nodes[this.decodeId()]);break;case 1:if(parent=this.decodeNode(),len=this.decodeU32(),0===len)parent.replaceWith(this.nodes[this.decodeId()]);else{for(children=[],i=0;i<len;i++)children.push(this.nodes[this.decodeId()]);parent.replaceWith(...children)}break;case 2:if(parent=this.decodeNode(),len=this.decodeU32(),0===len)parent.after(this.nodes[this.decodeId()]);else{for(children=[],i=0;i<len;i++)children.push(this.nodes[this.decodeId()]);parent.after(...children)}break;case 3:if(parent=this.decodeNode(),len=this.decodeU32(),0===len)parent.before(this.nodes[this.decodeId()]);else{for(children=[],i=0;i<len;i++)children.push(this.nodes[this.decodeId()]);parent.before(...children)}break;case 4:1===this.view.getUint8(this.u8BufPos++)?this.nodes[this.decodeId()].remove():this.lastNode.remove();break;case 5:this.lastNode=document.createTextNode(this.strings.substring(this.strPos,this.strPos+=this.decodeU16())),1===this.view.getUint8(this.u8BufPos++)&&(this.nodes[this.decodeId()]=this.lastNode);break;case 6:name=this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),1===this.nodes[this.u8BufPos++]?this.lastNode=document.createElementNS(name,this.strings.substring(this.strPos,this.strPos+=this.decodeU16())):this.lastNode=document.createElement(name),1===this.view.getUint8(this.u8BufPos++)&&(this.nodes[this.decodeId()]=this.lastNode);break;case 10:1===this.view.getUint8(this.u8BufPos++)?this.nodes[this.decodeId()].textContent=this.strings.substring(this.strPos,this.strPos+=this.decodeU16()):this.lastNode.textContent=this.strings.substring(this.strPos,this.strPos+=this.decodeU16());break;case 11:switch(node=this.decodeNode(),attr=this.view.getUint8(this.u8BufPos++),attr){case 254:attr=this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),ns=this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),value=this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),"style"===ns?node.style[attr]=value:null==ns&&null==ns||node.setAttributeNS(ns,attr,value);break;case 255:node.setAttribute(this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),this.strings.substring(this.strPos,this.strPos+=this.decodeU16()));break;default:node.setAttribute(convertAttribute(attr),this.strings.substring(this.strPos,this.strPos+=this.decodeU16()))}break;case 12:switch(node=this.decodeNode(),attr=this.view.getUint8(this.u8BufPos++),attr){case 254:attr=this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),node.removeAttributeNS(this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),attr);break;case 255:node.removeAttribute(this.strings.substring(this.strPos,this.strPos+=this.decodeU16()));break;default:node.removeAttribute(convertAttribute(attr))}break;case 13:this.lastNode=this.decodeNode().cloneNode(!0),1===this.view.getUint8(this.u8BufPos++)&&(this.nodes[this.decodeId()]=this.lastNode);break;case 14:for(let e=this.decodeNode().cloneNode(!0).firstChild;null!==e;e=e.nextSibling)1===this.view.getUint8(this.u8BufPos++)&&(this.nodes[this.decodeId()]=e);break;case 15:this.lastNode=this.lastNode.firstChild;break;case 16:this.lastNode=this.lastNode.nextSibling;break;case 17:this.lastNode=this.lastNode.parentNode;break;case 18:this.nodes[this.decodeId()]=this.lastNode;break;case 19:this.lastNode=this.nodes[this.decodeId()];break;case 20:this.idSize=this.view.getUint8(this.u8BufPos++),this.updateDecodeIdFn();break;case 21:return;case 22:this.createFullElement();default:return void this.u8BufPos--}}createElement(){return element=this.view.getUint8(this.u8BufPos++),255===element?document.createElement(this.strings.substring(this.strPos,this.strPos+=this.decodeU16())):document.createElement(convertElement(element))}createFullElement(){const e=this.decodeMaybeId(),t=this.createElement(),s=this.view.getUint8(this.u8BufPos++);for(let e=0;e<s;e++)switch(attr=this.view.getUint8(this.u8BufPos++),attr){case 254:attr=this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),ns=this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),value=this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),t.setAttributeNS(ns,attr,value);break;case 255:t.setAttribute(this.strings.substring(this.strPos,this.strPos+=this.decodeU16()),this.strings.substring(this.strPos,this.strPos+=this.decodeU16()));break;default:t.setAttribute(convertAttribute(attr),this.strings.substring(this.strPos,this.strPos+=this.decodeU16()))}const i=this.view.getUint8(this.u8BufPos++);for(let e=0;e<i;e++)t.appendChild(this.createFullElement());return null!==e&&(this.nodes[e]=t),t}decodeNode(){return 1===this.view.getUint8(this.u8BufPos++)?this.nodes[this.decodeId()]:this.lastNode}decodeMaybeId(){return 0===this.view.getUint8(this.u8BufPos++)?null:this.decodeId()}updateDecodeIdFn(){switch(this.idSize){case 1:this.decodeId=function(){return this.view.getUint8(this.u8BufPos++)};break;case 2:this.decodeId=function(){return this.u8BufPos+=2,this.view.getUint16(this.u8BufPos-2,!0)};break;case 4:this.decodeId=function(){return this.u8BufPos+=4,this.view.getUint32(this.u8BufPos-4,!0)}}}decodeU32(){return this.u8BufPos+=4,this.view.getUint32(this.u8BufPos-4,!0)}decodeU16(){return this.u8BufPos+=2,this.view.getUint16(this.u8BufPos-2,!0)}SetNode(e,t){this.nodes[e]=t}GetNode(e){return this.nodes[e]}utf8Decode(e,t){let s=e;const i=s+t;let r,o="";for(;s<i;)if(r=this.view.getUint8(s++),0==(128&r))o+=String.fromCharCode(r);else if(192==(224&r))o+=String.fromCharCode((31&r)<<6|63&this.view.getUint8(s++));else if(224==(240&r))o+=String.fromCharCode((31&r)<<12|(63&this.view.getUint8(s++))<<6|63&this.view.getUint8(s++));else if(240==(248&r)){let e=(7&r)<<18|(63&this.view.getUint8(s++))<<12|(63&this.view.getUint8(s++))<<6|63&this.view.getUint8(s++);e>65535&&(e-=65536,o+=String.fromCharCode(e>>>10&1023|55296),e=56320|1023&e),o+=String.fromCharCode(e)}else o+=String.fromCharCode(r);return o}}const els=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","bdi","bdo","bgsound","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","del","details","dfn","dialog","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","head","header","hgroup","hr","html","i","iframe","image","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","marquee","menu","menuitem","meta","meter","nav","nobr","noembed","noframes","noscript","object","ol","optgroup","option","output","p","param","picture","plaintext","portal","pre","progress","q","rb","rp","rt","rtc","ruby","s","samp","script","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","tt","u","ul","var","video","wbr","xmp"];function convertElement(e){return els[e]}const attrs=["accept-charset","accept","accesskey","action","align","allow","alt","aria-atomic","aria-busy","aria-controls","aria-current","aria-describedby","aria-description","aria-details","aria-disabled","aria-dropeffect","aria-errormessage","aria-flowto","aria-grabbed","aria-haspopup","aria-hidden","aria-invalid","aria-keyshortcuts","aria-label","aria-labelledby","aria-live","aria-owns","aria-relevant","aria-roledescription","async","autocapitalize","autocomplete","autofocus","autoplay","background","bgcolor","border","buffered","capture","challenge","charset","checked","cite","class","code","codebase","color","cols","colspan","content","contenteditable","contextmenu","controls","coords","crossorigin","csp","data","datetime","decoding","default","defer","dir","dirname","disabled","download","draggable","enctype","enterkeyhint","for","form","formaction","formenctype","formmethod","formnovalidate","formtarget","headers","height","hidden","high","href","hreflang","http-equiv","icon","id","importance","inputmode","integrity","intrinsicsize","ismap","itemprop","keytype","kind","label","lang","language","list","loading","loop","low","manifest","max","maxlength","media","method","min","minlength","multiple","muted","name","novalidate","open","optimum","pattern","ping","placeholder","poster","preload","radiogroup","readonly","referrerpolicy","rel","required","reversed","role","rows","rowspan","sandbox","scope","scoped","selected","shape","size","sizes","slot","span","spellcheck","src","srcdoc","srclang","srcset","start","step","style","summary","tabindex","target","title","translate","type","usemap","value","width","wrap"];function convertAttribute(e){return attrs[e]}const events=["abort","activate","addstream","addtrack","afterprint","afterscriptexecute","animationcancel","animationend","animationiteration","animationstart","appinstalled","audioend","audioprocess","audiostart","auxclick","beforeinput","beforeprint","beforescriptexecute","beforeunload","beginEvent","blocked","blur","boundary","bufferedamountlow","cancel","canplay","canplaythrough","change","click","close","closing","complete","compositionend","compositionstart","compositionupdate","connect","connectionstatechange","contentdelete","contextmenu","copy","cuechange","cut","datachannel","dblclick","devicechange","devicemotion","deviceorientation","DOMActivate","DOMContentLoaded","DOMMouseScroll","drag","dragend","dragenter","dragleave","dragover","dragstart","drop","durationchange","emptied","end","ended","endEvent","enterpictureinpicture","error","focus","focusin","focusout","formdata","fullscreenchange","fullscreenerror","gamepadconnected","gamepaddisconnected","gatheringstatechange","gesturechange","gestureend","gesturestart","gotpointercapture","hashchange","icecandidate","icecandidateerror","iceconnectionstatechange","icegatheringstatechange","input","inputsourceschange","install","invalid","keydown","keypress","keyup","languagechange","leavepictureinpicture","load","loadeddata","loadedmetadata","loadend","loadstart","lostpointercapture","mark","merchantvalidation","message","messageerror","mousedown","mouseenter","mouseleave","mousemove","mouseout","mouseover","mouseup","mousewheel","msContentZoom","u8BufestureChange","u8BufestureEnd","u8BufestureHold","u8BufestureStart","u8BufestureTap","MSInertiaStart","MSManipulationStateChanged","mute","negotiationneeded","nomatch","notificationclick","offline","online","open","orientationchange","pagehide","pageshow","paste","pause","payerdetailchange","paymentmethodchange","play","playing","pointercancel","pointerdown","pointerenter","pointerleave","pointerlockchange","pointerlockerror","pointermove","pointerout","pointerover","pointerup","popstate","progress","push","pushsubscriptionchange","ratechange","readystatechange","rejectionhandled","removestream","removetrack","removeTrack","repeatEvent","reset","resize","resourcetimingbufferfull","result","resume","scroll","search","seeked","seeking","select","selectedcandidatepairchange","selectend","selectionchange","selectstart","shippingaddresschange","shippingoptionchange","show","signalingstatechange","slotchange","soundend","soundstart","speechend","speechstart","squeeze","squeezeend","squeezestart","stalled","start","statechange","storage","submit","success","suspend","timeout","timeupdate","toggle","tonechange","touchcancel","touchend","touchmove","touchstart","track","transitioncancel","transitionend","transitionrun","transitionstart","unhandledrejection","unload","unmute","upgradeneeded","versionchange","visibilitychange","voiceschanged","volumechange","vrdisplayactivate","vrdisplayblur","vrdisplayconnect","vrdisplaydeactivate","vrdisplaydisconnect","vrdisplayfocus","vrdisplaypointerrestricted","vrdisplaypointerunrestricted","vrdisplaypresentchange","waiting","webglcontextcreationerror","webglcontextlost","webglcontextrestored","webkitmouseforcechanged","webkitmouseforcedown","webkitmouseforceup","webkitmouseforcewillbegin","wheel"];function convertEvent(e){return events[e]}