jolt-ui
Version:
A web components based SPA framework
3 lines • 76.2 kB
JavaScript
(function(N,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(N=typeof globalThis<"u"?globalThis:N||self,q(N.joltUi={}))})(this,function(N){"use strict";var Tn=Object.defineProperty;var Qt=N=>{throw TypeError(N)};var Sn=(N,q,F)=>q in N?Tn(N,q,{enumerable:!0,configurable:!0,writable:!0,value:F}):N[q]=F;var p=(N,q,F)=>Sn(N,typeof q!="symbol"?q+"":q,F),St=(N,q,F)=>q.has(N)||Qt("Cannot "+F);var d=(N,q,F)=>(St(N,q,"read from private field"),F?F.call(N):q.get(N)),b=(N,q,F)=>q.has(N)?Qt("Cannot add the same private member more than once"):q instanceof WeakSet?q.add(N):q.set(N,F),z=(N,q,F,we)=>(St(N,q,"write to private field"),we?we.call(N,F):q.set(N,F),F),Vt=(N,q,F)=>(St(N,q,"access private method"),F);var Ae,oe,Ue,le,X,Ce,Be,We,ze,Qe,ue,x,Ie,Ge,xe,Je,Ye,Ze,Xe,Ke,et,tt,ce,he,Te,nt,at,Se,te,Nt,st,it,ot,lt,It,de,Ne,ut,ct,ht,De,Re,dt,ft,fe,pt,Oe,Q,$e,Me,ke,K,ne,pe,me,Le,mt,gt,Pe,vt,_t,qe,yt,bt;class q{constructor({redirect:r,redirectCallback:e,dataField:a,app:o}){p(this,"_authenticatedUserRoles");p(this,"setAuthenticatedUser",({user:r,roles:e})=>{this._authenticatedUser=r,e&&(this._authenticatedUserRoles=e),this._dataField&&this.app.setData(this._dataField,r)});p(this,"setUserRoles",r=>{this._authenticatedUserRoles=r});p(this,"removeAuthenticatedUser",()=>{var r,e,a;this._authenticatedUser=null,this._authenticatedUserRoles=null,(a=(e=(r=this.app)==null?void 0:r.router)==null?void 0:e.currentRoute)!=null&&a.authenticationRequired&&this.app.router.redirect(this._redirect),this._dataField&&this.app.removeData(this._dataField)});p(this,"hasRole",(r=[])=>{if(!this._authenticatedUser)return!1;if(r.length==0)return!0;if(!this._authenticatedUserRoles)return!1;const e=new Set(this._authenticatedUserRoles);return r.some(a=>e.has(a))});p(this,"getRoles",()=>this._authenticatedUserRoles);p(this,"getUser",()=>this._authenticatedUser);p(this,"isAuthenticated",()=>!!this._authenticatedUser);p(this,"unauthorizedRedirect",async()=>{await this.app.router.redirect(this.redirect)});if(!r||!o)throw new Error("Missing application instance or redirect route in Authenticator constructor");this._app=o,this._redirect=r,this._redirectCallback=e,this._authenticatedUser=null,this._authenticatedUserRoles=null,this._dataField=a}get redirectCallback(){return this._redirectCallback}get app(){return this._app}get redirect(){return this._redirect}}var F={name:"doT",version:"1.1.1",templateSettings:{evaluate:/\{\{([\s\S]+?(\}?)+)\}\}/g,interpolate:/\{\{=([\s\S]+?)\}\}/g,encode:/\{\{!([\s\S]+?)\}\}/g,use:/\{\{#([\s\S]+?)\}\}/g,useParams:/(^|[^\w$])def(?:\.|\[[\'\"])([\w$\.]+)(?:[\'\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})/g,define:/\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,defineParams:/^\s*([\w$]+):([\s\S]+)/,conditional:/\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,iterate:/\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,varname:"it",strip:!0,append:!0,selfcontained:!1,doNotSkipEncoded:!1},template:void 0,compile:void 0,log:!0};F.encodeHTMLSource=function(c){var r={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},e=c?/[&<>"'\/]/g:/&(?!#?\w+;)|<|>|"|'|\//g;return function(a){return a?a.toString().replace(e,function(o){return r[o]||o}):""}};var we={append:{start:"'+(",end:")+'",startencode:"'+encodeHTML("},split:{start:"';out+=(",end:");out+='",startencode:"';out+=encodeHTML("}},ee=/$^/;function Dt(c,r,e){return(typeof r=="string"?r:r.toString()).replace(c.define||ee,function(a,o,h,_){return o.indexOf("def.")===0&&(o=o.substring(4)),o in e||(h===":"?(c.defineParams&&_.replace(c.defineParams,function(g,w,y){e[o]={arg:w,text:y}}),o in e||(e[o]=_)):new Function("def","def['"+o+"']="+_)(e)),""}).replace(c.use||ee,function(a,o){c.useParams&&(o=o.replace(c.useParams,function(_,g,w,y){if(e[w]&&e[w].arg&&y){var O=(w+":"+y).replace(/'|\\/g,"_");return e.__exp=e.__exp||{},e.__exp[O]=e[w].text.replace(new RegExp("(^|[^\\w$])"+e[w].arg+"([^\\w$])","g"),"$1"+y+"$2"),g+"def.__exp['"+O+"']"}}));var h=new Function("def","return "+o)(e);return h&&Dt(c,h,e)})}function re(c){return c.replace(/\\('|\\)/g,"$1").replace(/[\r\t\n]/g," ")}F.template=function(c,r,e){r=r||F.templateSettings;var a=r.append?we.append:we.split,o,h=0,_;c=r.use||r.define?Dt(r,c,e||{}):c,c=c.replace(/<([a-zA-Z0-9\-]+)([^>]*)\sdata-bind="([^"]+)"([^>]*)>/g,(w,y,O,P,D)=>{var S=this.generateHash(),$=`<${y}${O} data-bind="${Ve(P)}" data-bind-id="${S}"${D}>`;return $});const g=document.createElement("div");this.app._originalInnerHTML.call(g,c),g.querySelectorAll("[data-bind]").forEach(w=>{const y=w.getAttribute("data-bind"),O=w.getAttribute("data-bind-id"),P=w.innerHTML;r.dataBinds.has(y)||r.dataBinds.set(y,{});const D=document.createElement("textarea");D.innerHTML=P;const S=r.dataBinds.get(y);S[O]=D.value,r.dataBinds.set(y,S)}),c=("var out='"+(r.strip?c.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g," ").replace(/\r|\n|\t|\/\*[\s\S]*?\*\//g,""):c).replace(/'|\\/g,"\\$&").replace(r.interpolate||ee,function(w,y){return a.start+re(y)+a.end}).replace(r.encode||ee,function(w,y){return o=!0,a.startencode+re(y)+a.end}).replace(r.conditional||ee,function(w,y,O){return y?O?"';}else if("+re(O)+"){out+='":"';}else{out+='":O?"';if("+re(O)+"){out+='":"';}out+='"}).replace(r.iterate||ee,function(w,y,O,P){return y?(h+=1,_=P||"i"+h,y=re(y),"';var arr"+h+"="+y+";if(arr"+h+"){var "+O+","+_+"=-1,l"+h+"=arr"+h+".length-1;while("+_+"<l"+h+"){"+O+"=arr"+h+"["+_+"+=1];out+='"):"';} } out+='"}).replace(r.evaluate||ee,function(w,y){return"';"+re(y)+"out+='"})+"';return out;").replace(/\n/g,"\\n").replace(/\t/g,"\\t").replace(/\r/g,"\\r").replace(/(\s|;|\}|^|\{)out\+='';/g,"$1").replace(/\+''/g,""),o&&(c="var encodeHTML = "+F.encodeHTMLSource.toString()+"("+(r.doNotSkipEncoded||"")+");"+c);try{return new Function(r.varname,c)}catch(w){throw typeof console<"u"&&console.log("Could not create a template function: "+c),w}},F.compile=function(c,r){return F.template(c,null,r)};const Gt={evaluate:/\{\{([\s\S]+?)\}\}/g,interpolate:/\{\{=([\s\S]+?)\}\}/g,encode:/\{\{!([\s\S]+?)\}\}/g,use:/\{\{#([\s\S]+?)\}\}/g,define:/\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,conditional:/\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,iterate:/\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,varname:"it",strip:!0,append:!0,selfcontained:!1,dataBinds:new Map,def:{}};function Rt(c=1e4,r=1){return Math.floor(Math.random()*(c-r+1))+r}function xt(c){return function(e){const a=window.structuredClone(c);return[void 0,null].includes(a)||(this._values[e]=a),{get(){return this._values[e]},set(o){this._values[e]=o,this._refreshBoundElements(Ve(e))}}}}function Jt(c){if([void 0,null,""].includes(c))throw new Error("Missing or invalid query selector for querySelector getter factory");return function(){const e=c;return{get(){return this.querySelector(e)}}}}function Yt(c){if([void 0,null,""].includes(c))throw new Error("Missing or invalid query selector for querySelector getter factory");return function(){const e=c;return{get(){return this.querySelectorAll(e)}}}}const At=String.raw,Ot=String.raw,rt=class rt extends HTMLElement{constructor(){super();p(this,"_startInitilization",()=>{this.resolveInitialization=null,this.initComplete=new Promise(e=>{this.resolveInitialization=e})});p(this,"initComplete");p(this,"_methods");p(this,"markup");p(this,"css");b(this,Ae);b(this,oe);p(this,"_beforeInit");p(this,"_beforeInitResolve");p(this,"_afterInit");p(this,"_beforeRerender");p(this,"_afterRerender");p(this,"_afterDisconnect");p(this,"app");p(this,"_parent");b(this,Ue,"virtual-render-div");p(this,"_values",{});b(this,le);b(this,X);p(this,"_templateFunctions",{});p(this,"_templateVariables");p(this,"_define");p(this,"initElement",()=>{d(this,Ce).call(this)});b(this,Ce,async()=>{var a;this._startInitilization(),this._abort=!1;const e=(a=this.closest("[app-id]"))==null?void 0:a.app;if(!e)throw new Error("Could not find container with application.");if(this.app=e,this.app.addEventListener(Y.ABORTROUTETRANSITION,d(this,Be)),this.rndId=Rt(),this.hashId=this.getAttribute("data-hash-id")||this.generateHash(),this.getAttribute("data-hash-id")||this.setAttribute("data-hash-id",this.hashId),!this.getAttribute("data-parent-id")){let o=this.parentElement.closest("[data-hash-id]");o&&(this.setAttribute("data-parent-id",o.getAttribute("data-hash-id")),this._parent=o)}if(this._templateVariables={},z(this,X,window.structuredClone(Gt)),d(this,We).call(this),z(this,le,Object.getOwnPropertyNames(this)),d(this,Qe).call(this),d(this,ze).call(this),await d(this,x).call(this,this._beforeInit),this.app.addEventListener(Z.CHANGE,this._updateBoundAppDataParts),this.app.addEventListener(Z.QUERYCHANGE,this._updateBoundQueryDataParts),await d(this,Ie).call(this),await this.render(),this._abort){this.resolveInitialization();return}await d(this,ue).call(this),await d(this,x).call(this,this._beforeInitResolve),this.resolveInitialization(),await d(this,x).call(this,this._afterInit)});b(this,Be,e=>{this._abort=!0,this.resolveInitialization()});b(this,We,()=>{for(const[e,a]of Object.entries(this._templateFunctions))d(this,X).def[e]=a.bind(this)});b(this,ze,()=>{for(const[e,a]of Object.entries(this._define)){if(d(this,le).includes(e)||e.startsWith("#")||e.startsWith("_"))throw new Error(`Illegal or protected property name. Can't assign property with name (${e}) that is protected or if it is of illegal format (startswith: # or _) to element ${this.tagName}`);if(typeof a=="function")Object.defineProperty(this,e,a.bind(this)(e));else{let o={get(){return a.get.bind(this)()}};a.set&&(o={...o,set(h){a.set.bind(this)(h),this._refreshBoundElements(e)}}),Object.defineProperty(this,e,o)}}});p(this,"_refreshBoundElements",e=>{var a;this.renderTime=Date.now(),(a=this.querySelectorAll(`[data-bind="${e}"]`))==null||a.forEach(o=>{const h=d(this,X).dataBinds.get(e);if(!h)return;const _=o.getAttribute("data-bind-id");if(!_)return;const g=h[_];g&&(o.setAttribute("data-render-time",`${this.renderTime}`),o.innerHTML=g)})});p(this,"_updateBoundAppDataParts",e=>{this._refreshBoundElements(`app.${e.detail.field}`)});p(this,"_updateBoundQueryDataParts",e=>{var a;(a=e==null?void 0:e.detail)!=null&&a.key?this._refreshBoundElements(`query.${e.detail.key}`):this._refreshBoundElements("query")});b(this,Qe,()=>{for(const[e,a]of Object.entries(this._methods)){if(d(this,le).includes(e)||e.startsWith("#")||e.startsWith("_"))throw new Error(`Illegal or protected method name. Can't assign method with name (${e})
that is protected or if it is of illegal format (startswith: # or _) to element ${this.tagName}`);try{this[e]=a.bind(this)}catch(o){throw new Error(`${a} is probably not a function. Failed to bind method ${a} to element ${this.tagName}.`+o)}}this._methods=null});b(this,ue,async()=>{const e=[];return Array.from(this.querySelectorAll("*")).filter(o=>o instanceof rt).forEach(o=>{e.push(o.initComplete)}),await Promise.all(e)});p(this,"awaitElementsActivation",async()=>await d(this,ue).call(this));b(this,x,async e=>{for(const[a,o]of Object.entries(e))await o.bind(this)()});b(this,Ie,async()=>{var e,a;Ot&&(z(this,Ae,((e=this==null?void 0:this.css)==null?void 0:e.scoped)||!1),z(this,oe,await((a=this.css)==null?void 0:a.style.bind(this)())||null),d(this,Ge).call(this))});b(this,Ge,()=>{if(!d(this,oe))return;const e=`[data-element="${this.tagName.toLowerCase()}"]`;if(document.head.querySelector(e))return;const a=document.createElement("style");if(a.textContent=d(this,oe),a.setAttribute("disabled",""),a.setAttribute("data-element",this.tagName.toLowerCase()),document.head.appendChild(a),!d(this,Ae)){a.removeAttribute("disabled");return}const o=a.sheet,h=(g,w)=>g.split(" ").map(y=>y.replace(/([a-zA-Z0-9\.\#\-_]+)([:].*)?/,(O,P,D)=>P+w+(D||""))).join(" "),_=[];for(let g of o.cssRules)if(g instanceof CSSStyleRule){const w=g.selectorText.split(",").map(y=>h(y.trim(),e)).join(", ");_.push(`${w} { ${g.style.cssText} }`)}else if(g instanceof CSSMediaRule){const w=[];for(let y of g.cssRules)if(y instanceof CSSStyleRule){const O=y.selectorText.split(",").map(P=>h(P.trim(),e)).join(", ");w.push(`${O} { ${y.style.cssText} }`)}_.push(`@media ${g.media.mediaText} { ${w.join(" ")} }`)}a.textContent=_.join(`
`),a.removeAttribute("disabled")});b(this,xe,async()=>{if(!this.markup)throw new Error(`Missing markup method for element ${this.tagName}`);try{return await this.markup()}catch(e){throw new Error(`Failed to run markup method of element: ${this.tagName} - `+e.message)}});p(this,"render",async()=>{let e=await d(this,xe).call(this);this.innerHTML=e});b(this,Je,e=>{e=d(this,Ze).call(this,e),e=d(this,Xe).call(this,e),e=d(this,Ke).call(this,e);const a=document.createElement("div");return a.classList.add(d(this,Ue)),this.app._originalInsertAdjacentHTML.call(a,"afterbegin",e),this.lastRender=Date.now(),d(this,et).call(this,a),d(this,at).call(this,a)});b(this,Ye,e=>{try{let o=F.template.bind(this)(e,d(this,X),void 0).bind(this)(this._templateVariables);return this._templateVariables={},d(this,Je).call(this,o)}catch{console.error("Failed to run #dotJSengine for element: ",this)}});p(this,"_dotJSengine",e=>d(this,Ye).call(this,e));p(this,"getAttrs",e=>{const a=e.dataset,o={};for(const[h,_]of Object.entries(a))if(!this.app._filterAttributeNames.includes(h))try{o[h]=JSON.parse(_.trim())}catch{o[h]=_}return o});p(this,"addTemplateVariable",(e,a)=>{this._templateVariables[e]=a});p(this,"clearTemplateVariables",()=>{this._templateVariables={}});b(this,Ze,e=>e.replace(/@(\w+)=/g,"jolt-$1="));b(this,Xe,e=>e.replace(/:(\w+)=/g,"data-$1="));b(this,Ke,e=>e.replace(/<([A-Z][a-zA-Z0-9]*|[a-z][a-zA-Z0-9]*)([^>]*)\s*(\/?)>/g,(a,o,h,_)=>{if(this.app._elements[o]){const w=this.app._elements[o].tagName;return _?`<${w}${h}/>`:`<${w}${h}></${w}>`}return a}));b(this,et,e=>{e.querySelectorAll("[jolt-show-if]").forEach(a=>{const o=a.getAttribute("jolt-show-if");[!1,"false",null,"null",void 0,"undefined"].includes(o)&&a.remove()})});b(this,tt,e=>this.getAttrs(e));p(this,"getEventTypeAndMethod",e=>{if(!e.attributes)return[null,null];for(const o of e.attributes)if(o.name.startsWith("jolt-")){const h=e.getAttribute(o.name);return[o.name,h]}return[null,null]});b(this,ce,e=>{for(let a of e){const o=a.element,h=a.eventName,_=a.methodName;if(o[`jolt-${h}:active`])return;const g=this._createEventListenerMethod(o,_);o.addEventListener(h,g),o[`jolt-${h}:active`]=!0,o[`jolt-${h}:active-method-${_}`]=g}});p(this,"_createEventListenerMethod",(e,a)=>async o=>{let h=d(this,tt).call(this,e);try{h&&Object.keys(h).length!=0?await this[a](e,o,h):await this[a](e,o)}catch(_){throw console.error(_),new Error(`Could not run method ${a} on element ${this.tagName}`)}});p(this,"createEventListenerMethod",(e,a)=>this._createEventListenerMethod(e,a));p(this,"_setEventListeners",e=>{d(this,ce).call(this,e)});b(this,he,e=>{const a=[];return e.forEach(o=>{a.push(...d(this,Te).call(this,o))}),a});b(this,Te,e=>{const a=[];return Array.from(e.attributes).forEach(o=>{o.name.startsWith("jolt-")&&!o.name.startsWith("jolt-show-if")&&a.push({element:e,eventName:o.name.replace("jolt-",""),methodName:o.value})}),a});p(this,"_elementWithEvent",e=>d(this,Te).call(this,e));p(this,"_allElementsWithEvents",e=>d(this,he).call(this,e));b(this,nt,()=>{const e=d(this,he).call(this,this.querySelectorAll(`[data-parent-id="${this.hashId}"][data-render-time="${this.lastRender}"]`));d(this,ce).call(this,e)});p(this,"_hydrate",()=>{d(this,nt).call(this)});b(this,at,e=>(e.querySelectorAll(":not([data-parent-id]:not(data-render-time))").forEach(a=>{a.setAttribute("data-parent-id",this.hashId),a.setAttribute("data-render-time",`${this.lastRender}`)}),e.innerHTML));p(this,"rerender",async e=>(d(this,X).dataBinds=new Map,await d(this,x).call(this,this._beforeRerender),await this.render(),await d(this,ue).call(this),await d(this,x).call(this,this._afterRerender)));p(this,"generateHash",(e=16)=>this.app.generateHash(e));p(this,"getData",e=>this.app.getData(e));p(this,"setData",(e,a)=>{this.app.setData(e,a)});p(this,"getQueryParams",(e=!1)=>this.app.getQueryParams(e));p(this,"getHTMLtemplate",async e=>{var a,o;try{const h=await fetch(e,{redirect:"manual"});return h.status==200?await h.text():(this._abort=!0,(a=this.app)!=null&&a.router?this.app.router._abortPageLoad(h.status):console.error(`Failed to fetch html markup for ${this.tagName} with response code ${h.status}`),"")}catch{return this._abort=!0,(o=this.app)!=null&&o.router?this.app.router._abortPageLoad(500):console.error(`Failed to fetch html markup for ${this.tagName}. Server failed to respond.`),""}});this.resolveInitialization=null,this.initComplete=null,this._startInitilization()}async connectedCallback(){if([!0,"true","","defer"].includes(this.getAttribute("defer"))){this.resolveInitialization();return}try{await d(this,Ce).call(this)}catch(e){this._abort=!0,this.resolveInitialization(),console.log(`Failed to initilize element ${this.tagName}`),console.error(e)}}disconnectedCallback(){this.app.removeEventListener(Z.CHANGE,this._updateBoundAppDataParts),this.app.removeEventListener(Z.QUERYCHANGE,this._updateBoundQueryDataParts);const e=document.head.querySelector(`style[data-parent-id="${this.hashId}"]`);e&&e.remove(),d(this,x).call(this,this._afterDisconnect)}activateElement(e){typeof e=="string"&&(e=this.querySelector(e));const a=d(this,he).call(this,e.querySelectorAll(`[data-parent-id="${this.hashId}"][data-render-time="${this.lastRender}"]`));d(this,ce).call(this,a)}get attrs(){return this.getAttrs(this)}get variables(){return this._templateVariables}get queryParams(){return this.app.queryParams}set queryParams(e){this.app.queryParams=e}addQueryParams(e){this.queryParams={...this.queryParams,...e}}removeQueryParams(e){this.app.removeQueryParams(e)}get parent(){return this._parent}get router(){return this.app.router}get hash(){return this.app.hash}get port(){return this.app.port}get hostname(){return this.app.hostname}get host(){return this.app.host}get pathname(){return this.app.pathname}get origin(){return this.app.origin}get routeParameters(){return this.app.router.routeParameters}get data(){return this.app.getAllData(!0)}get functions(){return this.app.renderFunctions}get properties(){return this.app.properties}get ext(){return this.app.ext}get authenticator(){return this.app.authenticator}static generate(e,a=null){a||(a={});let o=[];for(const[_,g]of Object.entries(a))o.push(`:${_}="${g}"`);let h=o.length>0?o.join(" "):"";return e?At`<${this.tagName} data-hash-id="${e}" ${h}></${this.tagName}>`:At`<${this.tagName} ${h}></${this.tagName}>`}};Ae=new WeakMap,oe=new WeakMap,Ue=new WeakMap,le=new WeakMap,X=new WeakMap,Ce=new WeakMap,Be=new WeakMap,We=new WeakMap,ze=new WeakMap,Qe=new WeakMap,ue=new WeakMap,x=new WeakMap,Ie=new WeakMap,Ge=new WeakMap,xe=new WeakMap,Je=new WeakMap,Ye=new WeakMap,Ze=new WeakMap,Xe=new WeakMap,Ke=new WeakMap,et=new WeakMap,tt=new WeakMap,ce=new WeakMap,he=new WeakMap,Te=new WeakMap,nt=new WeakMap,at=new WeakMap,p(rt,"tagName");let I=rt;function Zt({tagName:c,markup:r,css:e=null,methods:a={},beforeInit:o={},beforeInitResolve:h={},afterInit:_={},beforeRerender:g={},afterRerender:w={},afterDisconnect:y={},define:O={},templateFunctions:P={}}){var S;if(!c||!r)throw new Error("Missing tagName or markup method in ElementFactory");if(!($=>/^[a-z]+(-[a-z]+)*$/.test($))(c))throw new Error("Element tagName must be in a valid kebab-case synatx");return S=class extends I{constructor(){super();p(this,"_methods",a);p(this,"markup",r);p(this,"css",e);p(this,"_beforeInit",o);p(this,"_beforeInitResolve",h);p(this,"_afterInit",_);p(this,"_beforeRerender",g);p(this,"_afterRerender",w);p(this,"_afterDisconnect",y);p(this,"_define",O);p(this,"_templateFunctions",P)}},p(S,"tagName",c),S}const Y={START:"route-change.start",FINISHED:"route-change.finished",LAYOUTCHANGEFINISHED:"route-change.layout-change.finished",ERRORPAGESTART:"route-change.error-page.start",ERRORPAGEFINISHED:"route-change.error-page.finished",ABORTROUTETRANSITION:"route-change.abort"};class Xt{constructor({baseUrl:r="",routes:e,baseLayout:a,defaultTarget:o,pageNotFoundCode:h=404,index:_="/",app:g}){b(this,te);b(this,Se);p(this,"_currentRoute");b(this,st,(r,e)=>{const a=e[0].length-r[0].length;return a!==0?a:r[0].includes("<str:")&&e[0].includes("<int:")?-1:r[0].includes("<int:")&&e[0].includes("<str:")?1:0});b(this,it,async r=>{var _,g,w,y;const e=(_=r==null?void 0:r.target)==null?void 0:_.matches("a"),a=(g=r==null?void 0:r.target)==null?void 0:g.closest("a"),o=e?(w=r==null?void 0:r.target)==null?void 0:w.getAttribute("router-ignore"):a==null?void 0:a.getAttribute("router-ignore"),h=e?(y=r==null?void 0:r.target)==null?void 0:y.href:a==null?void 0:a.href;if((e||a)&&!o&&h&&!h.startsWith("mailto:")){if(r.preventDefault(),this._inTransition&&this._transitionToRoute==h){r.preventDefault();return}this._inTransition&&d(this,ct).call(this),this._inTransition=!0;try{this._transitionToRoute=h,await d(this,lt).call(this,h)}catch{this._abort||console.error("Routing failed for route: ",h),this._abort=!1}this._transitionToRoute="",this._inTransition=!1}});b(this,ot,async r=>{if(await this.route(),r.state&&r.state.scrollPosition){const{x:e,y:a}=r.state.scrollPosition;window.scrollTo(e,a)}});b(this,lt,async r=>{const e=d(this,fe).call(this);history.pushState(e,null,r),await this.route()});p(this,"route",async()=>{var a,o;let r=location.pathname;r=r.replace(this.baseUrl,""),r===""&&(r="/");const e=Vt(this,te,It).call(this,r);if(e&&!((a=this.app)!=null&&a.authenticatorInstalled)){await d(this,de).call(this,e);return}if(e&&((o=this.app)!=null&&o.authenticatorInstalled)){if(!e.authenticationRequired){await d(this,de).call(this,e);return}if(e.authenticationRequired&&this.app.authenticator.isAuthenticated&&this.app.authenticator.hasRole((e==null?void 0:e.rolesRequired)||[])){await d(this,de).call(this,e);return}if(e.authenticationRequired&&(!this.app.authenticator.isAuthenticated()||!this.app.authenticator.hasRole((e==null?void 0:e.rolesRequired)||[]))){await this.app.authenticator.unauthorizedRedirect(),this.app.authenticator.redirectCallback&&await this.app.authenticator.redirectCallback();return}}await d(this,ut).call(this)});p(this,"redirect",async r=>{const e=`${this.baseUrl}${r}`,a=d(this,fe).call(this);history.pushState(a,null,e),await this.route()});p(this,"home",async()=>{const r=`${this.baseUrl}${this.index}`,e=d(this,fe).call(this);history.pushState(e,null,r),await this.route()});b(this,de,async r=>{var h;d(this,ht).call(this);const e=[];await d(this,Ne).call(this,r.layout),await this.app.querySelector(r.layout.tagName).initComplete;const o=Object.entries(r.handlers);for(const[_,[g,w]]of o.entries()){const y=this.app.querySelector(g);if(!y)throw new Error(`Failed to get target (${g}) container for route ${r.route} and handler (${w})`);if(y.querySelector(w.tagName)&&o.length!=1&&_<o.length-1)continue;const P=this.app.generateHash();this.app._originalInnerHTML.call(y,w.generate(P,(h=r.attributes)==null?void 0:h[w.tagName]));const D=this.app.querySelector(`[data-hash-id="${P}"]`);D&&await D.initComplete,e.push([g,P,w])}d(this,pt).call(this,r.title),this._currentRoute={...r,renderSequence:e,href:window.location.href},d(this,De).call(this)});b(this,Ne,async r=>{if(!this.app.querySelector(r.tagName)){this.app.container.innerHTML=r.generate();const e=this.app.querySelector(r.tagName);await e.initComplete,d(this,Re).call(this,e.tagName)}});b(this,ut,async()=>{this.app.querySelector(this.baseLayout.tagName)||(this.app.container.innerHTML=this.baseLayout.generate(),await this.app.querySelector(this.baseLayout.tagName).initComplete,d(this,Re).call(this,this.baseLayout.tagName));const r=this.app.querySelector(this.defaultTarget);if(!r)return;const e=this.app._errorPages[this.pageNotFoundCode].generate();r.innerHTML=e,d(this,De).call(this)});p(this,"_abortPageLoad",async(r=null)=>{d(this,dt).call(this);let e=this.defaultTarget,a=this.baseLayout;this._currentRoute&&(a=this._currentRoute.layout,e=this._currentRoute.renderSequence[0][0]),await d(this,Ne).call(this,a);const o=this.app.querySelector(e);if(!o)throw new Error(`Failed to get target (${e}) container for error page`);Object.keys(this.app._errorPages).includes(`${r}`)||(r=500);const h=this.app._errorPages[r].generate();o.innerHTML=h,d(this,ft).call(this)});b(this,ct,()=>{const r=new CustomEvent(Y.ABORTROUTETRANSITION,{bubbles:!0,cancelable:!0});this._abort=!0,this.app.container.dispatchEvent(r)});b(this,ht,()=>{const r=new CustomEvent(Y.START,{bubbles:!0,cancelable:!0,detail:{...this._currentRoute}});this.app.container.dispatchEvent(r)});b(this,De,()=>{const r=new CustomEvent(Y.FINISHED,{bubbles:!0,cancelable:!0,detail:{...this._currentRoute}});this.app.container.dispatchEvent(r)});b(this,Re,r=>{const e=new CustomEvent(Y.LAYOUTCHANGEFINISHED,{bubbles:!0,cancelable:!0,detail:{layout:r}});this.app.container.dispatchEvent(e)});b(this,dt,r=>{const e=new CustomEvent(Y.ERRORPAGESTART,{bubbles:!0,cancelable:!0,detail:{errorStatus:r,errorPage:this.app._errorPages[r]}});this.app.container.dispatchEvent(e)});b(this,ft,r=>{const e=new CustomEvent(Y.ERRORPAGEFINISHED,{bubbles:!0,cancelable:!0,detail:{errorStatus:r,errorPage:this.app._errorPages[r]}});this.app.container.dispatchEvent(e)});b(this,fe,()=>({scrollPosition:{x:window.scrollX,y:window.scrollY}}));b(this,pt,r=>{const e=document.querySelector("title");if(!e)throw new Error("Missing title tag in page header. This is considered bad practice!");if(!r)return;let a=r;e.innerText=a});p(this,"getQueryParams",(r=!1)=>this.app.getQueryParams(r));if(!g)throw new Error("Missing application object in router constructor");if(!e)throw new Error("Missing routes object for router.");if(!a&&!(a instanceof I))throw new Error("Missing base layout element for the application");z(this,Se,g),this.baseLayout=a,this.pageNotFoundCode=h,typeof e=="function"&&(e=e.bind(this)()),this.defaultTarget=o,this._inTransition=!1,this._transitionToRoute="",this._abort=!1,this._parseRoutes({routes:e}),this._baseUrl=r,this.index=_,this.app.addEventListener("click",d(this,it)),window.addEventListener("popstate",d(this,ot)),this._currentRoute=null}_parseRoutes({routes:r,parentPath:e="",parentHandlers:a={},layout:o}){this.routeMap=new Map(Object.entries(Vt(this,te,Nt).call(this,{routes:r,parentPath:e,parentHandlers:a,layout:o}))),this.routeMap=this.sortRouteMap()}sortRouteMap(){const r=Array.from(this.routeMap.entries()).sort(d(this,st));return new Map(r)}get baseUrl(){return this._baseUrl}get hash(){return this.app.hash}get port(){return this.app.port}get hostname(){return this.app.hostname}get host(){return location.host}get pathname(){return location.pathname}get origin(){return location.origin}get app(){return d(this,Se)}get currentRoute(){return this._currentRoute}}Se=new WeakMap,te=new WeakSet,Nt=function({routes:r,parentPath:e="",parentHandlers:a={},layout:o}){let h=o;h||(h=this.baseLayout);const _={};return r.forEach(g=>{const w=e+g.path;if(typeof g.handler!="function")throw new Error("Route handler must be of type CustomElement from ElementFactory.");const y=g.handler?{...a,[g.target]:g.handler}:{...a};g.handlers&&Object.keys(g.handlers).forEach(P=>{y[P]=g.handlers[P]});const O=g.layout||h;_[w]={handlers:{...y},layout:O,title:g==null?void 0:g.title,roles:g.roles||null,details:(g==null?void 0:g.details)||null,attributes:g!=null&&g.attributes?{[g.handler.tagName]:g.attributes}:null,authenticationRequired:[void 0].includes(g==null?void 0:g.authenticationRequired)?!1:g==null?void 0:g.authenticationRequired,rolesRequired:[void 0].includes(g==null?void 0:g.authenticationRequired)?[]:g==null?void 0:g.rolesRequired},g.children&&Object.assign(_,Vt(this,te,Nt).call(this,{routes:g.children,parentPath:w,parentHandlers:y,layout:O}))}),_},st=new WeakMap,it=new WeakMap,ot=new WeakMap,lt=new WeakMap,It=function(r){for(const[e,a]of this.routeMap.entries()){const o=[],h=[],_=e.replace(/<(\w+):(\w+)>/g,(w,y,O)=>{if(o.push(O),h.push(y),y==="str")return"([^/]+)";if(y==="int")return"(\\d+)"}),g=r.match(new RegExp(`^${_}$`));if(g){const w=o.reduce((y,O,P)=>{let D=g[P+1];return h[P]==="int"&&(D=parseInt(D,10)),y[O]=D,y},{});return this.routeParameters=w||null,{route:e,handlers:a.handlers,details:(a==null?void 0:a.details)||null,title:a.title,rolesRequired:a.rolesRequired||[],authenticationRequired:a.authenticationRequired||!1,layout:a.layout,params:w,attributes:(a==null?void 0:a.attributes)||null}}}return null},de=new WeakMap,Ne=new WeakMap,ut=new WeakMap,ct=new WeakMap,ht=new WeakMap,De=new WeakMap,Re=new WeakMap,dt=new WeakMap,ft=new WeakMap,fe=new WeakMap,pt=new WeakMap;var M;(function(c){c.Attribute="attribute",c.Pseudo="pseudo",c.PseudoElement="pseudo-element",c.Tag="tag",c.Universal="universal",c.Adjacent="adjacent",c.Child="child",c.Descendant="descendant",c.Parent="parent",c.Sibling="sibling",c.ColumnCombinator="column-combinator"})(M||(M={}));var U;(function(c){c.Any="any",c.Element="element",c.End="end",c.Equals="equals",c.Exists="exists",c.Hyphen="hyphen",c.Not="not",c.Start="start"})(U||(U={}));const $t=/^[^\\#]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/,Kt=/\\([\da-f]{1,6}\s?|(\s)|.)/gi,en=new Map([[126,U.Element],[94,U.Start],[36,U.End],[42,U.Any],[33,U.Not],[124,U.Hyphen]]),tn=new Set(["has","not","matches","is","where","host","host-context"]);function nn(c){switch(c.type){case M.Adjacent:case M.Child:case M.Descendant:case M.Parent:case M.Sibling:case M.ColumnCombinator:return!0;default:return!1}}const an=new Set(["contains","icontains"]);function rn(c,r,e){const a=parseInt(r,16)-65536;return a!==a||e?r:a<0?String.fromCharCode(a+65536):String.fromCharCode(a>>10|55296,a&1023|56320)}function Ee(c){return c.replace(Kt,rn)}function Ct(c){return c===39||c===34}function Mt(c){return c===32||c===9||c===10||c===12||c===13}function sn(c){const r=[],e=kt(r,`${c}`,0);if(e<c.length)throw new Error(`Unmatched selector: ${c.slice(e)}`);return r}function kt(c,r,e){let a=[];function o(D){const S=r.slice(e+D).match($t);if(!S)throw new Error(`Expected name, found ${r.slice(e)}`);const[$]=S;return e+=D+$.length,Ee($)}function h(D){for(e+=D;e<r.length&&Mt(r.charCodeAt(e));)e++}function _(){e+=1;const D=e;let S=1;for(;S>0&&e<r.length;e++)r.charCodeAt(e)===40&&!g(e)?S++:r.charCodeAt(e)===41&&!g(e)&&S--;if(S)throw new Error("Parenthesis not matched");return Ee(r.slice(D,e-1))}function g(D){let S=0;for(;r.charCodeAt(--D)===92;)S++;return(S&1)===1}function w(){if(a.length>0&&nn(a[a.length-1]))throw new Error("Did not expect successive traversals.")}function y(D){if(a.length>0&&a[a.length-1].type===M.Descendant){a[a.length-1].type=D;return}w(),a.push({type:D})}function O(D,S){a.push({type:M.Attribute,name:D,action:S,value:o(1),namespace:null,ignoreCase:"quirks"})}function P(){if(a.length&&a[a.length-1].type===M.Descendant&&a.pop(),a.length===0)throw new Error("Empty sub-selector");c.push(a)}if(h(0),r.length===e)return e;e:for(;e<r.length;){const D=r.charCodeAt(e);switch(D){case 32:case 9:case 10:case 12:case 13:{(a.length===0||a[0].type!==M.Descendant)&&(w(),a.push({type:M.Descendant})),h(1);break}case 62:{y(M.Child),h(1);break}case 60:{y(M.Parent),h(1);break}case 126:{y(M.Sibling),h(1);break}case 43:{y(M.Adjacent),h(1);break}case 46:{O("class",U.Element);break}case 35:{O("id",U.Equals);break}case 91:{h(1);let S,$=null;r.charCodeAt(e)===124?S=o(1):r.startsWith("*|",e)?($="*",S=o(2)):(S=o(0),r.charCodeAt(e)===124&&r.charCodeAt(e+1)!==61&&($=S,S=o(1))),h(0);let L=U.Exists;const ge=en.get(r.charCodeAt(e));if(ge){if(L=ge,r.charCodeAt(e+1)!==61)throw new Error("Expected `=`");h(2)}else r.charCodeAt(e)===61&&(L=U.Equals,h(1));let ae="",He=null;if(L!=="exists"){if(Ct(r.charCodeAt(e))){const _e=r.charCodeAt(e);let J=e+1;for(;J<r.length&&(r.charCodeAt(J)!==_e||g(J));)J+=1;if(r.charCodeAt(J)!==_e)throw new Error("Attribute value didn't end");ae=Ee(r.slice(e+1,J)),e=J+1}else{const _e=e;for(;e<r.length&&(!Mt(r.charCodeAt(e))&&r.charCodeAt(e)!==93||g(e));)e+=1;ae=Ee(r.slice(_e,e))}h(0);const wt=r.charCodeAt(e)|32;wt===115?(He=!1,h(1)):wt===105&&(He=!0,h(1))}if(r.charCodeAt(e)!==93)throw new Error("Attribute selector didn't terminate");e+=1;const ve={type:M.Attribute,name:S,action:L,value:ae,namespace:$,ignoreCase:He};a.push(ve);break}case 58:{if(r.charCodeAt(e+1)===58){a.push({type:M.PseudoElement,name:o(2).toLowerCase(),data:r.charCodeAt(e)===40?_():null});continue}const S=o(1).toLowerCase();let $=null;if(r.charCodeAt(e)===40)if(tn.has(S)){if(Ct(r.charCodeAt(e+1)))throw new Error(`Pseudo-selector ${S} cannot be quoted`);if($=[],e=kt($,r,e+1),r.charCodeAt(e)!==41)throw new Error(`Missing closing parenthesis in :${S} (${r})`);e+=1}else{if($=_(),an.has(S)){const L=$.charCodeAt(0);L===$.charCodeAt($.length-1)&&Ct(L)&&($=$.slice(1,-1))}$=Ee($)}a.push({type:M.Pseudo,name:S,data:$});break}case 44:{P(),a=[],h(1);break}default:{if(r.startsWith("/*",e)){const L=r.indexOf("*/",e+2);if(L<0)throw new Error("Comment was not terminated");e=L+2,a.length===0&&h(0);break}let S=null,$;if(D===42)e+=1,$="*";else if(D===124){if($="",r.charCodeAt(e+1)===124){y(M.ColumnCombinator),h(2);break}}else if($t.test(r.slice(e)))$=o(0);else break e;r.charCodeAt(e)===124&&r.charCodeAt(e+1)!==124&&(S=$,r.charCodeAt(e+1)===42?($="*",e+=2):$=o(1)),a.push($==="*"?{type:M.Universal,namespace:S}:{type:M.Tag,name:$,namespace:S})}}}return P(),e}const Lt=["\\",'"'],Pt=[...Lt,"(",")"],on=new Set(Lt.map(c=>c.charCodeAt(0))),qt=new Set(Pt.map(c=>c.charCodeAt(0))),se=new Set([...Pt,"~","^","$","*","+","!","|",":","[","]"," ","."].map(c=>c.charCodeAt(0)));function Ht(c){return c.map(r=>r.map(ln).join("")).join(", ")}function ln(c,r,e){switch(c.type){case M.Child:return r===0?"> ":" > ";case M.Parent:return r===0?"< ":" < ";case M.Sibling:return r===0?"~ ":" ~ ";case M.Adjacent:return r===0?"+ ":" + ";case M.Descendant:return" ";case M.ColumnCombinator:return r===0?"|| ":" || ";case M.Universal:return c.namespace==="*"&&r+1<e.length&&"name"in e[r+1]?"":`${Ft(c.namespace)}*`;case M.Tag:return jt(c);case M.PseudoElement:return`::${G(c.name,se)}${c.data===null?"":`(${G(c.data,qt)})`}`;case M.Pseudo:return`:${G(c.name,se)}${c.data===null?"":`(${typeof c.data=="string"?G(c.data,qt):Ht(c.data)})`}`;case M.Attribute:{if(c.name==="id"&&c.action===U.Equals&&c.ignoreCase==="quirks"&&!c.namespace)return`#${G(c.value,se)}`;if(c.name==="class"&&c.action===U.Element&&c.ignoreCase==="quirks"&&!c.namespace)return`.${G(c.value,se)}`;const a=jt(c);return c.action===U.Exists?`[${a}]`:`[${a}${un(c.action)}="${G(c.value,on)}"${c.ignoreCase===null?"":c.ignoreCase?" i":" s"}]`}}}function un(c){switch(c){case U.Equals:return"";case U.Element:return"~";case U.Start:return"^";case U.End:return"$";case U.Any:return"*";case U.Not:return"!";case U.Hyphen:return"|";case U.Exists:throw new Error("Shouldn't be here")}}function jt(c){return`${Ft(c.namespace)}${G(c.name,se)}`}function Ft(c){return c!==null?`${c==="*"?"*":G(c,se)}|`:""}function G(c,r){let e=0,a="";for(let o=0;o<c.length;o++)r.has(c.charCodeAt(o))&&(a+=`${c.slice(e,o)}\\${c.charAt(o)}`,e=o+1);return a.length>0?a+c.slice(e):c}function Ut(c){return c.map(r=>{if(Array.isArray(r))return Ut(r);if(r.type==="attribute"){let e=r.name.replace(/:/g,"data-");return e=e.replace(/@/g,"jolt-"),{...r,name:Ve(e)}}return{...r}})}function Fe(c){const r=sn(c),e=Ut(r);return Ht(e)}var ie={},Bt;function cn(){if(Bt)return ie;Bt=1;var c=function(){return c=Object.assign||function(n){for(var t=arguments,l,i=1,u=arguments.length;i<u;i++){l=t[i];for(var m in l)Object.prototype.hasOwnProperty.call(l,m)&&(n[m]=l[m])}return n},c.apply(this,arguments)};function r(s,n,t){for(var l=0,i=n.length,u;l<i;l++)(u||!(l in n))&&(u||(u=Array.prototype.slice.call(n,0,l)),u[l]=n[l]);return s.concat(u||Array.prototype.slice.call(n))}typeof SuppressedError=="function"&&SuppressedError;var e=function(){function s(n){n===void 0&&(n={});var t=this;Object.entries(n).forEach(function(l){var i=l[0],u=l[1];return t[i]=u})}return s.prototype.toString=function(){return JSON.stringify(this)},s.prototype.setValue=function(n,t){return this[n]=t,this},s}();function a(s){for(var n=arguments,t=[],l=1;l<arguments.length;l++)t[l-1]=n[l];return typeof s>"u"||s===null?!1:t.some(function(i){var u,m;return typeof((m=(u=s==null?void 0:s.ownerDocument)===null||u===void 0?void 0:u.defaultView)===null||m===void 0?void 0:m[i])=="function"&&s instanceof s.ownerDocument.defaultView[i]})}function o(s,n,t){var l;return s.nodeName==="#text"?l=t.document.createTextNode(s.data):s.nodeName==="#comment"?l=t.document.createComment(s.data):(n?(l=t.document.createElementNS("http://www.w3.org/2000/svg",s.nodeName),s.nodeName==="foreignObject"&&(n=!1)):s.nodeName.toLowerCase()==="svg"?(l=t.document.createElementNS("http://www.w3.org/2000/svg","svg"),n=!0):l=t.document.createElement(s.nodeName),s.attributes&&Object.entries(s.attributes).forEach(function(i){var u=i[0],m=i[1];return l.setAttribute(u,m)}),s.childNodes&&(l=l,s.childNodes.forEach(function(i){return l.appendChild(o(i,n,t))})),t.valueDiffing&&(s.value&&a(l,"HTMLButtonElement","HTMLDataElement","HTMLInputElement","HTMLLIElement","HTMLMeterElement","HTMLOptionElement","HTMLProgressElement","HTMLParamElement")&&(l.value=s.value),s.checked&&a(l,"HTMLInputElement")&&(l.checked=s.checked),s.selected&&a(l,"HTMLOptionElement")&&(l.selected=s.selected))),l}var h=function(s,n){for(n=n.slice();n.length>0;){var t=n.splice(0,1)[0];s=s.childNodes[t]}return s};function _(s,n,t){var l=n[t._const.action],i=n[t._const.route],u;[t._const.addElement,t._const.addTextElement].includes(l)||(u=h(s,i));var m,A,v,E={diff:n,node:u};if(t.preDiffApply(E))return!0;switch(l){case t._const.addAttribute:if(!u||!a(u,"Element"))return!1;u.setAttribute(n[t._const.name],n[t._const.value]);break;case t._const.modifyAttribute:if(!u||!a(u,"Element"))return!1;u.setAttribute(n[t._const.name],n[t._const.newValue]),a(u,"HTMLInputElement")&&n[t._const.name]==="value"&&(u.value=n[t._const.newValue]);break;case t._const.removeAttribute:if(!u||!a(u,"Element"))return!1;u.removeAttribute(n[t._const.name]);break;case t._const.modifyTextElement:if(!u||!a(u,"Text"))return!1;t.textDiff(u,u.data,n[t._const.oldValue],n[t._const.newValue]),a(u.parentNode,"HTMLTextAreaElement")&&(u.parentNode.value=n[t._const.newValue]);break;case t._const.modifyValue:if(!u||typeof u.value>"u")return!1;u.value=n[t._const.newValue];break;case t._const.modifyComment:if(!u||!a(u,"Comment"))return!1;t.textDiff(u,u.data,n[t._const.oldValue],n[t._const.newValue]);break;case t._const.modifyChecked:if(!u||typeof u.checked>"u")return!1;u.checked=n[t._const.newValue];break;case t._const.modifySelected:if(!u||typeof u.selected>"u")return!1;u.selected=n[t._const.newValue];break;case t._const.replaceElement:{var V=n[t._const.newValue].nodeName.toLowerCase()==="svg"||u.parentNode.namespaceURI==="http://www.w3.org/2000/svg";u.parentNode.replaceChild(o(n[t._const.newValue],V,t),u);break}case t._const.relocateGroup:v=r([],new Array(n[t._const.groupLength])).map(function(){return u.removeChild(u.childNodes[n[t._const.from]])}),v.forEach(function(R,f){f===0&&(A=u.childNodes[n[t._const.to]]),u.insertBefore(R,A||null)});break;case t._const.removeElement:u.parentNode.removeChild(u);break;case t._const.addElement:{var T=i.slice(),k=T.splice(T.length-1,1)[0];if(u=h(s,T),!a(u,"Element"))return!1;u.insertBefore(o(n[t._const.element],u.namespaceURI==="http://www.w3.org/2000/svg",t),u.childNodes[k]||null);break}case t._const.removeTextElement:{if(!u||u.nodeType!==3)return!1;var C=u.parentNode;C.removeChild(u),a(C,"HTMLTextAreaElement")&&(C.value="");break}case t._const.addTextElement:{var T=i.slice(),k=T.splice(T.length-1,1)[0];if(m=t.document.createTextNode(n[t._const.value]),u=h(s,T),!u.childNodes)return!1;u.insertBefore(m,u.childNodes[k]||null),a(u.parentNode,"HTMLTextAreaElement")&&(u.parentNode.value=n[t._const.value]);break}default:console.log("unknown action")}return t.postDiffApply({diff:E.diff,node:E.node,newNode:m}),!0}function g(s,n,t){return n.every(function(l){return _(s,l,t)})}function w(s,n,t){var l=s[n];s[n]=s[t],s[t]=l}function y(s,n,t){switch(n[t._const.action]){case t._const.addAttribute:n[t._const.action]=t._const.removeAttribute,_(s,n,t);break;case t._const.modifyAttribute:w(n,t._const.oldValue,t._const.newValue),_(s,n,t);break;case t._const.removeAttribute:n[t._const.action]=t._const.addAttribute,_(s,n,t);break;case t._const.modifyTextElement:w(n,t._const.oldValue,t._const.newValue),_(s,n,t);break;case t._const.modifyValue:w(n,t._const.oldValue,t._const.newValue),_(s,n,t);break;case t._const.modifyComment:w(n,t._const.oldValue,t._const.newValue),_(s,n,t);break;case t._const.modifyChecked:w(n,t._const.oldValue,t._const.newValue),_(s,n,t);break;case t._const.modifySelected:w(n,t._const.oldValue,t._const.newValue),_(s,n,t);break;case t._const.replaceElement:w(n,t._const.oldValue,t._const.newValue),_(s,n,t);break;case t._const.relocateGroup:w(n,t._const.from,t._const.to),_(s,n,t);break;case t._const.removeElement:n[t._const.action]=t._const.addElement,_(s,n,t);break;case t._const.addElement:n[t._const.action]=t._const.removeElement,_(s,n,t);break;case t._const.removeTextElement:n[t._const.action]=t._const.addTextElement,_(s,n,t);break;case t._const.addTextElement:n[t._const.action]=t._const.removeTextElement,_(s,n,t);break;default:console.log("unknown action")}}function O(s,n,t){n=n.slice(),n.reverse(),n.forEach(function(l){y(s,l,t)})}var P=function(s){var n=[];return n.push(s.nodeName),s.nodeName!=="#text"&&s.nodeName!=="#comment"&&(s=s,s.attributes&&(s.attributes.class&&n.push("".concat(s.nodeName,".").concat(s.attributes.class.replace(/ /g,"."))),s.attributes.id&&n.push("".concat(s.nodeName,"#").concat(s.attributes.id)))),n},D=function(s){var n={},t={};return s.forEach(function(l){P(l).forEach(function(i){var u=i in n,m=i in t;!u&&!m?n[i]=!0:u&&(delete n[i],t[i]=!0)})}),n},S=function(s,n){var t=D(s),l=D(n),i={};return Object.keys(t).forEach(function(u){l[u]&&(i[u]=!0)}),i},$=function(s){return delete s.outerDone,delete s.innerDone,delete s.valueDone,s.childNodes?s.childNodes.every($):!0},L=function(s){if(Object.prototype.hasOwnProperty.call(s,"data")){var n={nodeName:s.nodeName==="#text"?"#text":"#comment",data:s.data};return n}else{var t={nodeName:s.nodeName};return s=s,Object.prototype.hasOwnProperty.call(s,"attributes")&&(t.attributes=c({},s.attributes)),Object.prototype.hasOwnProperty.call(s,"checked")&&(t.checked=s.checked),Object.prototype.hasOwnProperty.call(s,"value")&&(t.value=s.value),Object.prototype.hasOwnProperty.call(s,"selected")&&(t.selected=s.selected),Object.prototype.hasOwnProperty.call(s,"childNodes")&&(t.childNodes=s.childNodes.map(function(l){return L(l)})),t}},ge=function(s,n){if(!["nodeName","value","checked","selected","data"].every(function(i){return s[i]===n[i]}))return!1;if(Object.prototype.hasOwnProperty.call(s,"data"))return!0;if(s=s,n=n,!!s.attributes!=!!n.attributes||!!s.childNodes!=!!n.childNodes)return!1;if(s.attributes){var t=Object.keys(s.attributes),l=Object.keys(n.attributes);if(t.length!==l.length||!t.every(function(i){return s.attributes[i]===n.attributes[i]}))return!1}return!(s.childNodes&&(s.childNodes.length!==n.childNodes.length||!s.childNodes.every(function(i,u){return ge(i,n.childNodes[u])})))},ae=function(s,n,t,l,i){if(i===void 0&&(i=!1),!s||!n||s.nodeName!==n.nodeName)return!1;if(["#text","#comment"].includes(s.nodeName))return i?!0:s.data===n.data;if(s=s,n=n,s.nodeName in t)return!0;if(s.attributes&&n.attributes){if(s.attributes.id){if(s.attributes.id!==n.attributes.id)return!1;var u="".concat(s.nodeName,"#").concat(s.attributes.id);if(u in t)return!0}if(s.attributes.class&&s.attributes.class===n.attributes.class){var m="".concat(s.nodeName,".").concat(s.attributes.class.replace(/ /g,"."));if(m in t)return!0}}if(l)return!0;var A=s.childNodes?s.childNodes.slice().reverse():[],v=n.childNodes?n.childNodes.slice().reverse():[];if(A.length!==v.length)return!1;if(i)return A.every(function(V,T){return V.nodeName===v[T].nodeName});var E=S(A,v);return A.every(function(V,T){return ae(V,v[T],E,!0,!0)})},He=function(s,n,t,l){var i=0,u=[],m=s.length,A=n.length,v=r([],new Array(m+1)).map(function(){return[]}),E=S(s,n),V=m===A;V&&s.some(function(f,H){var W=P(f),B=P(n[H]);if(W.length!==B.length)return V=!1,!0;if(W.some(function(j,be){if(j!==B[be])return V=!1,!0}),!V)return!0});for(var T=0;T<m;T++)for(var k=s[T],C=0;C<A;C++){var R=n[C];!t[T]&&!l[C]&&ae(k,R,E,V)?(v[T+1][C+1]=v[T][C]?v[T][C]+1:1,v[T+1][C+1]>=i&&(i=v[T+1][C+1],u=[T+1,C+1])):v[T+1][C+1]=0}return i===0?!1:{oldValue:u[0]-i,newValue:u[1]-i,length:i}},ve=function(s,n){return r([],new Array(s)).map(function(){return n})},wt=function(s,n,t){var l=s.childNodes?ve(s.childNodes.length,!0):[],i=n.childNodes?ve(n.childNodes.length,!0):[],u=0;return t.forEach(function(m){for(var A=m.oldValue+m.length,v=m.newValue+m.length,E=m.oldValue;E<A;E+=1)l[E]=u;for(var E=m.newValue;E<v;E+=1)i[E]=u;u+=1}),{gaps1:l,gaps2:i}},_e=function(s,n,t,l){s[t.oldValue+l]=!0,n[t.newValue+l]=!0},J=function(s,n){for(var t=s.childNodes?s.childNodes:[],l=n.childNodes?n.childNodes:[],i=ve(t.length,!1),u=ve(l.length,!1),m=[],A=function(){return arguments[1]},v=!1,E=function(){var V=He(t,l,i,u);if(V){m.push(V);var T=r([],new Array(V.length)).map(A);T.forEach(function(k){return _e(i,u,V,k)})}else v=!0};!v;)E();return s.subsets=m,s.subsetsAge=100,m},gn=function(){function s(){this.list=[]}return s.prototype.add=function(n){var t;(t=this.list).push.apply(t,n)},s.prototype.forEach=function(n){this.list.forEach(function(t){return n(t)})},s}();function Tt(s,n){var t=s,l,i;for(n=n.slice();n.length>0;)i=n.splice(0,1)[0],l=t,t=t.childNodes?t.childNodes[i]:void 0;return{node:t,parentNode:l,nodeIndex:i}}function vn(s,n,t){var l,i,u,m;if(![t._const.addElement,t._const.addTextElement].includes(n[t._const.action])){var A=Tt(s,n[t._const.route]);i=A.node,u=A.parentNode,m=A.nodeIndex}var v=[],E={diff:n,node:i};if(t.preVirtualDiffApply(E))return!0;var V,T,k;switch(n[t._const.action]){case t._const.addAttribute:i.attributes||(i.attributes={}),i.attributes[n[t._const.name]]=n[t._const.value],n[t._const.name]==="checked"?i.checked=!0:n[t._const.name]==="selected"?i.selected=!0:i.nodeName==="INPUT"&&n[t._const.name]==="value"&&(i.value=n[t._const.value]);break;case t._const.modifyAttribute:i.attributes[n[t._const.name]]=n[t._const.newValue];break;case t._const.removeAttribute:delete i.attributes[n[t._const.name]],Object.keys(i.attributes).length===0&&delete i.attributes,n[t._const.name]==="checked"?i.checked=!1:n[t._const.name]==="selected"?delete i.selected:i.nodeName==="INPUT"&&n[t._const.name]==="value"&&delete i.value;break;case t._const.modifyTextElement:i.data=n[t._const.newValue],u.nodeName==="TEXTAREA"&&(u.value=n[t._const.newValue]);break;case t._const.modifyValue:i.value=n[t._const.newValue];break;case t._const.modifyComment:i.data=n[t._const.newValue];break;case t._const.modifyChecked:i.checked=n[t._const.newValue];break;case t._const.modifySelected:i.selected=n[t._const.newValue];break;case t._const.replaceElement:V=L(n[t._const.newValue]),u.childNodes[m]=V;break;case t._const.relocateGroup:T=i.childNodes.splice(n[t._const.from],n[t._const.groupLength]).reverse(),T.forEach(function(f){return i.childNodes.splice(n[t._const.to],0,f)}),i.subsets&&i.subsets.forEach(function(f){if(n[t._const.from]<n[t._const.to]&&f.oldValue<=n[t._const.to]&&f.oldValue>n[t._const.from]){f.oldValue-=n[t._const.groupLength];var H=f.oldValue+f.length-n[t._const.to];H>0&&(v.push({oldValue:n[t._const.to]+n[t._const.groupLength],newValue:f.newValue+f.length-H,length:H}),f.length-=H)}else if(n[t._const.from]>n[t._const.to]&&f.oldValue>n[t._const.to]&&f.oldValue<n[t._const.from]){f.oldValue+=n[t._const.groupLength];var H=f.oldValue+f.length-n[t._const.to];H>0&&(v.push({oldValue:n[t._const.to]+n[t._const.groupLength],newValue:f.newValue+f.length-H,length:H}),f.length-=H)}else f.oldValue===n[t._const.from]&&(f.oldValue=n[t._const.to])});break;case t._const.removeElement:u.childNodes.splice(m,1),u.subsets&&u.subsets.forEach(function(f){f.oldValue>m?f.oldValue-=1:f.oldValue===m?f.delete=!0:f.oldValue<m&&f.oldValue+f.length>m&&(f.oldValue+f.length-1===m?f.length--:(v.push({newValue:f.newValue+m-f.oldValue,oldValue:m,length:f.length-m+f.oldValue-1}),f.length=m-f.oldValue))}),i=u;break;case t._const.addElement:{k=n[t._const.route].slice();var C=k.splice(k.length-1,1)[0];i=(l=Tt(s,k))===null||l===void 0?void 0:l.node,V=L(n[t._const.element]),i.childNodes||(i.childNodes=[]),C>=i.childNodes.length?i.childNodes.push(V):i.childNodes.splice(C,0,V),i.subsets&&i.subsets.forEach(function(f){if(f.oldValue>=C)f.oldValue+=1;else if(f.oldValue<C&&f.oldValue+f.length>C){var H=f.oldValue+f.length-C;v.push({newValue:f.newValue+f.length-H,oldValue:C+1,length:H}),f.length-=H}});break}case t._const.removeTextElement:u.childNodes.splice(m,1),u.nodeName==="TEXTAREA"&&delete u.value,u.subsets&&u.subsets.forEach(function(f){f.oldValue>m?f.oldValue-=1:f.oldValue===m?f.delete=!0:f.oldValue<m&&f.oldValue+f.length>m&&(f.oldValue+f.length-1===m?f.length--:(v.push({newValue:f.newValue+m-f.oldValue,oldValue:m,length:f.length-m+f.oldValue-1}),f.length=m-f.oldValue))}),i=u;break;case t._const.addTextElement:{k=n[t._const.route].slice();var R=k.splice(k.length-1,1)[0];V={nodeName:"#text",data:n[t._const.value]},i=Tt(s,k).node,i.childNodes||(i.childNodes=[]),R>=i.childNodes.length?i.childNodes.push(V):i.childNodes.splice(R,0,V),i.nodeName==="TEXTAREA"&&(i.value=n[t._const.newValue]),i.subsets&&i.subsets.forEach(function(f){if(f.oldValue>=R&&(f.oldValue+=1),f.oldValue<R&&f.oldValue+f.length>R){var H=f.oldValue+f.length-R;v.push({newValue:f.newValue+f.length-H,oldValue:R+1,length:H}),f.length-=H}});break}default:console.log("unknown action")}i.subsets&&(i.subsets=i.subsets.filter(function(f){return!f.delete&&f.oldValue!==f.newValue}),v.length&&(i.subsets=i.subsets.concat(v))),t.postVirtualDiffApply({node:E.node,diff:E.diff,newNode:V})}function _n(s,n,t){return n.forEach(function(l){vn(s,l,t)}),!0}function ye(s,n){n===void 0&&