sledgehammer 0.2.0

Fast bindings for dom manipulations
Documentation
1
let t,s,e,i,r,o,u,a,n,l,d,f,h,g,c,P,b,p,m,B,w,v,U,k;export function work_last_created(){P.Work()}export function last_needs_memory(){return!b.byteLength}export function update_last_memory(t){P.UpdateMemory(t)}function exOp(){switch(t&31){case 0:P.lastNode=P.lastNode.firstChild;break;case 1:P.lastNode=P.lastNode.nextSibling;break;case 2:P.lastNode=P.lastNode.parentNode;break;case 3:P.nodes[P.view.getUint32(P.u8BufPos,true)]=P.lastNode;P.u8BufPos+=4;break;case 4:P.lastNode=P.nodes[P.view.getUint32(P.u8BufPos,true)];P.u8BufPos+=4;break;case 5:return true;case 6:P.lastNode=P.createFullElement();break;case 7:if(t&32){m=P.nodes[P.view.getUint32(P.u8BufPos,true)];P.u8BufPos+=4}else{m=P.lastNode}if(t&64){m.appendChild(P.nodes[P.view.getUint32(P.u8BufPos,true)]);P.u8BufPos+=4}else{m.appendChild(P.lastNode)}break;case 8:if(t&32){m=P.nodes[P.view.getUint32(P.u8BufPos,true)];P.u8BufPos+=4}else{m=P.lastNode}if(t&64){m.replaceWith(P.nodes[P.view.getUint32(P.u8BufPos,true)]);P.u8BufPos+=4}else{m.replaceWith(P.lastNode)}break;case 9:if(t&32){m=P.nodes[P.view.getUint32(P.u8BufPos,true)];P.u8BufPos+=4}else{m=P.lastNode}if(t&64){m.after(P.nodes[P.view.getUint32(P.u8BufPos,true)]);P.u8BufPos+=4}else{m.after(P.lastNode)}break;case 10:if(t&32){m=P.nodes[P.view.getUint32(P.u8BufPos,true)];P.u8BufPos+=4}else{m=P.lastNode}if(t&64){m.before(P.nodes[P.view.getUint32(P.u8BufPos,true)]);P.u8BufPos+=4}else{m.before(P.lastNode)}break;case 11:if(t&32){P.nodes[P.view.getUint32(P.u8BufPos,true)].remove();P.u8BufPos+=4}else{P.lastNode.remove()}break;case 12:P.lastNode=document.createTextNode(P.strings.substring(P.strPos,P.strPos+=P.view.getUint16(P.u8BufPos,true)));P.u8BufPos+=2;if(t&32){P.nodes[P.view.getUint32(P.u8BufPos,true)]=P.lastNode;P.u8BufPos+=4}break;case 13:P.lastNode=P.createElement();if(t&32){P.nodes[P.view.getUint32(P.u8BufPos,true)]=P.lastNode;P.u8BufPos+=4}break;case 14:if(t&32){U=P.view.getUint32(P.u8BufPos,true);P.u8BufPos+=4;P.nodes[U].textContent=P.strings.substring(P.strPos,P.strPos+=P.view.getUint16(P.u8BufPos,true));P.u8BufPos+=2}else{P.lastNode.textContent=P.strings.substring(P.strPos,P.strPos+=P.view.getUint16(P.u8BufPos,true));P.u8BufPos+=2}break;case 15:if(t&32){w=P.nodes[P.view.getUint32(P.u8BufPos,true)];P.u8BufPos+=4}else{w=P.lastNode}if(t&64){r=P.view.getUint32(P.u8BufPos,true);P.u8BufPos+=4;i=P.strings.substring(P.strPos,P.strPos+=r&65535);if(t&128){w.setAttributeNS(P.strings.substring(P.strPos,P.strPos+=(r&4294901760)>>>16),i,P.strings.substring(P.strPos,P.strPos+=P.view.getUint16(P.u8BufPos,true)));P.u8BufPos+=2}else{w.setAttribute(i,P.strings.substring(P.strPos,P.strPos+=(r&4294901760)>>>16))}}else{r=P.view.getUint32(P.u8BufPos,true);P.u8BufPos+=3;if(t&128){e=P.strings.substring(P.strPos,P.strPos+=r&65535);w.setAttributeNS(e,y[(r&16711680)>>>16],P.strings.substring(P.strPos,P.strPos+=P.view.getUint16(P.u8BufPos,true)));P.u8BufPos+=2}else{w.setAttribute(y[r&255],P.strings.substring(P.strPos,P.strPos+=(r&16776960)>>>8))}}break;case 16:if(t&32){w=P.nodes[P.view.getUint32(P.u8BufPos,true)];P.u8BufPos+=4}else{w=P.lastNode}if(t&64){if(t&128){r=P.view.getUint32(P.u8BufPos,true);P.u8BufPos+=4;i=P.strings.substring(P.strPos,P.strPos+=r&65535);w.removeAttributeNS(P.strings.substring(P.strPos,P.strPos+=(r&4294901760)>>>16),i)}else{w.removeAttribute(P.strings.substring(P.strPos,P.strPos+=P.view.getUint16(P.u8BufPos,true)));P.u8BufPos+=2}}else{if(t&128){r=P.view.getUint32(P.u8BufPos,true);P.u8BufPos+=3;i=y[r&255];w.removeAttributeNS(P.strings.substring(P.strPos,P.strPos+=(r&16776960)>>>8),i)}else{w.removeAttribute(y[P.view.getUint8(P.u8BufPos++)])}}break;case 17:if(t&32){w=P.nodes[P.view.getUint32(P.u8BufPos,true)];P.u8BufPos+=4}else{w=P.lastNode}r=P.view.getUint32(P.u8BufPos,true);P.u8BufPos+=4;w.style.setProperty(P.strings.substring(P.strPos,P.strPos+=r&65535),P.strings.substring(P.strPos,P.strPos+=(r&4294901760)>>>16));break;case 18:if(t&32){w=P.nodes[P.view.getUint32(P.u8BufPos,true)];P.u8BufPos+=4}else{w=P.lastNode}w.style.removeProperty(P.strings.substring(P.strPos,P.strPos+=P.view.getUint16(P.u8BufPos,true)));P.u8BufPos+=2;break;case 19:if(t&32){P.lastNode=P.nodes[P.view.getUint32(P.u8BufPos,true)].cloneNode(true);P.u8BufPos+=4}else{P.lastNode=P.lastNode.cloneNode(true)}if(t&64){P.nodes[P.view.getUint32(P.u8BufPos,true)]=P.lastNode;P.u8BufPos+=4}break;default:break}}export class JsInterpreter{constructor(t,s,e,i,r){this.lastNode;this.nodes=[];this.parents=[];this.UpdateMemory(t);this.last_start_pos;this.last_str_start;this.metadata_ptr=s;this.ptr_ptr=e;this.str_ptr_ptr=i;this.str_len_ptr=r;this.strings="";this.strPos=0;this.decoder=new TextDecoder;this.idSize=1;P=this}NeedsMemory(){return this.view.buffer.byteLength===0}UpdateMemory(t){this.view=new DataView(t.buffer);b=t.buffer}Work(){p=this.view.getUint8(this.metadata_ptr);if(p&1){this.last_start_pos=this.view.getUint32(this.ptr_ptr,true)}this.u8BufPos=this.last_start_pos;if(p&4){s=this.view.getUint32(this.str_len_ptr,true);if(p&2){this.last_str_start=this.view.getUint32(this.str_ptr_ptr,true)}if(p&8){l=this.last_str_start;this.strings="";c=l+(s/4|0)*4;while(l<c){h=this.view.getUint32(l);this.strings+=String.fromCharCode(h>>24,(h&16711680)>>16,(h&65280)>>8,h&255);l+=4}switch(this.last_str_start+s-l){case 3:h=this.view.getUint32(l);this.strings+=String.fromCharCode(h>>24,(h&16711680)>>16,(h&65280)>>8);break;case 2:h=this.view.getUint16(l);this.strings+=String.fromCharCode(h>>8,h&255);break;case 1:this.strings+=String.fromCharCode(this.view.getUint8(l));break;case 0:break}}else{this.strings=this.decoder.decode(new DataView(this.view.buffer,this.last_str_start,s))}this.strPos=0}for(;;){t=this.view.getUint32(this.u8BufPos,true);this.u8BufPos+=4;if(exOp())return;t>>>=8;if(exOp())return;t>>>=8;if(exOp())return;t>>>=8;if(exOp())return}}createElement(){o=this.view.getUint32(this.u8BufPos,true);a=o&255;switch(a){case 255:this.u8BufPos+=4;a=document.createElement(N[(o&65280)>>>8],this.strings.substring(this.strPos,this.strPos+=(o&4294901760)>>>16));return a;case 254:this.u8BufPos+=3;a=document.createElement(this.strings.substring(this.strPos,this.strPos+=(o&16776960)>>>8));return a;case 253:this.u8BufPos+=3;a=this.strings.substring(this.strPos,this.strPos+=(o&16776960)>>>8);a=document.createElementNS(this.strings.substring(this.strPos,this.strPos+=this.view.getUint16(this.u8BufPos,true)),a);this.u8BufPos+=2;return a;default:this.u8BufPos++;return document.createElement(N[a])}}createFullElement(){let t;o=this.view.getUint8(this.u8BufPos++);if(o&1){t=this.view.getUint32(this.u8BufPos,true);this.u8BufPos+=4}if(o&2){w=document.createTextNode(this.strings.substring(this.strPos,this.strPos+=this.view.getUint16(this.u8BufPos,true)));this.u8BufPos+=2;if(t!==null){this.nodes[t]=w}return w}else{const s=this.createElement();o=this.view.getUint16(this.u8BufPos,true);this.u8BufPos+=2;g=o&255;const a=(o&65280)>>>8;for(r=0;r<g;r++){o=this.view.getUint32(this.u8BufPos,true);i=o&255;switch(i){case 255:this.u8BufPos+=4;i=y[this.view.getUint8((o&65280)>>>8)];s.setAttributeNS(this.strings.substring(this.strPos,this.strPos+=(o&4294901760)>>>16),i);break;case 254:this.u8BufPos++;o=this.view.getUint32(this.u8BufPos,true);this.u8BufPos+=4;i=this.strings.substring(this.strPos,this.strPos+=o&65535);s.setAttribute(i,this.strings.substring(this.strPos,this.strPos+=(o&4294901760)>>>16));break;case 253:this.u8BufPos+=3;i=this.strings.substring(this.strPos,this.strPos+=(o&16776960)>>>8);o=this.view.getUint32(this.u8BufPos,true);this.u8BufPos+=4;e=this.strings.substring(this.strPos,this.strPos+=o&65535);u=this.strings.substring(this.strPos,this.strPos+=(o&4294901760)>>>16);s.setAttributeNS(e,i,u);break;default:this.u8BufPos+=3;s.setAttribute(y[i],this.strings.substring(this.strPos,this.strPos+=(o&16776960)>>>8));break}}for(let n=0;n<a;n++){s.appendChild(this.createFullElement())}if(t!==null){this.nodes[t]=s}return s}}decodeU32(){this.u8BufPos+=4;return this.view.getUint32(this.u8BufPos-4,true)}SetNode(t,s){this.nodes[t]=s}GetNode(t){return this.nodes[t]}}const N=["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"];const y=["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"];