create-prisma-php-app 4.1.0-alpha.2 → 4.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,7 +17,7 @@ Defaulting to 2020, but this will stop working in the future.`)),e.ecmaVersion=1
|
|
|
17
17
|
`).join(`
|
|
18
18
|
`)}
|
|
19
19
|
`,p=Object.keys(o),f=p.map(x=>o[x]);if(this.checkIfInLoopItem()){const x=this.extractLoopItemContext();this.domBindingManager.stateManager.currentLoopContext=x}try{new Function(...p,h).call(window[s],...f),window[s].getContext=o.getContext,window[s].withContext=o.withContext,window[s].__getProp=o.__getProp;for(const C of n){const S=window[s][C];typeof S=="function"&&this.storeFunctionForComponent(s,C,S)}this.invalidateComponent(s)}catch(x){console.error("Script execution failed:",x),console.error("Component:",s),console.error("Original script:",e),console.error("Processed script:",l),console.error("Execution context keys:",Object.keys(o))}finally{this.domBindingManager.stateManager.currentLoopContext=null}}checkIfInLoopItem(){return!1}extractLoopItemContext(){return{}}extractVariableDeclarations(e){const n=z.getInstance().extractStateDeclarations(e).map(l=>l.variableName),r=[],a=/(?:const|let|var)\s*\[\s*([^,\]]+)(?:\s*,\s*([^,\]]+))?\s*\]/g;let o;for(;(o=a.exec(e))!==null;)o[1]&&!n.includes(o[1].trim())&&r.push(o[1].trim()),o[2]&&!n.includes(o[2].trim())&&r.push(o[2].trim());const c=/(?:const|let|var)\s+([a-zA-Z_$][\w$]*)/g;for(;(o=c.exec(e))!==null;)n.includes(o[1])||r.push(o[1]);return[...n,...r]}modifyScriptForReactiveProps(e,s,i){if(!i||!this.elementProps.has(i))return e;const n=this.elementProps.get(i),r=Array.from(n.keys());let a=e;return r.forEach(o=>{a=this.replacePropOutsideStrings(a,o)}),a}replacePropOutsideStrings(e,s){let i="",n=0;const r=e.length;for(;n<r;){const a=e[n];if(a==="'"){const o=this.findStringEnd(e,n,"'");i+=e.slice(n,o+1),n=o+1;continue}if(a==='"'){const o=this.findStringEnd(e,n,'"');i+=e.slice(n,o+1),n=o+1;continue}if(a==="`"){const o=this.findTemplateEnd(e,n);i+=e.slice(n,o+1),n=o+1;continue}if(a==="/"&&n+1<r){if(e[n+1]==="/"){const o=e.indexOf(`
|
|
20
|
-
`,n),c=o===-1?r:o;i+=e.slice(n,c),n=c;continue}else if(e[n+1]==="*"){const o=e.indexOf("*/",n+2),c=o===-1?r:o+2;i+=e.slice(n,c),n=c;continue}}this.matchesPropName(e,n,s)?(i+=`__getProp('${s}')`,n+=s.length):(i+=a,n++)}return i}findStringEnd(e,s,i){let n=s+1;for(;n<e.length;){if(e[n]===i&&e[n-1]!=="\\")return n;e[n]==="\\"&&n++,n++}return e.length-1}findTemplateEnd(e,s){let i=s+1,n=0;for(;i<e.length;){const r=e[i];if(r==="`"&&n===0)return i;r==="$"&&i+1<e.length&&e[i+1]==="{"?(n++,i++):r==="}"&&n>0?n--:r==="\\"&&i++,i++}return e.length-1}matchesPropName(e,s,i){if(s+i.length>e.length||e.substr(s,i.length)!==i)return!1;const r=s>0?e[s-1]:"",a=s+i.length<e.length?e[s+i.length]:"",o=s===0||!/[a-zA-Z0-9_$]/.test(r),c=s+i.length===e.length||!/[a-zA-Z0-9_$]/.test(a);if(!o||!c||r==="."||a===".")return!1;const l=e.slice(s+i.length);if(/^\s*[=:]/.test(l))return!1;const h=e.slice(Math.max(0,s-20),s);return!/[a-zA-Z0-9_$]\s*\.\s*$/.test(h)}extractFunctionNames(e){return z.getInstance().extractFunctionNames(e)}storeFunctionForComponent(e,s,i){this.componentFunctions.has(e)||this.componentFunctions.set(e,new Map),this.componentFunctions.get(e).set(s,i),window[e]||(window[e]={}),window[e][s]=i}getComponentFunctions(e){return this.componentFunctions.get(e)}destroy(){if(this.updateTimeouts){for(const e of this.updateTimeouts.values())clearTimeout(e);this.updateTimeouts.clear()}}}class Ms{stateManager;componentManager;expressionEvaluator;textNodeManager;observer;listeners=new WeakMap;pendingBindings=[];pendingTextNodes=[];applyingUpdates=!1;elementCache=new WeakMap;batchedUpdates=new Set;processingRAF=null;updateQueue=new Map;eventDelegation=new se;processedElements=new WeakSet;loopManager;templateRenderer;BOOL_REFLECTED={checked:"checked",disabled:"disabled",hidden:"hidden",readonly:"readOnly",required:"required",multiple:"multiple",selected:"selected",autofocus:"autofocus",autoplay:"autoplay",controls:"controls",defer:"defer",loop:"loop",muted:"muted",open:"open",reversed:"reversed",async:"async",default:"default",formnovalidate:"formNoValidate",novalidate:"noValidate",allowfullscreen:"allowFullscreen",capture:"capture",itemscope:"itemScope"};lastValueCache=new WeakMap;stringValueCache=new $(500);refBindings=new WeakMap;constructor(e,s,i){this.stateManager=e,this.componentManager=s,this.expressionEvaluator=i,this.textNodeManager=new Ps(i,e),this.textNodeManager.componentManager=this.componentManager,this.componentManager.setDOMBindingManager(this),this.setupMutationObserver(),this.eventDelegation.setupEventDelegation(),this.loopManager=new Ft(e,i),this.loopManager.setDependencies(s,this),this.loopManager.eventDelegation=this.eventDelegation,this.eventDelegation.setDependencies(this.componentManager,this.expressionEvaluator,this.loopManager),this.templateRenderer=new Ke(i)}refreshComponentElement(e,s){this.elementCache.delete(e),this.processedElements.delete(e);const i=[...this.componentManager.componentStack];this.componentManager.componentStack=["app"],s!=="app"&&this.componentManager.componentStack.push(s);try{const n=this.componentManager.buildComponentContextWithProps(s,e);this.processElementInContext(e,n,s,!0),this.walkComponentChildren(e,s),this.refreshComponentTextNodes(e,s)}finally{this.componentManager.componentStack=i}}refreshComponentTextNodes(e,s){const i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:a=>{const o=a;return!o.textContent||!d.MUSTACHE_PATTERN.test(o.textContent)||y.isTextNodeInsideScript(o)||this.isTextNodeInsideLoopItem(o)||y.getComponentForNode(o)!==s?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}});let n;const r=[];for(;n=i.nextNode();)r.push(n);r.forEach(a=>{this.textNodeManager.cleanupTextNode(a),this.textNodeManager.cleanupTextNode(a),this.textNodeManager.processTextNode(a,s)})}walkComponentChildren(e,s){const i=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:a=>{const o=a;return y.getElementComponent(o)!==s?NodeFilter.FILTER_REJECT:o===e?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT}});let n;const r=[];for(;n=i.nextNode();){const a=n;r.push(a)}r.forEach(a=>{this.elementCache.delete(a),this.processedElements.delete(a);const o=this.componentManager.buildComponentContextWithProps(s,e);this.processElementInContext(a,o,s,!0)})}createSpreadDirectiveBinding(e,s,i){const n=`spread_${Date.now()}_${Math.random()}`,r=_.parseSpreadDirective(s);if(r.spreads.length===0&&r.objects.length===0){console.warn(`Invalid pp-spread directive: ${s}`);return}const a=new Set,o=()=>{if(!document.contains(e)){this.stateManager.removeSubscription(n);return}try{const h=this.componentManager.buildComponentContextWithProps(i,e);this.clearSpreadAttributes(e,a);for(const p of r.spreads){const f=this.expressionEvaluator.evaluateExpression(p,h,i);f&&typeof f=="object"&&this.applySpreadObject(e,f,a)}for(const p of r.objects)this.applyObjectProperties(e,p,h,i,a)}catch(h){console.error(`Spread directive evaluation error for "${s}":`,h)}},c=new Set;for(const h of r.spreads)this.templateRenderer.dependencies(h,i,this.stateManager).forEach(f=>c.add(f));for(const h of r.objects)for(const p of h)this.templateRenderer.dependencies(p.value,i,this.stateManager).forEach(m=>c.add(m));const l={id:n,selector:"",dependencies:c,callback:o,element:e,component:i};this.stateManager.addSubscription(l),this.storeSpreadSubscription(e,n),o()}applyObjectProperties(e,s,i,n,r){for(const a of s)try{const o=this.expressionEvaluator.evaluateExpression(a.value,i,n);if(this.isEventProperty(a.key)){this.handleSpreadEventProperty(e,a.key,o);continue}const c=this.normalizeAttributeName(a.key);this.updateElementProperty(e,c,o),r.add(c)}catch(o){console.error(`Error evaluating object property "${a.key}: ${a.value}":`,o)}}applySpreadObject(e,s,i){for(const[n,r]of Object.entries(s))if(r!=null){if(this.isEventProperty(n)){this.handleSpreadEventProperty(e,n,r);continue}const a=this.normalizeAttributeName(n);(!e.hasAttribute(a)||i.has(a))&&(this.updateElementProperty(e,a,r),i.add(a))}}isEventProperty(e){return e.startsWith("on")&&e.length>2}handleSpreadEventProperty(e,s,i){const n=s.substring(2).toLowerCase();if(typeof i=="function"){const r=a=>{try{const o=y.getContextComponent(e),c=this.componentManager?.buildComponentContextWithProps(o,e)||{};i.call(c,a)}catch(o){console.error("Spread event handler error:",o)}};e.addEventListener(n,r),this.storeDirectEventListener(e,n,r);return}if(typeof i=="string"){const r=y.getContextComponent(e);this.eventDelegation.registerEventHandler(e,n,i,r)}}storeDirectEventListener(e,s,i){e.__directEventListeners||(e.__directEventListeners=[]),e.__directEventListeners.push({eventType:s,listener:i})}clearSpreadAttributes(e,s){for(const i of s)e.hasAttribute(i)&&e.removeAttribute(i);s.clear()}normalizeAttributeName(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}storeSpreadSubscription(e,s){e.__spreadSubscriptions||(e.__spreadSubscriptions=[]),e.__spreadSubscriptions.push(s)}setupMutationObserver(){this.observer=new MutationObserver(e=>{const s=e.filter(this.isRelevantMutation);if(s.length===0)return;const i=L.getInstance();for(const n of s)if(n.type==="childList"&&(n.removedNodes.forEach(r=>{if(r.nodeType===Node.ELEMENT_NODE){const a=r;this.cleanupRefBinding(a),a.querySelectorAll("[pp-ref]").forEach(l=>{this.cleanupRefBinding(l)}),i.invalidateElement(a);const c=a.getAttribute(d.ATTR_PREFIXES.COMPONENT);c&&i.invalidateByComponent(c)}}),n.addedNodes.forEach(r=>{if(r.nodeType===Node.ELEMENT_NODE){const o=r.getAttribute(d.ATTR_PREFIXES.COMPONENT);o&&i.invalidateByComponent(o)}})),n.type==="attributes"&&n.target){const r=n.target;i.invalidateElement(r);const a=r.getAttribute(d.ATTR_PREFIXES.COMPONENT);a&&i.invalidateByComponent(a)}this.processMutationsBatch(s)}),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,characterData:!0,attributeFilter:[d.ATTR_PREFIXES.COMPONENT]})}isRelevantMutation=e=>{if(this.applyingUpdates&&e.type==="attributes")return!1;if(e.type==="childList"||e.type==="characterData")return!0;if(e.type==="attributes"){const s=e.attributeName;return s===d.ATTR_PREFIXES.COMPONENT||s!==null&&oe.isEventAttribute(s)}return!1};processElement(e,s=!0){if(e===document.body){const n=Array.from(document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}]`)).sort((r,a)=>{const o=y.getElementDepth(r),c=y.getElementDepth(a);return o-c});this.processElementsBatch([e],s),n.forEach(r=>{this.processElementsBatch([r],s)}),s&&this.loopManager.processPendingTemplates()}else this.processElementsBatch([e],s)}processElementsBatch(e,s=!0){for(const i of e)this.processSingleElement(i,s);s&&(e.forEach(i=>{this.componentManager.executePhpScripts(i)}),this.processPendingBindings())}processSingleElement(e,s){const i=y.getElementComponent(e),n=e.getAttribute(d.ATTR_PREFIXES.CONTEXT);let r;n?n==="app"?r="app":n==="parent"?r=y.getParentOfComponent(i,e):r=n:r=y.getParentComponentForElement(e);const a=this.componentManager.componentStack.length;i!=="app"&&this.componentManager.pushComponent(i),this.componentManager.setupProps(e,r),s&&this.componentManager.executePhpScripts(e),this.processLoopTemplates(e,i);const o=s?this.componentManager.buildComponentContextWithProps(i,e):{};for(this.processElementInContext(e,o,i,s),this.walkDOM(e,o,i,s);this.componentManager.componentStack.length>a;)this.componentManager.popComponent()}processLoopTemplates(e,s){this.getDirectComponentTemplates(e,s).forEach(n=>{this.loopManager.queueTemplate(n,s)})}getDirectComponentTemplates(e,s){const i=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:a=>{const o=a;return o!==e&&o.hasAttribute(d.ATTR_PREFIXES.COMPONENT)?NodeFilter.FILTER_REJECT:o.tagName==="TEMPLATE"&&o.hasAttribute("pp-for")?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let r;for(;r=n.nextNode();)i.push(r);return i}walkDOM(e,s,i,n){const r=ae.getInstance(),a=`walkDOM_${i}_${n}`,o=r.getCachedTraversal(e,a,()=>{const h=r.traverseElementsAndText(e,p=>{if(p===e||p.tagName.toLowerCase()==="script"||this.loopManager.isLoopItem(p))return!1;let f=p.parentElement;for(;f&&f!==e;){if(this.loopManager.isLoopItem(f))return!1;f=f.parentElement}return!(y.getElementComponent(p)!==i||this.processedElements.has(p))},p=>{if(!p.textContent||!d.MUSTACHE_PATTERN.test(p.textContent)||y.isTextNodeInsideScript(p)||this.isTextNodeInsideLoopItem(p))return!1;const f=p.parentElement;if(f){const m=y.getContextComponent(f),x=y.getComponentForNode(p);if(m!==i&&x!==i)return!1}else if(y.getComponentForNode(p)!==i)return!1;return!0});return[...h.textNodes,...h.elements]}),c=[],l=[];o.forEach(h=>{if(h.nodeType===Node.TEXT_NODE)c.push(h);else if(h.nodeType===Node.ELEMENT_NODE){const p=h;if(p.hasAttribute("pp-ref")&&n){const f=p.getAttribute("pp-ref");this.createRefBinding(p,f,i),p.removeAttribute("pp-ref")}l.push(p),this.processedElements.add(p)}}),c.forEach(h=>{const p=h.parentElement,f=p?y.getContextComponent(p):i;n?this.textNodeManager.processTextNode(h,f):this.pendingTextNodes.push({textNode:h,component:f})}),l.forEach(h=>{this.processElementInContext(h,s,i,n)})}isTextNodeInsideLoopItem(e){let s=e.parentElement;for(;s&&s!==document.body;){if(this.loopManager.isLoopItem(s))return!0;s=s.parentElement}return!1}processElementInContext(e,s,i,n){if(e.hasAttribute("pp-ref")){const l=e.getAttribute("pp-ref");n&&this.createRefBinding(e,l,i),e.removeAttribute("pp-ref")}if(e.hasAttribute(d.ATTR_PREFIXES.SPREAD)){const l=e.getAttribute(d.ATTR_PREFIXES.SPREAD);n&&this.createSpreadDirectiveBinding(e,l,i),e.removeAttribute(d.ATTR_PREFIXES.SPREAD)}if(this.loopManager.isLoopItem(e)||this.isElementInLoopItem(e))return;const r=this.extractDomMustacheBindings(e),a=this.elementCache.get(e),o=this.getElementHash(e);if(a&&a.hash===o&&this.isCacheValid(a)&&n){this.applyBindingsFromCache(e,a,s);return}const c={bindings:r,component:i,listeners:[],lastProcessed:Date.now(),hash:o};n?this.applyBindings(e,r,s,i):r.forEach((l,h)=>{this.pendingBindings.push({element:e,property:h,expression:l,component:i})}),this.setupEventBindings(e,i),this.elementCache.set(e,c)}createRefBinding(e,s,i){try{const n=_.decodeEntities(s),r=_.isSingleExpression(n)||n,a=y.getContextComponent(e),o=this.componentManager.buildComponentContextWithProps(a,e);try{const c=this.expressionEvaluator.evaluateExpression(r,o,a);if(typeof c=="function"){const l=c;this.refBindings.set(e,{element:e,callback:l,component:a}),l(e)}else if(c&&typeof c=="object"&&"current"in c){const l=c;this.refBindings.set(e,{element:e,refObject:l,component:a}),l.current=e}else console.warn(`⚠️ pp-ref expression did not return a ref object or callback: ${r}`,c)}catch(c){console.error(`❌ Failed to evaluate ref "${r}":`,c)}}catch(n){console.error(`❌ Failed to create ref binding for "${s}":`,n)}}isElementInLoopItem(e){let s=e;for(;s;){if(this.loopManager.isLoopItem(s))return!0;s=s.parentElement}return!1}extractDomMustacheBindings(e){const s=new Map,i=e.attributes,n=this.elementCache.get(e),r=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT),o=a&&this.componentManager?.hasStoredProps(e),c=r&&a&&r!==a;for(let l=0;l<i.length;l++){const h=i[l];if(!(h.name===d.ATTR_PREFIXES.COMPONENT||h.name===d.ATTR_PREFIXES.CONTEXT||h.name==="key"||oe.isEventAttribute(h.name))&&!(n&&n.bindings.has(h.name))&&h.value){const p=d.MUSTACHE_PATTERN.test(h.value),f=_.decodeEntities(h.value),m=d.MUSTACHE_PATTERN.test(f);if(p||m){if(this.looksLikeSerializedObject(f))continue;o||c&&y.shouldBeDirectBinding(e,h.name)?s.set(h.name,h.value):c||s.set(h.name,h.value)}}}return s}applyBindings(e,s,i,n){s.forEach((r,a)=>{this.createMustacheBinding(e,a,r)}),this.setupEventBindings(e,n)}applyBindingsFromCache(e,s,i){s.bindings.forEach((n,r)=>{try{const a=this.componentManager.buildComponentContextWithProps(s.component,e),o=this.templateRenderer.render(n,a,s.component);this.updateElementProperty(e,r,o)}catch(a){console.error(`Cached binding evaluation error for "${n}":`,a)}})}createMustacheBinding(e,s,i){const n=`mustache_${Date.now()}_${Math.random()}`;let r;const a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(a&&this.componentManager?.hasStoredProps(e)){const f=this.componentManager.elementProps.get(e);(f?Array.from(f.keys()):[]).some(C=>i.includes(C))?r=a:r=y.getContextComponent(e)}else r=y.getContextComponent(e);e.removeAttribute(s);const o=new Set;this.templateRenderer.dependencies(i,r,this.stateManager).forEach(f=>o.add(f));const l=this.findComponentElementForMustacheBinding(e,r);l&&this.componentManager&&this.componentManager.getComponentPropDependencies(l,r).forEach(m=>o.add(m));const h=()=>{if(!document.contains(e)){this.stateManager.removeSubscription(n);return}try{const f=r===a?e:l||void 0,m=this.componentManager.buildComponentContextWithProps(r,f),x=this.templateRenderer.render(i,m,r);this.scheduleElementUpdate(e,s,x)}catch(f){console.error(`Mustache binding evaluation error for "${i}":`,f)}},p={id:n,selector:"",dependencies:o,callback:h,element:e,component:r};this.stateManager.addSubscription(p),h()}findComponentElementForMustacheBinding(e,s){if(e.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return e;let n=e.parentElement;for(;n;){if(n.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return n;n=n.parentElement}const r=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${s}"]`);for(const a of r)if(this.componentManager&&this.componentManager.hasStoredProps(a))return a;return r[0]||null}setupEventBindings(e,s){for(let i=0;i<e.attributes.length;i++){const n=e.attributes[i];if(oe.isEventAttribute(n.name)){const r=n.name.substring(2),a=y.getContextComponent(e);this.eventDelegation.registerEventHandler(e,r,n.value,a),e.removeAttribute(n.name)}}}scheduleElementUpdate(e,s,i){if(this.isCriticalProperty(s)){this.updateElementProperty(e,s,i);return}this.updateQueue.has(e)||(this.updateQueue.set(e,new Set),this.batchedUpdates.add(e)),this.updateQueue.get(e).add(s),this.processingRAF||(this.processingRAF=requestAnimationFrame(()=>{this.processBatchedElementUpdates()})),e[`__pending_${s}`]=i}isCriticalProperty(e){return["textContent","innerHTML","value","checked","selected","disabled","class","className","style","hidden","display"].includes(e)}processBatchedElementUpdates(){this.applyingUpdates=!0;try{for(const e of this.batchedUpdates){const s=this.updateQueue.get(e);if(s)for(const i of s){const n=e[`__pending_${i}`];this.updateElementProperty(e,i,n),delete e[`__pending_${i}`]}}}finally{this.batchedUpdates.clear(),this.updateQueue.clear(),this.processingRAF=null,this.applyingUpdates=!1}}updateElementProperty(e,s,i){const n=this.lastValueCache.get(e);if(n&&this.isSameValue(n.get(s),i))return;const r=this.applyingUpdates;this.applyingUpdates=!0;try{switch(s){case"textContent":const a=this.cachedValueToString(i);e.textContent!==a&&(e.textContent=a);break;case"innerHTML":const o=this.cachedValueToString(i);e.innerHTML!==o&&(e.innerHTML=o);break;case"value":const c=this.cachedValueToString(i);e instanceof HTMLOptionElement?e.value!==c&&(e.value=c,e.setAttribute("value",c)):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.value!==c&&(e.value=c);break;case"selectedIndex":if(e instanceof HTMLSelectElement){const h=Number(i);e.selectedIndex!==h&&(e.selectedIndex=h)}break;case"checked":case"disabled":case"hidden":case"readonly":case"required":case"multiple":case"selected":case"autofocus":case"autoplay":case"controls":case"defer":case"loop":case"muted":case"open":case"reversed":case"async":case"default":case"formnovalidate":case"novalidate":case"allowfullscreen":case"capture":case"itemscope":this.setBooleanProperty(e,s,i);break;case"indeterminate":if(e instanceof HTMLInputElement&&e.type==="checkbox"){const h=!!i;e.indeterminate!==h&&(e.indeterminate=h)}break;case"class":case"className":const l=this.cachedValueToString(i);e.className!==l&&(e.className=l);break;case"htmlFor":case"for":if(e instanceof HTMLLabelElement){const h=this.cachedValueToString(i);e.htmlFor!==h&&(e.htmlFor=h)}break;case"style":if(e instanceof HTMLElement)if(typeof i=="object"&&i&&!Array.isArray(i))this.updateStyleObject(e,i);else{const h=this.cachedValueToString(i);e.style.cssText!==h&&(e.style.cssText=h)}break;case"tabIndex":if(e instanceof HTMLElement){const h=i==null?-1:Number(i);e.tabIndex!==h&&(e.tabIndex=h)}break;case"contentEditable":if(e instanceof HTMLElement){const h=i===!0?"true":i===!1?"false":String(i);e.contentEditable!==h&&(e.contentEditable=h)}break;case"draggable":if(e instanceof HTMLElement){const h=i===!0,p=h?"true":"false";e.draggable!==h&&(e.draggable=h,e.setAttribute("draggable",p))}break;case"spellcheck":if(e instanceof HTMLElement){const h=!!i,p=h?"true":"false";e.spellcheck!==h&&(e.spellcheck=h,e.setAttribute("spellcheck",p))}break;case"src":case"href":case"action":case"alt":case"title":case"placeholder":case"id":case"name":case"type":case"method":case"target":case"rel":case"pattern":case"accept":case"autocomplete":case"enctype":case"wrap":case"download":case"ping":case"referrerpolicy":case"crossorigin":case"integrity":case"loading":case"decoding":case"srcset":case"sizes":case"dir":case"lang":case"translate":case"role":this.setStringAttribute(e,s,i);break;case"min":case"max":case"step":case"maxLength":case"minLength":case"size":case"rows":case"cols":case"rowSpan":case"colSpan":this.setNumericAttribute(e,s,i);break;default:s.startsWith("aria-")?this.setAriaAttribute(e,s,i):s.startsWith("data-")?this.setDataAttribute(e,s,i):this.setGenericAttribute(e,s,i);break}this.updateValueCache(e,s,i)}catch(a){console.error(`Failed to update property "${s}" on element:`,e,a)}finally{this.applyingUpdates=r}}looksLikeSerializedObject(e){if(!e.startsWith("{")||!e.endsWith("}"))return!1;try{const s=JSON.parse(e);return typeof s=="object"&&s!==null&&!Array.isArray(s)&&Object.keys(s).length>0}catch{return!1}}cachedValueToString(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(e==null)return"";if(typeof e=="boolean")return e?"true":"false";if(this.stringValueCache.has(e))return this.stringValueCache.get(e);const s=ie(e);return this.stringValueCache.set(e,s),s}isSameValue(e,s){if(e===s)return!0;if(typeof e=="object"&&typeof s=="object"){if(e===null||s===null)return e===s;if(Array.isArray(e)&&Array.isArray(s))return e.length===s.length&&e.every((i,n)=>i===s[n]);if(this.isStyleObject(e)&&this.isStyleObject(s)){const i=Object.keys(e),n=Object.keys(s);return i.length===n.length&&i.every(r=>e[r]===s[r])}}return!1}isStyleObject(e){return e&&typeof e=="object"&&!Array.isArray(e)}setBooleanProperty(e,s,i){const n=!!i;this.setBooleanProp(e,s,i)||(n&&!e.hasAttribute(s)?e.setAttribute(s,""):!n&&e.hasAttribute(s)&&e.removeAttribute(s))}updateStyleObject(e,s){const i=this.lastValueCache.get(e)?.get("style"),n=i&&typeof i=="object"?i:{};for(const[r,a]of Object.entries(s))n[r]!==a&&(e.style[r]=a)}setStringAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setNumericAttribute(e,s,i){const n=String(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setAriaAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null||i===!1?e.removeAttribute(s):e.setAttribute(s,n))}setDataAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setGenericAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null||i===!1?e.removeAttribute(s):e.setAttribute(s,n))}updateValueCache(e,s,i){this.lastValueCache.has(e)||this.lastValueCache.set(e,new Map),this.lastValueCache.get(e).set(s,i)}setBooleanProp(e,s,i){const n=this.BOOL_REFLECTED[s];if(!n)return!1;const r=!!i;return e instanceof HTMLElement&&n in e?(e[n]!==r&&(e[n]=r),!0):(r?e.hasAttribute(s)||e.setAttribute(s,""):e.hasAttribute(s)&&e.removeAttribute(s),!0)}processPendingBindings(){const e=[...this.pendingBindings];this.pendingBindings=[];const s=new Map;for(const i of e)s.has(i.component)||s.set(i.component,[]),s.get(i.component).push(i);for(const[i,n]of s){const r=[...this.componentManager.componentStack];i!=="app"?this.componentManager.componentStack=["app",i]:this.componentManager.componentStack=["app"];for(const a of n)try{if(!document.contains(a.element))continue;this.createMustacheBinding(a.element,a.property,a.expression)}catch(o){console.error(`❌ Failed to create binding for ${i}:`,o)}this.componentManager.componentStack=r}this.processTextNodesPending()}processTextNodesPending(){const e=new Map;for(const s of this.pendingTextNodes)e.has(s.component)||e.set(s.component,[]),e.get(s.component).push(s);this.pendingTextNodes=[];for(const[s,i]of e){const n=[...this.componentManager.componentStack];s!=="app"?this.componentManager.componentStack=["app",s]:this.componentManager.componentStack=["app"];for(const{textNode:r,component:a}of i)if(document.contains(r))try{this.textNodeManager.processTextNode(r,a)}catch(o){console.error(`❌ Failed to process text node for ${a}:`,o)}this.componentManager.componentStack=n}}processMutationsBatch(e){const s=new Set,i=new Set,n=new Set,r=new Set;for(const a of e)if(a.type==="childList"&&(a.addedNodes.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE)s.add(o);else if(o.nodeType===Node.TEXT_NODE){const c=o;c.textContent&&d.MUSTACHE_PATTERN.test(c.textContent)&&r.add(c)}}),a.removedNodes.forEach(o=>{o.nodeType===Node.ELEMENT_NODE?i.add(o):o.nodeType===Node.TEXT_NODE&&this.textNodeManager.cleanupTextNode(o)})),a.type==="attributes"&&a.target&&n.add(a.target),a.type==="characterData"&&a.target){const o=a.target;o.textContent&&d.MUSTACHE_PATTERN.test(o.textContent)&&r.add(o)}i.size>0&&this.cleanupElementsBatch(Array.from(i)),s.size>0&&this.processElementsBatch(Array.from(s)),r.size>0&&this.processTextNodesBatch(Array.from(r)),n.size>0&&this.rebindChangedElements(Array.from(n))}processTextNodesBatch(e){const s=new Map;for(const i of e){const n=y.getComponentForNode(i);s.has(n)||s.set(n,[]),s.get(n).push(i)}for(const[i,n]of s)n.forEach(r=>{this.textNodeManager.processTextNode(r,i)})}rebindChangedElements(e){e.forEach(s=>{this.processElementBindings(s,!0)})}processElementBindings(e,s=!0){const i=this.extractDomMustacheBindings(e),n=y.getElementComponent(e);i.forEach((r,a)=>{s?this.createMustacheBinding(e,a,r):this.pendingBindings.push({element:e,property:a,expression:r,component:n})}),s&&this.setupEventBindings(e,n)}cleanupElementsBatch(e){e.forEach(s=>this.cleanupElement(s))}cleanupElement(e){this.cleanupRefBinding(e),this.stateManager.subscriptionManager?.cleanupElement(e);const s=this.listeners.get(e)||[];for(const{type:l,fn:h}of s)e.removeEventListener(l,h);this.listeners.delete(e),this.elementCache.delete(e),this.processedElements.delete(e),this.componentManager.cleanupProps(e);const i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null);let n;for(;n=i.nextNode();)this.textNodeManager.cleanupTextNode(n);e.tagName==="TEMPLATE"&&e.hasAttribute("pp-for")&&this.loopManager.cleanupTemplate(e),e.querySelectorAll("template[pp-for]").forEach(l=>{this.loopManager.cleanupTemplate(l)});const a=e.__directEventListeners;a&&(a.forEach(({eventType:l,listener:h})=>{e.removeEventListener(l,h)}),delete e.__directEventListeners);const o=e.__spreadEventHandlers;o&&(o.forEach(l=>{window.__spreadHandlers&&window.__spreadHandlers.delete(l)}),delete e.__spreadEventHandlers);const c=e.__spreadSubscriptions;c&&(c.forEach(l=>{this.stateManager.removeSubscription(l)}),delete e.__spreadSubscriptions),this.lastValueCache.delete(e),this.stringValueCache.size()>1500&&this.stringValueCache.clear()}cleanupRefBinding(e){const s=this.refBindings.get(e);if(s){try{s.callback?s.callback(null):s.refObject&&(s.refObject.current=null)}catch(i){console.error("Failed to cleanup ref:",i)}this.refBindings.delete(e)}}getElementHash(e){const s=[];for(let i=0;i<e.attributes.length;i++){const n=e.attributes[i];(n.name===d.ATTR_PREFIXES.COMPONENT||oe.isEventAttribute(n.name)||n.value&&d.MUSTACHE_PATTERN.test(n.value))&&s.push(`${n.name}=${n.value}`)}return s.sort().join("|")}isCacheValid(e){return Date.now()-e.lastProcessed<3e4}refreshAllBindings(){this.elementCache=new WeakMap,this.processedElements=new WeakSet,this.processElement(document.body,!0)}destroy(){this.observer&&this.observer.disconnect(),document.querySelectorAll("[pp-ref]").forEach(s=>{this.cleanupRefBinding(s)}),this.eventDelegation.cleanup(),this.batchedUpdates.clear(),this.updateQueue.clear(),this.processingRAF&&cancelAnimationFrame(this.processingRAF),this.elementCache=new WeakMap,this.listeners=new WeakMap,this.processedElements=new WeakSet,this.loopManager.destroy()}}class se{static eventCache=null;delegatedEvents=new Map;elementHandlers=new WeakMap;handlerCache=new $(200);componentManager;expressionEvaluator;loopManager;setupEvents=new Set;static getAllAvailableEvents(){if(se.eventCache)return se.eventCache;const e=new Set,s=["click","input","change","submit","focus","blur","keydown","keyup","mousedown","mouseup","mouseover","mouseout"];try{Object.getOwnPropertyNames(HTMLElement.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get HTMLElement events:",n),s.forEach(r=>e.add(r))}try{Object.getOwnPropertyNames(Document.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Document events:",n)}try{Object.getOwnPropertyNames(Window.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Window events:",n)}try{Object.getOwnPropertyNames(Element.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Element events:",n)}return new Set(["beforeunload","unload","pagehide","pageshow","popstate","hashchange","storage","message","messageerror","offline","online","languagechange","rejectionhandled","unhandledrejection","afterprint","beforeprint","devicemotion","deviceorientation","deviceorientationabsolute"]).forEach(n=>e.delete(n)),se.eventCache=e,e}setupEventDelegation(){const e=["click","input","change","submit","focus","blur"];for(const s of e)this.ensureEventSetup(s)}getEventOptions(e){const s={capture:!0,passive:!1};return["wheel","touchstart","touchmove","touchend","scroll","mousewheel"].includes(e)&&(s.passive=!0),(e==="focusin"||e==="focusout")&&(s.capture=!1),s}isEventSupported(e){return se.getAllAvailableEvents().has(e.toLowerCase())}getAllSupportedEvents(){return Array.from(se.getAllAvailableEvents()).sort()}getDelegatedEvents(){return Array.from(this.delegatedEvents.keys()).sort()}setDependencies(e,s,i){this.componentManager=e,this.expressionEvaluator=s,this.loopManager=i}createDelegatedListener(e){return s=>{const i=s.target;if(!i)return;const n=this.findHandler(i,e);n&&this.executeHandler(n.handler,n.element,s)}}registerEventHandler(e,s,i,n){const r=s.toLowerCase();if(this.ensureEventSetup(r),!this.isEventSupported(r)){console.warn(`⚠️ Event type "${s}" is not supported`);return}const a=y.getContextComponent(e);this.elementHandlers.has(e)||this.elementHandlers.set(e,new Map);const o=this.elementHandlers.get(e),c={code:i,component:a};o.set(r,c);const l=this.delegatedEvents.get(r);l?l.elements.add(e):(console.warn(`⚠️ No delegated listener for ${r}, attaching directly`),this.attachDirectListener(e,r,c))}ensureEventSetup(e){if(!this.setupEvents.has(e)){if(!this.isEventSupported(e)){console.warn(`⚠️ Attempting to setup unsupported event: ${e}`);return}try{const s=this.createDelegatedListener(e),i=this.getEventOptions(e);document.addEventListener(e,s,i),this.setupEvents.add(e),this.delegatedEvents.set(e,{listener:s,elements:new WeakSet})}catch(s){console.error(`Failed to setup event delegation for ${e}:`,s),this.setupEvents.delete(e)}}}findHandler(e,s){let i=e;for(;i;){const n=this.elementHandlers.get(i);if(n?.has(s))return{handler:n.get(s),element:i};i=i.parentElement}return null}compileHandler(e,s){const i=`${s}:${e}`;if(this.handlerCache.has(i))return this.handlerCache.get(i);let n=e;e.includes("this")&&(n=n.replace(/\bthis\b/g,"thisElement")),e.includes("event")&&(n=n.replace(/\bevent\b/g,"eventObject"));const r=new Function("eventObject","thisElement","context",`
|
|
20
|
+
`,n),c=o===-1?r:o;i+=e.slice(n,c),n=c;continue}else if(e[n+1]==="*"){const o=e.indexOf("*/",n+2),c=o===-1?r:o+2;i+=e.slice(n,c),n=c;continue}}this.matchesPropName(e,n,s)?(i+=`__getProp('${s}')`,n+=s.length):(i+=a,n++)}return i}findStringEnd(e,s,i){let n=s+1;for(;n<e.length;){if(e[n]===i&&e[n-1]!=="\\")return n;e[n]==="\\"&&n++,n++}return e.length-1}findTemplateEnd(e,s){let i=s+1,n=0;for(;i<e.length;){const r=e[i];if(r==="`"&&n===0)return i;r==="$"&&i+1<e.length&&e[i+1]==="{"?(n++,i++):r==="}"&&n>0?n--:r==="\\"&&i++,i++}return e.length-1}matchesPropName(e,s,i){if(s+i.length>e.length||e.substr(s,i.length)!==i)return!1;const r=s>0?e[s-1]:"",a=s+i.length<e.length?e[s+i.length]:"",o=s===0||!/[a-zA-Z0-9_$]/.test(r),c=s+i.length===e.length||!/[a-zA-Z0-9_$]/.test(a);if(!o||!c||r==="."||a===".")return!1;const l=e.slice(s+i.length);if(/^\s*[=:]/.test(l))return!1;const h=e.slice(Math.max(0,s-20),s);return!/[a-zA-Z0-9_$]\s*\.\s*$/.test(h)}extractFunctionNames(e){return z.getInstance().extractFunctionNames(e)}storeFunctionForComponent(e,s,i){this.componentFunctions.has(e)||this.componentFunctions.set(e,new Map),this.componentFunctions.get(e).set(s,i),window[e]||(window[e]={}),window[e][s]=i}getComponentFunctions(e){return this.componentFunctions.get(e)}destroy(){if(this.updateTimeouts){for(const e of this.updateTimeouts.values())clearTimeout(e);this.updateTimeouts.clear()}}}class Ms{stateManager;componentManager;expressionEvaluator;textNodeManager;observer;listeners=new WeakMap;pendingBindings=[];pendingTextNodes=[];applyingUpdates=!1;elementCache=new WeakMap;batchedUpdates=new Set;processingRAF=null;updateQueue=new Map;eventDelegation=new se;processedElements=new WeakSet;loopManager;templateRenderer;BOOL_REFLECTED={checked:"checked",disabled:"disabled",hidden:"hidden",readonly:"readOnly",required:"required",multiple:"multiple",selected:"selected",autofocus:"autofocus",autoplay:"autoplay",controls:"controls",defer:"defer",loop:"loop",muted:"muted",open:"open",reversed:"reversed",async:"async",default:"default",formnovalidate:"formNoValidate",novalidate:"noValidate",allowfullscreen:"allowFullscreen",capture:"capture",itemscope:"itemScope"};lastValueCache=new WeakMap;stringValueCache=new $(500);refBindings=new WeakMap;constructor(e,s,i){this.stateManager=e,this.componentManager=s,this.expressionEvaluator=i,this.textNodeManager=new Ps(i,e),this.textNodeManager.componentManager=this.componentManager,this.componentManager.setDOMBindingManager(this),this.setupMutationObserver(),this.eventDelegation.setupEventDelegation(),this.loopManager=new Ft(e,i),this.loopManager.setDependencies(s,this),this.loopManager.eventDelegation=this.eventDelegation,this.eventDelegation.setDependencies(this.componentManager,this.expressionEvaluator,this.loopManager),this.templateRenderer=new Ke(i)}refreshComponentElement(e,s){this.elementCache.delete(e),this.processedElements.delete(e);const i=[...this.componentManager.componentStack];this.componentManager.componentStack=["app"],s!=="app"&&this.componentManager.componentStack.push(s);try{const n=this.componentManager.buildComponentContextWithProps(s,e);this.processElementInContext(e,n,s,!0),this.walkComponentChildren(e,s),this.refreshComponentTextNodes(e,s)}finally{this.componentManager.componentStack=i}}refreshComponentTextNodes(e,s){const i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:a=>{const o=a;return!o.textContent||!d.MUSTACHE_PATTERN.test(o.textContent)||y.isTextNodeInsideScript(o)||this.isTextNodeInsideLoopItem(o)||y.getComponentForNode(o)!==s?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}});let n;const r=[];for(;n=i.nextNode();)r.push(n);r.forEach(a=>{this.textNodeManager.cleanupTextNode(a),this.textNodeManager.cleanupTextNode(a),this.textNodeManager.processTextNode(a,s)})}walkComponentChildren(e,s){const i=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:a=>{const o=a;return y.getElementComponent(o)!==s?NodeFilter.FILTER_REJECT:o===e?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT}});let n;const r=[];for(;n=i.nextNode();){const a=n;r.push(a)}r.forEach(a=>{this.elementCache.delete(a),this.processedElements.delete(a);const o=this.componentManager.buildComponentContextWithProps(s,e);this.processElementInContext(a,o,s,!0)})}createSpreadDirectiveBinding(e,s,i){const n=`spread_${Date.now()}_${Math.random()}`,r=_.parseSpreadDirective(s);if(r.spreads.length===0&&r.objects.length===0){console.warn(`Invalid pp-spread directive: ${s}`);return}const a=new Set,o=()=>{if(!document.contains(e)){this.stateManager.removeSubscription(n);return}try{const h=this.componentManager.buildComponentContextWithProps(i,e);this.clearSpreadAttributes(e,a);for(const p of r.spreads){const f=this.expressionEvaluator.evaluateExpression(p,h,i);f&&typeof f=="object"&&this.applySpreadObject(e,f,a)}for(const p of r.objects)this.applyObjectProperties(e,p,h,i,a)}catch(h){console.error(`Spread directive evaluation error for "${s}":`,h)}},c=new Set;for(const h of r.spreads)this.templateRenderer.dependencies(h,i,this.stateManager).forEach(f=>c.add(f));for(const h of r.objects)for(const p of h)this.templateRenderer.dependencies(p.value,i,this.stateManager).forEach(m=>c.add(m));const l={id:n,selector:"",dependencies:c,callback:o,element:e,component:i};this.stateManager.addSubscription(l),this.storeSpreadSubscription(e,n),o()}applyObjectProperties(e,s,i,n,r){for(const a of s)try{const o=this.expressionEvaluator.evaluateExpression(a.value,i,n);if(this.isEventProperty(a.key)){this.handleSpreadEventProperty(e,a.key,o);continue}const c=this.normalizeAttributeName(a.key);this.updateElementProperty(e,c,o),r.add(c)}catch(o){console.error(`Error evaluating object property "${a.key}: ${a.value}":`,o)}}applySpreadObject(e,s,i){for(const[n,r]of Object.entries(s))if(r!=null){if(this.isEventProperty(n)){this.handleSpreadEventProperty(e,n,r);continue}const a=this.normalizeAttributeName(n);(!e.hasAttribute(a)||i.has(a))&&(this.updateElementProperty(e,a,r),i.add(a))}}isEventProperty(e){return e.startsWith("on")&&e.length>2}handleSpreadEventProperty(e,s,i){const n=s.substring(2).toLowerCase();if(typeof i=="function"){const r=a=>{try{const o=y.getContextComponent(e),c=this.componentManager?.buildComponentContextWithProps(o,e)||{};i.call(c,a)}catch(o){console.error("Spread event handler error:",o)}};e.addEventListener(n,r),this.storeDirectEventListener(e,n,r);return}if(typeof i=="string"){const r=y.getContextComponent(e);this.eventDelegation.registerEventHandler(e,n,i,r)}}storeDirectEventListener(e,s,i){e.__directEventListeners||(e.__directEventListeners=[]),e.__directEventListeners.push({eventType:s,listener:i})}clearSpreadAttributes(e,s){for(const i of s)e.hasAttribute(i)&&e.removeAttribute(i);s.clear()}normalizeAttributeName(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}storeSpreadSubscription(e,s){e.__spreadSubscriptions||(e.__spreadSubscriptions=[]),e.__spreadSubscriptions.push(s)}setupMutationObserver(){this.observer=new MutationObserver(e=>{const s=e.filter(this.isRelevantMutation);if(s.length===0)return;const i=L.getInstance();for(const n of s)if(n.type==="childList"&&(n.removedNodes.forEach(r=>{if(r.nodeType===Node.ELEMENT_NODE){const a=r;this.cleanupRefBinding(a),a.querySelectorAll("[pp-ref]").forEach(l=>{this.cleanupRefBinding(l)}),i.invalidateElement(a);const c=a.getAttribute(d.ATTR_PREFIXES.COMPONENT);c&&i.invalidateByComponent(c)}}),n.addedNodes.forEach(r=>{if(r.nodeType===Node.ELEMENT_NODE){const o=r.getAttribute(d.ATTR_PREFIXES.COMPONENT);o&&i.invalidateByComponent(o)}})),n.type==="attributes"&&n.target){const r=n.target;i.invalidateElement(r);const a=r.getAttribute(d.ATTR_PREFIXES.COMPONENT);a&&i.invalidateByComponent(a)}this.processMutationsBatch(s)}),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,characterData:!0,attributeFilter:[d.ATTR_PREFIXES.COMPONENT]})}isRelevantMutation=e=>{if(this.applyingUpdates&&e.type==="attributes")return!1;if(e.type==="childList"||e.type==="characterData")return!0;if(e.type==="attributes"){const s=e.attributeName;return s===d.ATTR_PREFIXES.COMPONENT||s!==null&&oe.isEventAttribute(s)}return!1};processElement(e,s=!0){if(e===document.body){const n=Array.from(document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}]`)).sort((r,a)=>{const o=y.getElementDepth(r),c=y.getElementDepth(a);return o-c});this.processElementsBatch([e],s),n.forEach(r=>{this.processElementsBatch([r],s)}),s&&this.loopManager.processPendingTemplates()}else this.processElementsBatch([e],s)}processElementsBatch(e,s=!0){for(const i of e)this.processSingleElement(i,s);s&&(e.forEach(i=>{this.componentManager.executePhpScripts(i)}),this.processPendingBindings())}processSingleElement(e,s){const i=y.getElementComponent(e),n=e.getAttribute(d.ATTR_PREFIXES.CONTEXT);let r;n?n==="app"?r="app":n==="parent"?r=y.getParentOfComponent(i,e):r=n:r=y.getParentComponentForElement(e);const a=this.componentManager.componentStack.length;i!=="app"&&this.componentManager.pushComponent(i),this.componentManager.setupProps(e,r),s&&this.componentManager.executePhpScripts(e),this.processLoopTemplates(e,i);const o=s?this.componentManager.buildComponentContextWithProps(i,e):{};for(this.processElementInContext(e,o,i,s),this.walkDOM(e,o,i,s);this.componentManager.componentStack.length>a;)this.componentManager.popComponent()}processLoopTemplates(e,s){this.getDirectComponentTemplates(e,s).forEach(n=>{this.loopManager.queueTemplate(n,s)})}getDirectComponentTemplates(e,s){const i=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:a=>{const o=a;return o!==e&&o.hasAttribute(d.ATTR_PREFIXES.COMPONENT)?NodeFilter.FILTER_REJECT:o.tagName==="TEMPLATE"&&o.hasAttribute("pp-for")?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let r;for(;r=n.nextNode();)i.push(r);return i}walkDOM(e,s,i,n){const r=ae.getInstance(),a=`walkDOM_${i}_${n}`,o=r.getCachedTraversal(e,a,()=>{const h=r.traverseElementsAndText(e,p=>{if(p===e||p.tagName.toLowerCase()==="script"||this.loopManager.isLoopItem(p))return!1;let f=p.parentElement;for(;f&&f!==e;){if(this.loopManager.isLoopItem(f))return!1;f=f.parentElement}return!(y.getElementComponent(p)!==i||this.processedElements.has(p))},p=>{if(!p.textContent||!d.MUSTACHE_PATTERN.test(p.textContent)||y.isTextNodeInsideScript(p)||this.isTextNodeInsideLoopItem(p))return!1;const f=p.parentElement;if(f){const m=y.getContextComponent(f),x=y.getComponentForNode(p);if(m!==i&&x!==i)return!1}else if(y.getComponentForNode(p)!==i)return!1;return!0});return[...h.textNodes,...h.elements]}),c=[],l=[];o.forEach(h=>{if(h.nodeType===Node.TEXT_NODE)c.push(h);else if(h.nodeType===Node.ELEMENT_NODE){const p=h;if(p.hasAttribute("pp-ref")&&n){const f=p.getAttribute("pp-ref");this.createRefBinding(p,f,i),p.removeAttribute("pp-ref")}l.push(p),this.processedElements.add(p)}}),c.forEach(h=>{const p=h.parentElement,f=p?y.getContextComponent(p):i;n?this.textNodeManager.processTextNode(h,f):this.pendingTextNodes.push({textNode:h,component:f})}),l.forEach(h=>{this.processElementInContext(h,s,i,n)})}isTextNodeInsideLoopItem(e){let s=e.parentElement;for(;s&&s!==document.body;){if(this.loopManager.isLoopItem(s))return!0;s=s.parentElement}return!1}processElementInContext(e,s,i,n){if(e.hasAttribute("pp-ref")){const l=e.getAttribute("pp-ref");n&&this.createRefBinding(e,l,i),e.removeAttribute("pp-ref")}if(e.hasAttribute(d.ATTR_PREFIXES.SPREAD)){const l=e.getAttribute(d.ATTR_PREFIXES.SPREAD);n&&this.createSpreadDirectiveBinding(e,l,i),e.removeAttribute(d.ATTR_PREFIXES.SPREAD)}if(this.loopManager.isLoopItem(e)||this.isElementInLoopItem(e))return;const r=this.extractDomMustacheBindings(e),a=this.elementCache.get(e),o=this.getElementHash(e);if(a&&a.hash===o&&this.isCacheValid(a)&&n){this.applyBindingsFromCache(e,a,s);return}const c={bindings:r,component:i,listeners:[],lastProcessed:Date.now(),hash:o};n?this.applyBindings(e,r,s,i):r.forEach((l,h)=>{this.pendingBindings.push({element:e,property:h,expression:l,component:i})}),this.setupEventBindings(e,i),this.elementCache.set(e,c)}createRefBinding(e,s,i){try{const n=_.decodeEntities(s),r=_.isSingleExpression(n)||n,a=y.getContextComponent(e),o=this.componentManager.buildComponentContextWithProps(a,e);try{const c=this.expressionEvaluator.evaluateExpression(r,o,a);if(typeof c=="function"){const l=c;this.refBindings.set(e,{element:e,callback:l,component:a}),l(e)}else if(c&&typeof c=="object"&&"current"in c){const l=c;this.refBindings.set(e,{element:e,refObject:l,component:a}),l.current=e}else console.warn(`⚠️ pp-ref expression did not return a ref object or callback: ${r}`,c)}catch(c){console.error(`❌ Failed to evaluate ref "${r}":`,c)}}catch(n){console.error(`❌ Failed to create ref binding for "${s}":`,n)}}isElementInLoopItem(e){let s=e;for(;s;){if(this.loopManager.isLoopItem(s))return!0;s=s.parentElement}return!1}extractDomMustacheBindings(e){const s=new Map,i=e.attributes,n=this.elementCache.get(e),r=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT),o=a&&this.componentManager?.hasStoredProps(e),c=r&&a&&r!==a;for(let l=0;l<i.length;l++){const h=i[l];if(!(h.name===d.ATTR_PREFIXES.COMPONENT||h.name===d.ATTR_PREFIXES.CONTEXT||h.name==="key"||oe.isEventAttribute(h.name))&&!(n&&n.bindings.has(h.name))&&h.value){const p=d.MUSTACHE_PATTERN.test(h.value),f=_.decodeEntities(h.value),m=d.MUSTACHE_PATTERN.test(f);if(p||m){if(this.looksLikeSerializedObject(f))continue;o||c&&y.shouldBeDirectBinding(e,h.name)?s.set(h.name,h.value):c||s.set(h.name,h.value)}}}return s}applyBindings(e,s,i,n){s.forEach((r,a)=>{this.createMustacheBinding(e,a,r)}),this.setupEventBindings(e,n)}applyBindingsFromCache(e,s,i){s.bindings.forEach((n,r)=>{try{const a=this.componentManager.buildComponentContextWithProps(s.component,e),o=this.templateRenderer.render(n,a,s.component);this.updateElementProperty(e,r,o)}catch(a){console.error(`Cached binding evaluation error for "${n}":`,a)}})}createMustacheBinding(e,s,i){const n=`mustache_${Date.now()}_${Math.random()}`;let r;const a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(a&&this.componentManager?.hasStoredProps(e)){const f=this.componentManager.elementProps.get(e);(f?Array.from(f.keys()):[]).some(C=>i.includes(C))?r=a:r=y.getContextComponent(e)}else r=y.getContextComponent(e);e.removeAttribute(s);const o=new Set;this.templateRenderer.dependencies(i,r,this.stateManager).forEach(f=>o.add(f));const l=this.findComponentElementForMustacheBinding(e,r);l&&this.componentManager&&this.componentManager.getComponentPropDependencies(l,r).forEach(m=>o.add(m));const h=()=>{if(!document.contains(e)){this.stateManager.removeSubscription(n);return}try{const f=r===a?e:l||void 0,m=this.componentManager.buildComponentContextWithProps(r,f),x=this.templateRenderer.render(i,m,r);this.scheduleElementUpdate(e,s,x)}catch(f){console.error(`Mustache binding evaluation error for "${i}":`,f)}},p={id:n,selector:"",dependencies:o,callback:h,element:e,component:r};this.stateManager.addSubscription(p),h()}findComponentElementForMustacheBinding(e,s){if(e.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return e;let n=e.parentElement;for(;n;){if(n.getAttribute(d.ATTR_PREFIXES.COMPONENT)===s)return n;n=n.parentElement}const r=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${s}"]`);for(const a of r)if(this.componentManager&&this.componentManager.hasStoredProps(a))return a;return r[0]||null}setupEventBindings(e,s){for(let i=0;i<e.attributes.length;i++){const n=e.attributes[i];if(oe.isEventAttribute(n.name)){const r=n.name.substring(2),a=y.getContextComponent(e);this.eventDelegation.registerEventHandler(e,r,n.value,a),e.removeAttribute(n.name)}}}scheduleElementUpdate(e,s,i){if(this.isCriticalProperty(s)){this.updateElementProperty(e,s,i);return}this.updateQueue.has(e)||(this.updateQueue.set(e,new Set),this.batchedUpdates.add(e)),this.updateQueue.get(e).add(s),this.processingRAF||(this.processingRAF=requestAnimationFrame(()=>{this.processBatchedElementUpdates()})),e[`__pending_${s}`]=i}isCriticalProperty(e){return["textContent","innerHTML","value","checked","selected","disabled","class","className","style","hidden","display"].includes(e)}processBatchedElementUpdates(){this.applyingUpdates=!0;try{for(const e of this.batchedUpdates){const s=this.updateQueue.get(e);if(s)for(const i of s){const n=e[`__pending_${i}`];this.updateElementProperty(e,i,n),delete e[`__pending_${i}`]}}}finally{this.batchedUpdates.clear(),this.updateQueue.clear(),this.processingRAF=null,this.applyingUpdates=!1}}updateElementProperty(e,s,i){const n=this.lastValueCache.get(e);if(n&&this.isSameValue(n.get(s),i))return;const r=this.applyingUpdates;this.applyingUpdates=!0;try{switch(s){case"textContent":const a=this.cachedValueToString(i);e.textContent!==a&&(e.textContent=a);break;case"innerHTML":const o=this.cachedValueToString(i);e.innerHTML!==o&&(e.innerHTML=o);break;case"value":const c=this.cachedValueToString(i);e instanceof HTMLOptionElement?e.value!==c&&(e.value=c,e.setAttribute("value",c)):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.value!==c&&(e.value=c);break;case"selectedIndex":if(e instanceof HTMLSelectElement){const h=Number(i);e.selectedIndex!==h&&(e.selectedIndex=h)}break;case"checked":case"disabled":case"hidden":case"readonly":case"required":case"multiple":case"selected":case"autofocus":case"autoplay":case"controls":case"defer":case"loop":case"muted":case"open":case"reversed":case"async":case"default":case"formnovalidate":case"novalidate":case"allowfullscreen":case"capture":case"itemscope":this.setBooleanProperty(e,s,i);break;case"indeterminate":if(e instanceof HTMLInputElement&&e.type==="checkbox"){const h=!!i;e.indeterminate!==h&&(e.indeterminate=h)}break;case"class":case"className":const l=this.cachedValueToString(i);e instanceof SVGElement?e.getAttribute("class")!==l&&e.setAttribute("class",l):e.className!==l&&(e.className=l);break;case"htmlFor":case"for":if(e instanceof HTMLLabelElement){const h=this.cachedValueToString(i);e.htmlFor!==h&&(e.htmlFor=h)}break;case"style":if(e instanceof HTMLElement)if(typeof i=="object"&&i&&!Array.isArray(i))this.updateStyleObject(e,i);else{const h=this.cachedValueToString(i);e.style.cssText!==h&&(e.style.cssText=h)}break;case"tabIndex":if(e instanceof HTMLElement){const h=i==null?-1:Number(i);e.tabIndex!==h&&(e.tabIndex=h)}break;case"contentEditable":if(e instanceof HTMLElement){const h=i===!0?"true":i===!1?"false":String(i);e.contentEditable!==h&&(e.contentEditable=h)}break;case"draggable":if(e instanceof HTMLElement){const h=i===!0,p=h?"true":"false";e.draggable!==h&&(e.draggable=h,e.setAttribute("draggable",p))}break;case"spellcheck":if(e instanceof HTMLElement){const h=!!i,p=h?"true":"false";e.spellcheck!==h&&(e.spellcheck=h,e.setAttribute("spellcheck",p))}break;case"src":case"href":case"action":case"alt":case"title":case"placeholder":case"id":case"name":case"type":case"method":case"target":case"rel":case"pattern":case"accept":case"autocomplete":case"enctype":case"wrap":case"download":case"ping":case"referrerpolicy":case"crossorigin":case"integrity":case"loading":case"decoding":case"srcset":case"sizes":case"dir":case"lang":case"translate":case"role":this.setStringAttribute(e,s,i);break;case"min":case"max":case"step":case"maxLength":case"minLength":case"size":case"rows":case"cols":case"rowSpan":case"colSpan":this.setNumericAttribute(e,s,i);break;default:s.startsWith("aria-")?this.setAriaAttribute(e,s,i):s.startsWith("data-")?this.setDataAttribute(e,s,i):this.setGenericAttribute(e,s,i);break}this.updateValueCache(e,s,i)}catch(a){console.error(`Failed to update property "${s}" on element:`,e,a)}finally{this.applyingUpdates=r}}looksLikeSerializedObject(e){if(!e.startsWith("{")||!e.endsWith("}"))return!1;try{const s=JSON.parse(e);return typeof s=="object"&&s!==null&&!Array.isArray(s)&&Object.keys(s).length>0}catch{return!1}}cachedValueToString(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(e==null)return"";if(typeof e=="boolean")return e?"true":"false";if(this.stringValueCache.has(e))return this.stringValueCache.get(e);const s=ie(e);return this.stringValueCache.set(e,s),s}isSameValue(e,s){if(e===s)return!0;if(typeof e=="object"&&typeof s=="object"){if(e===null||s===null)return e===s;if(Array.isArray(e)&&Array.isArray(s))return e.length===s.length&&e.every((i,n)=>i===s[n]);if(this.isStyleObject(e)&&this.isStyleObject(s)){const i=Object.keys(e),n=Object.keys(s);return i.length===n.length&&i.every(r=>e[r]===s[r])}}return!1}isStyleObject(e){return e&&typeof e=="object"&&!Array.isArray(e)}setBooleanProperty(e,s,i){const n=!!i;this.setBooleanProp(e,s,i)||(n&&!e.hasAttribute(s)?e.setAttribute(s,""):!n&&e.hasAttribute(s)&&e.removeAttribute(s))}updateStyleObject(e,s){const i=this.lastValueCache.get(e)?.get("style"),n=i&&typeof i=="object"?i:{};for(const[r,a]of Object.entries(s))n[r]!==a&&(e.style[r]=a)}setStringAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setNumericAttribute(e,s,i){const n=String(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setAriaAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null||i===!1?e.removeAttribute(s):e.setAttribute(s,n))}setDataAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null?e.removeAttribute(s):e.setAttribute(s,n))}setGenericAttribute(e,s,i){const n=this.cachedValueToString(i);e.getAttribute(s)!==n&&(i==null||i===!1?e.removeAttribute(s):e.setAttribute(s,n))}updateValueCache(e,s,i){this.lastValueCache.has(e)||this.lastValueCache.set(e,new Map),this.lastValueCache.get(e).set(s,i)}setBooleanProp(e,s,i){const n=this.BOOL_REFLECTED[s];if(!n)return!1;const r=!!i;return e instanceof HTMLElement&&n in e?(e[n]!==r&&(e[n]=r),!0):(r?e.hasAttribute(s)||e.setAttribute(s,""):e.hasAttribute(s)&&e.removeAttribute(s),!0)}processPendingBindings(){const e=[...this.pendingBindings];this.pendingBindings=[];const s=new Map;for(const i of e)s.has(i.component)||s.set(i.component,[]),s.get(i.component).push(i);for(const[i,n]of s){const r=[...this.componentManager.componentStack];i!=="app"?this.componentManager.componentStack=["app",i]:this.componentManager.componentStack=["app"];for(const a of n)try{if(!document.contains(a.element))continue;this.createMustacheBinding(a.element,a.property,a.expression)}catch(o){console.error(`❌ Failed to create binding for ${i}:`,o)}this.componentManager.componentStack=r}this.processTextNodesPending()}processTextNodesPending(){const e=new Map;for(const s of this.pendingTextNodes)e.has(s.component)||e.set(s.component,[]),e.get(s.component).push(s);this.pendingTextNodes=[];for(const[s,i]of e){const n=[...this.componentManager.componentStack];s!=="app"?this.componentManager.componentStack=["app",s]:this.componentManager.componentStack=["app"];for(const{textNode:r,component:a}of i)if(document.contains(r))try{this.textNodeManager.processTextNode(r,a)}catch(o){console.error(`❌ Failed to process text node for ${a}:`,o)}this.componentManager.componentStack=n}}processMutationsBatch(e){const s=new Set,i=new Set,n=new Set,r=new Set;for(const a of e)if(a.type==="childList"&&(a.addedNodes.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE)s.add(o);else if(o.nodeType===Node.TEXT_NODE){const c=o;c.textContent&&d.MUSTACHE_PATTERN.test(c.textContent)&&r.add(c)}}),a.removedNodes.forEach(o=>{o.nodeType===Node.ELEMENT_NODE?i.add(o):o.nodeType===Node.TEXT_NODE&&this.textNodeManager.cleanupTextNode(o)})),a.type==="attributes"&&a.target&&n.add(a.target),a.type==="characterData"&&a.target){const o=a.target;o.textContent&&d.MUSTACHE_PATTERN.test(o.textContent)&&r.add(o)}i.size>0&&this.cleanupElementsBatch(Array.from(i)),s.size>0&&this.processElementsBatch(Array.from(s)),r.size>0&&this.processTextNodesBatch(Array.from(r)),n.size>0&&this.rebindChangedElements(Array.from(n))}processTextNodesBatch(e){const s=new Map;for(const i of e){const n=y.getComponentForNode(i);s.has(n)||s.set(n,[]),s.get(n).push(i)}for(const[i,n]of s)n.forEach(r=>{this.textNodeManager.processTextNode(r,i)})}rebindChangedElements(e){e.forEach(s=>{this.processElementBindings(s,!0)})}processElementBindings(e,s=!0){const i=this.extractDomMustacheBindings(e),n=y.getElementComponent(e);i.forEach((r,a)=>{s?this.createMustacheBinding(e,a,r):this.pendingBindings.push({element:e,property:a,expression:r,component:n})}),s&&this.setupEventBindings(e,n)}cleanupElementsBatch(e){e.forEach(s=>this.cleanupElement(s))}cleanupElement(e){this.cleanupRefBinding(e),this.stateManager.subscriptionManager?.cleanupElement(e);const s=this.listeners.get(e)||[];for(const{type:l,fn:h}of s)e.removeEventListener(l,h);this.listeners.delete(e),this.elementCache.delete(e),this.processedElements.delete(e),this.componentManager.cleanupProps(e);const i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null);let n;for(;n=i.nextNode();)this.textNodeManager.cleanupTextNode(n);e.tagName==="TEMPLATE"&&e.hasAttribute("pp-for")&&this.loopManager.cleanupTemplate(e),e.querySelectorAll("template[pp-for]").forEach(l=>{this.loopManager.cleanupTemplate(l)});const a=e.__directEventListeners;a&&(a.forEach(({eventType:l,listener:h})=>{e.removeEventListener(l,h)}),delete e.__directEventListeners);const o=e.__spreadEventHandlers;o&&(o.forEach(l=>{window.__spreadHandlers&&window.__spreadHandlers.delete(l)}),delete e.__spreadEventHandlers);const c=e.__spreadSubscriptions;c&&(c.forEach(l=>{this.stateManager.removeSubscription(l)}),delete e.__spreadSubscriptions),this.lastValueCache.delete(e),this.stringValueCache.size()>1500&&this.stringValueCache.clear()}cleanupRefBinding(e){const s=this.refBindings.get(e);if(s){try{s.callback?s.callback(null):s.refObject&&(s.refObject.current=null)}catch(i){console.error("Failed to cleanup ref:",i)}this.refBindings.delete(e)}}getElementHash(e){const s=[];for(let i=0;i<e.attributes.length;i++){const n=e.attributes[i];(n.name===d.ATTR_PREFIXES.COMPONENT||oe.isEventAttribute(n.name)||n.value&&d.MUSTACHE_PATTERN.test(n.value))&&s.push(`${n.name}=${n.value}`)}return s.sort().join("|")}isCacheValid(e){return Date.now()-e.lastProcessed<3e4}refreshAllBindings(){this.elementCache=new WeakMap,this.processedElements=new WeakSet,this.processElement(document.body,!0)}destroy(){this.observer&&this.observer.disconnect(),document.querySelectorAll("[pp-ref]").forEach(s=>{this.cleanupRefBinding(s)}),this.eventDelegation.cleanup(),this.batchedUpdates.clear(),this.updateQueue.clear(),this.processingRAF&&cancelAnimationFrame(this.processingRAF),this.elementCache=new WeakMap,this.listeners=new WeakMap,this.processedElements=new WeakSet,this.loopManager.destroy()}}class se{static eventCache=null;delegatedEvents=new Map;elementHandlers=new WeakMap;handlerCache=new $(200);componentManager;expressionEvaluator;loopManager;setupEvents=new Set;static getAllAvailableEvents(){if(se.eventCache)return se.eventCache;const e=new Set,s=["click","input","change","submit","focus","blur","keydown","keyup","mousedown","mouseup","mouseover","mouseout"];try{Object.getOwnPropertyNames(HTMLElement.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get HTMLElement events:",n),s.forEach(r=>e.add(r))}try{Object.getOwnPropertyNames(Document.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Document events:",n)}try{Object.getOwnPropertyNames(Window.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Window events:",n)}try{Object.getOwnPropertyNames(Element.prototype).filter(r=>r.startsWith("on")&&r.length>2).map(r=>r.substring(2).toLowerCase()).forEach(r=>e.add(r))}catch(n){console.warn("Could not get Element events:",n)}return new Set(["beforeunload","unload","pagehide","pageshow","popstate","hashchange","storage","message","messageerror","offline","online","languagechange","rejectionhandled","unhandledrejection","afterprint","beforeprint","devicemotion","deviceorientation","deviceorientationabsolute"]).forEach(n=>e.delete(n)),se.eventCache=e,e}setupEventDelegation(){const e=["click","input","change","submit","focus","blur"];for(const s of e)this.ensureEventSetup(s)}getEventOptions(e){const s={capture:!0,passive:!1};return["wheel","touchstart","touchmove","touchend","scroll","mousewheel"].includes(e)&&(s.passive=!0),(e==="focusin"||e==="focusout")&&(s.capture=!1),s}isEventSupported(e){return se.getAllAvailableEvents().has(e.toLowerCase())}getAllSupportedEvents(){return Array.from(se.getAllAvailableEvents()).sort()}getDelegatedEvents(){return Array.from(this.delegatedEvents.keys()).sort()}setDependencies(e,s,i){this.componentManager=e,this.expressionEvaluator=s,this.loopManager=i}createDelegatedListener(e){return s=>{const i=s.target;if(!i)return;const n=this.findHandler(i,e);n&&this.executeHandler(n.handler,n.element,s)}}registerEventHandler(e,s,i,n){const r=s.toLowerCase();if(this.ensureEventSetup(r),!this.isEventSupported(r)){console.warn(`⚠️ Event type "${s}" is not supported`);return}const a=y.getContextComponent(e);this.elementHandlers.has(e)||this.elementHandlers.set(e,new Map);const o=this.elementHandlers.get(e),c={code:i,component:a};o.set(r,c);const l=this.delegatedEvents.get(r);l?l.elements.add(e):(console.warn(`⚠️ No delegated listener for ${r}, attaching directly`),this.attachDirectListener(e,r,c))}ensureEventSetup(e){if(!this.setupEvents.has(e)){if(!this.isEventSupported(e)){console.warn(`⚠️ Attempting to setup unsupported event: ${e}`);return}try{const s=this.createDelegatedListener(e),i=this.getEventOptions(e);document.addEventListener(e,s,i),this.setupEvents.add(e),this.delegatedEvents.set(e,{listener:s,elements:new WeakSet})}catch(s){console.error(`Failed to setup event delegation for ${e}:`,s),this.setupEvents.delete(e)}}}findHandler(e,s){let i=e;for(;i;){const n=this.elementHandlers.get(i);if(n?.has(s))return{handler:n.get(s),element:i};i=i.parentElement}return null}compileHandler(e,s){const i=`${s}:${e}`;if(this.handlerCache.has(i))return this.handlerCache.get(i);let n=e;e.includes("this")&&(n=n.replace(/\bthis\b/g,"thisElement")),e.includes("event")&&(n=n.replace(/\bevent\b/g,"eventObject"));const r=new Function("eventObject","thisElement","context",`
|
|
21
21
|
try {
|
|
22
22
|
with(context) {
|
|
23
23
|
${n}
|