create-prisma-php-app 4.1.0-alpha.11 → 4.1.0-alpha.13

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.
@@ -13,7 +13,7 @@ Defaulting to 2020, but this will stop working in the future.`)),e.ecmaVersion=1
13
13
  ⚠️ Failed to extract mustache expression - unclosed braces`),console.warn(` Content: ${e}`),console.warn(` Starting at position: ${t}
14
14
  `),{endIndex:-1,expression:""}}static checkForMismatchedQuotes(e){let t=0,i=0,n=!1;for(let r=0;r<e.length;r++){if(n){n=!1;continue}if(e[r]==="\\"){n=!0;continue}e[r]==="'"&&t++,e[r]==='"'&&i++}return t%2!==0?{hasIssue:!0,message:`Unmatched single quotes (found ${t})`}:i%2!==0?{hasIssue:!0,message:`Unmatched double quotes (found ${i})`}:{hasIssue:!1,message:""}}static isSingleExpression(e){const t=N.decodeEntities(e),i=N.parseContentWithNesting(t);return i.length===1&&i[0].type==="expression"?i[0].expression:null}static extractExpressions(e){const t=N.decodeEntities(e),i=N.parseContentWithNesting(t),n=i.filter(r=>r.type==="expression").map(r=>r.expression).filter(r=>r);return i.some(r=>r.type==="expression")&&n.length===0&&(console.error(`
15
15
  ❌ Failed to extract expressions from content:`),console.error(` Content: ${e}`),console.error(` Parsed ${i.length} parts, but extracted 0 expressions`),console.error(` This usually means malformed mustache syntax
16
- `)),n}}class ks{textNodeBindings=new Map;expressionEvaluator;stateManager;componentManager;cleanupObserver;bindingCount=0;constructor(e,t){this.expressionEvaluator=e,this.stateManager=t,this.cleanupObserver=new MutationObserver(i=>{this.cleanupDetachedNodes(i)}),this.cleanupObserver.observe(document.body,{childList:!0,subtree:!0})}cleanupDetachedNodes(e){const t=[];for(const i of e)i.type==="childList"&&i.removedNodes.forEach(n=>{if(n.nodeType===Node.TEXT_NODE)t.push(n);else if(n.nodeType===Node.ELEMENT_NODE){const r=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null);let a;for(;a=r.nextNode();)t.push(a)}});Promise.resolve().then(()=>{t.forEach(i=>{document.contains(i)||this.cleanupTextNode(i)})})}processTextNode(e,t){if(this.textNodeBindings.has(e)||S.isTextNodeInsideScript(e)||this.isInsideLoopItem(e))return;const i=e.parentElement,n=i?S.getContextComponent(i):t,r=e.textContent||"",a=N.parse(r);if(!a.some(l=>l.type==="expression"))return;const c={originalContent:r,expressions:a,subscriptionIds:[]};a.filter(l=>l.type==="expression").forEach(l=>{if(!l.expression)return;const p=`text_${Date.now()}_${Math.random()}`,h=this.expressionEvaluator.extractDependencies(l.expression,n,this.stateManager),f={id:p,selector:"",dependencies:new Set(h),callback:()=>{this.updateTextNode(e)},element:e.parentElement??void 0,component:n};this.stateManager.addSubscription(f),c.subscriptionIds.push(p)}),this.textNodeBindings.set(e,c),this.bindingCount++,this.updateTextNode(e)}isInsideLoopItem(e){let t=e.parentElement;for(;t&&t!==document.body;){const i=t.previousSibling;if(i&&i.nodeType===Node.COMMENT_NODE&&i.textContent?.startsWith("pp-for:"))return!0;let n=t.parentElement?.firstChild||null;for(;n;){if(n.nodeType===Node.COMMENT_NODE&&n.textContent?.startsWith("pp-for:")&&n!==t)return!0;n=n.nextSibling}t=t.parentElement}return!1}updateTextNode(e){const t=this.textNodeBindings.get(e);if(!t||!e.parentElement)return;const i=e.parentElement,n=S.getContextComponent(i),r=this.resolveComponentRootForElement(e,n),a=this.getContextForComponent(n,r);let o="";for(const c of t.expressions)if(c.type==="static")o+=c.content;else if(c.expression)try{const l=this.expressionEvaluator.evaluateExpression(c.expression,a,n);o+=ae(l)}catch(l){const p=typeof l=="object"&&l!==null&&"message"in l?l.message:String(l);console.warn(`Text binding evaluation warning for "${c.expression}": ${p}`),o+=""}e.textContent!==o&&(e.textContent=o)}resolveComponentRootForElement(e,t){let i=e.parentElement;for(;i&&i.nodeType===Node.ELEMENT_NODE;){const n=i;if(n.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t)return n;i=i.parentElement}}getContextForComponent(e,t){return this.componentManager?this.componentManager.buildComponentContextWithProps(e,t):{}}cleanupTextNode(e){const t=this.textNodeBindings.get(e);t&&(t.subscriptionIds.forEach(i=>{this.stateManager.removeSubscription(i)}),this.textNodeBindings.delete(e),this.bindingCount=Math.max(0,this.bindingCount-1))}getBindingCount(){return this.textNodeBindings.size}getAllBindings(){return new Map(this.textNodeBindings)}clearAllBindings(){for(const[e]of this.textNodeBindings)this.cleanupTextNode(e)}destroy(){this.cleanupObserver.disconnect(),this.clearAllBindings()}}class Is{listeners=new Map;on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>this.off(e,t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,...t){const i=this.listeners.get(e);i&&i.forEach(n=>{try{n(...t)}catch(r){console.error(`Event listener error for ${e}:`,r)}})}}class Ms{stateStore={};subscriptions=new Map;updateQueue=new Set;isUpdating=!1;eventBus=new Is;contextCache=new Map;previousValues=new Map;_subscriptionManager=new _s;originalStateStore={};domUpdateCallbacks=[];domUpdateScheduled=!1;constructor(){this.setupGlobalStateProxy(),setInterval(()=>{this.subscriptionManager.cleanupStaleSubscriptions()},3e4)}clearSubscriptions(){const e=this._subscriptionManager.getAllSubscriptions();for(const[t]of e)this._subscriptionManager.removeSubscription(t);this.updateQueue.clear()}clearComponentSubscriptions(e){const t=this._subscriptionManager.getAllSubscriptions();for(const[i,n]of t)n.component===e&&this._subscriptionManager.removeSubscription(i)}clearState(){Object.keys(this.stateStore).forEach(e=>{delete this.stateStore[e],delete this.originalStateStore[e]}),this.previousValues.clear(),this.updateQueue.clear(),this.contextCache.clear()}clearComponentState(e){Object.keys(this.stateStore).filter(i=>i.startsWith(`${e}.`)).forEach(i=>{delete this.stateStore[i],delete this.originalStateStore[i],this.previousValues.delete(i)})}onDOMUpdateComplete(e){this.domUpdateCallbacks.push(e),this.domUpdateScheduled||(this.domUpdateScheduled=!0,requestAnimationFrame(()=>{requestAnimationFrame(()=>{const t=[...this.domUpdateCallbacks];this.domUpdateCallbacks=[],this.domUpdateScheduled=!1,t.forEach(i=>{try{i()}catch(n){console.error("DOM update callback error:",n)}})})}))}setInitialState(e,t){if(this.previousValues.set(e,void 0),this.originalStateStore[e]=t,this.previousValues.size>100){const i=this.previousValues.keys().next().value;typeof i=="string"&&this.previousValues.delete(i)}}get subscriptionManager(){return this._subscriptionManager}batchStateUpdates(e){const t=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=t,!this.isUpdating&&this.updateQueue.size>0&&this.scheduleFlush()}}invalidateContextCache(){this.contextCache.clear()}setupGlobalStateProxy(){this.originalStateStore=this.stateStore,this.stateStore=new Proxy(this.stateStore,{set:(e,t,i,n)=>{const r=e[t],a=Reflect.set(e,t,i,n);return r!==i&&this.notifySubscribers(t),a},get:(e,t)=>Reflect.get(e,t)})}notifySubscribers(e){if(this.eventBus.emit("stateChanged",e),this.updateQueue.add(e),e.includes(".")){const t=e.split(".")[0];this.updateQueue.add(t)}this.notifyPathBasedSubscribers(e),this.isUpdating||this.scheduleFlush()}notifyPathBasedSubscribers(e){const t=this.stateStore[e],i=this.previousValues?.get(e);for(const[n,r]of this.subscriptions)for(const a of r.dependencies)if(this.isPathDependency(a)&&a.startsWith(e+".")){const o=a.substring(e.length+1),c=this.getPathValue(i,o),l=this.getPathValue(t,o);this.deepEqual(c,l)||this.updateQueue.add(a)}}isPathDependency(e){return e.includes(".")&&e.split(".").length>1}getPathValue(e,t){if(!e||typeof e!="object")return;const i=t.split(".");let n=e;for(const r of i){if(n==null)return;if(Array.isArray(n))return r==="length"?n.length:n.map(a=>a?.[r]).filter(a=>a!==void 0);n=n[r]}return n}deepEqual(e,t){if(e===t)return!0;if(e==null||t==null)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((i,n)=>this.deepEqual(i,t[n]));if(typeof e=="object"&&typeof t=="object"){const i=Object.keys(e),n=Object.keys(t);return i.length!==n.length?!1:i.every(r=>this.deepEqual(e[r],t[r]))}return!1}scheduleFlush=ws(()=>{this.flushUpdates()},d.DEBOUNCE_MS);flushUpdates(){if(!this.isUpdating){this.isUpdating=!0;try{const e=new Set,t=this.subscriptionManager.getSubscriptionsForKey("*");if(t&&t.size>0&&this.updateQueue.size>0)for(const i of t){const n=this.subscriptionManager.getSubscription(i);if(!n)continue;if(n.element&&!document.contains(n.element)){this.subscriptionManager.removeSubscription(i);continue}const r=n.element??document.body;try{const a=Array.from(this.updateQueue)[0];n.callback(r,{key:a})}catch(a){console.error("Wildcard subscription callback failed:",a)}}for(const i of this.updateQueue){if(e.has(i))continue;e.add(i);const n=this.subscriptionManager.getSubscriptionsForKey(i);if(n)for(const r of n){const a=this.subscriptionManager.getSubscription(r);if(!a)continue;if(a.element&&!document.contains(a.element)){this.subscriptionManager.removeSubscription(r);continue}const o=a.element??document.body;try{a.callback(o,{key:i})}catch(c){console.error("Subscription callback failed:",c)}}}}finally{this.updateQueue.clear(),this.isUpdating=!1}}}getState(){return this.stateStore}setState(e,t){if(this.previousValues.set(e,this.stateStore[e]),this.stateStore[e]=t,this.previousValues.size>100){const i=this.previousValues.keys().next().value;typeof i=="string"&&this.previousValues.delete(i)}}hasState(e){return e in this.originalStateStore}addSubscription(e){this._subscriptionManager.addSubscription(e)}removeSubscription(e){this._subscriptionManager.removeSubscription(e)}onStateChange(e){return this.eventBus.on("stateChanged",e)}batch(e){const t=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=t,!this.isUpdating&&this.updateQueue.size&&this.flushUpdates()}}getSubscriptions(){return this.subscriptionManager.getAllSubscriptions()}getKeyIndex(){const e=new Map,t=this.subscriptionManager.getAllSubscriptions();for(const[i,n]of t)for(const r of n.dependencies)e.has(r)||e.set(r,new Set),e.get(r).add(i);return e}destroy(){this.clearState(),this.clearSubscriptions(),this.contextCache.clear(),this.previousValues.clear(),this.domUpdateCallbacks=[]}}class pe{expressionCache=new j(d.MAX_CACHE_SIZE);dependencyCache=new j(d.MAX_CACHE_SIZE);commonExpressionsCache=new j(100);dependencyParser=new Os;static CACHE_KEYS={EXPRESSION:(e,t)=>`expr:${e}:${t}`,DEPENDENCY:(e,t)=>`deps:${e}:${t}`,COMMON:e=>`common:${e}`};constructor(){this.precompileCommonExpressions()}normalizeExpression(e){return e.replace(/\r\n/g," ").replace(/\r/g," ").replace(/\n/g," ").replace(/\s+/g," ").trim()}precompileCommonExpressions(){["true","false","null","undefined"].forEach(t=>{const i={fn:new Function("return "+t),contextMap:new Map,dependencies:[t],timestamp:Date.now(),hitCount:0},n=pe.CACHE_KEYS.COMMON(t);this.commonExpressionsCache.set(n,i)})}extractDependencies(e,t,i){const n=this.normalizeExpression(e),r=pe.CACHE_KEYS.DEPENDENCY(t,n);let a=this.dependencyCache.get(r);return a||(a=this.dependencyParser.extract(n,t,i),this.dependencyCache.set(r,a),a)}evaluateExpression(e,t,i){const n=this.normalizeExpression(e),r=pe.CACHE_KEYS.COMMON(n);let a=this.commonExpressionsCache.get(r);if(a){a.hitCount++;try{return a.fn()}catch(c){console.error(`Common expression evaluation failed: "${n}"`,c);return}}const o=pe.CACHE_KEYS.EXPRESSION(i,n);a=this.expressionCache.get(o),(!a||this.isStale(a))&&(a=this.compileExpression(n,t,i),this.expressionCache.set(o,a)),a.hitCount++;try{const c=this.buildArguments(a.contextMap,t);return a.fn(...c)}catch(c){console.error(`Expression evaluation failed: "${n}"`,c),console.error("Available context:",Object.keys(t));return}}compileExpression(e,t,i){const n=this.prepareSafeContext(t),r=new Map,a=[];Object.keys(n).forEach((c,l)=>{r.set(c,l),a.push(c)});const o=this.dependencyParser.extract(e,i);return{fn:new Function(...a,`return (${e})`),contextMap:r,dependencies:o,timestamp:Date.now(),hitCount:0}}buildArguments(e,t){const i=new Array(e.size);for(const[n,r]of e)i[r]=t[n];return i}isStale(e){return Date.now()-e.timestamp>3e5}prepareSafeContext(e){const t={};for(const[i,n]of Object.entries(e))be.has(i)||!this.isValidJavaScriptIdentifier(i)||(t[i]=n);return t}isValidJavaScriptIdentifier(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)&&!be.has(e)}invalidateCache(e){switch(e){case"expressions":this.expressionCache.clear();break;case"dependencies":this.dependencyCache.clear();break;case"common":this.commonExpressionsCache.clear(),this.precompileCommonExpressions();break;case"parser":this.dependencyParser.clearCache();break;default:this.clearAllCaches()}}invalidateByComponent(e){this.expressionCache.deleteByPrefix(`expr:${e}:`),this.dependencyCache.deleteByPrefix(`deps:${e}:`)}clearAllCaches(){this.expressionCache.clear(),this.dependencyCache.clear(),this.commonExpressionsCache.clear(),this.dependencyParser.clearCache(),this.precompileCommonExpressions()}getCacheStats(){return{expressions:this.expressionCache.getStats(),dependencies:this.dependencyCache.getStats(),commonExpressions:this.commonExpressionsCache.getStats(),dependencyParser:this.getDependencyParserStats()}}getDependencyParserStats(){return this.dependencyParser.getCacheSize?{size:this.dependencyParser.getCacheSize(),maxSize:500,hitRate:0,hits:0,misses:0}:{size:0,maxSize:0,hitRate:0,hits:0,misses:0}}cleanupStaleExpressions(){let e=0;return this.expressionCache.keys().forEach(i=>{const n=this.expressionCache.get(i);n&&this.isStale(n)&&(this.expressionCache.delete(i),e++)}),e}}class Os{parseCache=new j(500);extract(e,t,i){const n=this.normalizeExpression(e),r=`${t}:${n}`;if(this.parseCache.has(r))return this.parseCache.get(r);const a=this.parseExpression(n,t,i);return this.parseCache.set(r,a),a}normalizeExpression(e){return e.replace(/\r\n/g," ").replace(/\r/g," ").replace(/\n/g," ").replace(/\s+/g," ").trim()}parseExpression(e,t,i){const n=this.extractIdentifiers(e),r=[],a=i?.getState()||{};for(const c of n){if(be.has(c))continue;const l=c.indexOf("."),p=l===-1?c:c.substring(0,l),h=je.findExistingStateKey(p,t,a);if(h)r.push(h);else{const f=t==="app"?[`app.${p}`]:[`${t}.${p}`,`app.${p}`];r.push(...f)}if(l!==-1){const f=t==="app"?[`app.${p}`]:[`${t}.${p}`,`app.${p}`];r.push(...f)}}return Array.from(new Set(r))}extractIdentifiers(e){const t=[];let i=0;for(;i<e.length;){const n=e[i];if(n==="'"){i=this.skipString(e,i,"'");continue}if(n==='"'){i=this.skipString(e,i,'"');continue}if(n==="`"){i=this.skipTemplateLiteral(e,i,t);continue}if(this.isIdentifierStart(n)){const r=this.extractIdentifier(e,i);t.push(r.value),i=r.endIndex;continue}i++}return t}skipString(e,t,i){let n=t+1;for(;n<e.length&&e[n]!==i;)e[n]==="\\"&&n++,n++;return n+1}skipTemplateLiteral(e,t,i){let n=t+1;for(;n<e.length&&e[n]!=="`";){if(e[n]==="$"&&n+1<e.length&&e[n+1]==="{"){n+=2;let r=1;for(;n<e.length&&r>0;){const a=e[n];if(a==='"'||a==="'"){n=this.skipString(e,n,a);continue}if(a==="{"?r++:a==="}"&&r--,r>0&&this.isIdentifierStart(a)){const o=this.extractIdentifier(e,n);i.push(o.value),n=o.endIndex-1}n++}continue}e[n]==="\\"&&n++,n++}return n+1}extractIdentifier(e,t){let i=t;for(;i<e.length&&(this.isIdentifierPart(e[i])||e[i]===".");)i++;return{value:e.substring(t,i),endIndex:i}}isIdentifierStart(e){return/[a-zA-Z_$]/.test(e)}isIdentifierPart(e){return/[a-zA-Z0-9_$]/.test(e)}clearCache(){this.parseCache.clear()}getCacheSize(){return this.parseCache.cache.size}}class Rs{componentStack=["app"];elementProps=new WeakMap;contextCache=new j(100);contextIndex=new Map;contextInvalidated=new Set;stateManager;processedScripts=new WeakSet;componentFunctions=new Map;expressionEvaluator;domBindingManager;loopManager;templateRenderer;updateTimeouts;updateBatcher=new st;propDependencyCache=new Map;constructor(e){this.stateManager=e,this.updateBatcher=new st,this.stateManager.onStateChange(t=>this.invalidateContextCache(t))}getPropDependencies(e,t){const i=this.findElementWithProps(t);if(!i)return[];const n=this.elementProps.get(i);if(!n||!n.has(e))return[];const r=n.get(e);return this.templateRenderer?.dependencies(r.expression,r.component,this.stateManager)||[]}buildRestrictedComponentContext(e,t=!1){const i={};window[e]&&Object.assign(i,window[e]);const n=this.componentFunctions.get(e);if(n)for(const[a,o]of n)i[a]=o;const r=this.stateManager.getState();for(const a of Object.keys(r))if(a.startsWith(e+".")){const o=a.substring(e.length+1);o in i||(i[o]=r[a])}if(t){if(window.app)for(const[o,c]of Object.entries(window.app))o in i||(i[o]=c);const a=this.componentFunctions.get("app");if(a)for(const[o,c]of a)o in i||(i[o]=c);for(const o of Object.keys(r))if(o.startsWith("app.")){const c=o.substring(4);c in i||(i[c]=r[o])}}return i}getComponentPropDependencies(e,t){if(this.propDependencyCache.has(e))return this.propDependencyCache.get(e);const i=[],n=this.elementProps.get(e);n&&this.templateRenderer&&n.forEach(a=>{const o=this.templateRenderer?.dependencies(a.expression,a.component,this.stateManager);i.push(...o??[])});const r=Array.from(new Set(i));return this.propDependencyCache.set(e,r),r}setDOMBindingManager(e){this.domBindingManager=e,this.updateBatcher.setManagers(this,e)}hasStoredProps(e){return this.elementProps.has(e)&&this.elementProps.get(e).size>0}setExpressionEvaluator(e){this.expressionEvaluator=e,this.templateRenderer=new Qe(e),this.loopManager=new Bt(this.stateManager,e)}extractProps(e,t){const i=new Map,n=e.attributes,r=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);let o=t;r&&(r==="app"?o="app":r==="parent"?o=S.getParentOfComponent(a||"app",e):o=r);for(let c=0;c<n.length;c++){const l=n[c];if(!(l.name===d.ATTR_PREFIXES.COMPONENT||l.name===d.ATTR_PREFIXES.CONTEXT||l.name===d.ATTR_PREFIXES.SPREAD||l.name===d.ATTR_PREFIXES.LOOP)&&!le.isEventAttribute(l.name)&&l.value&&Ns.containsMustacheExpression(l.value)){if(a&&this.mightReferenceSelfProps(l.value,e))continue;const p=this.attributeToPropName(l.name),h={name:p,expression:l.value,component:o,subscriptionIds:[]};i.set(p,h)}}return i}mightReferenceSelfProps(e,t){const i=this.elementProps.get(t);return i?Array.from(i.keys()).some(r=>e.includes(r)&&r!=="dataState"):!1}attributeToPropName(e){return e.replace(/-([a-z])/g,(t,i)=>i.toUpperCase())}setupProps(e,t){const i=this.extractProps(e,t);i.size!==0&&(this.elementProps.set(e,i),this.expressionEvaluator&&i.forEach((n,r)=>{this.setupPropBinding(e,n)}))}setupPropBinding(e,t){if(!this.expressionEvaluator)return;const i=`prop_${Date.now()}_${Math.random()}`,n=this.templateRenderer?.dependencies(t.expression,t.component,this.stateManager)||[],r={id:i,selector:"",dependencies:new Set(n),callback:()=>{const a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);a&&(this.updateBatcher.scheduleUpdate(a,e),this.refreshComponentBindings(e,a))},element:e,component:t.component};this.stateManager.addSubscription(r),t.subscriptionIds.push(i)}refreshComponentBindings(e,t){this.contextInvalidated.add(t),this.contextCache.delete(t),this.domBindingManager&&this.domBindingManager.refreshComponentElement(e,t)}evaluateProps(e){const t={},i=this.elementProps.get(e);if(!i||!this.expressionEvaluator)return t;const n=i.values().next().value;if(!n)return t;const r=this.buildComponentContext(n.component);return i.forEach((a,o)=>{try{const c=this.templateRenderer?.render(a.expression,r,a.component);typeof c=="function"?t[o]=(...l)=>c.apply(this,l):t[o]=c}catch(c){console.error(`❌ Failed to evaluate prop "${o}":`,c),t[o]=void 0}}),t}cleanupProps(e){const t=this.elementProps.get(e);t&&(t.forEach(i=>{i.subscriptionIds.forEach(n=>{this.stateManager.removeSubscription(n)})}),this.elementProps.delete(e))}buildComponentContextWithProps(e,t){const i=this.buildComponentContext(e);let n=this.findElementWithProps(e);if(t&&this.elementProps.has(t)&&(n=t),n)try{const r=this.evaluatePropsWithContext(n,e,t);Object.keys(r).length>0&&Object.keys(r).forEach(a=>{i[a]=r[a]})}catch(r){console.error(`❌ Error evaluating props for ${e}:`,r)}return i}evaluatePropsWithContext(e,t,i){const n={},r=this.elementProps.get(e);if(!r||!this.expressionEvaluator)return n;const a=r.values().next().value;if(!a)return n;let o;const c=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),l=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(c)if(c==="app")o=this.buildComponentContext("app");else if(c==="parent"){const g=S.getParentOfComponent(l||"app",e);o=this.buildComponentContext(g)}else o=this.buildComponentContext(c);else o=this.buildComponentContext(a.component);const p=this.loopManager?.getLoopContextForElement(e);p&&(o={...o,...p});const h=new Map,f=new Map,E=Array.from(r.keys());r.forEach((g,b)=>{E.some(P=>P!==b&&g.expression.includes(P))?f.set(b,g):h.set(b,g)}),h.forEach((g,b)=>{try{const v=this.templateRenderer?.render(g.expression,o,c||g.component);typeof v=="function"?this.isFunctionExplicitlyPassed(g.expression)?n[b]=(...k)=>v.apply(this,k):(console.warn(`⚠️ Function "${b}" not passed - not from shared namespace or explicitly passed`),n[b]=void 0):n[b]=v}catch(v){console.error(`❌ Failed to evaluate simple prop "${b}":`,v),console.error("Expression:",g.expression),console.error("Available context keys:",Object.keys(o)),n[b]=void 0}});const m={...o,...n};return f.forEach((g,b)=>{try{const v=this.templateRenderer?.render(g.expression,m,c||g.component);typeof v=="function"?this.isFunctionExplicitlyPassed(g.expression)?n[b]=(...k)=>v.apply(this,k):(console.warn(`⚠️ Function "${b}" not passed - not from shared namespace or explicitly passed`),n[b]=void 0):n[b]=v}catch(v){console.error(`❌ Failed to evaluate complex prop "${b}":`,v),console.error("Expression:",g.expression),console.error("Available context keys:",Object.keys(m)),n[b]=void 0}}),n}isFunctionExplicitlyPassed(e){const t=N.isSingleExpression(e);return t?/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t.trim()):!1}findElementWithProps(e){const t=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${e}"]`);for(const i of t){const n=this.elementProps.get(i);if(n&&n.size>0)return i}return null}pushComponent(e){this.componentStack.push(e)}popComponent(){return this.componentStack.pop()}getCurrentComponent(){return this.componentStack[this.componentStack.length-1]}buildComponentContext(e){if(!this.contextInvalidated.has(e)&&this.contextCache.has(e))return this.contextCache.get(e);const t=this.computeComponentContext(e);return this.contextCache.set(e,t),this.contextInvalidated.delete(e),t}computeComponentContext(e){const t={};if(e.includes("_loop_")||e.match(/_[a-zA-Z0-9]{8}$/)){const r=e.split("_");r.pop();const a=r.join("_");window[a]&&Object.assign(t,window[a])}e!=="app"&&window[e]&&Object.assign(t,window[e]),e==="app"&&window.app&&Object.assign(t,window.app);const i=this.componentFunctions.get(e);if(i)for(const[r,a]of i)t[r]=a;if(e!=="app"){const r=this.componentFunctions.get("app");if(r)for(const[a,o]of r)a in t||(t[a]=o);if(window.app)for(const[a,o]of Object.entries(window.app))a in t||(t[a]=o)}const n=this.stateManager.getState();for(const r of Object.keys(n))if(r.startsWith(e+".")){const a=r.substring(e.length+1);a in t||(t[a]=n[r])}if(e!=="app"){for(const r of Object.keys(n))if(r.startsWith("app.")){const a=r.substring(4);a in t||(t[a]=n[r])}}return t}invalidateContextCache(e){if(e.startsWith("app.")){this.contextCache.clear();for(const i of this.contextInvalidated.keys())this.contextInvalidated.add(i);return}const t=e.indexOf(".");if(t!==-1){const i=e.slice(0,t);this.invalidateComponent(i)}}invalidateComponent(e){this.contextInvalidated.add(e),this.contextIndex.delete(e)}executePhpScripts(e){const t=this.componentStack.length,i=e.getAttribute(d.ATTR_PREFIXES.COMPONENT),n=e===document.body;if(i||n){if(i){this.pushComponent(i);const a=this.getParentComponent(e);this.setupProps(e,a)}this.getRelevantScripts(e,n).forEach(a=>{const o=a.getAttribute(d.ATTR_PREFIXES.COMPONENT);o&&o!==i?(this.pushComponent(o),this.executeScript(a),this.popComponent()):this.executeScript(a)})}for(Array.from(e.children).forEach(r=>this.executePhpScripts(r));this.componentStack.length>t;)this.popComponent()}getParentComponent(e){let t=e.parentElement;for(;t;){const i=t.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(i)return i;t=t.parentElement}return"app"}getRelevantScripts(e,t){return Array.from(e.querySelectorAll(`script[type="${d.SCRIPT_TYPE}"]`)).filter(i=>{if(this.processedScripts.has(i))return!1;if(t)return i.hasAttribute(d.ATTR_PREFIXES.COMPONENT)?!0:!i.closest(`[${d.ATTR_PREFIXES.COMPONENT}]`);let n=i.parentElement;for(;n&&n!==e;){if(n.hasAttribute(d.ATTR_PREFIXES.COMPONENT))return!1;n=n.parentElement}return n===e||e.contains(i)})}executeScript(e){if(this.processedScripts.has(e))return;this.processedScripts.add(e);const t=this.getCurrentComponent(),i=e.textContent||"",n=N.decodeEntities(i);try{const r=this.findComponentElementForScript(e,t);if(r===e){const o=this.getParentComponent(e);this.setupProps(e,o)}const a=this.buildComponentContextWithProps(t,r);window[t]||(window[t]={}),this.executeScriptFunctions(n,t,a)}catch(r){console.error(`Script execution failed in component ${t}:`,r),console.error("Script content:",n)}}findComponentElementForScript(e,t){if(e.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t)return e;let i=e.parentElement;for(;i;){if(i.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t)return i;i=i.parentElement}const n=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${t}"]`);for(const r of n)if(this.elementProps.has(r))return r;return n[0]||void 0}executeScriptFunctions(e,t,i){const n=this.extractFunctionNames(e),r=this.findElementWithProps(t),a=this.extractVariableDeclarations(e);let o={...i};if(a.forEach(m=>{delete o[m];const g=`set${Dt(m)}`,b=`${m}Getter`;delete o[g],delete o[b]}),r){const m=this.evaluateProps(r);Object.assign(o,m)}o.getContext=()=>this.buildComponentContextWithProps(t),o.withContext=m=>{const g=this.buildComponentContextWithProps(t);return m.call(g,g)},o.__getProp=m=>{if(r)return this.evaluateProps(r)[m]};let l=z.getInstance().transformStateDeclarations(e);l=this.modifyScriptForReactiveProps(l,t,r||void 0);const p=`
16
+ `)),n}}class ks{textNodeBindings=new Map;expressionEvaluator;stateManager;componentManager;cleanupObserver;bindingCount=0;constructor(e,t){this.expressionEvaluator=e,this.stateManager=t,this.cleanupObserver=new MutationObserver(i=>{this.cleanupDetachedNodes(i)}),this.cleanupObserver.observe(document.body,{childList:!0,subtree:!0})}cleanupDetachedNodes(e){const t=[];for(const i of e)i.type==="childList"&&i.removedNodes.forEach(n=>{if(n.nodeType===Node.TEXT_NODE)t.push(n);else if(n.nodeType===Node.ELEMENT_NODE){const r=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null);let a;for(;a=r.nextNode();)t.push(a)}});Promise.resolve().then(()=>{t.forEach(i=>{document.contains(i)||this.cleanupTextNode(i)})})}processTextNode(e,t){if(this.textNodeBindings.has(e)||S.isTextNodeInsideScript(e)||this.isInsideLoopItem(e))return;const i=e.parentElement,n=i?S.getContextComponent(i):t,r=e.textContent||"",a=N.parse(r);if(!a.some(p=>p.type==="expression"))return;const c=this.resolveComponentRootForElement(e,n),l={originalContent:r,expressions:a,subscriptionIds:[],component:n,componentElement:c};a.filter(p=>p.type==="expression").forEach(p=>{if(!p.expression)return;const h=`text_${Date.now()}_${Math.random()}`,f=this.expressionEvaluator.extractDependencies(p.expression,n,this.stateManager);if(c&&this.componentManager){const m=this.componentManager.getComponentPropDependencies(c,n);f.push(...m)}const E={id:h,selector:"",dependencies:new Set(f),callback:()=>{this.updateTextNode(e)},element:e.parentElement??void 0,component:n};this.stateManager.addSubscription(E),l.subscriptionIds.push(h)}),this.textNodeBindings.set(e,l),this.bindingCount++,this.updateTextNode(e)}isInsideLoopItem(e){let t=e.parentElement;for(;t&&t!==document.body;){const i=t.previousSibling;if(i&&i.nodeType===Node.COMMENT_NODE&&i.textContent?.startsWith("pp-for:"))return!0;let n=t.parentElement?.firstChild||null;for(;n;){if(n.nodeType===Node.COMMENT_NODE&&n.textContent?.startsWith("pp-for:")&&n!==t)return!0;n=n.nextSibling}t=t.parentElement}return!1}updateTextNode(e){const t=this.textNodeBindings.get(e);if(!t||!e.parentElement)return;const i=t.component;let n=t.componentElement;(!n||!document.contains(n))&&(n=this.resolveComponentRootForElement(e,i),t.componentElement=n);const r=this.isTextNodeInPortal(e);let a;r&&n?a=this.getFreshComponentContext(i,n):a=this.getContextForComponent(i,n);let o="";for(const c of t.expressions)if(c.type==="static")o+=c.content;else if(c.expression)try{const l=this.expressionEvaluator.evaluateExpression(c.expression,a,i);o+=ae(l)}catch(l){const p=typeof l=="object"&&l!==null&&"message"in l?l.message:String(l);console.warn(`Text binding evaluation warning for "${c.expression}": ${p}`),o+=""}e.textContent!==o&&(e.textContent=o)}isTextNodeInPortal(e){let t=e.parentElement;for(;t;){if(t.id&&t.id.startsWith("portal-")||t.getAttribute("data-slot")==="portal"||t.id==="pp-portal-root")return!0;t=t.parentElement}return!1}getFreshComponentContext(e,t){return this.componentManager?(this.componentManager.contextInvalidated.add(e),this.componentManager.contextCache.delete(e),this.componentManager.buildComponentContextWithProps(e,t)):{}}resolveComponentRootForElement(e,t){if(!this.isTextNodeInPortal(e)){let r=e.parentElement;for(;r&&r.nodeType===Node.ELEMENT_NODE;){const a=r;if(a.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t)return a;r=r.parentElement}}const n=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${t}"]`);if(this.componentManager){for(const r of n)if(this.componentManager.hasStoredProps(r))return r}return n[0]||void 0}getContextForComponent(e,t){return this.componentManager?this.componentManager.buildComponentContextWithProps(e,t):{}}cleanupTextNode(e){const t=this.textNodeBindings.get(e);t&&(t.subscriptionIds.forEach(i=>{this.stateManager.removeSubscription(i)}),this.textNodeBindings.delete(e),this.bindingCount=Math.max(0,this.bindingCount-1))}getBindingCount(){return this.textNodeBindings.size}getAllBindings(){return new Map(this.textNodeBindings)}clearAllBindings(){for(const[e]of this.textNodeBindings)this.cleanupTextNode(e)}destroy(){this.cleanupObserver.disconnect(),this.clearAllBindings()}}class Is{listeners=new Map;on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>this.off(e,t)}off(e,t){this.listeners.get(e)?.delete(t)}emit(e,...t){const i=this.listeners.get(e);i&&i.forEach(n=>{try{n(...t)}catch(r){console.error(`Event listener error for ${e}:`,r)}})}}class Ms{stateStore={};subscriptions=new Map;updateQueue=new Set;isUpdating=!1;eventBus=new Is;contextCache=new Map;previousValues=new Map;_subscriptionManager=new _s;originalStateStore={};domUpdateCallbacks=[];domUpdateScheduled=!1;constructor(){this.setupGlobalStateProxy(),setInterval(()=>{this.subscriptionManager.cleanupStaleSubscriptions()},3e4)}clearSubscriptions(){const e=this._subscriptionManager.getAllSubscriptions();for(const[t]of e)this._subscriptionManager.removeSubscription(t);this.updateQueue.clear()}clearComponentSubscriptions(e){const t=this._subscriptionManager.getAllSubscriptions();for(const[i,n]of t)n.component===e&&this._subscriptionManager.removeSubscription(i)}clearState(){Object.keys(this.stateStore).forEach(e=>{delete this.stateStore[e],delete this.originalStateStore[e]}),this.previousValues.clear(),this.updateQueue.clear(),this.contextCache.clear()}clearComponentState(e){Object.keys(this.stateStore).filter(i=>i.startsWith(`${e}.`)).forEach(i=>{delete this.stateStore[i],delete this.originalStateStore[i],this.previousValues.delete(i)})}onDOMUpdateComplete(e){this.domUpdateCallbacks.push(e),this.domUpdateScheduled||(this.domUpdateScheduled=!0,requestAnimationFrame(()=>{requestAnimationFrame(()=>{const t=[...this.domUpdateCallbacks];this.domUpdateCallbacks=[],this.domUpdateScheduled=!1,t.forEach(i=>{try{i()}catch(n){console.error("DOM update callback error:",n)}})})}))}setInitialState(e,t){if(this.previousValues.set(e,void 0),this.originalStateStore[e]=t,this.previousValues.size>100){const i=this.previousValues.keys().next().value;typeof i=="string"&&this.previousValues.delete(i)}}get subscriptionManager(){return this._subscriptionManager}batchStateUpdates(e){const t=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=t,!this.isUpdating&&this.updateQueue.size>0&&this.scheduleFlush()}}invalidateContextCache(){this.contextCache.clear()}setupGlobalStateProxy(){this.originalStateStore=this.stateStore,this.stateStore=new Proxy(this.stateStore,{set:(e,t,i,n)=>{const r=e[t],a=Reflect.set(e,t,i,n);return r!==i&&this.notifySubscribers(t),a},get:(e,t)=>Reflect.get(e,t)})}notifySubscribers(e){if(this.eventBus.emit("stateChanged",e),this.updateQueue.add(e),e.includes(".")){const t=e.split(".")[0];this.updateQueue.add(t)}this.notifyPathBasedSubscribers(e),this.isUpdating||this.scheduleFlush()}notifyPathBasedSubscribers(e){const t=this.stateStore[e],i=this.previousValues?.get(e);for(const[n,r]of this.subscriptions)for(const a of r.dependencies)if(this.isPathDependency(a)&&a.startsWith(e+".")){const o=a.substring(e.length+1),c=this.getPathValue(i,o),l=this.getPathValue(t,o);this.deepEqual(c,l)||this.updateQueue.add(a)}}isPathDependency(e){return e.includes(".")&&e.split(".").length>1}getPathValue(e,t){if(!e||typeof e!="object")return;const i=t.split(".");let n=e;for(const r of i){if(n==null)return;if(Array.isArray(n))return r==="length"?n.length:n.map(a=>a?.[r]).filter(a=>a!==void 0);n=n[r]}return n}deepEqual(e,t){if(e===t)return!0;if(e==null||t==null)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((i,n)=>this.deepEqual(i,t[n]));if(typeof e=="object"&&typeof t=="object"){const i=Object.keys(e),n=Object.keys(t);return i.length!==n.length?!1:i.every(r=>this.deepEqual(e[r],t[r]))}return!1}scheduleFlush=ws(()=>{this.flushUpdates()},d.DEBOUNCE_MS);flushUpdates(){if(!this.isUpdating){this.isUpdating=!0;try{const e=new Set,t=this.subscriptionManager.getSubscriptionsForKey("*");if(t&&t.size>0&&this.updateQueue.size>0)for(const i of t){const n=this.subscriptionManager.getSubscription(i);if(!n)continue;if(n.element&&!document.contains(n.element)){this.subscriptionManager.removeSubscription(i);continue}const r=n.element??document.body;try{const a=Array.from(this.updateQueue)[0];n.callback(r,{key:a})}catch(a){console.error("Wildcard subscription callback failed:",a)}}for(const i of this.updateQueue){if(e.has(i))continue;e.add(i);const n=this.subscriptionManager.getSubscriptionsForKey(i);if(n)for(const r of n){const a=this.subscriptionManager.getSubscription(r);if(!a)continue;if(a.element&&!document.contains(a.element)){this.subscriptionManager.removeSubscription(r);continue}const o=a.element??document.body;try{a.callback(o,{key:i})}catch(c){console.error("Subscription callback failed:",c)}}}}finally{this.updateQueue.clear(),this.isUpdating=!1}}}getState(){return this.stateStore}setState(e,t){if(this.previousValues.set(e,this.stateStore[e]),this.stateStore[e]=t,this.previousValues.size>100){const i=this.previousValues.keys().next().value;typeof i=="string"&&this.previousValues.delete(i)}}hasState(e){return e in this.originalStateStore}addSubscription(e){this._subscriptionManager.addSubscription(e)}removeSubscription(e){this._subscriptionManager.removeSubscription(e)}onStateChange(e){return this.eventBus.on("stateChanged",e)}batch(e){const t=this.isUpdating;this.isUpdating=!0;try{return e()}finally{this.isUpdating=t,!this.isUpdating&&this.updateQueue.size&&this.flushUpdates()}}getSubscriptions(){return this.subscriptionManager.getAllSubscriptions()}getKeyIndex(){const e=new Map,t=this.subscriptionManager.getAllSubscriptions();for(const[i,n]of t)for(const r of n.dependencies)e.has(r)||e.set(r,new Set),e.get(r).add(i);return e}destroy(){this.clearState(),this.clearSubscriptions(),this.contextCache.clear(),this.previousValues.clear(),this.domUpdateCallbacks=[]}}class pe{expressionCache=new j(d.MAX_CACHE_SIZE);dependencyCache=new j(d.MAX_CACHE_SIZE);commonExpressionsCache=new j(100);dependencyParser=new Os;static CACHE_KEYS={EXPRESSION:(e,t)=>`expr:${e}:${t}`,DEPENDENCY:(e,t)=>`deps:${e}:${t}`,COMMON:e=>`common:${e}`};constructor(){this.precompileCommonExpressions()}normalizeExpression(e){return e.replace(/\r\n/g," ").replace(/\r/g," ").replace(/\n/g," ").replace(/\s+/g," ").trim()}precompileCommonExpressions(){["true","false","null","undefined"].forEach(t=>{const i={fn:new Function("return "+t),contextMap:new Map,dependencies:[t],timestamp:Date.now(),hitCount:0},n=pe.CACHE_KEYS.COMMON(t);this.commonExpressionsCache.set(n,i)})}extractDependencies(e,t,i){const n=this.normalizeExpression(e),r=pe.CACHE_KEYS.DEPENDENCY(t,n);let a=this.dependencyCache.get(r);return a||(a=this.dependencyParser.extract(n,t,i),this.dependencyCache.set(r,a),a)}evaluateExpression(e,t,i){const n=this.normalizeExpression(e),r=pe.CACHE_KEYS.COMMON(n);let a=this.commonExpressionsCache.get(r);if(a){a.hitCount++;try{return a.fn()}catch(c){console.error(`Common expression evaluation failed: "${n}"`,c);return}}const o=pe.CACHE_KEYS.EXPRESSION(i,n);a=this.expressionCache.get(o),(!a||this.isStale(a))&&(a=this.compileExpression(n,t,i),this.expressionCache.set(o,a)),a.hitCount++;try{const c=this.buildArguments(a.contextMap,t);return a.fn(...c)}catch(c){console.error(`Expression evaluation failed: "${n}"`,c),console.error("Available context:",Object.keys(t));return}}compileExpression(e,t,i){const n=this.prepareSafeContext(t),r=new Map,a=[];Object.keys(n).forEach((c,l)=>{r.set(c,l),a.push(c)});const o=this.dependencyParser.extract(e,i);return{fn:new Function(...a,`return (${e})`),contextMap:r,dependencies:o,timestamp:Date.now(),hitCount:0}}buildArguments(e,t){const i=new Array(e.size);for(const[n,r]of e)i[r]=t[n];return i}isStale(e){return Date.now()-e.timestamp>3e5}prepareSafeContext(e){const t={};for(const[i,n]of Object.entries(e))be.has(i)||!this.isValidJavaScriptIdentifier(i)||(t[i]=n);return t}isValidJavaScriptIdentifier(e){return/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(e)&&!be.has(e)}invalidateCache(e){switch(e){case"expressions":this.expressionCache.clear();break;case"dependencies":this.dependencyCache.clear();break;case"common":this.commonExpressionsCache.clear(),this.precompileCommonExpressions();break;case"parser":this.dependencyParser.clearCache();break;default:this.clearAllCaches()}}invalidateByComponent(e){this.expressionCache.deleteByPrefix(`expr:${e}:`),this.dependencyCache.deleteByPrefix(`deps:${e}:`)}clearAllCaches(){this.expressionCache.clear(),this.dependencyCache.clear(),this.commonExpressionsCache.clear(),this.dependencyParser.clearCache(),this.precompileCommonExpressions()}getCacheStats(){return{expressions:this.expressionCache.getStats(),dependencies:this.dependencyCache.getStats(),commonExpressions:this.commonExpressionsCache.getStats(),dependencyParser:this.getDependencyParserStats()}}getDependencyParserStats(){return this.dependencyParser.getCacheSize?{size:this.dependencyParser.getCacheSize(),maxSize:500,hitRate:0,hits:0,misses:0}:{size:0,maxSize:0,hitRate:0,hits:0,misses:0}}cleanupStaleExpressions(){let e=0;return this.expressionCache.keys().forEach(i=>{const n=this.expressionCache.get(i);n&&this.isStale(n)&&(this.expressionCache.delete(i),e++)}),e}}class Os{parseCache=new j(500);extract(e,t,i){const n=this.normalizeExpression(e),r=`${t}:${n}`;if(this.parseCache.has(r))return this.parseCache.get(r);const a=this.parseExpression(n,t,i);return this.parseCache.set(r,a),a}normalizeExpression(e){return e.replace(/\r\n/g," ").replace(/\r/g," ").replace(/\n/g," ").replace(/\s+/g," ").trim()}parseExpression(e,t,i){const n=this.extractIdentifiers(e),r=[],a=i?.getState()||{};for(const c of n){if(be.has(c))continue;const l=c.indexOf("."),p=l===-1?c:c.substring(0,l),h=je.findExistingStateKey(p,t,a);if(h)r.push(h);else{const f=t==="app"?[`app.${p}`]:[`${t}.${p}`,`app.${p}`];r.push(...f)}if(l!==-1){const f=t==="app"?[`app.${p}`]:[`${t}.${p}`,`app.${p}`];r.push(...f)}}return Array.from(new Set(r))}extractIdentifiers(e){const t=[];let i=0;for(;i<e.length;){const n=e[i];if(n==="'"){i=this.skipString(e,i,"'");continue}if(n==='"'){i=this.skipString(e,i,'"');continue}if(n==="`"){i=this.skipTemplateLiteral(e,i,t);continue}if(this.isIdentifierStart(n)){const r=this.extractIdentifier(e,i);t.push(r.value),i=r.endIndex;continue}i++}return t}skipString(e,t,i){let n=t+1;for(;n<e.length&&e[n]!==i;)e[n]==="\\"&&n++,n++;return n+1}skipTemplateLiteral(e,t,i){let n=t+1;for(;n<e.length&&e[n]!=="`";){if(e[n]==="$"&&n+1<e.length&&e[n+1]==="{"){n+=2;let r=1;for(;n<e.length&&r>0;){const a=e[n];if(a==='"'||a==="'"){n=this.skipString(e,n,a);continue}if(a==="{"?r++:a==="}"&&r--,r>0&&this.isIdentifierStart(a)){const o=this.extractIdentifier(e,n);i.push(o.value),n=o.endIndex-1}n++}continue}e[n]==="\\"&&n++,n++}return n+1}extractIdentifier(e,t){let i=t;for(;i<e.length&&(this.isIdentifierPart(e[i])||e[i]===".");)i++;return{value:e.substring(t,i),endIndex:i}}isIdentifierStart(e){return/[a-zA-Z_$]/.test(e)}isIdentifierPart(e){return/[a-zA-Z0-9_$]/.test(e)}clearCache(){this.parseCache.clear()}getCacheSize(){return this.parseCache.cache.size}}class Rs{componentStack=["app"];elementProps=new WeakMap;contextCache=new j(100);contextIndex=new Map;contextInvalidated=new Set;stateManager;processedScripts=new WeakSet;componentFunctions=new Map;expressionEvaluator;domBindingManager;loopManager;templateRenderer;updateTimeouts;updateBatcher=new st;propDependencyCache=new Map;constructor(e){this.stateManager=e,this.updateBatcher=new st,this.stateManager.onStateChange(t=>this.invalidateContextCache(t))}getPropDependencies(e,t){const i=this.findElementWithProps(t);if(!i)return[];const n=this.elementProps.get(i);if(!n||!n.has(e))return[];const r=n.get(e);return this.templateRenderer?.dependencies(r.expression,r.component,this.stateManager)||[]}buildRestrictedComponentContext(e,t=!1){const i={};window[e]&&Object.assign(i,window[e]);const n=this.componentFunctions.get(e);if(n)for(const[a,o]of n)i[a]=o;const r=this.stateManager.getState();for(const a of Object.keys(r))if(a.startsWith(e+".")){const o=a.substring(e.length+1);o in i||(i[o]=r[a])}if(t){if(window.app)for(const[o,c]of Object.entries(window.app))o in i||(i[o]=c);const a=this.componentFunctions.get("app");if(a)for(const[o,c]of a)o in i||(i[o]=c);for(const o of Object.keys(r))if(o.startsWith("app.")){const c=o.substring(4);c in i||(i[c]=r[o])}}return i}getComponentPropDependencies(e,t){if(this.propDependencyCache.has(e))return this.propDependencyCache.get(e);const i=[],n=this.elementProps.get(e);n&&this.templateRenderer&&n.forEach(a=>{const o=this.templateRenderer?.dependencies(a.expression,a.component,this.stateManager);i.push(...o??[])});const r=Array.from(new Set(i));return this.propDependencyCache.set(e,r),r}setDOMBindingManager(e){this.domBindingManager=e,this.updateBatcher.setManagers(this,e)}hasStoredProps(e){return this.elementProps.has(e)&&this.elementProps.get(e).size>0}setExpressionEvaluator(e){this.expressionEvaluator=e,this.templateRenderer=new Qe(e),this.loopManager=new Bt(this.stateManager,e)}extractProps(e,t){const i=new Map,n=e.attributes,r=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);let o=t;r&&(r==="app"?o="app":r==="parent"?o=S.getParentOfComponent(a||"app",e):o=r);for(let c=0;c<n.length;c++){const l=n[c];if(!(l.name===d.ATTR_PREFIXES.COMPONENT||l.name===d.ATTR_PREFIXES.CONTEXT||l.name===d.ATTR_PREFIXES.SPREAD||l.name===d.ATTR_PREFIXES.LOOP)&&!le.isEventAttribute(l.name)&&l.value&&Ns.containsMustacheExpression(l.value)){if(a&&this.mightReferenceSelfProps(l.value,e))continue;const p=this.attributeToPropName(l.name),h={name:p,expression:l.value,component:o,subscriptionIds:[]};i.set(p,h)}}return i}mightReferenceSelfProps(e,t){const i=this.elementProps.get(t);return i?Array.from(i.keys()).some(r=>e.includes(r)&&r!=="dataState"):!1}attributeToPropName(e){return e.replace(/-([a-z])/g,(t,i)=>i.toUpperCase())}setupProps(e,t){const i=this.extractProps(e,t);i.size!==0&&(this.elementProps.set(e,i),this.expressionEvaluator&&i.forEach((n,r)=>{this.setupPropBinding(e,n)}))}setupPropBinding(e,t){if(!this.expressionEvaluator)return;const i=`prop_${Date.now()}_${Math.random()}`,n=this.templateRenderer?.dependencies(t.expression,t.component,this.stateManager)||[],r={id:i,selector:"",dependencies:new Set(n),callback:()=>{const a=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);a&&(this.updateBatcher.scheduleUpdate(a,e),this.refreshComponentBindings(e,a))},element:e,component:t.component};this.stateManager.addSubscription(r),t.subscriptionIds.push(i)}refreshComponentBindings(e,t){this.contextInvalidated.add(t),this.contextCache.delete(t),this.domBindingManager&&this.domBindingManager.refreshComponentElement(e,t)}evaluateProps(e){const t={},i=this.elementProps.get(e);if(!i||!this.expressionEvaluator)return t;const n=i.values().next().value;if(!n)return t;const r=this.buildComponentContext(n.component);return i.forEach((a,o)=>{try{const c=this.templateRenderer?.render(a.expression,r,a.component);typeof c=="function"?t[o]=(...l)=>c.apply(this,l):t[o]=c}catch(c){console.error(`❌ Failed to evaluate prop "${o}":`,c),t[o]=void 0}}),t}cleanupProps(e){const t=this.elementProps.get(e);t&&(t.forEach(i=>{i.subscriptionIds.forEach(n=>{this.stateManager.removeSubscription(n)})}),this.elementProps.delete(e))}buildComponentContextWithProps(e,t){const i=this.buildComponentContext(e);let n=this.findElementWithProps(e);if(t&&this.elementProps.has(t)&&(n=t),n)try{const r=this.evaluatePropsWithContext(n,e,t);Object.keys(r).length>0&&Object.keys(r).forEach(a=>{i[a]=r[a]})}catch(r){console.error(`❌ Error evaluating props for ${e}:`,r)}return i}evaluatePropsWithContext(e,t,i){const n={},r=this.elementProps.get(e);if(!r||!this.expressionEvaluator)return n;const a=r.values().next().value;if(!a)return n;let o;const c=e.getAttribute(d.ATTR_PREFIXES.CONTEXT),l=e.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(c)if(c==="app")o=this.buildComponentContext("app");else if(c==="parent"){const g=S.getParentOfComponent(l||"app",e);o=this.buildComponentContext(g)}else o=this.buildComponentContext(c);else o=this.buildComponentContext(a.component);const p=this.loopManager?.getLoopContextForElement(e);p&&(o={...o,...p});const h=new Map,f=new Map,E=Array.from(r.keys());r.forEach((g,b)=>{E.some(P=>P!==b&&g.expression.includes(P))?f.set(b,g):h.set(b,g)}),h.forEach((g,b)=>{try{const v=this.templateRenderer?.render(g.expression,o,c||g.component);typeof v=="function"?this.isFunctionExplicitlyPassed(g.expression)?n[b]=(...k)=>v.apply(this,k):(console.warn(`⚠️ Function "${b}" not passed - not from shared namespace or explicitly passed`),n[b]=void 0):n[b]=v}catch(v){console.error(`❌ Failed to evaluate simple prop "${b}":`,v),console.error("Expression:",g.expression),console.error("Available context keys:",Object.keys(o)),n[b]=void 0}});const m={...o,...n};return f.forEach((g,b)=>{try{const v=this.templateRenderer?.render(g.expression,m,c||g.component);typeof v=="function"?this.isFunctionExplicitlyPassed(g.expression)?n[b]=(...k)=>v.apply(this,k):(console.warn(`⚠️ Function "${b}" not passed - not from shared namespace or explicitly passed`),n[b]=void 0):n[b]=v}catch(v){console.error(`❌ Failed to evaluate complex prop "${b}":`,v),console.error("Expression:",g.expression),console.error("Available context keys:",Object.keys(m)),n[b]=void 0}}),n}isFunctionExplicitlyPassed(e){const t=N.isSingleExpression(e);return t?/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t.trim()):!1}findElementWithProps(e){const t=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${e}"]`);for(const i of t){const n=this.elementProps.get(i);if(n&&n.size>0)return i}return null}pushComponent(e){this.componentStack.push(e)}popComponent(){return this.componentStack.pop()}getCurrentComponent(){return this.componentStack[this.componentStack.length-1]}buildComponentContext(e){if(!this.contextInvalidated.has(e)&&this.contextCache.has(e))return this.contextCache.get(e);const t=this.computeComponentContext(e);return this.contextCache.set(e,t),this.contextInvalidated.delete(e),t}computeComponentContext(e){const t={};if(e.includes("_loop_")||e.match(/_[a-zA-Z0-9]{8}$/)){const r=e.split("_");r.pop();const a=r.join("_");window[a]&&Object.assign(t,window[a])}e!=="app"&&window[e]&&Object.assign(t,window[e]),e==="app"&&window.app&&Object.assign(t,window.app);const i=this.componentFunctions.get(e);if(i)for(const[r,a]of i)t[r]=a;if(e!=="app"){const r=this.componentFunctions.get("app");if(r)for(const[a,o]of r)a in t||(t[a]=o);if(window.app)for(const[a,o]of Object.entries(window.app))a in t||(t[a]=o)}const n=this.stateManager.getState();for(const r of Object.keys(n))if(r.startsWith(e+".")){const a=r.substring(e.length+1);a in t||(t[a]=n[r])}if(e!=="app"){for(const r of Object.keys(n))if(r.startsWith("app.")){const a=r.substring(4);a in t||(t[a]=n[r])}}return t}invalidateContextCache(e){if(e.startsWith("app.")){this.contextCache.clear();for(const i of this.contextInvalidated.keys())this.contextInvalidated.add(i);return}const t=e.indexOf(".");if(t!==-1){const i=e.slice(0,t);this.invalidateComponent(i)}}invalidateComponent(e){this.contextInvalidated.add(e),this.contextIndex.delete(e)}executePhpScripts(e){const t=this.componentStack.length,i=e.getAttribute(d.ATTR_PREFIXES.COMPONENT),n=e===document.body;if(i||n){if(i){this.pushComponent(i);const a=this.getParentComponent(e);this.setupProps(e,a)}this.getRelevantScripts(e,n).forEach(a=>{const o=a.getAttribute(d.ATTR_PREFIXES.COMPONENT);o&&o!==i?(this.pushComponent(o),this.executeScript(a),this.popComponent()):this.executeScript(a)})}for(Array.from(e.children).forEach(r=>this.executePhpScripts(r));this.componentStack.length>t;)this.popComponent()}getParentComponent(e){let t=e.parentElement;for(;t;){const i=t.getAttribute(d.ATTR_PREFIXES.COMPONENT);if(i)return i;t=t.parentElement}return"app"}getRelevantScripts(e,t){return Array.from(e.querySelectorAll(`script[type="${d.SCRIPT_TYPE}"]`)).filter(i=>{if(this.processedScripts.has(i))return!1;if(t)return i.hasAttribute(d.ATTR_PREFIXES.COMPONENT)?!0:!i.closest(`[${d.ATTR_PREFIXES.COMPONENT}]`);let n=i.parentElement;for(;n&&n!==e;){if(n.hasAttribute(d.ATTR_PREFIXES.COMPONENT))return!1;n=n.parentElement}return n===e||e.contains(i)})}executeScript(e){if(this.processedScripts.has(e))return;this.processedScripts.add(e);const t=this.getCurrentComponent(),i=e.textContent||"",n=N.decodeEntities(i);try{const r=this.findComponentElementForScript(e,t);if(r===e){const o=this.getParentComponent(e);this.setupProps(e,o)}const a=this.buildComponentContextWithProps(t,r);window[t]||(window[t]={}),this.executeScriptFunctions(n,t,a)}catch(r){console.error(`Script execution failed in component ${t}:`,r),console.error("Script content:",n)}}findComponentElementForScript(e,t){if(e.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t)return e;let i=e.parentElement;for(;i;){if(i.getAttribute(d.ATTR_PREFIXES.COMPONENT)===t)return i;i=i.parentElement}const n=document.querySelectorAll(`[${d.ATTR_PREFIXES.COMPONENT}="${t}"]`);for(const r of n)if(this.elementProps.has(r))return r;return n[0]||void 0}executeScriptFunctions(e,t,i){const n=this.extractFunctionNames(e),r=this.findElementWithProps(t),a=this.extractVariableDeclarations(e);let o={...i};if(a.forEach(m=>{delete o[m];const g=`set${Dt(m)}`,b=`${m}Getter`;delete o[g],delete o[b]}),r){const m=this.evaluateProps(r);Object.assign(o,m)}o.getContext=()=>this.buildComponentContextWithProps(t),o.withContext=m=>{const g=this.buildComponentContextWithProps(t);return m.call(g,g)},o.__getProp=m=>{if(r)return this.evaluateProps(r)[m]};let l=z.getInstance().transformStateDeclarations(e);l=this.modifyScriptForReactiveProps(l,t,r||void 0);const p=`
17
17
  ${l}
18
18
 
19
19
  ${n.map(m=>`
@@ -1,9 +1,9 @@
1
1
  import { createProxyMiddleware } from "http-proxy-middleware";
2
- import { writeFileSync } from "fs";
2
+ import { writeFileSync, existsSync, mkdirSync } from "fs";
3
3
  import browserSync, { BrowserSyncInstance } from "browser-sync";
4
4
  import prismaPhpConfigJson from "../prisma-php.json";
5
5
  import { generateFileListJson } from "./files-list.js";
6
- import { join } from "path";
6
+ import { join, dirname } from "path";
7
7
  import { getFileMeta, PUBLIC_DIR, SRC_DIR } from "./utils.js";
8
8
  import { updateAllClassLogs } from "./class-log.js";
9
9
  import {
@@ -39,6 +39,10 @@ const pipeline = new DebouncedWorker(
39
39
  }
40
40
  await checkComponentImports(file, fileImports);
41
41
  }
42
+
43
+ if (bs.active) {
44
+ bs.reload();
45
+ }
42
46
  },
43
47
  350,
44
48
  "bs-pipeline"
@@ -46,7 +50,10 @@ const pipeline = new DebouncedWorker(
46
50
 
47
51
  const publicPipeline = new DebouncedWorker(
48
52
  async () => {
49
- console.log("Public directory changed");
53
+ console.log("Public directory changed, reloading browser...");
54
+ if (bs.active) {
55
+ bs.reload();
56
+ }
50
57
  },
51
58
  350,
52
59
  "bs-public-pipeline"
@@ -68,6 +75,27 @@ createSrcWatcher(join(PUBLIC_DIR, "**", "*"), {
68
75
  interval: 1000,
69
76
  });
70
77
 
78
+ const viteFlagFile = join(__dirname, "..", ".pp", ".vite-build-complete");
79
+ mkdirSync(dirname(viteFlagFile), { recursive: true });
80
+ writeFileSync(viteFlagFile, "");
81
+
82
+ if (!existsSync(viteFlagFile)) {
83
+ writeFileSync(viteFlagFile, "0");
84
+ }
85
+
86
+ createSrcWatcher(viteFlagFile, {
87
+ onEvent: (ev) => {
88
+ if (ev === "change" && bs.active) {
89
+ console.log("→ Vite build complete, reloading browser...");
90
+ bs.reload();
91
+ }
92
+ },
93
+ awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 50 },
94
+ logPrefix: "watch-vite",
95
+ usePolling: true,
96
+ interval: 500,
97
+ });
98
+
71
99
  bs.init(
72
100
  {
73
101
  proxy: "http://localhost:3000",
@@ -85,15 +113,10 @@ bs.init(
85
113
  }),
86
114
  ],
87
115
 
88
- files: [`${SRC_DIR}/**/*.*`, `${PUBLIC_DIR}/**/*.*`],
89
116
  notify: false,
90
117
  open: false,
91
118
  ghostMode: false,
92
119
  codeSync: true,
93
- watchOptions: {
94
- usePolling: true,
95
- interval: 1000,
96
- },
97
120
  },
98
121
  (err, bsInstance) => {
99
122
  if (err) {
@@ -1,6 +1,7 @@
1
- import { defineConfig } from "vite";
1
+ import { defineConfig, Plugin } from "vite";
2
2
  import path from "path";
3
3
  import fg from "fast-glob";
4
+ import { writeFileSync } from "fs";
4
5
 
5
6
  const entries = Object.fromEntries(
6
7
  fg.sync("ts/**/*.ts", { ignore: ["**/*.test.ts"] }).map((f) => {
@@ -9,6 +10,17 @@ const entries = Object.fromEntries(
9
10
  })
10
11
  );
11
12
 
13
+ function browserSyncNotify(): Plugin {
14
+ const flagFile = path.resolve(__dirname, ".pp", ".vite-build-complete");
15
+
16
+ return {
17
+ name: "browsersync-notify",
18
+ writeBundle() {
19
+ writeFileSync(flagFile, Date.now().toString());
20
+ },
21
+ };
22
+ }
23
+
12
24
  export default defineConfig({
13
25
  publicDir: false,
14
26
  build: {
@@ -28,6 +40,7 @@ export default defineConfig({
28
40
  },
29
41
  },
30
42
  },
43
+ plugins: [browserSyncNotify()],
31
44
  esbuild: { legalComments: "none" },
32
45
  define: { "process.env.NODE_ENV": '"production"' },
33
46
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "4.1.0-alpha.11",
3
+ "version": "4.1.0-alpha.13",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",