UNPKG

juris-test

Version:

JavaScript Unified Reactive Interface Solution - Browser-optimized version for script tags and CDN usage

1 lines 55.4 kB
"use strict";const jurisLinesOfCode=2907,jurisVersion="0.9.2",jurisMinifiedSize="54 kB",isValidPath=e=>"string"==typeof e&&e.trim().length>0&&!e.includes(".."),getPathParts=e=>e.split(".").filter(Boolean),deepEquals=(e,t)=>{if(e===t)return!0;if(null==e||null==t||typeof e!=typeof t)return!1;if("object"==typeof e){if(Array.isArray(e)!==Array.isArray(t))return!1;const n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&n.every((n=>r.includes(n)&&deepEquals(e[n],t[n])))}return!1},createLogger=()=>{const e=[],t=(t,n,r)=>{const s={formatted:`${r?`[${r}] `:""}${t}${n?` ${JSON.stringify(n)}`:""}`,message:t,context:n,category:r,timestamp:Date.now()};return setTimeout((()=>e.forEach((e=>e(s)))),0),s};return{log:{l:t,w:t,e:t,i:t,d:t,ei:!0,ee:!0,el:!0,ew:!0,ed:!0},sub:t=>e.push(t),unsub:t=>e.splice(e.indexOf(t),1)}},{log:log,logSub:logSub,logUnsub:logUnsub}=createLogger(),createPromisify=()=>{const e=new Set;let t=!1;const n=new Set,r=()=>{0===e.size&&n.size>0&&n.forEach((e=>e()))};return{promisify:n=>{const s="function"==typeof n?.then?n:Promise.resolve(n);return t&&s!==n&&(e.add(s),s.finally((()=>{e.delete(s),setTimeout(r,0)}))),s},startTracking:()=>{t=!0,e.clear()},stopTracking:()=>{t=!1,n.clear()},onAllComplete:t=>(n.add(t),0===e.size&&setTimeout(t,0),()=>n.delete(t))}},{promisify:promisify,startTracking:startTracking,stopTracking:stopTracking,onAllComplete:onAllComplete}=createPromisify();class StateManager{constructor(e={},t=[]){log.ei&&console.info(log.i("StateManager initialized",{initialStateKeys:Object.keys(e),middlewareCount:t.length},"framework")),this.state={...e},this.middleware=[...t],this.subscribers=new Map,this.externalSubscribers=new Map,this.currentTracking=null,this.isUpdating=!1,this.initialState=JSON.parse(JSON.stringify(e)),this.maxUpdateDepth=50,this.updateDepth=0,this.currentlyUpdating=new Set,this.isBatching=!1,this.batchQueue=[],this.batchedPaths=new Set}reset(){log.ei&&console.info(log.i("State reset to initial state",{},"framework")),this.isBatching&&(this.batchQueue=[],this.batchedPaths.clear(),this.isBatching=!1),this.state=JSON.parse(JSON.stringify(this.initialState))}getState(e,t=null,n=!0){if(!isValidPath(e))return t;n&&this.currentTracking?.add(e);const r=getPathParts(e);let s=this.state;for(const e of r){if(void 0===s?.[e])return t;s=s[e]}return s}setState(e,t,n={}){log.ed&&console.debug(log.d("State change initiated",{path:e,hasValue:void 0!==t},"application")),isValidPath(e)&&!this.#e(e)&&(this.isBatching?this.#t(e,t,n):this.#n(e,t,n))}executeBatch(e){if(this.isBatching)return e();this.#r();try{const t=e();return t&&"function"==typeof t.then?t.then((e=>(this.#s(),e))).catch((e=>{throw this.#s(),e})):(this.#s(),t)}catch(e){throw this.#s(),e}}#r(){log.ed&&console.debug(log.d("Manual batch started",{},"framework")),this.isBatching=!0,this.batchQueue=[],this.batchedPaths.clear()}#s(){this.isBatching?(log.ed&&console.debug(log.d("Manual batch ending",{queuedUpdates:this.batchQueue.length},"framework")),this.isBatching=!1,0!==this.batchQueue.length&&this.#o()):log.ew&&console.warn(log.w("endBatch() called without beginBatch()",{},"framework"))}isBatchingActive(){return this.isBatching}getBatchQueueSize(){return this.batchQueue.length}clearBatch(){this.isBatching&&(log.ei&&console.info(log.i("Clearing current batch",{clearedUpdates:this.batchQueue.length},"framework")),this.batchQueue=[],this.batchedPaths.clear())}#t(e,t,n){this.batchQueue=this.batchQueue.filter((t=>t.path!==e)),this.batchQueue.push({path:e,value:t,context:n,timestamp:Date.now()}),this.batchedPaths.add(e)}#o(){const e=[...this.batchQueue];this.batchQueue=[],this.batchedPaths.clear();const t=new Map;e.forEach((e=>t.set(e.path,e)));const n=this.isUpdating;this.isUpdating=!0;const r=[];t.forEach((e=>{const t=this.getState(e.path);let n=e.value;for(const r of this.middleware)try{const s=r({path:e.path,oldValue:t,newValue:n,context:e.context,state:this.state});void 0!==s&&(n=s)}catch(t){log.ee&&console.error(log.e("Middleware error in batch",{path:e.path,error:t.message},"application"))}if(deepEquals(t,n))return;const s=getPathParts(e.path);let o=this.state;for(let e=0;e<s.length-1;e++){const t=s[e];null!=o[t]&&"object"==typeof o[t]||(o[t]={}),o=o[t]}o[s[s.length-1]]=n,r.push({path:e.path,oldValue:t,newValue:n})})),this.isUpdating=n;const s=new Set;r.forEach((({path:e})=>{const t=getPathParts(e);for(let e=1;e<=t.length;e++)s.add(t.slice(0,e).join("."))})),s.forEach((e=>{this.subscribers.has(e)&&this.#i(e),this.externalSubscribers.has(e)&&this.externalSubscribers.get(e).forEach((({callback:t,hierarchical:n})=>{try{t(this.getState(e),null,e)}catch(e){log.ee&&console.error(log.e("External subscriber error:",e),"application")}}))}))}#n(e,t,n={}){const r=this.getState(e);let s=t;for(const t of this.middleware)try{const o=t({path:e,oldValue:r,newValue:s,context:n,state:this.state});void 0!==o&&(s=o)}catch(n){log.ee&&console.error(log.e("Middleware error",{path:e,error:n.message,middlewareName:t.name||"anonymous"},"application"))}if(deepEquals(r,s))return void(log.ed&&console.debug(log.d("State unchanged, skipping update",{path:e},"framework")));log.ed&&console.debug(log.d("State updated",{path:e,oldValue:typeof r,newValue:typeof s},"application"));const o=getPathParts(e);let i=this.state;for(let e=0;e<o.length-1;e++){const t=o[e];null!=i[t]&&"object"==typeof i[t]||(i[t]={}),i=i[t]}i[o[o.length-1]]=s,this.isUpdating||(this.isUpdating=!0,this.currentlyUpdating||(this.currentlyUpdating=new Set),this.currentlyUpdating.add(e),this.#a(e,s,r),this.#c(e,s,r),this.currentlyUpdating.delete(e),this.isUpdating=!1)}subscribe(e,t,n=!0){this.externalSubscribers.has(e)||this.externalSubscribers.set(e,new Set);const r={callback:t,hierarchical:n};return this.externalSubscribers.get(e).add(r),()=>{const t=this.externalSubscribers.get(e);t&&(t.delete(r),0===t.size&&this.externalSubscribers.delete(e))}}subscribeExact(e,t){return this.subscribe(e,t,!1)}subscribeInternal(e,t){return this.subscribers.has(e)||this.subscribers.set(e,new Set),this.subscribers.get(e).add(t),()=>{const n=this.subscribers.get(e);n&&(n.delete(t),0===n.size&&this.subscribers.delete(e))}}#a(e,t,n){this.#i(e);const r=getPathParts(e);for(let e=r.length-1;e>0;e--)this.#i(r.slice(0,e).join("."));const s=e?e+".":"";new Set([...this.subscribers.keys(),...this.externalSubscribers.keys()]).forEach((t=>{t.startsWith(s)&&t!==e&&this.#i(t)}))}#c(e,t,n){this.externalSubscribers.forEach(((r,s)=>{r.forEach((({callback:r,hierarchical:o})=>{if(o?e===s||e.startsWith(s+"."):e===s)try{r(t,n,e)}catch(e){log.ee&&console.error(log.e("External subscriber error:",e),"application")}}))}))}#i(e){const t=this.subscribers.get(e);t&&t.size>0&&(log.ed&&console.debug(log.d("Triggering subscribers",{path:e,subscriberCount:t.size},"framework")),new Set(t).forEach((e=>{let t;try{t=this.currentTracking;const n=new Set;this.currentTracking=n,e(),this.currentTracking=t,n.forEach((t=>{const n=this.subscribers.get(t);n&&n.has(e)||this.subscribeInternal(t,e)}))}catch(e){log.ee&&console.error(log.e("Subscriber error:",e),"application"),this.currentTracking=t}})))}#e(e){return this.currentlyUpdating||(this.currentlyUpdating=new Set),!!this.currentlyUpdating.has(e)&&(log.ew&&console.warn(log.w("Circular dependency detected",{path:e},"framework")),!0)}startTracking(){const e=new Set;return this.currentTracking=e,e}endTracking(){const e=this.currentTracking;return this.currentTracking=null,e||new Set}}class ComponentManager{constructor(e){log.ei&&console.info(log.i("ComponentManager initialized",{},"framework")),this.juris=e,this.components=new Map,this.instances=new WeakMap,this.namedComponents=new Map,this.componentCounters=new Map,this.componentStates=new WeakMap,this.asyncPlaceholders=new WeakMap,this.asyncPropsCache=new Map}register(e,t){log.ei&&console.info(log.i("Component registered",{name:e},"application")),this.components.set(e,t)}create(e,t={}){const n=this.components.get(e);if(!n)return log.ee&&console.error(log.e("Component not found",{name:e},"application")),null;try{if(this.juris.domRenderer._hasAsyncProps(t))return log.ed&&console.debug(log.d("Component has async props",{name:e},"framework")),this.#l(e,n,t);const{componentId:r,componentStates:s}=this.#h(e);log.ed&&console.debug(log.d("Component setup complete",{name:e,componentId:r,stateCount:s.size},"framework"));const o=n(t,this.#d(r,s));return o?.then?this.#u(promisify(o),e,t,s):this.#p(o,e,t,s)}catch(t){return log.ee&&console.error(log.e("Component creation failed!",{name:e,error:t.message},"application")),this.#g(new Error(t.message))}}#h(e){this.componentCounters.has(e)||this.componentCounters.set(e,0);const t=this.componentCounters.get(e)+1;this.componentCounters.set(e,t);return{componentId:`${e}#${t}`,componentStates:new Set}}#d(e,t){const n=this.juris.createContext();return n.newState=(n,r)=>{const s=`##local.${e}.${n}`;return this.juris.stateManager.getState(s,Symbol("not-found"))===Symbol("not-found")&&this.juris.stateManager.setState(s,r),t.add(s),[()=>this.juris.stateManager.getState(s,r),e=>this.juris.stateManager.setState(s,e)]},n}#l(e,t,n){log.ed&&console.debug(log.d("Creating component with async props",{name:e},"framework"));const r=document.createElement("div");r.id=e.toLowerCase().replace(/[^a-z0-9]/g,"-");const s=this._createPlaceholder(`Loading ${e}...`,"juris-async-props-loading",r);return this.asyncPlaceholders.set(s,{name:e,props:n,type:"async-props"}),this.#m(n).then((n=>{try{const r=this.#f(e,t,n);r&&s.parentNode&&s.parentNode.replaceChild(r,s),this.asyncPlaceholders.delete(s)}catch(e){this.#y(s,e)}})).catch((e=>this.#y(s,e))),s}async#m(e){const t=this.#C(e),n=this.asyncPropsCache.get(t);if(n&&Date.now()-n.timestamp<5e3)return n.props;const r={};for(const[t,n]of Object.entries(e))if(n?.then)try{r[t]=await n}catch(e){r[t]={__asyncError:e.message}}else r[t]=n;return this.asyncPropsCache.set(t,{props:r,timestamp:Date.now()}),r}#C(e){return JSON.stringify(e,((e,t)=>t?.then?"[Promise]":t))}#f(e,t,n){const{componentId:r,componentStates:s}=this.#h(e),o=t(n,this.#d(r,s));return o?.then?this.#u(promisify(o),e,n,s):this.#p(o,e,n,s)}#u(e,t,n,r){log.ed&&console.debug(log.d("Handling async component",{name:t},"framework"));const s=document.createElement("div");s.id=t.toLowerCase().replace(/[^a-z0-9]/g,"-");const o=this._createPlaceholder(`Loading ${t}...`,"juris-async-loading",s);return this.asyncPlaceholders.set(o,{name:t,props:n,componentStates:r}),e.then((e=>{log.ed&&console.debug(log.d("Async component resolved",{name:t},"framework"));try{const s=this.#p(e,t,n,r);s&&o.parentNode&&o.parentNode.replaceChild(s,o),this.asyncPlaceholders.delete(o)}catch(e){log.ee&&console.error(log.e("Async component failed",{name:t,error:e.message},"application")),this.#y(o,e)}})).catch((e=>this.#y(o,e))),o}#p(e,t,n,r){if(Array.isArray(e)){const s=document.createDocumentFragment(),o={_isVirtual:!0,_fragment:s,_componentName:t,_componentProps:n,appendChild:e=>s.appendChild(e),removeChild:e=>{e.parentNode===s&&s.removeChild(e)},replaceChild:(e,t)=>{t.parentNode===s&&s.replaceChild(e,t)},get children(){return Array.from(s.childNodes)},get parentNode(){return null},textContent:""};Object.defineProperty(o,"textContent",{set(e){for(;s.firstChild;)s.removeChild(s.firstChild);e&&s.appendChild(document.createTextNode(e))},get:()=>""});const i=[];return this.juris.domRenderer._handleChildrenFineGrained(o,e,i),s._jurisComponent={name:t,props:n,virtual:o,cleanup:()=>{i.forEach((e=>{try{e()}catch(e){}}))}},r?.size>0&&(s._jurisComponentStates=r),s}if(e&&"object"==typeof e){if(this.#b(e)){const s={name:t,props:n,hooks:e.hooks||{onMount:e.onMount,onUpdate:e.onUpdate,onUnmount:e.onUnmount},api:e.api||{},render:e.render},o=s.render?s.render():e;if(o?.then)return this.#E(promisify(o),s,r);const i=this.juris.domRenderer.render(o,!1,t);return i&&(this.instances.set(i,s),r?.size>0&&this.componentStates.set(i,r),s.api&&Object.keys(s.api).length>0&&this.namedComponents.set(t,{element:i,instance:s}),s.hooks.onMount&&setTimeout((()=>{try{const e=s.hooks.onMount();e?.then&&promisify(e).catch((e=>log.ee&&console.error(log.e(`Async onMount error in ${t}:`,e),"application")))}catch(e){log.ee&&console.error(log.e(`onMount error in ${t}:`,e),"application")}}),0)),i}if("function"==typeof e.render&&!this.#b(e)){const n=document.createElement("div");n.setAttribute("data-juris-reactive-render",t);const s={name:t,api:e.api||{},render:e.render};this.instances.set(n,s),e.api&&this.namedComponents.set(t,{element:n,instance:s});const o=()=>{try{const r=e.render();if(r?.then)return n.innerHTML='<div class="juris-loading">Loading...</div>',void promisify(r).then((e=>{n.innerHTML="";const t=this.juris.domRenderer.render(e);t&&n.appendChild(t)})).catch((e=>{log.ee&&console.error(`Async render error for ${t}:`,e),n.innerHTML=`<div class="juris-error">Error: ${e.message}</div>`}));Array.from(n.children).forEach((e=>this.cleanup(e))),n.innerHTML="";const s=this.juris.domRenderer.render(r);s&&n.appendChild(s)}catch(e){log.ee&&console.error(`Error in reactive render for ${t}:`,e),n.innerHTML=`<div class="juris-error">Render Error: ${e.message}</div>`}},i=[];return this.juris.domRenderer._createReactiveUpdate(n,o,i),i.length>0&&this.juris.domRenderer.subscriptions.set(n,{subscriptions:i,eventListeners:[]}),r?.size>0&&this.componentStates.set(n,r),n}const s=Object.keys(e);if(1===s.length&&"string"==typeof s[0]&&s[0].length>0){const n=this.juris.domRenderer.render(e,!1,t);return n&&r.size>0&&this.componentStates.set(n,r),n}}const s=this.juris.domRenderer.render(e);return s&&r.size>0&&this.componentStates.set(s,r),s}#b(e){return e.hooks&&(e.hooks.onMount||e.hooks.onUpdate||e.hooks.onUnmount)||e.onMount||e.onUpdate||e.onUnmount}#E(e,t,n){const r=document.createElement("div");r.id=t.name.toLowerCase().replace(/[^a-z0-9]/g,"-");const s=this._createPlaceholder(`Loading ${t.name}...`,"juris-async-lifecycle",r);return e.then((e=>{try{const r=this.juris.domRenderer.render(e);r&&(this.instances.set(r,t),n?.size>0&&this.componentStates.set(r,n),s.parentNode&&s.parentNode.replaceChild(r,s),t.hooks.onMount&&setTimeout((()=>{try{const e=t.hooks.onMount();e?.then&&promisify(e).catch((e=>log.ee&&console.error(log.e(`Async onMount error in ${t.name}:`,e),"application")))}catch(e){log.ee&&console.error(log.e(`onMount error in ${t.name}:`,e),"application")}}),0))}catch(e){this.#y(s,e)}})).catch((e=>this.#y(s,e))),s}getComponent(e){return this.namedComponents.get(e)?.instance||null}getComponentAPI(e){return this.namedComponents.get(e)?.instance?.api||null}getComponentElement(e){return this.namedComponents.get(e)?.element||null}getNamedComponents(){return Array.from(this.namedComponents.keys())}updateInstance(e,t){const n=this.instances.get(e);if(!n)return;const r=n.props;deepEquals(r,t)||(this.juris.domRenderer._hasAsyncProps(t)?this.#m(t).then((t=>{n.props=t,this.#w(n,e,r,t)})).catch((e=>log.ee&&console.error(log.e(`Error updating async props for ${n.name}:`,e),"application"))):(n.props=t,this.#w(n,e,r,t)))}#w(e,t,n,r){if(e.hooks.onUpdate)try{const t=e.hooks.onUpdate(n,r);t?.then&&promisify(t).catch((t=>log.ee&&console.error(log.e(`Async onUpdate error in ${e.name}:`,t),"application")))}catch(t){log.ee&&console.error(log.e(`onUpdate error in ${e.name}:`,t),"application")}try{const n=e.render(),r=promisify(n);r!==n?r.then((e=>{this.juris.domRenderer.updateElementContent(t,e)})).catch((t=>log.ee&&console.error(log.e(`Async re-render error in ${e.name}:`,t),"application"))):this.juris.domRenderer.updateElementContent(t,n)}catch(t){log.ee&&console.error(log.e(`Re-render error in ${e.name}:`,t),"application")}}cleanup(e){if(e instanceof DocumentFragment)return e._jurisComponent?.cleanup&&e._jurisComponent.cleanup(),void(e._jurisComponentStates&&e._jurisComponentStates.forEach((e=>{const t=e.split(".");let n=this.juris.stateManager.state;for(let e=0;e<t.length-1;e++){if(!n[t[e]])return;n=n[t[e]]}delete n[t[t.length-1]]})));const t=this.instances.get(e);if(t&&log.ed&&console.debug(log.d("Cleaning up component",{name:t.name},"framework")),t?.hooks?.onUnmount)try{const e=t.hooks.onUnmount();e?.then&&promisify(e).catch((e=>log.ee&&console.error(log.e(`Async onUnmount error in ${t.name}:`,e),"application")))}catch(e){log.ee&&console.error(log.e(`onUnmount error in ${t.name}:`,e),"application")}e._reactiveSubscriptions&&(e._reactiveSubscriptions.forEach((e=>{try{e()}catch(e){log.ew&&console.warn("Error cleaning up reactive subscription:",e)}})),e._reactiveSubscriptions=[]);const n=this.componentStates.get(e);n&&(n.forEach((e=>{const t=e.split(".");let n=this.juris.stateManager.state;for(let e=0;e<t.length-1;e++){if(!n[t[e]])return;n=n[t[e]]}delete n[t[t.length-1]]})),this.componentStates.delete(e)),this.asyncPlaceholders.has(e)&&this.asyncPlaceholders.delete(e),this.instances.delete(e)}_createPlaceholder(e,t,n=null){const r=this.juris.domRenderer._getPlaceholderConfig(n),s=document.createElement("div");return s.className=r.className,s.textContent=r.text,r.style&&(s.style.cssText=r.style),s}#g(e){const t=document.createElement("div");return t.style.cssText="color: red; border: 1px solid red; padding: 8px; background: #ffe6e6;",t.textContent=`Component Error: ${e.message}`,t}#y(e,t){const n=this.#g(t);e.parentNode&&e.parentNode.replaceChild(n,e),this.asyncPlaceholders.delete(e)}clearAsyncPropsCache(){this.asyncPropsCache.clear()}getAsyncStats(){return{registeredComponents:this.components.size,cachedAsyncProps:this.asyncPropsCache.size}}}class DOMRenderer{constructor(e){log.ei&&console.info(log.i("DOMRenderer initialized",{renderMode:"fine-grained"},"framework")),this.juris=e,this.subscriptions=new WeakMap,this.componentStack=[],this.cssCache=new Map,this.injectedCSS=new Set,this.styleSheet=null,this.camelCaseRegex=/([A-Z])/g,this.eventMap={ondoubleclick:"dblclick",onmousedown:"mousedown",onmouseup:"mouseup",onmouseover:"mouseover",onmouseout:"mouseout",onmousemove:"mousemove",onkeydown:"keydown",onkeyup:"keyup",onkeypress:"keypress",onfocus:"focus",onblur:"blur",onchange:"change",oninput:"input",onsubmit:"submit",onload:"load",onresize:"resize",onscroll:"scroll"},this.BOOLEAN_ATTRS=new Set(["disabled","checked","selected","readonly","multiple","autofocus","autoplay","controls","hidden","loop","open","required","reversed","itemScope"]),this.PRESERVED_ATTRIBUTES=new Set(["viewBox","preserveAspectRatio","textLength","gradientUnits","gradientTransform","spreadMethod","patternUnits","patternContentUnits","patternTransform","clipPath","crossOrigin","xmlns","xmlns:xlink","xlink:href"]),this.SVG_ELEMENTS=new Set(["svg","g","defs","desc","metadata","title","circle","ellipse","line","polygon","polyline","rect","path","text","tspan","textPath","marker","pattern","clipPath","mask","image","switch","foreignObject","linearGradient","radialGradient","stop","animate","animateMotion","animateTransform","set","use","symbol"]),this.KEY_PROPS=["id","className","text"],this.SKIP_ATTRS=new Set(["children","key"]),this.ATTRIBUTES_TO_KEEP=new Set(["id","data-juris-key"]),this.elementCache=new Map,this.recyclePool=new Map,this.renderMode="fine-grained",this.failureCount=0,this.maxFailures=3,this.asyncCache=new Map,this.asyncPlaceholders=new WeakMap,this.placeholderConfigs=new Map,this.defaultPlaceholder={className:"juris-async-loading",style:"padding: 8px; background: #f0f0f0; border: 1px dashed #ccc; opacity: 0.7;",text:"Loading...",children:null},this.tempArray=[],this.tempKeyParts=[],this.TOUCH_CONFIG={moveThreshold:10,timeThreshold:300,touchAction:"manipulation",tapHighlight:"transparent",touchCallout:"none"},this.RECYCLE_POOL_SIZE=100}setRenderMode(e){["fine-grained","batch"].includes(e)?(this.renderMode=e,log.ei&&console.info(log.i("Render mode changed",{mode:e},"framework"))):log.ew&&console.warn(log.w("Invalid render mode",{mode:e},"application"))}getRenderMode(){return this.renderMode}isFineGrained(){return"fine-grained"===this.renderMode}isBatchMode(){return"batch"===this.renderMode}render(e,t=!1,n=null){if("string"==typeof e||"number"==typeof e)return document.createTextNode(String(e));if(!e||"object"!=typeof e)return null;if(Array.isArray(e)){if(!t&&e.some((e=>"function"==typeof e))){const t=document.createDocumentFragment(),n=[];return this.#S(t,e,n),n.length>0&&(t._jurisCleanup=()=>{n.forEach((e=>{try{e()}catch(e){}}))}),t}const r=document.createDocumentFragment();for(let s=0;s<e.length;s++){const o=this.render(e[s],t,n);o&&r.appendChild(o)}return r}const r=Object.keys(e)[0],s=e[r]||{};if(!t&&this.componentStack.includes(r))return this.#M(r,this.componentStack);if(!t&&this.juris.componentManager.components.has(r)){const e=this.juris.stateManager.currentTracking;this.juris.stateManager.currentTracking=null,this.componentStack.push(r);const t=this.juris.componentManager.create(r,s);return this.componentStack.pop(),this.juris.stateManager.currentTracking=e,t}if(!t&&/^[A-Z]/.test(r))return this.#v(r);if("string"!=typeof r||0===r.length)return null;let o=s;if(s.style&&!t&&this.customCSSExtractor){const e=n||r;o=this.customCSSExtractor.processProps(s,e,this)}const i=n||(s.style?r:null);if(t)return this.#k(r,o,i);if("fine-grained"===this.renderMode)return this.#x(r,o,i);try{const e=o.key||this.#P(r,o),t=this.elementCache.get(e);return t&&this.#A(t,r,o)?(this.#T(t,o),t):this.#R(r,o,e,i)}catch(e){return this.failureCount++,this.failureCount>=this.maxFailures&&(this.renderMode="fine-grained"),this.#x(r,o,i)}}#S(e,t,n){const r=[],s=[];for(let o=0;o<t.length;o++){const i=t[o];if("function"==typeof i){let t=document.createTextNode(""),o=[];const a=()=>{o.forEach((e=>{try{e()}catch(e){}})),o=[];const e=this.juris.stateManager.startTracking(),n=this.juris.stateManager.currentTracking;let r;this.juris.stateManager.currentTracking=e;try{r=i()}finally{this.juris.stateManager.currentTracking=n}if(this.#j(r)){const e=document.createTextNode("Loading...");t.parentNode&&t.parentNode.replaceChild(e,t),t=e,promisify(r).then((e=>{const n=this.#N(e,null,!1)||document.createTextNode("");t.parentNode&&t.parentNode.replaceChild(n,t),t=n})).catch((e=>{const n=document.createTextNode(`Error: ${e.message}`);t.parentNode&&t.parentNode.replaceChild(n,t),t=n}))}else{const e=this.#N(r,null,!1)||document.createTextNode("");t.parentNode&&t.parentNode.replaceChild(e,t),t=e}e.forEach((e=>{const t=this.juris.stateManager.subscribeInternal(e,a);o.push(t)}))};a(),e.appendChild(t),r.push(t),s.push((()=>{o.forEach((e=>{try{e()}catch(e){}}))})),n.push((()=>{o.forEach((e=>{try{e()}catch(e){}}))}))}else if(null!=i){const t=this.#N(i,null,!1);t&&(e.appendChild(t),r.push(t))}}e._reactiveCleanup=()=>{s.forEach((e=>{try{e()}catch(e){}}))}}#v(e){const t=document.createElement("div");return t.style.cssText="color: red; border: 1px solid red; padding: 8px; background: #ffe6e6; font-family: monospace;",t.textContent=`Component "${e}" not registered`,t}#M(e,t){const n=document.createElement("div");n.style.cssText="color: red; border: 1px solid red; padding: 8px; background: #ffe6e6; font-family: monospace;";const r=[...t,e].join(" → ");return n.textContent=`Recursion detected: ${r}`,n}#k(e,t,n=null){const r=this.SVG_ELEMENTS.has(e.toLowerCase())?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e);for(const e in t){if(!t.hasOwnProperty(e))continue;const s=t[e];if("children"===e)this.#L(r,s,n);else if("text"===e)r.textContent=s;else if("style"===e&&"object"==typeof s)Object.assign(r.style,s);else if(e.startsWith("on")){const t="onclick"===e?"click":e.slice(2).toLowerCase();r.addEventListener(t,s)}else"key"!==e&&this._setStaticAttributeFast(r,e,s)}return r}_setStaticAttributeFast(e,t,n){this.PRESERVED_ATTRIBUTES.has(t)||t.includes("-")||t.includes(":")?e.setAttribute(t,n):"className"===t?e.className=n:"htmlFor"===t?e.setAttribute("for",n):"tabIndex"===t?e.tabIndex=n:t in e&&"function"!=typeof e[t]?e[t]=n:e.setAttribute(t,n)}#L(e,t,n=null){if("ignore"===t)return;e.textContent="";const r=document.createDocumentFragment();if(Array.isArray(t)){let e=t,s=!1;t.length>0&&t[0]?.config?.staticMode&&(s=!0,e=t.slice(1));for(let t=0;t<e.length;t++){const o=e[t];let i;i="string"==typeof o||"number"==typeof o?document.createTextNode(String(o)):this.render(o,s,n),i&&r.appendChild(i)}}else if(t){let e;e="string"==typeof t||"number"==typeof t?document.createTextNode(String(t)):this.render(t,!1,n),e&&r.appendChild(e)}r.hasChildNodes()&&e.appendChild(r)}#x(e,t,n=null){const r=this.SVG_ELEMENTS.has(e.toLowerCase())?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e);this.tempArray.length=0;const s=this.tempArray,o=[];for(const e in t){if(!t.hasOwnProperty(e))continue;const i=t[e];"children"===e?this.#_(r,i,s,n):"text"===e?this._handleText(r,i,s):"style"===e?this._handleStyle(r,i,s):e.startsWith("on")?this._handleEvent(r,e,i,o):"function"==typeof i?this._handleReactiveAttribute(r,e,i,s):this.#j(i)?this.#O(r,e,i,s):"key"!==e&&this._setStaticAttribute(r,e,i)}return(s.length>0||o.length>0)&&this.subscriptions.set(r,{subscriptions:[...s],eventListeners:o}),r}#_(e,t,n){"fine-grained"===this.renderMode?this._handleChildrenFineGrained(e,t,n):this._handleChildrenOptimized(e,t,n)}_handleChildrenFineGrained(e,t,n){if(Array.isArray(t)&&t.length>0&&t[0]?.config?.staticMode)return this.#L(e,t);"function"==typeof t?this.#U(e,t,n):this.#j(t)?this.#I(e,t):this.#z(e,t)}_handleChildrenOptimized(e,t,n){if(Array.isArray(t)&&t.length>0&&t[0]?.config?.staticMode)return this.#L(e,t);if("function"==typeof t){let r=null,s=[],o=!0;const i=()=>{try{const n=t(e);if(this.#j(n))promisify(n).then((t=>{if("ignore"!==t&&!this.#H(r,t))if(o)try{s=this.#$(e,s,t),r=t}catch(n){log.ew&&console.warn(log.w("Reconciliation failed, falling back to safe rendering:",n.message),"framework"),o=!1,this.#z(e,t),r=t}else this.#z(e,t),r=t})).catch((e=>{log.ee&&console.error(log.e("Error in async children function:",e),"framework"),o=!1}));else if("ignore"!==n&&!this.#H(r,n))if(o)try{s=this.#$(e,s,n),r=n}catch(t){log.ew&&console.warn(log.w("Reconciliation failed, falling back to safe rendering:",t.message),"framework"),o=!1,this.#z(e,n),r=n}else this.#z(e,n),r=n}catch(t){log.ee&&console.error(log.e("Error in children function:",t),"application"),o=!1;try{this.#z(e,[])}catch(e){log.ee&&console.error(log.e("Even safe fallback failed:",e),"application")}}};this._createReactiveUpdate(e,i,n);try{const n=t();this.#j(n)?promisify(n).then((t=>{s=this.#$(e,[],t),r=t})).catch((t=>{log.ew&&console.warn(log.w("Initial async children failed, using safe method:",t.message),"framework"),o=!1,this.#z(e,[])})):(s=this.#$(e,[],n),r=n)}catch(n){log.ew&&console.warn(log.w("Initial reconciliation failed, using safe method:",n.message),"framework"),o=!1;const s=t();this.#z(e,s),r=s}}else if(this.#j(t))this.#I(e,t);else try{this.#$(e,[],t)}catch(n){log.ew&&console.warn(log.w("Static reconciliation failed, using safe method:",n.message),"framework"),this.#z(e,t)}}#O(e,t,n,r){"text"===t?this.#B(e,n):"children"===t?this.#I(e,n):"style"===t?this.#F(e,n):"innerHTML"===t?this.#D(e,n):(this.#W(e,t),promisify(n).then((n=>{const r=this._getPlaceholderConfig(e);e.classList.remove(r.className),this._setStaticAttribute(e,t,n)})).catch((n=>{log.ee&&console.error(log.e(`Async prop '${t}' failed:`,n),"application"),this.#q(e,t,n.message)})))}#D(e,t){const n=this._getPlaceholderConfig(e);e.innerHTML=`<span class="${n.className}">${n.text}</span>`,promisify(t).then((t=>{e.innerHTML=t})).catch((t=>{log.ee&&console.error(log.e("Async innerHTML failed:",t),"application"),e.innerHTML=`<span class="juris-async-error">Error: ${t.message}</span>`}))}_hasAsyncProps(e){for(const t in e)if(e.hasOwnProperty(t)&&!t.startsWith("on")&&this.#j(e[t]))return!0;return!1}#j(e){return e?.then}_getPlaceholderConfig(e){if(e?.id&&this.placeholderConfigs.has(e.id))return this.placeholderConfigs.get(e.id);let t=e?.parentElement;for(;t;){if(t.id&&this.placeholderConfigs.has(t.id))return this.placeholderConfigs.get(t.id);t=t.parentElement}return this.defaultPlaceholder}#W(e,t){const n=this._getPlaceholderConfig(e);({text:()=>{e.textContent=n.text,e.className=n.className,n.style&&(e.style.cssText=n.style)},children:()=>{if(n.children){const t=this.render(n.children);if(t)return void e.appendChild(t)}const t=document.createElement("span");t.textContent=n.text,t.className=n.className,n.style&&(t.style.cssText=n.style),e.appendChild(t)},className:()=>e.classList.add(n.className),style:()=>{n.style&&(e.style.cssText=n.style),e.classList.add(n.className)}}[t]||(()=>{e.setAttribute(t,"loading"),e.classList.add(n.className)}))()}#q(e,t,n){e.classList.add("juris-async-error"),"text"===t?e.textContent=`Error: ${n}`:"children"===t&&(e.innerHTML=`<span class="juris-async-error">Error: ${n}</span>`)}#H(e,t){return e===t||Array.isArray(e)===Array.isArray(t)&&((!Array.isArray(e)||e.length===t.length)&&(deepEquals&&deepEquals(e,t)))}#$(e,t,n){log.ed&&console.debug(log.d("Reconciling children",{parentTag:e.tagName,oldCount:t.length,newCount:Array.isArray(n)?n.length:n?1:0},"framework")),Array.isArray(n)||(n=n?[n]:[]);const r=[],s=document.createDocumentFragment(),o=new Map;for(let e=0;e<t.length;e++){const n=t[e],r=n._jurisKey||`auto-${e}`;o.set(r,n)}const i=new Set;for(let t=0;t<n.length;t++){const a=n[t];if(!a||"object"!=typeof a)continue;const c=Object.keys(a)[0],l=a[c]||{},h=l.key||this.#P(c,l),d=o.get(h);if(d&&!i.has(d)&&this.#A(d,c,l)&&!this.#G(e,d))d.parentNode&&d.parentNode.removeChild(d),this.#T(d,l),r.push(d),s.appendChild(d),i.add(d),o.delete(h);else{const t=this.render(a);t&&!this.#G(e,t)&&(t._jurisKey=h,r.push(t),s.appendChild(t))}}o.forEach((e=>{i.has(e)||this.#J(e)}));try{e.textContent="",s.hasChildNodes()&&e.appendChild(s)}catch(t){log.ee&&console.error(log.e("Error in reconcileChildren:",t),"framework"),e.textContent="";for(let t=0;t<r.length;t++){const n=r[t];try{n&&!this.#G(e,n)&&e.appendChild(n)}catch(t){log.ee&&console.error(log.e("Reconciliation failed",{parentTag:e.tagName,error:t.message},"framework"))}}}return r}#G(e,t){if(!e||!t)return!1;if(e===t)return!0;try{let n=e.parentNode;for(;n;){if(n===t)return!0;n=n.parentNode}if(t.contains&&t.contains(e))return!0;if(t.children)for(let n=0;n<t.children.length;n++)if(this.#G(e,t.children[n]))return!0}catch(e){return log.ew&&console.warn(log.w("Error checking circular reference, assuming unsafe:",e),"application"),!0}return!1}#J(e){if(!e||!e.tagName)return;const t=e.tagName.toLowerCase();e.parentNode&&e.parentNode.removeChild(e),this.recyclePool.has(t)||this.recyclePool.set(t,[]);const n=this.recyclePool.get(t);n.length<this.RECYCLE_POOL_SIZE&&(this.cleanup(e),this.#V(e),n.push(e))}#I(e,t){const n=this._getPlaceholderConfig(e);let r;n.children?r=this.render(n.children):(r=document.createElement("div"),r.className=n.className,r.textContent=n.text,n.style&&(r.style.cssText=n.style)),e.appendChild(r),this.asyncPlaceholders.set(e,{type:"children",placeholder:r}),promisify(t).then((t=>{r.parentNode&&e.removeChild(r),this.#z(e,t),this.asyncPlaceholders.delete(e)})).catch((e=>{log.ee&&console.error(log.e("Async children failed:",e),"application"),r.textContent=`Error loading content: ${e.message}`,r.className="juris-async-error"}))}#U(e,t,n){let r=null,s=!1;this._createReactiveUpdate(e,(()=>{try{const n=t(e);this.#j(n)?promisify(n).then((t=>{"ignore"===t||s&&deepEquals(t,r)||("string"==typeof t||"number"==typeof t?e.textContent=String(t):this.#z(e,t),r=t,s=!0)})).catch((e=>log.ee&&console.error(log.e("Error in async reactive children:",e),"application"))):"ignore"===n||s&&deepEquals(n,r)||("string"==typeof n||"number"==typeof n?e.textContent=String(n):this.#z(e,n),r=n,s=!0)}catch(e){log.ee&&console.error(log.e("Error in reactive children function:",e),"application")}}),n)}#z(e,t,n=null){if("ignore"!==t)if(Array.isArray(t)){let r=t,s=!1;t.length>0&&t[0]?.config?.staticMode&&(s=!0,r=t.slice(1));r.some((e=>"function"==typeof e))?this.#K(e,r,n,s):this.#Q(e,r,n,s)}else if(t)if(e.textContent="","function"==typeof t)this.#Y(e,t,n);else{const r=this.#N(t,n,!1);r&&e.appendChild(r)}else e.textContent=""}#Y(e,t,n){let r=null;const s=()=>{if(r)try{r()}catch(e){}const o=this.juris.stateManager.startTracking(),i=this.juris.stateManager.currentTracking;let a;this.juris.stateManager.currentTracking=o;try{a=t(e)}finally{this.juris.stateManager.currentTracking=i}if(this.#j(a))e.textContent="Loading...",promisify(a).then((t=>{e.textContent="";const r=this.#N(t,n,!1);r&&e.appendChild(r)})).catch((t=>{e.textContent=`Error: ${t.message}`}));else{e.textContent="";const t=this.#N(a,n,!1);t&&e.appendChild(t)}if(o.size>0){const e=[];o.forEach((t=>{e.push(this.juris.stateManager.subscribeInternal(t,s))})),r=()=>e.forEach((e=>{try{e()}catch(e){}}))}};e._reactiveCleanup=r,s()}#K(e,t,n,r){e.textContent="";const s=[],o=[],i=document.createDocumentFragment();for(let a=0;a<t.length;a++){const c=t[a];if("function"==typeof c){const{node:t,cleanup:l}=this.#Z(c,a,n,r,e);t&&(s.push(t),i.appendChild(t),o.push(l))}else if(null!=c){const e=this.#N(c,n,r);e&&(s.push(e),i.appendChild(e))}}i.hasChildNodes()&&e.appendChild(i),e._reactiveCleanup=()=>{o.forEach((e=>{try{e()}catch(e){}}))}}#Z(e,t,n,r,s){let o=document.createTextNode(""),i=[];const a=()=>{i.forEach((e=>{try{e()}catch(e){}})),i=[];const t=this.juris.stateManager.startTracking(),c=this.juris.stateManager.currentTracking;let l;this.juris.stateManager.currentTracking=t;try{l=e(s)}finally{this.juris.stateManager.currentTracking=c}if(this.#j(l)){const e=document.createTextNode("Loading...");o.parentNode&&o.parentNode.replaceChild(e,o),o=e,promisify(l).then((e=>{const t=this.#N(e,n,r)||document.createTextNode("");o.parentNode&&o.parentNode.replaceChild(t,o),o=t})).catch((e=>{const t=document.createTextNode(`Error: ${e.message}`);o.parentNode&&o.parentNode.replaceChild(t,o),o=t}))}else{const e=this.#N(l,n,r)||document.createTextNode("");o.parentNode&&o.parentNode.replaceChild(e,o),o=e}t.forEach((e=>{const t=this.juris.stateManager.subscribeInternal(e,a);i.push(t)}))};return a(),{node:o,cleanup:()=>{i.forEach((e=>{try{e()}catch(e){}})),i=[]}}}#N(e,t,n){if(null==e)return null;if("string"==typeof e||"number"==typeof e)return document.createTextNode(String(e));if(Array.isArray(e)){const r=document.createDocumentFragment();for(let s=0;s<e.length;s++){const o=this.#N(e[s],t,n);o&&r.appendChild(o)}return r.hasChildNodes()?r:null}return this.render(e,n,t)}#Q(e,t,n,r){e.textContent="";const s=document.createDocumentFragment();for(let e=0;e<t.length;e++){const o=t[e];if(null!=o){const e=this.#N(o,n,r);e&&s.appendChild(e)}}s.hasChildNodes()&&e.appendChild(s)}_handleText(e,t,n){"function"==typeof t?this.#X(e,t,n):this.#j(t)?this.#B(e,t):e.textContent=t}#B(e,t){const n=this._getPlaceholderConfig(e);e.textContent=n.text,e.className=n.className,n.style&&(e.style.cssText=n.style),promisify(t).then((t=>{e.textContent=t,e.classList.remove(n.className),n.style&&(e.style.cssText="")})).catch((t=>{log.ee&&console.error(log.e("Async text failed:",t),"application"),e.textContent=`Error: ${t.message}`,e.classList.add("juris-async-error")}))}#X(e,t,n){let r=null,s=!1;this._createReactiveUpdate(e,(()=>{try{const n=t(e);this.#j(n)?promisify(n).then((t=>{s&&t===r||(e.textContent=t,r=t,s=!0)})).catch((e=>log.ee&&console.error(log.e("Error in async reactive text:",e),"application"))):s&&n===r||(e.textContent=n,r=n,s=!0)}catch(e){log.ee&&console.error(log.e("Error in reactive text function:",e),"application")}}),n)}_handleStyle(e,t,n){if("function"==typeof t)this.#ee(e,t,n);else if(this.#j(t))this.#F(e,t);else if("object"==typeof t)for(const r in t)if(t.hasOwnProperty(r)){const s=t[r];"function"==typeof s?this.#te(e,r,s,n):r.startsWith("--")?e.style.setProperty(r,s):e.style[r]=s}}#te(e,t,n,r){let s=null,o=!1;this._createReactiveUpdate(e,(()=>{try{const r=n(e);this.#j(r)?promisify(r).then((n=>{o&&n===s||(t.startsWith("--")?e.style.setProperty(t,n):e.style[t]=n,s=n,o=!0)})).catch((e=>log.ee&&console.error(`Error in async reactive style property '${t}':`,e))):o&&r===s||(t.startsWith("--")?e.style.setProperty(t,r):e.style[t]=r,s=r,o=!0)}catch(e){log.ee&&console.error(`Error in reactive style property '${t}':`,e)}}),r)}#F(e,t){const n=this._getPlaceholderConfig(e);if(e.classList.add(n.className),n.style){const t=n.style.split(";").filter((e=>e.trim()));for(let n=0;n<t.length;n++){const r=t[n],[s,o]=r.split(":").map((e=>e.trim()));s&&o&&(s.startsWith("--")?e.style.setProperty(s,o):e.style[s]=o)}}promisify(t).then((t=>{if(e.classList.remove(n.className),"object"==typeof t){if(n.style){const t=n.style.split(";").map((e=>e.split(":")[0].trim())).filter((e=>e));for(let n=0;n<t.length;n++)e.style.removeProperty(t[n])}Object.assign(e.style,t)}})).catch((e=>log.ee&&console.error(log.e("Async style failed:",e),"application")))}#ee(e,t,n){let r=null,s=!1;this._createReactiveUpdate(e,(()=>{try{let n;n=t.length>0?t(e):t(),this.customCSSExtractor&&this.customCSSExtractor.postProcessReactiveResult&&"object"==typeof n&&(n=this.customCSSExtractor.postProcessReactiveResult(n,"reactive",e)),this.#j(n)?promisify(n).then((t=>{s&&deepEquals(t,r)||"object"==typeof t&&(Object.assign(e.style,t),r={...t},s=!0)})).catch((e=>log.ee&&console.error("Error in async reactive style:",e))):s&&deepEquals(n,r)||"object"==typeof n&&(Object.assign(e.style,n),r={...n},s=!0)}catch(e){log.ee&&console.error("Error in reactive style function:",e)}}),n)}#R(e,t,n){let r=this.#ne(e);r||(r=this.SVG_ELEMENTS.has(e.toLowerCase())?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e)),n&&(this.elementCache.set(n,r),r._jurisKey=n);const s=[],o=[];return this.#re(r,t,s,o),(s.length>0||o.length>0)&&this.subscriptions.set(r,{subscriptions:s,eventListeners:o}),r}#re(e,t,n,r){for(const s in t){if(!t.hasOwnProperty(s)||"key"===s)continue;const o=t[s];switch(s){case"children":this.#_(e,o,n);break;case"text":this._handleText(e,o,n);break;case"innerHTML":"function"==typeof o?this._handleReactiveAttribute(e,s,o,n):e.innerHTML=o;break;case"style":this._handleStyle(e,o,n);break;default:111===s.charCodeAt(0)&&110===s.charCodeAt(1)?this._handleEvent(e,s,o,r):"function"==typeof o?this._handleReactiveAttribute(e,s,o,n):this._setStaticAttribute(e,s,o)}}}_handleEvent(e,t,n,r){if(log.ed&&console.debug(log.d("Event handler attached",{tagName:e.tagName,eventName:t},"framework")),"onclick"===t){const t=this.TOUCH_CONFIG;e.style.touchAction=t.touchAction,e.style.webkitTapHighlightColor=t.tapHighlight,e.style.webkitTouchCallout=t.touchCallout,e.addEventListener("click",n),r.push({eventName:"click",handler:n});let s=0,o=!1,i=0,a=0;const c=e=>{s=Date.now(),o=!1,e.touches?.[0]&&(i=e.touches[0].clientX,a=e.touches[0].clientY)},l=e=>{if(e.touches?.[0]){const n=Math.abs(e.touches[0].clientX-i),r=Math.abs(e.touches[0].clientY-a);(n>t.moveThreshold||r>t.moveThreshold)&&(o=!0)}},h=e=>{const r=Date.now()-s;!touchMovlog.ed&&r<t.timeThreshold&&(e.preventDefault(),e.stopPropagation(),n(e))};e.addEventListener("touchstart",c,{passive:!0}),e.addEventListener("touchmove",l,{passive:!0}),e.addEventListener("touchend",h,{passive:!1}),r.push({eventName:"touchstart",handler:c},{eventName:"touchmove",handler:l},{eventName:"touchend",handler:h})}else{const s=t.toLowerCase(),o=this.eventMap[s]||s.slice(2);e.addEventListener(o,n),r.push({eventName:o,handler:n})}}_handleReactiveAttribute(e,t,n,r){let s=null,o=!1;this._createReactiveUpdate(e,(()=>{try{const r=n(e);this.#j(r)?promisify(r).then((n=>{o&&deepEquals(n,s)||(this._setStaticAttribute(e,t,n),s=n,o=!0)})).catch((e=>log.ee&&console.error(log.e(`Error in async reactive attribute '${t}':`,e),"application"))):o&&deepEquals(r,s)||(this._setStaticAttribute(e,t,r),s=r,o=!0)}catch(e){log.ee&&console.error(log.e(`Error in reactive attribute '${t}':`,e),"application")}}),r)}_setStaticAttribute(e,t,n){if(this.SKIP_ATTRS.has(t))return;if("function"==typeof n)return"value"!==t||"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName&&"SELECT"!==e.tagName?void(log.ew&&console.warn(log.w(`Function value for attribute '${t}' should be handled reactively`),"application")):void(e.value=n(e));if(this.BOOLEAN_ATTRS.has(t))return void(n&&"false"!==n?e.setAttribute(t,""):e.removeAttribute(t));if("http://www.w3.org/2000/svg"===e.namespaceURI)return void e.setAttribute(t,n);switch(t){case"htmlFor":return void e.setAttribute("for",n);case"className":return void(e.className=n)}const r=t.charCodeAt(0);this.PRESERVED_ATTRIBUTES.has(t)||100===r&&45===t.charCodeAt(4)||97===r&&45===t.charCodeAt(4)||-1!==t.indexOf("-")||-1!==t.indexOf(":")?e.setAttribute(t,n):t in e&&"function"!=typeof e[t]?e[t]=n:e.setAttribute(t,n)}_createReactiveUpdate(e,t,n){const r=this.juris.stateManager.startTracking(),s=this.juris.stateManager.currentTracking;this.juris.stateManager.currentTracking=r;try{t(e)}catch(e){log.ee&&console.error(log.e("Error capturing dependencies:",e),"application")}finally{this.juris.stateManager.currentTracking=s}const o=Array.from(r);for(let e=0;e<o.length;e++){const r=o[e],s=this.juris.stateManager.subscribeInternal(r,t);n.push(s)}}updateElementContent(e,t){this.#z(e,[t])}setupIndicators(e,t){this.placeholderConfigs.set(e,{...this.defaultPlaceholder,...t})}cleanup(e){log.ed&&console.debug(log.d("Cleaning up element",{tagName:e.tagName},"framework")),this.juris.componentManager.cleanup(e);const t=this.subscriptions.get(e);if(t&&(t.subscriptions&&t.subscriptions.forEach((e=>{try{e()}catch(e){}})),t.eventListeners&&t.eventListeners.forEach((({eventName:t,handler:n})=>{try{e.removeEventListener(t,n)}catch(e){}})),this.subscriptions.delete(e)),e._reactiveCleanup){try{e._reactiveCleanup()}catch(e){}e._reactiveCleanup=null}e._jurisKey&&this.elementCache.delete(e._jurisKey),this.asyncPlaceholders.has(e)&&this.asyncPlaceholders.delete(e);try{const t=e.children;for(let e=0;e<t.length;e++)try{this.cleanup(t[e])}catch(e){}}catch(e){}}#P(e,t){if(t.key)return t.key;let n=e;for(let e=0;e<this.KEY_PROPS.length;e++){const r=this.KEY_PROPS[e];t[r]&&"function"!=typeof t[r]&&(n+=`|${r}:${t[r]}`)}return n+=`|hash:${this.#se(t)}`,n}#se(e){const t=JSON.stringify(e,((e,t)=>"function"==typeof t?"[function]":t));let n=0;for(let e=0;e<t.length;e++){n=(n<<5)-n+t.charCodeAt(e),n&=n}return Math.abs(n).toString(36)}#ne(e){const t=this.recyclePool.get(e);if(t?.length>0){const e=t.pop();return this.#V(e),e}return null}#V(e){e.textContent="",e.className="",e.removeAttribute("style");const t=Array.from(e.attributes);for(let n=0;n<t.length;n++){const r=t[n];this.ATTRIBUTES_TO_KEEP.has(r.name)||e.removeAttribute(r.name)}}#A(e,t,n){return e.tagName.toLowerCase()===t.toLowerCase()}#T(e,t){for(const n in t)if(t.hasOwnProperty(n)&&!["key","children","text","style"].includes(n)){const r=t[n];"function"!=typeof r&&this._setStaticAttribute(e,n,r)}}clearAsyncCache(){this.asyncCache.clear()}getAsyncStats(){return{cachedAsyncProps:this.asyncCache.size,cachedCSS:this.cssCache.size,injectedCSS:this.injectedCSS.size}}clearCSSCache(){if(this.cssCache.clear(),this.injectedCSS.clear(),this.styleSheet){try{this.styleSheet.ownerNode.remove()}catch(e){}this.styleSheet=null}}getStats(){return{cssCache:this.cssCache.size,injectedCSS:this.injectedCSS.size,estimatedSubscriptions:2*this.cssCache.size,elementCache:this.elementCache.size,recyclePoolSize:Array.from(this.recyclePool.values()).reduce(((e,t)=>e+t.length),0),renderMode:this.renderMode,failureCount:this.failureCount}}}class Juris{static#oe=!1;constructor(e={}){e.logLevel&&this.setupLogging(e.logLevel),log.ei&&console.info(log.i("Juris framework initializing",{hasServices:!!e.services,hasLayout:!!e.layout,hasStates:!!e.states,hasComponents:!!e.components,renderMode:e.renderMode||"auto",features:e.features?Object.keys(e.features):"default"},"framework")),this.services=e.services||{},this.layout=e.layout,this.stateManager=new StateManager(e.states||{},e.middleware||[]),this.componentManager=new ComponentManager(this),this.domRenderer=new DOMRenderer(this),this.armedElements=new WeakMap;const t=e.features||{};t.headless&&(this.headlessManager=new t.headless(this,log),this.headlessAPIs={}),t.enhance&&(this.domEnhancer=new t.enhance(this)),t.template&&(this.templateCompiler=new t.template,e.autoCompileTemplates&&this.compileTemplates()),t.webComponentFactory&&(this.webComponentFactory=new t.webComponentFactory(this)),t.cssExtractor&&(this.domRenderer.customCSSExtractor=new t.cssExtractor),e.headlessComponents&&this.headlessManager&&Object.entries(e.headlessComponents).forEach((([e,t])=>{"function"==typeof t?this.headlessManager.register(e,t):this.headlessManager.register(e,t.fn,t.options)})),e.placeholders&&Object.entries(e.placeholders).forEach((([e,t])=>{this.domRenderer.setupIndicators(e,t)})),e.defaultPlaceholder&&(this.domRenderer.defaultPlaceholder={...this.domRenderer.defaultPlaceholder,...e.defaultPlaceholder}),this.headlessManager&&this.headlessManager.initializeQueued(),"fine-grained"===e.renderMode?this.domRenderer.setRenderMode("fine-grained"):"batch"===e.renderMode&&this.domRenderer.setRenderMode("batch"),e.components&&Object.entries(e.components).forEach((([e,t])=>{this.componentManager.register(e,t)})),log.ei&&console.info(log.i("Juris framework initialized",{componentsCount:this.componentManager.components.size,headlessCount:this.headlessManager?.components?.size||0,enabledFeatures:Object.keys(t)},"framework")),"undefined"==typeof requestIdleCallback&&(window.requestIdleCallback=function(e,t){const n=Date.now();return setTimeout((function(){e({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-n))}})}),1)}),this.#ie()}#ie(){Juris._done||(requestIdleCallback||setTimeout)((()=>{if(!Juris.#oe){Juris.#oe=!0;for(let e in globalThis)globalThis[e]instanceof Juris&&log.ew&&console.warn(`⚠️ JURIS GLOBAL: '${e}'`)}}))}getComponentAPI(e){return this.componentManager.getComponentAPI(e)}getComponentElement(e){return this.componentManager.getComponentElement(e)}getNamedComponents(){return this.componentManager.getNamedComponents()}compileTemplates(e=null){if(!this.templateCompiler)return void(log.ew&&console.warn(log.w("Template compilation requested but templateCompiler not available"),"framework"));const t=e||document.querySelectorAll("template[data-component]"),n=this.templateCompiler.compileTemplates(t);Object.entries(n).forEach((([e,t])=>{this.registerComponent(e,t)}))}setupLogging(e){log.ei=!0,log.ed=!0,log.el=!0,log.ew=!0,log.ee=!0;const t={debug:0,info:1,warn:2,error:3}[e]||1;t>0&&(log.ed=!1),t>1&&(log.el&&console.log("Juris logging initialized at level:",e),log.el&&console.log('To change log level, use juris.setupLogging("newLevel") or set logLevel in config'),log.el=!1,log.ei=!1)}setupIndicators(e,t){this.domRenderer.setupIndicators(e,t)}createHeadlessContext(e=null){const t={getState:(e,t,n)=>this.stateManager.getState(e,t,n),setState:(e,t,n)=>this.stateManager.setState(e,t,n),executeBatch:e=>this.executeBatch(e),subscribe:(e,t)=>this.stateManager.subscribe(e,t),services:this.services,...this.services||{},headless:this.headlessManager?.context,isSSR:"undefined"==typeof MutationObserver,...this.headlessAPIs||{},components:{register:(e,t)=>this.componentManager.register(e,t),registerHeadless:(e,t,n)=>this.headlessManager?.register(e,t,n),get:e=>this.componentManager.components.get(e),getHeadless:e=>this.headlessManager?.getInstance(e),initHeadless:(e,t)=>this.headlessManager?.initialize(e,t),reinitHeadless:(e,t)=>this.headlessManager?.reinitialize(e,t),getComponentAPI:e=>this.getComponentAPI(e),getComponentElement:e=>this.getComponentElement(e),getNamedComponents:()=>this.componentManager.getNamedComponents()},utils:{render:e=>this.render(e),cleanup:()=>this.cleanup(),forceRender:()=>this.render(),getHeadlessStatus:()=>this.headlessManager?.getStatus()},juris:this,logger:{log:log,lwarn:log.w,error:log.e,info:log.i,debug:log.d,subscribe:logSub,unsubscribe:logUnsub}};return e&&(t.element=e),t}executeBatch(e){return this.stateManager.executeBatch(e)}createWebComponent(e,t,n={}){return this.webComponentFactory?this.webComponentFactory.create(e,t,n):(log.ee&&console.error(log.e("WebComponent creation requested but webComponentFactory not available"),"application"),null)}createWebComponents(e,t={}){return this.webComponentFactory?this.webComponentFactory.createMultiple(e,t):(log.ee&&console.error(log.e("WebComponents creation requested but webComponentFactory not available"),"framework"),{})}createContext(e=null){const t={getState:(e,t,n)=>this.stateManager.getState(e,t,n),setState:(e,t,n)=>this.stateManager.setState(e,t,n),executeBatch:e=>this.executeBatch(e),subscribe:(e,t)=>this.stateManager.subscribe(e,t),services:this.services,...this.services||{},...this.headlessAPIs||{},headless:this.headlessManager?.context,isSSR:"undefined"==typeof window,components:{register:(e,t)=>this.componentManager.register(e,t),registerHeadless:(e,t,n)=>this.headlessManager?.register(e,t,n),get:e=>this.componentManager.components.get(e),getHeadless:e=>this.headlessManager.getInstance(e),initHeadless:(e,t)=>this.headlessManager?.initialize(e,t),reinitHeadless:(e,t)=>this.headlessManager?.reinitialize(e,t),getHeadlessAPI:e=>this.headlessManager?.getAPI(e),getAllHeadlessAPIs:()=>this.headlessManager?.getAllAPIs(),getComponentAPI:e=>this.getComponentAPI(e),getComponentElement:e=>this.getComponentElement(e),getNamedComponents:()=>this.componentManager.getNamedComponents()},utils:{render:e=>this.render(e),cleanup:()=>this.cleanup(),forceRender:()=>this.render(),setRenderMode:e=>this.setRenderMode(e),getRenderMode:()=>this.getRenderMode(),isFineGrained:()=>this.isFineGrained(),isBatchMode:()=>this.isBatchMode(),getHeadlessStatus:()=>this.headlessManager?.getStatus(),objectToHtml:e=>this.objectToHtml(e)},objectToHtml:e=>this.objectToHtml(e),setupIndicators:(e,t)=>this.setupIndicators(e,t),juris:this,logger:{log:log,lwarn:log.w,error:log.e,info:log.i,debug:log.d,subscribe:logSub,unsubscribe:logUnsub}};return e&&(t.element=e),t}getState(e,t,n){return this.stateManager.getState(e,t,n)}setState(e,t,n){return log.ed&&console.debug(log.d("Public setState called",{path:e},"application")),this.stateManager.setState(e,t,n)}subscribe(e,t,n=!