@memoized-dom/compiler 0.0.2 → 0.0.4

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.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{transformSync as fa}from"@babel/core";import ma from"@babel/plugin-syntax-jsx";import ga from"@babel/plugin-transform-typescript";import*as J from"@babel/types";import"@babel/types";function Qt(e={}){let t=e.moduleId??"./component.tsx",n=new Map,r=new Map,o=new Map,i=new Map,s=new Map,a=new Map,l=new Map,d=new Set,u=new Map,c=new Map;for(let[y,f]of Object.entries(e.linkedImports??{}))f.type==="state"?(n.set(y,f.kind),r.set(y,f.key),f.tagCandidates!==void 0&&o.set(y,[...f.tagCandidates]),f.componentCandidates!==void 0&&l.set(y,f.componentCandidates.map(m=>({...m}))),d.add(y)):f.type==="function"?(f.tagCandidates!==void 0&&i.set(y,[...f.tagCandidates]),f.componentCandidates!==void 0&&l.set(y,f.componentCandidates.map(m=>({...m}))),u.set(y,{reads:new Set(f.reads),writes:new Set(f.writes),boundedWrites:new Set(f.boundedWrites),parameterWrites:f.parameterWrites.map(m=>({index:m.index,path:[...m.path]})),unbounded:f.unbounded})):c.set(y,{...f,props:[...f.props]});let g=new Map;for(let[y,f]of c)g.set(y,{mode:f.objectProps?"object":"positional",names:[...f.props],acceptsUnknown:f.acceptsUnknownProps,bindings:[],params:[],hasWholeDefault:f.hasWholeDefault,renderProps:[...f.renderProps??[]],renderCallbacks:[...f.renderCallbacks??[]],refProps:[...f.refProps??[]]});let x=new Map(Object.entries(e.linkedComponentRenderProps??{}).map(([y,f])=>[y,[...f]]));return{runtimePath:e.runtimePath??"@memoized-dom/runtime",rootId:e.rootId??"App",moduleId:t,state:n,stateKeys:r,stateTagCandidates:o,functionTagCandidates:i,stateComponentCandidates:s,functionComponentCandidates:a,linkedDynamicComponentCandidates:l,importedState:d,importedFunctions:u,importedComponents:c,linkedComponentPaths:new Map(Object.entries(e.linkedComponentPaths??{}).map(([y,f])=>[y,[...f]])),linkedComponentRows:new Map(Object.entries(e.linkedComponentRows??{}).map(([y,f])=>[y,f.map(m=>({keyPath:m.keyPath===null?null:[...m.keyPath],sourceKey:m.sourceKey,sourceLocal:m.sourceLocal}))])),linkedComponentPropSources:new Map(Object.entries(e.linkedComponentPropSources??{}).map(([y,f])=>[y,new Map(Object.entries(f).map(([m,w])=>[m,{keys:[...w.keys],rootFallback:w.rootFallback}]))])),comps:new Map,compPaths:new Map,helpers:new Map,jsxHelpers:new Map,helperSummaries:new Map,compReads:new Map,childRefCounts:new Map,renderSlotOwners:new Set,listedSites:new Map,componentsWithHostEvents:new Set,conditionalComponentSites:new Map,rowComponentSites:new Map,componentProps:g,linkedComponentRenderProps:x,lightweightCache:new Map,rowReads:new Map,condReads:new Map,targetedListDependencies:new WeakMap,targetedListComponents:new Set,instanceState:new Map,instanceDerivations:new Map,instanceControlFlow:new Map,instanceDerivedBindings:new Map,instanceReasonIds:new Map,selectiveDerivationComponents:new Set,effects:new Map,moduleEffects:[],computeds:new Map,moduleControlFlow:[],header:[],readers:new Map,writeConstCounter:0,writeConsts:new Map,reasonConstCounter:0,reasonConsts:new Map,analyzedFunctions:new WeakSet,handlerHasRootCommit:new WeakMap,identifiers:null}}import*as G from"@babel/types";import*as ot from"@babel/types";var Dn=class{constructor(t,n){this.scope=t;Ni(n.node,r=>this.reserved.add(r)),this.runtimeId=this.generate("MD").name}scope;runtimeId;reserved=new Set;componentIds=new Map;generate(t){let n;do n=this.scope.generateUidIdentifier(t);while(this.reserved.has(n.name));return this.reserved.add(n.name),n}registerComponentId(t,n){this.componentIds.set(t,n)}componentId(t){let n=this.componentIds.get(t);if(n===void 0)throw new Error(`memo-dom: missing generated factory id for '${t}'`);return ot.identifier(n)}runtimeMember(t){return ot.memberExpression(ot.identifier(this.runtimeId),ot.identifier(t))}};function en(e,t){let n=new Dn(t.scope,t);return e.identifiers=n,n}function j(e,t){return wt(e).generate(t)}function Le(e,t){return wt(e).componentId(t)}function Z(e,t){return wt(e).runtimeMember(t)}function wt(e){if(e.identifiers===null)throw new Error("memo-dom: generated identifier allocator was not initialized");return e.identifiers}function Ni(e,t){let n=r=>{ot.isIdentifier(r)&&t(r.name);for(let o of ot.VISITOR_KEYS[r.type]??[]){let i=r[o];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&"type"in s&&n(s);else i&&typeof i=="object"&&"type"in i&&n(i)}};n(e)}function mt(e,t,n){e.state.set(t,n),e.stateKeys.has(t)||e.stateKeys.set(t,`${e.moduleId}#${t}`)}function _e(e,t){if(t.includes("#"))return t;let n=t.indexOf("."),r=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n);return`${e.stateKeys.get(r)??r}${o}`}function Tt(e,t){let n=[...new Set(t.map(s=>_e(e,s)))].sort(),r=n.join(" "),o=e.writeConsts.get(r);if(o!==void 0)return G.identifier(o);let i=j(e,`WRITES_${e.writeConstCounter++}`);return e.writeConsts.set(r,i.name),e.header.push(G.variableDeclaration("const",[G.variableDeclarator(i,G.arrayExpression(n.map(s=>G.stringLiteral(s))))])),i}function hr(e,t){let n=[...new Set(t)].sort((s,a)=>s-a),r=n.join(" "),o=e.reasonConsts.get(r);if(o!==void 0)return G.identifier(o);let i=j(e,`REASONS_${e.reasonConstCounter++}`);return e.reasonConsts.set(r,i.name),e.header.push(G.variableDeclaration("const",[G.variableDeclarator(i,G.arrayExpression(n.map(s=>G.numericLiteral(s))))])),i}function ye(e){let t=[],n=e;for(;G.isMemberExpression(n);){if(n.computed){if(!G.isStringLiteral(n.property))return null;t.unshift(n.property.value)}else{if(!G.isIdentifier(n.property))return null;t.unshift(n.property.name)}if(G.isSuper(n.object))return null;n=n.object}for(;G.isTSNonNullExpression(n)||G.isTSAsExpression(n);)n=n.expression;return G.isIdentifier(n)?(t.unshift(n.name),t.join(".")):null}function lt(e,t){if(e===null)return[];let n=[],r=e;for(;G.isMemberExpression(r)&&!r.computed;){if(!G.isIdentifier(r.property)||(n.unshift(r.property.name),G.isSuper(r.object)))return null;r=r.object}return!G.isIdentifier(r,{name:t})||n.length===0?null:n}function Mn(e,t){return t===null?!0:t.length===0||e.length>t.length?!1:e.every((n,r)=>t[r]===n)}function we(e){let t=e;for(;;){if(G.isMemberExpression(t)){if(G.isSuper(t.object))return null;t=t.object;continue}if(G.isTSNonNullExpression(t)||G.isTSAsExpression(t)){t=t.expression;continue}break}return G.isIdentifier(t)?t.name:null}function Pt(e){return!e||!G.isObjectExpression(e)?!1:e.properties.every(t=>G.isObjectProperty(t)&&!t.computed&&(G.isIdentifier(t.key)||G.isStringLiteral(t.key)))}function vt(e){return e?G.isArrayExpression(e)||G.isNewExpression(e):!1}function $e(e){return e==null?null:G.isStringLiteral(e)?e:G.isJSXExpressionContainer(e)?G.isJSXEmptyExpression(e.expression)?null:e.expression:null}function Ln(e,t,n){let r=n!==void 0?e.instanceState.get(n):void 0,o=n!==void 0?e.instanceDerivedBindings.get(n):void 0,i=n!==void 0?e.componentProps.get(n)?.bindings:void 0,s=!1,a=l=>{if(!s){if(G.isIdentifier(l)&&(e.state.has(l.name)||r?.has(l.name)===!0||o?.has(l.name)===!0||i?.includes(l.name)===!0)){s=!0;return}for(let d of G.VISITOR_KEYS[l.type]??[]){let u=l[d];if(Array.isArray(u))for(let c of u)c&&typeof c=="object"&&"type"in c&&a(c);else u&&typeof u=="object"&&"type"in u&&a(u)}}};return a(t),s}function Er(e,t,n){let r=new Set([...e.instanceState.get(n)??[],...e.instanceDerivedBindings.get(n)??[],...e.componentProps.get(n)?.bindings??[]]);if(r.size===0)return!1;let o=!1;return Xe(t,i=>G.isIdentifier(i)&&r.has(i.name)?(o=!0,!1):o?!1:void 0),o}function Xe(e,t){let n=(r,o)=>{if(t(r,o)!==!1)for(let i of G.VISITOR_KEYS[r.type]??[]){let s=r[i];if(Array.isArray(s))for(let a of s)a&&typeof a=="object"&&"type"in a&&n(a,r);else s&&typeof s=="object"&&"type"in s&&n(s,r)}};n(e,null)}function ce(e){let t=!1;return Xe(e,n=>{(G.isJSXElement(n)||G.isJSXFragment(n))&&(t=!0)}),t}function tn(e,t){let n=new Set;return Xe(t,r=>{if(G.isJSXAttribute(r)&&G.isJSXIdentifier(r.name,{name:"ref"}))return!1;G.isIdentifier(r)&&e.state.has(r.name)&&n.add(r.name)}),n}import*as k from"@babel/types";import*as ue from"@babel/types";import*as Ue from"@babel/types";function nn(e){let t=Ue.cloneNode(e,!0);return Ue.traverseFast(t,n=>{(Ue.isIdentifier(n)||Ue.isObjectPattern(n)||Ue.isArrayPattern(n)||Ue.isRestElement(n)||Ue.isAssignmentPattern(n))&&(n.typeAnnotation=null)}),t}import*as xe from"@babel/types";import*as H from"@babel/types";function rn(e){if(e.some(i=>H.isTSParameterProperty(i)))throw new Error("TypeScript parameter properties are not valid component props");let t=e;if(t.length===0)return{mode:"positional",names:[],acceptsUnknown:!1,bindings:[],params:[],hasWholeDefault:!1,renderProps:[],renderCallbacks:[],refProps:[]};let n=gt(t[0]);if(t.length===1&&(H.isObjectPattern(n)||H.isIdentifier(n)&&n.name==="props"))return{mode:"object",names:H.isObjectPattern(n)?Ii(n):[],acceptsUnknown:H.isIdentifier(n)||n.properties.some(s=>H.isRestElement(s)),bindings:Bt(n),params:t.map(s=>H.cloneNode(s)),hasWholeDefault:H.isAssignmentPattern(t[0]),renderProps:[],renderCallbacks:[],refProps:[]};let o=[];for(let i of t){let s=gt(i);if(!H.isIdentifier(s))throw new Error("object-destructured props must be the component's only parameter");o.push(s.name)}return{mode:"positional",names:o,acceptsUnknown:!1,bindings:t.flatMap(i=>Bt(gt(i))),params:t.map(i=>H.cloneNode(i)),hasWholeDefault:!1,renderProps:[],renderCallbacks:[],refProps:[]}}function yr(e,t){return e.params.length===0?null:H.variableDeclaration("let",e.params.map((n,r)=>H.variableDeclarator(Fi(gt(n)),Cr(n,t[r]??H.identifier("undefined")))))}function An(e,t){return e.params.map((n,r)=>H.expressionStatement(H.assignmentExpression("=",wr(gt(n)),Cr(n,t[r]??H.identifier("undefined")))))}function Sr(e){return H.expressionStatement(H.assignmentExpression("=",wr(e.target),H.cloneNode(e.source)))}function Bt(e){return Object.keys(H.getBindingIdentifiers(e))}function Ve(e){if(e.mode!=="object"||e.params.length!==1)return null;let t=gt(e.params[0]);return H.isIdentifier(t)?t.name:null}function on(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=gt(e.params[0]);if(!H.isObjectPattern(n))return null;for(let r of n.properties){if(!H.isObjectProperty(r)||r.computed||(H.isIdentifier(r.key)?r.key.name:H.isStringLiteral(r.key)?r.key.value:null)!==t)continue;let i=H.isAssignmentPattern(r.value)?r.value.left:r.value;return H.isIdentifier(i)?i.name:null}return null}function He(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=gt(e.params[0]);if(!H.isObjectPattern(n))return null;for(let r of n.properties)if(!(!H.isObjectProperty(r)||r.computed)&&Object.keys(H.getBindingIdentifiers(r.value)).includes(t)){if(H.isIdentifier(r.key))return r.key.name;if(H.isStringLiteral(r.key))return r.key.value}return null}function gt(e){if(H.isRestElement(e))throw new Error("rest component parameters are not supported");let t=H.isAssignmentPattern(e)?e.left:e;if(!H.isIdentifier(t)&&!H.isObjectPattern(t)&&!H.isArrayPattern(t))throw new Error("unsupported component parameter target");return t}function xr(e){let t=H.cloneNode(e);return Vt(t),t}function Cr(e,t){return H.isAssignmentPattern(e)?H.conditionalExpression(H.binaryExpression("===",H.cloneNode(t),H.identifier("undefined")),H.cloneNode(e.right),H.cloneNode(t)):H.cloneNode(t)}function Ii(e){let t=[];for(let n of e.properties)if(!H.isRestElement(n)){if(n.computed)throw new Error("computed keys are not supported in component prop patterns");if(H.isIdentifier(n.key))t.push(n.key.name);else if(H.isStringLiteral(n.key))t.push(n.key.value);else throw new Error("component prop pattern keys must be identifiers or strings")}return t}function Fi(e){let t=H.cloneNode(e);return Vt(t),t}function wr(e){let t=H.cloneNode(e);return Vt(t),t}function Vt(e){let t=e;"typeAnnotation"in t&&(t.typeAnnotation=null),"optional"in t&&(t.optional=null);for(let n of H.VISITOR_KEYS[e.type]??[]){let r=e[n];if(Array.isArray(r))for(let o of r)o&&typeof o=="object"&&"type"in o&&Vt(o);else r&&typeof r=="object"&&"type"in r&&Vt(r)}}function Pr(e,t){let n=t.findParent(d=>d.isArrowFunctionExpression()||d.isFunctionExpression());if(n===null||!n.isArrowFunctionExpression()&&!n.isFunctionExpression())return!1;let r=n.get("body");if(!(r.isJSXElement()&&r.node===t.node||r.isBlockStatement()&&r.node.body.length===1&&xe.isReturnStatement(r.node.body[0])&&r.node.body[0].argument===t.node))return!1;let i=n.parentPath,s=i?.parentPath,a=s?.parentPath;if(!i?.isJSXExpressionContainer()||!s?.isJSXAttribute()||!a?.isJSXOpeningElement()||!xe.isJSXIdentifier(a.node.name))return!1;let l=xe.isJSXIdentifier(s.node.name)?s.node.name.name:s.node.name.name.name;return e.componentProps.get(a.node.name.name)?.renderCallbacks.includes(l)===!0||/^[A-Z]/.test(a.node.name.name)}function Ri(e){return xe.isMemberExpression(e.callee)&&!e.callee.computed&&xe.isIdentifier(e.callee.property,{name:"map"})}function Di(e,t,n){let r=e.componentProps.get(t);if(r===void 0)return null;let o=Ve(r);return o!==null&&xe.isMemberExpression(n)&&!n.computed&&xe.isIdentifier(n.object,{name:o})&&xe.isIdentifier(n.property)?n.property.name:xe.isIdentifier(n)?He(r,n.name)??(on(r,n.name)!==null?n.name:null):null}function Mi(e){return xe.isExpression(e.body)?e.body:e.body.body.length===1&&xe.isReturnStatement(e.body.body[0])&&xe.isExpression(e.body.body[0].argument)?e.body.body[0].argument:null}function Rt(e,t,n){if(!Ri(n)||n.arguments.length!==1)return null;let r=n.arguments[0];if(!xe.isArrowFunctionExpression(r))return null;let o=Mi(r);if(o===null||!xe.isCallExpression(o)||!xe.isExpression(o.callee)||o.arguments.some(s=>!xe.isExpression(s)))return null;let i=Di(e,t,o.callee);return i===null?null:{propName:i,target:xe.cloneNode(o.callee,!0),arguments:o.arguments.map(s=>xe.cloneNode(s,!0))}}function vr(e){for(let[t,n]of e.compPaths){let r=e.componentProps.get(t);n.traverse({CallExpression(o){let i=Rt(e,t,o.node);i!==null&&!r.renderCallbacks.includes(i.propName)&&r.renderCallbacks.push(i.propName)}})}}import*as ke from"@babel/types";function jn(e){for(;ke.isTSAsExpression(e)||ke.isTSTypeAssertion(e)||ke.isTSNonNullExpression(e)||ke.isTSInstantiationExpression(e);)e=e.expression;return e}function sn(e){let t=jn(e);return ke.isArrayExpression(t)&&t.elements.every(n=>n!==null&&!ke.isSpreadElement(n)&&(ke.isStringLiteral(n)||ke.isNumericLiteral(n)||ke.isBooleanLiteral(n)||ke.isNullLiteral(n)||ke.isBigIntLiteral(n)))}function Oe(e){if(!ue.isCallExpression(e))return null;let t=e.callee;return ue.isMemberExpression(t)&&!t.computed&&ue.isIdentifier(t.property,{name:"map"})?e:null}function De(e){let t=!1;return e.traverse({JSXElement(){t=!0},JSXFragment(){t=!0}}),t}function kt(e,t,n,r,o,i){let s=g=>{throw n.buildCodeFrameError(g)},a=t.callee,l=Li(e,a.object,r,i,s),d=Ji(e,t,r,s),u=$i(e,d,s),c=Ti(l.suffixBase,o);return{sourceKey:l.key,sourceExpr:ue.cloneNode(l.expression),sourceLocal:l.local,itemPattern:d.itemPattern,itemParam:d.itemParam,indexParam:d.indexParam,keyExpr:Oi(d.jsx?.openingElement??null,s),jsx:d.jsx,form:u.form,rowComp:u.rowComp,renderCallback:u.renderCallback,owner:r,suffix:c,prefix:`${r}/${c}`}}function Li(e,t,n,r,o){return ue.isIdentifier(t)?Ai(e,t,n,o):ue.isMemberExpression(t)?ji(e,t,n,r,o):ue.isExpression(t)&&sn(t)?{expression:t,key:"$static-list",local:!0,suffixBase:"$static-list"}:o("memo-dom: assign an ordered collection view to reactive state or a local derivation before mapping it")}function Ai(e,t,n,r){let o=e.componentProps.get(n)?.bindings??[],i=e.instanceState.get(n)?.has(t.name)===!0||e.instanceDerivedBindings.get(n)?.has(t.name)===!0||o.includes(t.name),s=e.state.get(t.name);return!i&&s!=="let"&&s!=="const"&&s!=="computed"?r("memo-dom: list views must come from reactive module state, component props, component state, or a local derivation"):{expression:t,key:t.name,local:i,suffixBase:t.name}}function ji(e,t,n,r,o){let i=we(t),s=ye(t),a=e.componentProps.get(n)?.bindings??[],l=i!==null&&(e.instanceState.get(n)?.has(i)===!0||a.includes(i)),d=i!==null&&s!==null&&r!==void 0&&i===r.itemParam;return i===null||s===null||!s.includes(".")||!d&&!l&&e.state.get(i)!=="store"?o("memo-dom: list member views must be a static path on reactive module state, component props, or component state"):{expression:t,key:d?r.sourceKey:s,local:d?r.sourceLocal:l,suffixBase:s.slice(s.lastIndexOf(".")+1)}}function Ji(e,t,n,r){if(t.arguments.length!==1||!ue.isArrowFunctionExpression(t.arguments[0]))return r("memo-dom: list rendering expects items.map(item => <JSX />) \u2014 R7 L1");let o=t.arguments[0],i=o.params[0],s=o.params[1];if(o.params.length<1||o.params.length>2||!ue.isIdentifier(i)&&!ue.isObjectPattern(i)&&!ue.isArrayPattern(i)||s!==void 0&&!ue.isIdentifier(s))return r("memo-dom: list callback must take an item binding pattern and optional index identifier \u2014 R7 L1");let a=nn(i),l=Object.keys(ue.getBindingIdentifiers(a));if(l.length===0)return r("memo-dom: list callback item pattern must bind at least one name \u2014 R7 L1");let d=ue.isIdentifier(a)?a.name:l[0],u=ue.isIdentifier(s)?s.name:null,c=ue.isBlockStatement(o.body)&&o.body.body.length===1&&ue.isReturnStatement(o.body.body[0])?o.body.body[0].argument:null,g=ue.isJSXElement(o.body)?o.body:ue.isJSXElement(c)?c:null,x=Rt(e,n,t);return g===null&&x===null?r("memo-dom: list callback body must be one JSX element or a block containing only return <JSX /> \u2014 R7 L1"):{itemPattern:a,itemParam:d,indexParam:u,jsx:g,renderInvocation:x}}function $i(e,t,n){let r=t.jsx?.openingElement??null;if(r!==null&&!ue.isJSXIdentifier(r.name))return n("memo-dom: namespaced JSX tags are not supported (L1)");let o=r!==null&&ue.isJSXIdentifier(r.name)?r.name.name:null;return t.renderInvocation!==null?(Xi(t,n),{form:"callback",rowComp:null,renderCallback:ue.cloneNode(t.renderInvocation.target,!0)}):o!==null&&/^[A-Z]/.test(o)?!e.comps.has(o)&&!e.importedComponents.has(o)?n(`memo-dom: <${o} /> is not a linked component factory`):{form:"component",rowComp:o,renderCallback:null}:{form:"inline",rowComp:null,renderCallback:null}}function Xi(e,t){let n=e.renderInvocation;(!ue.isIdentifier(e.itemPattern)||n.arguments.length<1||n.arguments.length>2||!ue.isIdentifier(n.arguments[0],{name:e.itemPattern.name})||n.arguments.length===2&&(e.indexParam===null||!ue.isIdentifier(n.arguments[1],{name:e.indexParam})))&&t("memo-dom: render callback maps must pass their item and optional index bindings directly")}function Oi(e,t){let n=null;for(let r of e?.attributes??[])if(ue.isJSXAttribute(r)&&ue.isJSXIdentifier(r.name,{name:"key"})&&(n=$e(r.value),n===null))return t("memo-dom: key={...} needs an expression");return n}function Ti(e,t){let n=t.get(e)??0;return t.set(e,n+1),n===0?e:`${e}${n}`}import*as re from"@babel/types";function an(e){return re.isConditionalExpression(e)||re.isLogicalExpression(e)&&(e.operator==="&&"||e.operator==="||")?e:null}function Bi(e){return re.isNullLiteral(e)||re.isBooleanLiteral(e,{value:!1})||re.isIdentifier(e,{name:"undefined"})}function Vi(e,t){let n=[e];for(;n.length>0;){let r=n.pop();if(re.isJSXElement(r)){for(let o of r.openingElement.attributes)!re.isJSXSpreadAttribute(o)&&o.name.name==="key"&&t("memo-dom: key={...} is only meaningful on list rows");n.push(...r.children)}else if(re.isJSXFragment(r))n.push(...r.children);else if(re.isJSXExpressionContainer(r)&&re.isExpression(r.expression)){let o=r.expression;if(Oe(o)!==null&&ce(o))continue}}}function ln(e,t,n){let r=l=>{throw t.buildCodeFrameError(l)},o,i;if(re.isConditionalExpression(e)){let l=[];i=[];let d=e;for(;re.isConditionalExpression(d);)l.push(re.cloneNode(d.test)),i.push(d.consequent),d=d.alternate;i.push(d),o=re.numericLiteral(i.length-1);for(let u=l.length-1;u>=0;u--)o=re.conditionalExpression(l[u],re.numericLiteral(u),o)}else e.operator==="&&"?(o=re.conditionalExpression(re.cloneNode(e.left),re.numericLiteral(0),re.numericLiteral(1)),i=[e.right,null]):(o=re.conditionalExpression(re.cloneNode(e.left),re.numericLiteral(1),re.numericLiteral(0)),i=[e.right,null]);let s=l=>l===null||Bi(l)?null:re.isJSXElement(l)||re.isJSXFragment(l)?l:re.isExpression(l)?re.jsxFragment(re.jsxOpeningFragment(),re.jsxClosingFragment(),[re.jsxExpressionContainer(re.cloneNode(l,!0))]):r("memo-dom: conditional branches must be JSX, renderable text expressions, or null/false"),a=i.map(s);for(let l of a)l!==null&&Vi(l,r);return{pickExpr:o,branches:a,suffix:`when${n.count++}`}}import*as Fe from"@babel/types";import*as ge from"@babel/types";var Dt=class{constructor(t){this.fallback=t}fallback;origins=new WeakMap;trackDeclarator(t,n){if(!ge.isIdentifier(n.id)||n.init===null)return;let r=this.resolveExpression(t,n.init);if(r===null)return;let o=t.getBinding(n.id.name);o!==void 0&&this.origins.set(o.identifier,r)}referencedOrigins(t,n){let r=new Map,o=i=>{if(ge.isIdentifier(i)||ge.isMemberExpression(i)){let s=this.resolveExpression(t,i);if(s!==null){let a=[s.locality,s.root,s.key??"*"].join(":");r.set(a,s);return}}for(let s of ge.VISITOR_KEYS[i.type]??[]){let a=i[s];if(Array.isArray(a))for(let l of a)l&&typeof l=="object"&&"type"in l&&o(l);else a&&typeof a=="object"&&"type"in a&&o(a)}};return o(n),[...r.values()]}resolveName(t,n){let r=t.getBinding(n);if(r!==void 0){let o=this.origins.get(r.identifier);if(o!==void 0)return o}return this.fallback(n,r)}resolveExpression(t,n){let r=kr(n);if(ge.isIdentifier(r))return this.resolveName(t,r.name);if(!ge.isMemberExpression(r))return null;let o=Wi(r);if(o===null)return null;let i=this.resolveName(t,o);if(i===null)return null;let s=ye(r);if(i.key===null||s===null)return{...i,key:null};let a=s.split(".").slice(1);return{...i,key:[i.key,...a].join(".")}}};function dn(e,t){return{locality:"module",root:e,key:e,stateKind:t}}function bt(e,t){return e.key===null?e:{...e,key:[e.key,...t].join(".")}}function cn(e,t){if(e.key===null)return null;let n=[];for(let r of t){if(!ge.isObjectExpression(r))return null;for(let o of r.properties){if(!ge.isObjectProperty(o)||o.computed||!ge.isIdentifier(o.key)&&!ge.isStringLiteral(o.key))return null;let i=ge.isIdentifier(o.key)?o.key.name:o.key.value;n.push(`${e.key}.${i}`)}}return n}function un(e){let t=[];for(let n of e)ge.isExpression(n)?t.push(n):ge.isSpreadElement(n)&&t.push(n.argument);return t}function pn(e){return!e.computed&&ge.isIdentifier(e.property)?e.property.name:e.computed&&ge.isStringLiteral(e.property)?e.property.value:null}function Wi(e){let t=e;for(;ge.isMemberExpression(t);){if(ge.isSuper(t.object))return null;t=kr(t.object)}return ge.isIdentifier(t)?t.name:null}function kr(e){let t=e;for(;ge.isTSAsExpression(t)||ge.isTSTypeAssertion(t)||ge.isTSNonNullExpression(t)||ge.isTypeCastExpression(t)||ge.isTSSatisfiesExpression(t);)t=t.expression;return t}function We(e,t,n=new Set){let r=e.helperSummaries.get(t);if(r)return r;if(n.has(t))return{reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!0};let o=e.helpers.get(t),i=new Set,s=new Map(o.node.params.flatMap((f,m)=>Fe.isIdentifier(f)?[[f.name,m]]:[])),a={reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!1},l=new Dt((f,m)=>{if(s.has(f)&&m?.scope.block===o.node)return{locality:"prop",root:f,key:f};let w=e.state.get(f);return w===void 0||m!==void 0&&!m.scope.path.isProgram()?null:dn(f,w)}),d=f=>f.stateKind==="computed"||e.state.get(f.root)==="computed";n.add(t),o.traverse({VariableDeclarator(f){Fe.isIdentifier(f.node.id)&&(i.add(f.node.id.name),f.parentPath.isVariableDeclaration()&&l.trackDeclarator(f.scope,f.node))},Function(f){for(let m of f.node.params)Fe.isIdentifier(m)&&i.add(m.name)}});let u=(f,m)=>{a.parameterWrites.some(w=>w.index===f&&w.path.length===m.length&&w.path.every((S,I)=>S===m[I]))||a.parameterWrites.push({index:f,path:m})},c=f=>{if(!d(f)){if(f.locality==="module"){a.boundedWrites.add(f.key??f.root);return}if(f.locality==="prop"){let m=s.get(f.root);if(m!==void 0){let w=f.key===null?[]:f.key.split(".").slice(1);u(m,w);return}}a.unbounded=!0}},g=f=>{f.locality==="prop"?c(f):f.locality!=="module"?a.unbounded=!0:f.stateKind!=="store"?a.writes.add(f.root):f.key!==null&&f.key.includes(".")?a.writes.add(f.key):a.boundedWrites.add(f.root)},x=(f,m)=>{let w=l.resolveExpression(f.scope,m);w!==null&&g(w)},y=(f,m)=>{for(let w of un(m)){if(!Fe.isIdentifier(w))continue;let S=l.resolveExpression(f.scope,w);S!==null&&!d(S)&&c(S)}};return o.traverse({VariableDeclarator(f){if(!Fe.isIdentifier(f.node.id)&&f.node.init!==null)for(let m of l.referencedOrigins(f.scope,f.node.init))c(m)},AssignmentExpression(f){let m=f.node.left;if(Fe.isIdentifier(m))if(i.has(m.name)){if(Fe.isIdentifier(f.node.right)){let w=l.resolveExpression(f.scope,f.node.right);w!==null&&c(w)}}else e.state.has(m.name)&&a.writes.add(m.name);else if(Fe.isMemberExpression(m))x(f,m);else for(let w of l.referencedOrigins(f.scope,f.node.right))c(w)},UpdateExpression(f){let m=f.node.argument;Fe.isIdentifier(m)?!i.has(m.name)&&e.state.has(m.name)&&a.writes.add(m.name):Fe.isMemberExpression(m)&&x(f,m)},UnaryExpression(f){f.node.operator==="delete"&&Fe.isMemberExpression(f.node.argument)&&x(f,f.node.argument)},CallExpression(f){let m=f.node.callee;if(Fe.isMemberExpression(m)){if(pn(m)==="assign"&&Fe.isIdentifier(m.object,{name:"Object"})){let I=f.node.arguments[0],$=I!==void 0&&Fe.isExpression(I)?l.resolveExpression(f.scope,I):null;if($!==null){let F=cn($,f.node.arguments.slice(1));if(F===null)c($);else for(let N of F)g({...$,key:N})}return}let S=Fe.isExpression(m.object)?l.resolveExpression(f.scope,m.object):null;S!==null?c(S):y(f,f.node.arguments);return}if(Fe.isIdentifier(m)&&(e.helpers.has(m.name)||e.importedFunctions.has(m.name))){let w=e.importedFunctions.get(m.name)??We(e,m.name,n);for(let S of w.reads)a.reads.add(S);for(let S of w.writes)a.writes.add(S);for(let S of w.boundedWrites)a.boundedWrites.add(S);for(let S of w.parameterWrites){let I=f.node.arguments[S.index];if(I===void 0||!Fe.isExpression(I))continue;let $=l.resolveExpression(f.scope,I);$!==null&&c(bt($,S.path))}w.unbounded&&(a.unbounded=!0);return}y(f,f.node.arguments)},Identifier(f){let m=f.node.name;if(!e.state.has(m)||i.has(m))return;let w=f.parentPath;w.isAssignmentExpression({operator:"="})&&w.node.left===f.node||a.reads.add(m)},MemberExpression(f){let m=zi(e,f);m!==null&&a.reads.add(m)}}),n.delete(t),e.helperSummaries.set(t,a),a}function zi(e,t){let n=ye(t.node);if(!n||!n.includes("."))return null;let r=n.split(".")[0];if(e.state.get(r)!=="store"||t.scope.getBinding(r)?.scope.path.isProgram()!==!0)return null;let o=t.parentPath;return o.isAssignmentExpression({operator:"="})&&o.node.left===t.node||Ki(t)?null:n}function Ki(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}import*as b from"@babel/types";import*as ae from"@babel/types";function Ye(e,t=!1){return{slots:[],tempVar:j(e,"value").name,updateVar:j(e,"update").name,reasonVar:null,delegatedEventRootVar:null,creation:[],mounts:[],updaters:[],tagCounters:new Map,childCounts:new Map,usedPrefixes:new Map,usedConds:{count:0},textCounter:0,regionCounter:0,disposableRegions:[],disposableEntities:[],disposableCallbacks:[],forwardedSlotCounter:0,manualDisposal:t}}function Qe(e){return ae.variableDeclaration("let",[...e.slots.map(t=>ae.variableDeclarator(ae.identifier(t))),ae.variableDeclarator(ae.identifier(e.tempVar))])}function Jn(e,t){let n=j(e,`slot${t.slots.length}`).name;return t.slots.push(n),n}function $n(e,t,n){let r=t.tagCounters.get(n)??0;return t.tagCounters.set(n,r+1),j(e,`${n}${r}`).name}function Nt(e,t,n,r){let o=()=>ae.identifier(e.tempVar),i=()=>ae.identifier(t);return ae.ifStatement(ae.binaryExpression("!==",i(),ae.assignmentExpression("=",o(),n)),ae.blockStatement([ae.expressionStatement(ae.assignmentExpression("=",i(),o())),r(o())]))}function et(e){return ae.variableDeclaration("const",[ae.variableDeclarator(ae.identifier(e.updateVar),ae.arrowFunctionExpression(e.reasonVar===null?[]:[ae.assignmentPattern(ae.identifier(e.reasonVar),ae.nullLiteral())],ae.blockStatement(e.updaters.map(t=>t()))))])}function ht(e,t,n,r){return ae.expressionStatement(ae.callExpression(Z(e,"register"),[ae.objectExpression([ae.objectProperty(ae.identifier("id"),t),ae.objectProperty(ae.identifier("parent"),n),ae.objectProperty(ae.identifier("render"),r)])]))}function Xn(e){let t=e.replace(/\s+/g," ");return/^\s*\n/.test(e)&&(t=t.replace(/^ /,"")),/\n\s*$/.test(e)&&(t=t.replace(/ $/,"")),t}function Wt(e){return e.some(t=>!b.isJSXText(t)||t.value.trim()!=="")}function dt(e,t,n){let r=e.componentProps.get(t);if(r===void 0)return null;let o=Ve(r);if(o!==null&&b.isMemberExpression(n)&&!n.computed&&b.isIdentifier(n.object,{name:o})&&b.isIdentifier(n.property))return n.property.name;if(b.isIdentifier(n)){let i=He(r,n.name);if(i!==null)return i;if(n.name==="children"&&e.instanceDerivedBindings.get(t)?.has("children")===!0)return"children"}return null}function tt(e,t,n){let r=dt(e,t,n);return r!==null&&e.componentProps.get(t)?.renderProps.includes(r)===!0}function Nr(e,t,n,r){let o=Ye(e,!0);o.childCounts=t.childCounts,o.usedPrefixes=t.usedPrefixes,o.usedConds=t.usedConds;let i=j(e,"childrenUpdate"),s=j(e,"childrenUpdates"),a=j(e,"childrenMountSequence"),l=j(e,"children"),d=j(e,"childrenParent"),u=j(e,"childrenOwner"),c=j(e,"childrenKey"),g=j(e,"childrenSlot"),x=j(e,"childrenNextUpdate"),y=j(e,"childrenActive"),f=j(e,"childrenDispose");return r(o,d,g),t.creation.push(b.variableDeclaration("let",[b.variableDeclarator(b.cloneNode(i),b.nullLiteral()),b.variableDeclarator(b.cloneNode(s),b.nullLiteral()),b.variableDeclarator(b.cloneNode(a),b.numericLiteral(0))]),b.variableDeclaration("const",[b.variableDeclarator(b.cloneNode(l),b.arrowFunctionExpression([b.cloneNode(d),b.cloneNode(u),b.cloneNode(c)],b.blockStatement([b.variableDeclaration("const",[b.variableDeclarator(b.cloneNode(g),b.conditionalExpression(b.binaryExpression("===",b.cloneNode(a),b.numericLiteral(0)),b.cloneNode(n,!0),b.binaryExpression("+",b.binaryExpression("+",b.cloneNode(n,!0),b.stringLiteral("/$slot[")),b.binaryExpression("+",b.cloneNode(a),b.stringLiteral("]")))))]),b.expressionStatement(b.updateExpression("++",b.cloneNode(a))),b.variableDeclaration("let",[b.variableDeclarator(b.cloneNode(y),b.booleanLiteral(!0))]),Qe(o),et(o),...o.creation,...o.mounts,b.ifStatement(b.binaryExpression("===",b.cloneNode(i),b.nullLiteral()),b.expressionStatement(b.assignmentExpression("=",b.cloneNode(i),b.identifier(o.updateVar))),b.blockStatement([b.ifStatement(b.binaryExpression("===",b.cloneNode(s),b.nullLiteral()),b.expressionStatement(b.assignmentExpression("=",b.cloneNode(s),b.newExpression(b.identifier("Set"),[])))),b.expressionStatement(b.callExpression(b.memberExpression(b.cloneNode(s),b.identifier("add")),[b.identifier(o.updateVar)]))])),b.variableDeclaration("const",[b.variableDeclarator(b.cloneNode(f),b.arrowFunctionExpression([],b.blockStatement([b.ifStatement(b.unaryExpression("!",b.cloneNode(y)),b.returnStatement()),b.expressionStatement(b.assignmentExpression("=",b.cloneNode(y),b.booleanLiteral(!1))),b.ifStatement(b.binaryExpression("===",b.cloneNode(i),b.identifier(o.updateVar)),b.expressionStatement(b.assignmentExpression("=",b.cloneNode(i),b.nullLiteral())),b.ifStatement(b.binaryExpression("!==",b.cloneNode(s),b.nullLiteral()),b.expressionStatement(b.callExpression(b.memberExpression(b.cloneNode(s),b.identifier("delete")),[b.identifier(o.updateVar)])))),...o.disposableRegions.map(m=>b.expressionStatement(b.callExpression(b.memberExpression(b.identifier(m),b.identifier("dispose")),[]))),...[...o.disposableCallbacks].reverse().map(m=>b.ifStatement(b.binaryExpression("!==",b.cloneNode(m),b.nullLiteral()),b.expressionStatement(b.callExpression(b.cloneNode(m),[])))),...o.disposableEntities.map(m=>b.expressionStatement(b.callExpression(Z(e,"unregisterSubtree"),[b.cloneNode(m,!0)])))])))]),b.expressionStatement(b.callExpression(Z(e,"cleanup"),[b.cloneNode(u),b.cloneNode(f)])),b.returnStatement(b.cloneNode(f))])))])),t.updaters.push(()=>b.blockStatement([b.ifStatement(b.binaryExpression("!==",b.cloneNode(i),b.nullLiteral()),b.expressionStatement(b.callExpression(b.cloneNode(i),[]))),b.ifStatement(b.binaryExpression("!==",b.cloneNode(s),b.nullLiteral()),b.forOfStatement(b.variableDeclaration("const",[b.variableDeclarator(b.cloneNode(x))]),b.cloneNode(s),b.expressionStatement(b.callExpression(b.cloneNode(x),[]))))])),l}function On(e,t,n,r,o){let i=j(e,"slotDispose"),s=t.forwardedSlotCounter++;t.creation.push(b.variableDeclaration("const",[b.variableDeclarator(b.cloneNode(i),b.conditionalExpression(b.binaryExpression("==",b.cloneNode(n,!0),b.nullLiteral()),b.nullLiteral(),b.callExpression(b.cloneNode(n,!0),[b.identifier(r),b.cloneNode(o,!0),b.stringLiteral(String(s))])))])),t.disposableCallbacks.push(i)}function Ir(e,t,n,r){let o=i=>{e.creation.push(b.expressionStatement(b.callExpression(b.memberExpression(b.identifier(n),b.identifier("appendChild")),[b.identifier(i)])))};for(let i of t){if(b.isJSXText(i)){let d=Xn(i.value);d!==""&&o(r.emitText(b.stringLiteral(d)));continue}if(b.isJSXElement(i)||b.isJSXFragment(i)){o(r.emitNode(i));continue}if(b.isJSXExpressionContainer(i)||r.fail("memo-dom: spread children are not supported (L1)"),b.isJSXEmptyExpression(i.expression))continue;b.isExpression(i.expression)||r.fail("memo-dom: unsupported expression in component children");let s=i.expression;if(b.isNullLiteral(s)||b.isBooleanLiteral(s)||b.isIdentifier(s,{name:"undefined"}))continue;if(r.isForwarded(s)){r.emitForwarded(s,n);continue}let a=Oe(s);if(a!==null){r.emitList(a,n);continue}let l=an(s);if(l!==null&&ce(l)){r.emitCondition(l,n);continue}o(r.emitText(b.cloneNode(s)))}}import*as L from"@babel/types";function gn(e){return L.isIdentifier(e.node.callee,{name:"effect"})&&e.scope.getBinding("effect")===void 0}function mn(e,t){return L.binaryExpression("+",L.identifier(e),L.stringLiteral(`/$effects/${t}`))}function Ui(e,t){return L.binaryExpression("+",mn(e,t),L.stringLiteral("/$active"))}function Hi(e){if(e.isFunctionDeclaration())return e;if(!e.isVariableDeclarator())return null;let t=e.get("init");return t.isArrowFunctionExpression()||t.isFunctionExpression()?t:null}function Lr(e,t){let n=t.get("arguments"),r=n[0];if(n.length!==1||r===void 0)throw t.buildCodeFrameError("memo-dom: effect() requires exactly one callback");if(r.isArrowFunctionExpression()||r.isFunctionExpression()){if(r.node.async||r.node.generator)throw r.buildCodeFrameError("memo-dom: effect callback must be synchronous; start async work inside it and return a synchronous teardown");return{expression:r.node,path:r,importedReads:new Set}}if(!r.isIdentifier())throw r.buildCodeFrameError("memo-dom: effect callback must be an inline function or a resolvable function identifier");if(e.importedFunctions.get(r.node.name)!==void 0)throw r.buildCodeFrameError(`memo-dom: imported named effect callback '${r.node.name}' is not supported yet; define a local synchronous wrapper so its cleanup and writes can be instrumented`);let i=r.scope.getBinding(r.node.name),s=i===void 0?null:Hi(i.path);if(s===null)throw r.buildCodeFrameError(`memo-dom: cannot resolve effect callback '${r.node.name}' \u2014 use an inline function or a local/module-level function declaration or const`);if(s.node.async||s.node.generator)throw s.buildCodeFrameError("memo-dom: effect callback must be synchronous; start async work inside it and return a synchronous teardown");if(ce(s.node.body))throw s.buildCodeFrameError("memo-dom: a JSX component cannot be used as an effect callback");return{expression:L.cloneNode(r.node),path:s,importedReads:new Set}}function Fr(e,t,n,r){let o=new Set,i=new Set,s=new Map,a=new Set([...e.componentProps.get(t)?.bindings??[],...e.instanceState.get(t)??[]]),l=new Map;for(let m of e.instanceDerivations.get(t)??[])for(let w of m.bindings)l.set(w,m.sources);for(let m of e.instanceControlFlow.get(t)??[])for(let w of m.bindings)l.set(w,m.sources);for(let m of a){let w=n.scope.getBinding(m);w!==void 0&&s.set(w,{source:m,local:!0})}for(let m of l.keys()){let w=n.scope.getBinding(m);w!==void 0&&s.set(w,{source:m,local:!0})}for(let m of e.state.keys()){let w=n.scope.getBinding(m);w?.scope.path.isProgram()===!0&&s.set(w,{source:m,local:!1})}let d=m=>{let w=m.scope.getBinding(m.node.name),S=w===void 0?void 0:s.get(w);if(S===void 0)return;let I=m.parentPath;!S.local&&e.state.get(S.source)==="store"&&I?.isMemberExpression()&&I.node.object===m.node||(S.local?i.add(S.source):o.add(S.source))},u=m=>{let w=ye(m.node),S=we(m.node);w===null||S===null||e.state.get(S)!=="store"||m.scope.getBinding(S)?.scope.path.isProgram()!==!0||o.add(w)},c=m=>{let w=m.node.callee;if(!L.isIdentifier(w)||m.scope.getBinding(w.name)?.scope.path.isProgram()!==!0||!e.helpers.has(w.name)&&!e.importedFunctions.has(w.name))return;let S=e.importedFunctions.get(w.name)??We(e,w.name);for(let I of S.reads)o.add(I)};r.isIdentifier()&&r.isReferencedIdentifier()&&d(r),r.isMemberExpression()&&u(r),r.isCallExpression()&&c(r),r.traverse({Function(m){m.skip()},ReferencedIdentifier(m){m.isIdentifier()&&d(m)},MemberExpression(m){u(m)},CallExpression(m){c(m)}});let g=new Set,x=new Set,y=new Set;for(let m of i)a.has(m)&&y.add(m);let f=(m,w)=>{if(w.has(m))return;let S=l.get(m);if(S===void 0){a.has(m)?g.add(m):e.state.has(m)&&o.add(m);return}w.add(m),S.some($=>y.has($))||x.add(m);for(let $ of S)f($,w);w.delete(m)};for(let m of i)f(m,new Set);return{moduleReads:o,localReads:g,localDerivationReads:x}}function Rr(e,t){let n=new Set,r=s=>{let a=s.node.name;if(!e.state.has(a)||s.scope.getBinding(a)?.scope.path.isProgram()!==!0)return;let l=s.parentPath;e.state.get(a)==="store"&&l?.isMemberExpression()&&l.node.object===s.node||n.add(a)},o=s=>{let a=ye(s.node),l=we(s.node);a!==null&&l!==null&&e.state.get(l)==="store"&&s.scope.getBinding(l)?.scope.path.isProgram()===!0&&n.add(a)},i=s=>{let a=s.node.callee;if(!L.isIdentifier(a)||s.scope.getBinding(a.name)?.scope.path.isProgram()!==!0||!e.helpers.has(a.name)&&!e.importedFunctions.has(a.name))return;let l=e.importedFunctions.get(a.name)??We(e,a.name);for(let d of l.reads)n.add(d)};return t.isIdentifier()&&t.isReferencedIdentifier()&&r(t),t.isMemberExpression()&&o(t),t.isCallExpression()&&i(t),t.traverse({Function(s){s.skip()},ReferencedIdentifier(s){s.isIdentifier()&&r(s)},MemberExpression(s){o(s)},CallExpression(s){i(s)}}),n}function Tn(e){if(!e.isExpressionStatement())return null;let t=e.get("expression");return t.isCallExpression()&&gn(t)?t:null}function Ar(e){if(Tn(e)!==null)return!0;let t=!1;return e.traverse({Function(n){n.skip()},CallExpression(n){gn(n)&&(t=!0,n.stop())}}),t}function fn(e,t,n,r){let o=Tn(e);if(o!==null){r.push({callPath:o,rootStatement:t,conditions:[...n]});return}if(!e.isEmptyStatement()){if(e.isBlockStatement()){for(let i of e.get("body"))if(!i.isEmptyStatement()){if(!Ar(i))throw i.buildCodeFrameError("memo-dom: a conditional effect branch may contain only effect() calls, nested if statements, or empty statements");fn(i,t,n,r)}return}if(e.isIfStatement()){let i=e.get("test");fn(e.get("consequent"),t,[...n,{path:i,negated:!1}],r);let s=e.get("alternate");s.node!==null&&fn(s,t,[...n,{path:i,negated:!0}],r);return}throw e.buildCodeFrameError("memo-dom: conditional effect() calls must be controlled by top-level if statements")}}function jr(e){let t=[];for(let n of e){let r=Tn(n);if(r!==null){t.push({callPath:r,rootStatement:n.node,conditions:[]});continue}!n.isIfStatement()||!Ar(n)||fn(n,n.node,[],t)}return t}function Jr(e){return e.length===0?null:e.map(({path:n,negated:r})=>r?L.unaryExpression("!",L.cloneNode(n.node,!0)):L.cloneNode(n.node,!0)).reduce((n,r)=>L.logicalExpression("&&",n,r))}function _i(e,t){let n=[],r=jr(t.get("body"));for(let o of r){let i=Lr(e,o.callPath),s=i.path===null?i.importedReads:Rr(e,i.path),a=new Set;for(let d of o.conditions)for(let u of Rr(e,d.path))a.add(u);let l=n.length;n.push({index:l,statement:o.rootStatement,callback:i.expression,moduleReads:s,condition:Jr(o.conditions),conditionModuleReads:a,entityId:`${e.rootId}/$module-effects/${encodeURIComponent(e.moduleId)}/${l}`})}e.moduleEffects.push(...n)}function $r(e,t){_i(e,t);for(let[n,r]of e.compPaths){let o=[],i=new Set,s=jr(r.get("body").get("body"));for(let l of s){let d=Lr(e,l.callPath),u=d.path===null?{moduleReads:d.importedReads,localReads:new Set,localDerivationReads:new Set}:Fr(e,n,r,d.path),c=new Set,g=new Set,x=new Set;for(let y of l.conditions){let f=Fr(e,n,r,y.path);for(let m of f.moduleReads)c.add(m);for(let m of f.localReads)g.add(m);for(let m of f.localDerivationReads)x.add(m)}o.push({index:o.length,statement:l.rootStatement,callback:d.expression,...u,condition:Jr(l.conditions),conditionModuleReads:c,conditionLocalReads:g,conditionLocalDerivationReads:x}),i.add(l.callPath.node)}if(r.traverse({CallExpression(l){if(!(!gn(l)||i.has(l.node)))throw l.buildCodeFrameError("memo-dom: effect() must be a direct top-level statement in a component body")}}),o.length===0)continue;e.effects.set(n,o);let a=new Set([...e.instanceReasonIds.get(n)?.keys()??[],...e.instanceState.get(n)??[],...e.componentProps.get(n)?.bindings??[],...o.flatMap(l=>[...l.localReads]),...o.flatMap(l=>[...l.conditionLocalReads])]);a.size>0&&e.instanceReasonIds.set(n,new Map([...a].sort().map((l,d)=>[l,d])))}}function Dr(e){return e.reduce((t,n)=>L.logicalExpression("||",t,n))}function qi(e,t,n,r){let o=e.instanceReasonIds.get(t);if(o===void 0)return null;let i=[...r].map(d=>o.get(d)).filter(d=>d!==void 0).sort((d,u)=>d-u);if(i.length===0||i.length!==r.size)return null;let s=()=>L.identifier(n),a=Dr(i.map(d=>L.binaryExpression("===",s(),L.numericLiteral(d)))),l=Dr(i.map(d=>L.callExpression(L.memberExpression(s(),L.identifier("has")),[L.numericLiteral(d)])));return L.logicalExpression("||",L.binaryExpression("===",s(),L.nullLiteral()),L.conditionalExpression(L.binaryExpression("===",L.unaryExpression("typeof",s()),L.stringLiteral("number")),a,l))}function Xr(e,t,n,r,o,i){let s=(l,d,u,c,g)=>{if(u.size===0&&c.size===0)return null;let x=L.expressionStatement(L.callExpression(Z(e,"markDirty"),[d]));if(c.size>0&&i!==void 0){let f=[],m=[];for(let S of c){let I=j(e,`eff${l.index}_${g}_${S}`).name;i.creation.push(L.variableDeclaration("let",[L.variableDeclarator(L.identifier(I),L.identifier(S))])),f.push(L.binaryExpression("!==",L.identifier(I),L.identifier(S))),m.push(L.expressionStatement(L.assignmentExpression("=",L.identifier(I),L.identifier(S))))}let w=f.length===1?f[0]:f.reduce((S,I)=>L.logicalExpression("||",S,I));x=L.ifStatement(w,L.blockStatement([...m,x]))}if(r===null)return x;let y=qi(e,t,r,u);return y===null?x:L.ifStatement(y,x)},a=o.flatMap(l=>{let d=l.condition===null?null:s(l,mn(n,l.index),l.conditionLocalReads,l.conditionLocalDerivationReads,"condition"),u=s(l,l.condition===null?mn(n,l.index):Ui(n,l.index),l.localReads,l.localDerivationReads,"callback");return[d,u].filter(c=>c!==null)});return L.blockStatement(a)}function Or(e,t,n){return n.map(r=>L.expressionStatement(L.callExpression(Z(e,r.condition===null?"registerEffect":"registerConditionalEffect"),[mn(t,r.index),L.identifier(t),...r.condition===null?[]:[L.arrowFunctionExpression([],L.cloneNode(r.condition,!0))],L.cloneNode(r.callback,!0)])))}function Mr(){return L.memberExpression(L.metaProperty(L.identifier("import"),L.identifier("meta")),L.identifier("hot"))}function Tr(e,t){if(e.moduleEffects.length===0)return;let n=new Map(t.get("body").map(o=>[o.node,o])),r=new Map;for(let o of e.moduleEffects){let i=r.get(o.statement)??[];i.push(o),r.set(o.statement,i)}for(let[o,i]of r){let s=n.get(o);if(s===void 0)continue;let a=[];for(let l of i)a.push(L.expressionStatement(L.callExpression(Z(e,l.condition===null?"registerEffect":"registerConditionalEffect"),[L.stringLiteral(l.entityId),L.nullLiteral(),...l.condition===null?[]:[L.arrowFunctionExpression([],L.cloneNode(l.condition,!0))],L.cloneNode(l.callback,!0)])),L.ifStatement(Mr(),L.expressionStatement(L.callExpression(L.memberExpression(Mr(),L.identifier("dispose")),[L.arrowFunctionExpression([],L.callExpression(Z(e,"unregisterSubtree"),[L.stringLiteral(l.entityId)]))]))));s.replaceWithMultiple(a)}}function Br(e){e.traverse({CallExpression(t){if(gn(t))throw t.buildCodeFrameError("memo-dom: effect() must be a direct top-level statement or be controlled by a top-level effect-only if branch in a component or module")}})}import*as qe from"@babel/types";function Vr(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function Wr(e){let t=new Set,n=[];for(let r of e){let o=bn(r);if(o===null)return null;for(let i of o.bindings){if(t.has(i))return null;t.add(i)}n.push(...o.expressions)}return t.size===0?null:{bindings:t,expressions:n}}function bn(e){if(qe.isExpressionStatement(e)&&qe.isAssignmentExpression(e.expression,{operator:"="})&&qe.isIdentifier(e.expression.left))return{bindings:new Set([e.expression.left.name]),expressions:[e.expression.right]};if(qe.isBlockStatement(e))return Wr(e.body);if(qe.isIfStatement(e)){let t=e.alternate;if(t==null)return null;let n=bn(e.consequent),r=bn(t);return n===null||r===null||!Vr(n.bindings,r.bindings)?null:{bindings:n.bindings,expressions:[e.test,...n.expressions,...r.expressions]}}return null}function Gi(e){if(!e.cases.some(o=>o.test==null))return null;let t=null,n=!1,r=[e.discriminant];for(let o of e.cases){o.test!=null&&r.push(o.test);let i=[...o.consequent];if(i.length===0){n=!0;continue}if(i.at(-1)&&qe.isBreakStatement(i.at(-1))&&i.pop(),i.some(a=>qe.isBreakStatement(a)))return null;let s=Wr(i);if(s===null)return null;if(n=!1,t===null)t=s.bindings;else if(!Vr(t,s.bindings))return null;r.push(...s.expressions)}return t===null||n?null:{bindings:t,expressions:r}}function Zi(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function Yi(e,t){let n=e;for(;n?.parentPath!==t;)n=n?.parentPath??null;return n}function zr(e,t,n){let r=t.get("body"),o=new Map(r.map((i,s)=>[i.node,s]));for(let i of r){if(!i.isIfStatement()&&!i.isSwitchStatement())continue;let s=i.node,a=i.isIfStatement()?bn(s):Gi(s);if(a===null)continue;let l=!0,d=[];for(let y of a.bindings){let f=t.scope.getBinding(y),m=f?.path,w=m?.parentPath,S=m===void 0?null:Yi(m,t);if(f===void 0||!m?.isVariableDeclarator()||!w?.isVariableDeclaration()||w.node.kind!=="let"&&w.node.kind!=="var"||S===null||(o.get(S.node)??Number.MAX_SAFE_INTEGER)>=(o.get(s)??-1)){l=!1;break}d.push(...f.constantViolations.filter(I=>!Zi(I,s)))}if(!l)continue;let u=new Set,c=null;for(let y of a.expressions){let f=n(e,y);for(let m of f.reads)u.add(m);f.impure&&c===null&&(c=f.reason??"cannot be analyzed")}if(u.size===0)continue;if(c!==null)throw i.buildCodeFrameError(`memo-dom: module control-flow derivation ${c}`);for(let y of a.bindings)if(u.has(y))throw i.buildCodeFrameError(`memo-dom: module control-flow derivation '${y}' reads its own previous value`);if(d.length>0)throw d[0].buildCodeFrameError(`memo-dom: cannot assign module control-flow computed '${[...a.bindings].sort().join(", ")}' outside its derivation`);let g=e.moduleControlFlow.length,x=[...a.bindings].sort();for(let y of x)mt(e,y,"computed");e.moduleControlFlow.push({statement:s,bindings:x,sources:[...u].sort(),entityId:`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#$flow${g}`})}}import*as pe from"@babel/types";function Bn(e,t){let n=new Set,r=!1,o,i=new Set,s=l=>{r||(r=!0,o=l)},a=l=>{pe.isIdentifier(l)?i.add(l.name):Xe(l,d=>{pe.isIdentifier(d)&&i.add(d.name)})};return Xe(t,(l,d)=>{if(pe.isFunction(l)){if(!(d!==null&&(pe.isCallExpression(d)||pe.isNewExpression(d))))return!1;for(let c of l.params)pe.isLVal(c)&&a(c);return}if(pe.isVariableDeclarator(l)&&pe.isLVal(l.id)){a(l.id);return}if(pe.isAssignmentExpression(l)){let u=pe.isIdentifier(l.left)?l.left.name:pe.isMemberExpression(l.left)?we(l.left):null;(u===null||!i.has(u))&&s("contains an assignment \u2014 writes belong in handlers, not derivations");return}if(pe.isUpdateExpression(l)){let u=l.argument,c=pe.isIdentifier(u)?u.name:pe.isMemberExpression(u)?we(u):null;(c===null||!i.has(c))&&s("contains an update (++/--) \u2014 writes belong in handlers, not derivations");return}if(pe.isAwaitExpression(l)||pe.isYieldExpression(l)){s("uses await/yield \u2014 derivations must be synchronous");return}if(pe.isCallExpression(l)){let u=l.callee;if(pe.isIdentifier(u)&&(e.helpers.has(u.name)||e.importedFunctions.has(u.name))){let c=e.importedFunctions.get(u.name)??We(e,u.name);for(let g of c.reads)n.add(g);if(c.writes.size>0){for(let g of c.writes)n.add(g);s(`calls helper '${u.name}' which writes state \u2014 writes belong in handlers`)}else c.unbounded&&e.helpers.has(u.name)&&s(`calls recursive helper '${u.name}' which cannot be analyzed`)}return}if(pe.isIdentifier(l)){!i.has(l.name)&&e.state.has(l.name)&&n.add(l.name);return}if(pe.isMemberExpression(l)&&!l.computed){let u=ye(l);if(u!==null&&u.includes(".")){let c=u.split(".")[0];!i.has(c)&&e.state.get(c)==="store"&&n.add(u)}}}),{reads:n,impure:r,reason:o}}function Kr(e,t){for(let n of t.node.body){let r=pe.isExportNamedDeclaration(n)?n.declaration:n;if(!(!pe.isVariableDeclaration(r)||r.kind!=="const"))for(let o of r.declarations){if(!pe.isIdentifier(o.id)||o.init==null)continue;let i=o.id.name;if(e.state.get(i)==="let"||e.state.get(i)==="computed"||pe.isFunction(o.init)||pe.isJSX(o.init))continue;let s=Bn(e,o.init);if(s.impure){if(s.reads.size>0)throw new Error(`memo-dom: const '${i}' is a state derivation but ${s.reason??"cannot be analyzed"}. Fix the derivation, or make it a 'let' you update in handlers.`);continue}s.reads.size!==0&&(mt(e,i,"computed"),e.computeds.set(i,{reads:s.reads}))}}}import*as Me from"@babel/types";function Ur(e){for(let[t,n]of e.compPaths){let r=new Set;for(let o of n.node.body.body)if(Me.isVariableDeclaration(o)&&!(o.kind!=="let"&&o.kind!=="var"&&o.kind!=="const"))for(let i of o.declarations)Me.isIdentifier(i.id)&&(o.kind==="let"||o.kind==="var"||Pt(i.init)||vt(i.init))&&r.add(i.id.name);r.size>0&&e.instanceState.set(t,r)}}function Hr(e){for(let[t,n]of e.compPaths){let r=new Map;for(let c of e.componentProps.get(t)?.bindings??[]){let g=n.scope.getBinding(c);g&&r.set(g,c)}for(let c of e.instanceState.get(t)??[]){let g=n.scope.getBinding(c);g&&r.set(g,c)}for(let c of e.state.keys()){let g=n.scope.getBinding(c);g?.scope.path.isProgram()&&r.set(g,c)}let o=[],i=new Set,s=new Map,a=n.get("body").get("body");for(let c of a)if(c.isVariableDeclaration({kind:"const"}))for(let g of c.get("declarations")){let x=g.node;if(!Me.isIdentifier(x.id)&&!Me.isObjectPattern(x.id)&&!Me.isArrayPattern(x.id)||x.init==null||Me.isFunction(x.init)||Me.isIdentifier(x.id)&&e.instanceState.get(t)?.has(x.id.name)===!0&&(Pt(x.init)||vt(x.init)))continue;let y=g.get("init");if(!y.isExpression())continue;let f=new Set,m=null,w=(N,K)=>{let _=K.scope.getBinding(N);return _!==void 0&&r.has(_)},S=N=>{if(!Me.isIdentifier(N.node))return;let K=N.scope.getBinding(N.node.name),_=K===void 0?void 0:r.get(K);_!==void 0&&f.add(_)},I=N=>Me.isIdentifier(N)?N.name:Me.isMemberExpression(N)?we(N):null;if(y.isReferencedIdentifier()&&S(y),y.isAssignmentExpression()){let N=I(y.node.left);N!==null&&w(N,y)&&(m="contains an assignment to reactive state")}else if(y.isUpdateExpression()){let N=I(y.node.argument);N!==null&&w(N,y)&&(m="contains an update (++/--) to reactive state")}else y.isAwaitExpression()?m="uses await; per-instance derivations must be synchronous":y.isYieldExpression()&&(m="uses yield; per-instance derivations must be synchronous");if(y.traverse({Function(N){N.skip()},ReferencedIdentifier(N){S(N)},AssignmentExpression(N){let K=I(N.node.left);K!==null&&w(K,N)&&(m="contains an assignment to reactive state")},UpdateExpression(N){let K=I(N.node.argument);K!==null&&w(K,N)&&(m="contains an update (++/--) to reactive state")},AwaitExpression(){m="uses await; per-instance derivations must be synchronous"},YieldExpression(){m="uses yield; per-instance derivations must be synchronous"}}),f.size===0)continue;if(y.traverse({ReferencedIdentifier(N){S(N)},AssignmentExpression(N){let K=I(N.node.left);K!==null&&w(K,N)&&(m="contains an assignment to reactive state")},UpdateExpression(N){let K=I(N.node.argument);K!==null&&w(K,N)&&(m="contains an update (++/--) to reactive state")}}),m!==null){let N=Bt(x.id);throw g.buildCodeFrameError(`memo-dom: local const '${N.join(", ")||"<pattern>"}' is a per-instance derivation but ${m}`)}let $=Bt(x.id),F=new Set;for(let N of f){let K=s.get(N);if(K===void 0)F.add(N);else for(let _ of K)F.add(_)}o.push({declaration:c.node,target:Me.cloneNode(x.id),source:Me.cloneNode(x.init),bindings:$,sources:[...F].sort()});for(let N of $){i.add(N),s.set(N,new Set(F));let K=n.scope.getBinding(N);K&&r.set(K,N),e.instanceState.get(t)?.delete(N)}}if(o.length===0)continue;e.instanceDerivations.set(t,o),e.instanceDerivedBindings.set(t,i);let l=new Set([...e.instanceState.get(t)??[],...e.componentProps.get(t)?.bindings??[]]);if(![...l].some(c=>o.some(g=>!g.sources.includes(c))))continue;let u=new Set([...l,...o.flatMap(c=>c.sources)]);e.instanceReasonIds.set(t,new Map([...u].sort().map((c,g)=>[c,g]))),e.selectiveDerivationComponents.add(t)}}import*as fe from"@babel/types";function Kt(e){let t=!0;return fe.traverseFast(e,n=>{if(fe.isAssignmentExpression(n)||fe.isUpdateExpression(n)||fe.isAwaitExpression(n)||fe.isYieldExpression(n)||fe.isNewExpression(n)||fe.isTaggedTemplateExpression(n)||fe.isFunction(n)){t=!1;return}if(fe.isCallExpression(n)||fe.isOptionalCallExpression(n)){let r=n.callee;t=t&&fe.isMemberExpression(r)&&!r.computed&&fe.isIdentifier(r.object,{name:"Math"})&&fe.isIdentifier(r.property)}}),t}function Qi(e){return!fe.isExpressionStatement(e)||!fe.isAssignmentExpression(e.expression,{operator:"="})||!fe.isIdentifier(e.expression.left)||!Kt(e.expression.right)?null:e.expression.left.name}function _r(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function zt(e){if(fe.isExpressionStatement(e)){let t=Qi(e);return t===null?null:{bindings:new Set([t]),partial:new Set}}if(fe.isBlockStatement(e)){let t=new Set,n=new Set;for(let r of e.body){let o=zt(r);if(o===null)return null;for(let i of o.bindings){if(t.has(i))return null;t.add(i)}for(let i of o.partial)n.add(i)}return t.size===0?null:{bindings:t,partial:n}}if(fe.isIfStatement(e)){if(!Kt(e.test))return null;let t=zt(e.consequent);if(t===null)return null;if(e.alternate==null)return{bindings:t.bindings,partial:new Set([...t.bindings,...t.partial])};let n=zt(e.alternate);return n===null||!_r(t.bindings,n.bindings)?null:{bindings:t.bindings,partial:new Set([...t.partial,...n.partial])}}return null}function es(e){if(!Kt(e.discriminant))return null;let t=null;for(let n of e.cases){if(n.test!=null&&!Kt(n.test))return null;let r=[...n.consequent];if(r.at(-1)&&fe.isBreakStatement(r.at(-1))&&r.pop(),r.some(i=>fe.isBreakStatement(i)))return null;let o=zt(fe.blockStatement(r));if(o===null)return null;if(t===null)t=o;else{if(!_r(t.bindings,o.bindings))return null;for(let i of o.partial)t.partial.add(i)}}if(t!==null&&!e.cases.some(n=>n.test===null))for(let n of t.bindings)t.partial.add(n);return t}function ts(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function qr(e){for(let[t,n]of e.compPaths){let r=new Map;for(let s of e.componentProps.get(t)?.bindings??[]){let a=n.scope.getBinding(s);a&&r.set(a,s)}for(let s of e.instanceState.get(t)??[]){let a=n.scope.getBinding(s);a&&r.set(a,s)}for(let s of e.instanceDerivedBindings.get(t)??[]){let a=n.scope.getBinding(s);a&&r.set(a,s)}for(let s of e.state.keys()){let a=n.scope.getBinding(s);a?.scope.path.isProgram()&&r.set(a,s)}let o=[],i=e.instanceDerivedBindings.get(t)??new Set;for(let s of n.get("body").get("body")){if(!s.isIfStatement()&&!s.isSwitchStatement())continue;let a=s,l=a.isIfStatement()?zt(a.node):es(a.node);if(l===null)continue;let d=!0,u=[],c=[];for(let f of l.bindings){let m=n.scope.getBinding(f),w=m?.path,S=w?.parentPath;if(m===void 0||!w?.isVariableDeclarator()||!S?.isVariableDeclaration()||S.node.kind!=="let"&&S.node.kind!=="var"||m.constantViolations.some(I=>!ts(I,a.node))){d=!1;break}if(l.partial.has(f)){let I=w.get("init");if(!I.isExpression()||!Kt(I.node)){d=!1;break}u.push({binding:f,source:I.node}),c.push(I)}}if(!d)continue;let g=new Set,x=f=>{let m=f.scope.getBinding(f.node.name),w=m===void 0?void 0:r.get(m);w!==void 0&&g.add(w)},y={Function(f){f.skip()},ReferencedIdentifier(f){f.isIdentifier()&&x(f)}};a.traverse(y);for(let f of c)f.isReferencedIdentifier()&&x(f),f.traverse(y);if(g.size!==0){for(let f of l.bindings)if(g.has(f))throw a.buildCodeFrameError(`memo-dom: reactive control-flow derivation '${f}' reads its own previous value`);o.push({statement:a.node,bindings:[...l.bindings].sort(),resets:u,sources:[...g].sort()});for(let f of l.bindings){i.add(f);let m=n.scope.getBinding(f);m&&r.set(m,f),e.instanceState.get(t)?.delete(f)}}}o.length>0&&(e.instanceControlFlow.set(t,o),e.instanceDerivedBindings.set(t,i))}}function Gr(e){for(let[t]of e.compPaths){let n=e.instanceDerivations.get(t)??[],r=e.instanceControlFlow.get(t)??[];if(n.length===0&&r.length===0)continue;let o=new Map;for(let u of n)for(let c of u.bindings)o.set(c,new Set(u.sources));for(let u of r)for(let c of u.bindings)o.set(c,new Set(u.sources));let i=(u,c=new Set)=>{let g=o.get(u);if(g===void 0)return new Set([u]);if(c.has(u))return new Set([u]);let x=new Set(c).add(u),y=new Set;for(let f of g)for(let m of i(f,x))y.add(m);return y};for(let u of n)u.sources=[...new Set(u.sources.flatMap(c=>[...i(c)]))].sort();for(let u of r)u.sources=[...new Set(u.sources.flatMap(c=>[...i(c)]))].sort();let s=new Set([...e.instanceState.get(t)??[],...e.componentProps.get(t)?.bindings??[]]),a=[...n,...r],l=[...s].some(u=>a.some(c=>!c.sources.includes(u)));if(e.selectiveDerivationComponents.delete(t),e.instanceReasonIds.delete(t),!l)continue;let d=new Set([...s,...a.flatMap(u=>u.sources)]);e.instanceReasonIds.set(t,new Map([...d].sort().map((u,c)=>[u,c]))),e.selectiveDerivationComponents.add(t)}}import*as Ut from"@babel/types";function ns(e){let t=e.indexOf("[");return t<0?e:e.slice(0,t)}function Et(e,t){let n=new Set;for(let r of t){let o=r.split("/"),i=[[]];for(let s=0;s<o.length;s++){let a=o[s],l=i.map(d=>[...d,a]);if(s<o.length-1&&e.renderSlotOwners.has(ns(a)))for(let d of i)l.push([...d,a,"$slot[*]"]);i=l}for(let s of i)n.add(s.join("/"))}return[...n]}function Ge(e,t,n=new Set){let r=e.linkedComponentPaths.get(t);if(r!==void 0)return[...r];if(n.has(t))throw e.compPaths.get(t).buildCodeFrameError(`memo-dom: recursive component '${t}' \u2014 components cannot render themselves (L1)`);let o=e.listedSites.get(t);if(o!==void 0&&o.length>0){n.add(t);let d=o.flatMap(u=>Ge(e,u.owner,n).map(c=>`${c}/${u.suffix}/Row[*]`));return n.delete(t),[...new Set(d)]}let i=e.comps.get(t),s=e.conditionalComponentSites.get(t)??[],a=e.rowComponentSites.get(t)??[];if(i.parents.size===0&&s.length===0&&a.length===0)return[e.rootId];n.add(t);let l=[];for(let d of s)for(let u of Ge(e,d.owner,n))l.push(`${u}/${d.suffix}`);for(let d of a)for(let u of Ge(e,d.owner,n))l.push(`${u}/${d.suffix}`);for(let d of i.parents){let u=e.childRefCounts.get(d)?.get(t)??1;for(let c of Ge(e,d,n))u>1?l.push(`${c}/${t}`,`${c}/${t}[*]`):l.push(`${c}/${t}`)}return n.delete(t),l}function Vn(e,t){let n=e.linkedComponentPaths.get(t);if(n!==void 0)return Et(e,n.flatMap(i=>[i,`${i}/*`]));let r=e.listedSites.get(t),o=[];if(r&&r.length>0){if(Mt(e,t)){for(let i of r){let s=i.suffix.lastIndexOf("/"),a=s<0?"":`/${i.suffix.slice(0,s)}`;for(let l of Ge(e,i.owner))o.push(`${l}${a}`,`${l}${a}/*`)}return Et(e,o)}for(let i of r)for(let s of Ge(e,i.owner))o.push(`${s}/${i.suffix}/Row[*]`,`${s}/${i.suffix}/Row[*]/*`);return Et(e,o)}for(let i of Ge(e,t))o.push(i,`${i}/*`);return Et(e,o)}function Mt(e,t){let n=e.importedComponents.get(t);if(n!==void 0)return n.listLightweight;let r=e.lightweightCache.get(t);if(r!==void 0)return r;let o=!1,i=e.listedSites.get(t),s=e.linkedComponentRows.get(t);return(i!==void 0&&i.length>0||s!==void 0&&s.length>0)&&e.comps.get(t).parents.size===0&&hn(e,t)&&(o=!0),e.lightweightCache.set(t,o),o}function hn(e,t){if((e.instanceState.get(t)?.size??0)>0)return!1;let n=!0;return e.compPaths.get(t).traverse({JSXElement(o){let i=o.node.openingElement.name;Ut.isJSXIdentifier(i)&&/^[A-Z]/.test(i.name)&&(n=!1)},CallExpression(o){(Ut.isIdentifier(o.node.callee,{name:"cleanup"})&&o.scope.getBinding("cleanup")===void 0||Ut.isIdentifier(o.node.callee,{name:"effect"})&&o.scope.getBinding("effect")===void 0)&&(n=!1),Oe(o.node)&&De(o)&&(n=!1)},ConditionalExpression(o){De(o)&&(n=!1)},LogicalExpression(o){De(o)&&(n=!1)}}),n}import*as z from"@babel/types";function Zr(e,t){let n=e.findParent(r=>r.isFunctionDeclaration()||r.isFunctionExpression()||r.isArrowFunctionExpression());return n===t?!0:n?.findParent(r=>r===t)!==null}function Wn(e,t){let n=e;for(;n!==null;){let r=n.parentPath;if(r===null||r.isJSXAttribute()||r.isJSXSpreadAttribute())return!1;if(r.isJSXExpressionContainer()){if(r.parentPath?.isJSXAttribute()===!0){let o=r.parentPath.node,i=r.parentPath.parentPath;if(!i?.isJSXOpeningElement())return!1;let s=i.node.name;if(!z.isJSXIdentifier(s)||!/^[A-Z]/.test(s.name))return!1;let a=z.isJSXIdentifier(o.name)?o.name.name:o.name.name.name;return t.componentProps.get(s.name)?.renderProps.includes(a)===!0}return r.parentPath?.isJSXElement()===!0||r.parentPath?.isJSXFragment()===!0}if(r.isReturnStatement()&&r.node.argument===n.node||r.isArrowFunctionExpression()&&r.node.body===n.node||r.isVariableDeclarator()&&r.node.init===n.node)return!0;n=r}return!1}function rs(e,t){if(z.isArrayExpression(e))return e;if(!z.isIdentifier(e))return null;let n=t.scope.getBinding(e.name);return n?.path.isVariableDeclarator()&&z.isArrayExpression(n.path.node.init)?n.path.node.init:null}function zn(e,t,n=new Set){if(n.has(e))throw t.buildCodeFrameError("memo-dom: cyclic JSX array spread");n.add(e);let r=[];try{for(let o of e.elements)if(!(o==null||z.isNullLiteral(o)||z.isBooleanLiteral(o))){if(z.isSpreadElement(o)){if(!z.isExpression(o.argument))throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");let i=rs(o.argument,t);if(i===null)throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");r.push(...zn(i,t,n));continue}if(z.isArrayExpression(o)){r.push(...zn(o,t,n));continue}if(z.isJSXElement(o)||z.isJSXFragment(o)){r.push(z.cloneNode(o,!0));continue}if(!z.isExpression(o))throw t.buildCodeFrameError("memo-dom: JSX arrays require renderable expression entries");r.push(z.jsxExpressionContainer(z.cloneNode(o,!0)))}}finally{n.delete(e)}return r}function Yr(e,t){return z.jsxFragment(z.jsxOpeningFragment(),z.jsxClosingFragment(),zn(e,t))}function os(e,t){return z.isArrayExpression(e)?e.elements.map((n,r)=>{if(n==null||z.isSpreadElement(n))throw t.buildCodeFrameError("memo-dom: JSX arrays cannot contain holes or spread elements");return{key:z.numericLiteral(r),value:n}}):e.properties.map(n=>{if(!z.isObjectProperty(n)||n.computed||!z.isExpression(n.value))throw t.buildCodeFrameError("memo-dom: JSX objects require static data properties without spreads");let r=z.isIdentifier(n.key)?z.stringLiteral(n.key.name):z.isStringLiteral(n.key)||z.isNumericLiteral(n.key)?z.cloneNode(n.key):null;if(r===null)throw t.buildCodeFrameError("memo-dom: JSX objects require identifier, string, or numeric keys");return{key:r,value:n.value}})}function is(e,t){let n=e.node,r=null;if(!n.computed&&z.isIdentifier(n.property)?r=n.property.name:n.computed&&(z.isStringLiteral(n.property)||z.isNumericLiteral(n.property))&&(r=n.property.value),r!==null){let i=t.find(s=>(z.isStringLiteral(s.key)||z.isNumericLiteral(s.key))&&s.key.value===r);if(i===void 0)throw e.buildCodeFrameError(`memo-dom: JSX collection has no entry for '${r}'`);return z.cloneNode(i.value,!0)}if(!n.computed||!z.isExpression(n.property))throw e.buildCodeFrameError("memo-dom: JSX collection selection requires a static or expression key");let o=z.nullLiteral();for(let i=t.length-1;i>=0;i--){let s=t[i];o=z.conditionalExpression(z.binaryExpression("===",z.cloneNode(n.property,!0),z.cloneNode(s.key,!0)),z.cloneNode(s.value,!0),o)}return o}function Qr(e){for(let[,t]of e.compPaths){let n=!1;t.traverse({JSXExpressionContainer(o){if(!o.parentPath?.isJSXElement()&&!o.parentPath?.isJSXFragment())return;let i=o.get("expression");Array.isArray(i)||!i.isArrayExpression()||!ce(i.node)||(o.replaceWith(Yr(i.node,i)),n=!0)}});let r=!0;for(;r;){r=!1,t.scope.crawl();let o=t.get("body").get("body");for(let i of o)if(i.isVariableDeclaration({kind:"const"})){for(let s of i.get("declarations")){let a=s.node,l=a.init;if(!z.isIdentifier(a.id)||l==null||!ce(l))continue;let d=s.scope.getBinding(a.id.name);if(d?.path!==s)continue;let u=[...d.referencePaths];if(z.isObjectExpression(l)||z.isArrayExpression(l))for(let c of u){if(!c.isIdentifier()||!Zr(c,t))throw c.buildCodeFrameError(`memo-dom: JSX collection '${a.id.name}' is used outside its component`);if(c.parentPath?.isMemberExpression()&&c.parentPath.node.object===c.node){let g=c.parentPath;if(!Wn(g,e))throw g.buildCodeFrameError(`memo-dom: JSX collection '${a.id.name}' is used outside a render position`);g.replaceWith(is(g,os(l,s)));continue}if(z.isArrayExpression(l)&&c.parentPath?.isSpreadElement()&&c.parentPath.parentPath?.isArrayExpression()){c.replaceWith(z.cloneNode(l,!0));continue}if(z.isArrayExpression(l)&&Wn(c,e)){c.replaceWith(Yr(l,c));continue}throw c.buildCodeFrameError(z.isArrayExpression(l)?`memo-dom: JSX collection '${a.id.name}' must be rendered directly or selected with a direct index access`:`memo-dom: JSX collection '${a.id.name}' is used outside a render position`)}else for(let c of u)if(!(!c.isIdentifier()||!Zr(c,t))){if(!Wn(c,e))throw c.buildCodeFrameError(`memo-dom: JSX value '${a.id.name}' is used outside a render position`);c.replaceWith(z.cloneNode(l,!0))}i.node.declarations.length===1?i.remove():s.remove(),n=!0,r=!0;break}if(r)break}}n&&(t.traverse({JSXExpressionContainer(o){let i=o.node.expression;(o.parentPath?.isJSXElement()===!0||o.parentPath?.isJSXFragment()===!0)&&(z.isJSXElement(i)||z.isJSXFragment(i))&&o.replaceWith(i)}}),t.scope.crawl())}}import*as R from"@babel/types";function Kn(e){return R.isReturnStatement(e)&&R.isExpression(e.argument)?e.argument:R.isBlockStatement(e)&&e.body.length===1?Kn(e.body[0]):null}function Lt(e){let t=Kn(e);if(t!==null)return t;if(R.isIfStatement(e)&&e.alternate!=null){let n=Lt(e.consequent),r=Lt(e.alternate);return n===null||r===null?null:R.conditionalExpression(R.cloneNode(e.test,!0),R.cloneNode(n,!0),R.cloneNode(r,!0))}if(R.isSwitchStatement(e)){let n=e.cases.find(o=>o.test==null);if(n===void 0||n.consequent.length!==1)return null;let r=Lt(n.consequent[0]);if(r===null)return null;for(let o=e.cases.length-1;o>=0;o--){let i=e.cases[o];if(i.test==null)continue;if(i.consequent.length!==1)return null;let s=Lt(i.consequent[0]);if(s===null)return null;r=R.conditionalExpression(R.binaryExpression("===",R.cloneNode(e.discriminant,!0),R.cloneNode(i.test,!0)),R.cloneNode(s,!0),r)}return r}return null}function ss(e,t){if(R.isExpression(e.body))return{expression:R.cloneNode(e.body,!0),locals:new Map};let n=new Map,r=[];for(let s of e.body.body){if(R.isVariableDeclaration(s,{kind:"const"})){for(let a of s.declarations)(!R.isIdentifier(a.id)||a.init==null||!R.isExpression(a.init))&&t("memo-dom: JSX render functions require identifier const declarations with expression initializers"),n.set(a.id.name,R.cloneNode(a.init,!0));continue}R.isTypeScript(s)||R.isEmptyStatement(s)||r.push(s)}if(r.length===1){let s=Lt(r[0]);if(s!==null)return{expression:s,locals:n}}let o=r.at(-1),i=o===void 0?null:Kn(o);if(i!==null){let s=R.cloneNode(i,!0);for(let a=r.length-2;a>=0;a--){let l=r[a];if(R.isIfStatement(l)&&l.alternate==null){let d=Lt(l.consequent);if(d!==null){s=R.conditionalExpression(R.cloneNode(l.test,!0),R.cloneNode(d,!0),s);continue}}t("memo-dom: JSX render functions support pure const setup, JSX return expressions, tail early-return if statements, exhaustive return if/else, or exhaustive return switch statements")}return{expression:s,locals:n}}return t("memo-dom: JSX render function does not have supported exhaustive return control flow")}function as(e,t){return(R.isMemberExpression(e)||R.isOptionalMemberExpression(e))&&t==="property"&&!e.computed||(R.isObjectProperty(e)||R.isObjectMethod(e)||R.isClassMethod(e))&&t==="key"&&!e.computed||R.isVariableDeclarator(e)&&t==="id"||(R.isFunction(e)||R.isCatchClause(e))&&(t==="params"||t==="param"||t==="id")||R.isLabeledStatement(e)&&t==="label"}function eo(e,t,n=new Set){let r=R.cloneNode(e,!0),o=(i,s,a,l)=>{if(R.isIdentifier(i)&&!l.has(i.name)&&t.has(i.name)&&(s===null||!as(s,a)))return R.cloneNode(t.get(i.name),!0);let d=l;if(R.isFunction(i)&&i!==r){let u=i.params.flatMap(c=>Object.keys(R.getBindingIdentifiers(c)));d=new Set([...l,...u])}for(let u of R.VISITOR_KEYS[i.type]??[]){let c=i[u];Array.isArray(c)?i[u]=c.map(g=>g!=null&&typeof g=="object"&&"type"in g?o(g,i,u,d):g):c!=null&&typeof c=="object"&&"type"in c&&(i[u]=o(c,i,u,d))}return R.isObjectProperty(i)&&i.shorthand&&!R.isIdentifier(i.value,{name:R.isIdentifier(i.key)?i.key.name:""})&&(i.shorthand=!1),i};return o(r,null,"",n)}function ls(e,t){let n=a=>{throw t.buildCodeFrameError(a)},r=e.node;(r.async||r.generator)&&n("memo-dom: JSX render functions must be synchronous"),t.node.arguments.some(a=>R.isSpreadElement(a))&&n("memo-dom: JSX render function calls do not support spread arguments"),t.node.arguments.length>r.params.length&&n("memo-dom: JSX render function received more arguments than parameters");let o=new Map;for(let a=0;a<r.params.length;a++){let l=r.params[a],d=t.node.arguments[a],u=d!==void 0&&R.isExpression(d)?d:R.identifier("undefined");if(R.isIdentifier(l)){o.set(l.name,R.cloneNode(u,!0));continue}if(R.isAssignmentPattern(l)&&R.isIdentifier(l.left)){o.set(l.left.name,R.conditionalExpression(R.binaryExpression("===",R.cloneNode(u,!0),R.identifier("undefined")),R.cloneNode(l.right,!0),R.cloneNode(u,!0)));continue}n("memo-dom: JSX render functions currently require identifier parameters with optional defaults")}let i=ss(r,n);for(let[a,l]of i.locals)o.set(a,eo(l,o));let s=eo(i.expression,o);return ce(s)||n("memo-dom: JSX render function expansion did not produce JSX"),s}function ds(e,t){let n=t.get("callee");return Array.isArray(n)||!n.isIdentifier()?null:to(e,n)}function to(e,t){let n=t.node.name,r=e.jsxHelpers.get(n);if(r!==void 0)return{node:r.node,bindingPath:r};let o=t.scope.getBinding(n);if(o?.path.isFunctionDeclaration()&&ce(o.path.node))return{node:o.path.node,bindingPath:o.path};if(o?.path.isVariableDeclarator()){let i=o.path.node.init;if((R.isFunctionExpression(i)||R.isArrowFunctionExpression(i))&&ce(i.body))return{node:i,bindingPath:o.path}}return null}function no(e){return R.isMemberExpression(e.callee)&&!e.callee.computed&&R.isIdentifier(e.callee.property,{name:"map"})}function cs(e){let t=e.parentPath;return t?.isCallExpression()===!0&&(t.node.callee===e.node||no(t.node)&&t.node.arguments[0]===e.node)}function us(e,t){let n=e.node;if(n.async||n.generator)throw t.buildCodeFrameError("memo-dom: JSX render callbacks must be synchronous");return R.arrowFunctionExpression(n.params.map(r=>R.cloneNode(r,!0)),R.cloneNode(n.body,!0))}function En(e){if(!e.removed){if(e.isFunctionDeclaration()){e.parentPath?.isExportNamedDeclaration()?e.parentPath.remove():e.remove();return}if(e.isVariableDeclarator()){let t=e.parentPath;if(!t?.isVariableDeclaration())return;t.node.declarations.length===1?t.parentPath?.isExportNamedDeclaration()?t.parentPath.remove():t.remove():e.remove();return}if(e.isArrowFunctionExpression()||e.isFunctionExpression()){let t=e.parentPath;t?.isVariableDeclarator()&&En(t)}}}function ps(e,t){let n=t.findParent(r=>r.isProgram());if(n===null||!n.isProgram()){En(t);return}for(let r of n.get("body")){let o=r.isExportNamedDeclaration()?r.get("declaration"):r;if(Array.isArray(o)||o==null)continue;if(o.isFunctionDeclaration()&&o.node.id?.name===e){r.remove();return}if(!o.isVariableDeclaration())continue;let i=o.get("declarations"),s=i.find(a=>a.isVariableDeclarator()&&R.isIdentifier(a.node.id,{name:e}));if(s!==void 0){i.length===1?r.remove():s.remove();return}}En(t)}function fs(e,t){let n=e.parentPath,r=n?.parentPath;if((R.isJSXElement(t)||R.isJSXFragment(t))&&n?.isJSXExpressionContainer()&&(r?.isJSXElement()||r?.isJSXFragment())&&r.node.children.includes(n.node)){n.replaceWith(t);return}e.replaceWith(t)}function ro(e){let t=new Set;for(let[n,r]of e.jsxHelpers)if((r.scope.parent?.getBinding(n)??r.parentPath?.scope.getBinding(n))?.referencePaths.some(i=>i.isIdentifier()&&!cs(i)))throw r.buildCodeFrameError("memo-dom: JSX render functions may only be called in local render composition or passed directly to collection map()");for(let[,n]of e.compPaths){n.scope.crawl(),n.traverse({CallExpression(o){if(!no(o.node)||o.node.arguments.length!==1)return;let i=o.get("arguments")[0];if(i===void 0||Array.isArray(i)||!i.isIdentifier())return;let s=to(e,i);s!==null&&(i.replaceWith(us(s,i)),t.add(s.bindingPath))}});let r=!0;for(;r;){r=!1,n.scope.crawl();let o=[];n.traverse({CallExpression(i){o.push(i)}});for(let i of o.reverse()){if(i.removed)continue;let s=ds(e,i);s!==null&&(fs(i,ls(s,i)),t.add(s.bindingPath),r=!0)}}}for(let[n,r]of e.jsxHelpers)ps(n,r);for(let n of t)En(n)}import*as ze from"@babel/types";function ms(e){let t=jn(e);return ze.isIdentifier(t)||ze.isMemberExpression(t)||sn(t)}function gs(e,t){let n=e,r=t.get("body");for(;n!==null&&n.parentPath!==r;)n=n.parentPath;return n?.isStatement()===!0?n:null}function bs(e,t){return e.findParent(n=>n.isFunctionDeclaration()||n.isFunctionExpression()||n.isArrowFunctionExpression())===t}function oo(e){for(let[,t]of e.compPaths){let n=[];if(t.traverse({CallExpression(s){if(Oe(s.node)===null||!ze.isMemberExpression(s.node.callee)||!ze.isExpression(s.node.callee.object)||ms(s.node.callee.object)||!bs(s,t))return;let a=gs(s,t);a!==null&&n.push({path:s,source:ze.cloneNode(s.node.callee.object,!0),statement:a})}}),n.length===0)continue;let r=t.get("body").get("body"),o=new Map(r.map((s,a)=>[s.node,a]));n.sort((s,a)=>(o.get(s.statement.node)??0)-(o.get(a.statement.node)??0));let i=[];for(let s of n){let a=j(e,"listView");i.push(ze.variableDeclarator(ze.cloneNode(a),s.source));let l=s.path.get("callee");if(Array.isArray(l)||!l.isMemberExpression())continue;let d=l.get("object");Array.isArray(d)||d.replaceWith(ze.cloneNode(a))}n[0].statement.insertBefore(ze.variableDeclaration("const",i)),t.scope.crawl()}}import*as Te from"@babel/types";var hs=new Set(["==","==="]);function yn(e,t,n){if(n(e,t),!Te.isFunction(e))for(let r of Te.VISITOR_KEYS[e.type]??[]){let o=e[r];if(Array.isArray(o))for(let i of o)i&&yn(i,e,n);else o&&yn(o,e,n)}}function io(e,t,n){if(!Te.isBinaryExpression(t)||!hs.has(t.operator))return!1;let r=t.left===e?t.right:t.left;return Te.isExpression(r)&&Te.isNodesEquivalent(r,n)}function so(e,t){if(e.jsx===null||e.keyExpr===null||!e.sourceLocal||!Te.isIdentifier(e.sourceExpr)||!t.has(e.sourceExpr.name))return[];let n=e.sourceExpr.name,r=new Set;if(yn(e.jsx,null,(i,s)=>{Te.isIdentifier(i)&&t.has(i.name)&&i.name!==n&&io(i,s,e.keyExpr)&&r.add(i.name)}),r.size===0)return[];let o=new Set;return yn(e.jsx,null,(i,s)=>{Te.isIdentifier(i)&&r.has(i.name)&&Te.isReferenced(i,s)&&!io(i,s,e.keyExpr)&&o.add(i.name)}),[...r].filter(i=>!o.has(i)).sort()}import*as P from"@babel/types";function Es(e){return{mode:e.objectProps?"object":"positional",names:[...e.props],acceptsUnknown:e.acceptsUnknownProps,bindings:[],params:[],hasWholeDefault:e.hasWholeDefault,renderProps:[...e.renderProps??[]],renderCallbacks:[...e.renderCallbacks??[]],refProps:[...e.refProps??[]]}}function Sn(e,t){if(e.linkedDynamicComponentCandidates.size===0)return;t.scope.crawl();let n=new Set(Object.keys(t.scope.bindings)),r=new Map([...e.importedComponents].map(([i,s])=>[s.key,i])),o=[];for(let[i,s]of e.linkedDynamicComponentCandidates){let a=[];for(let d of s){let u=r.get(d.key);if(u===void 0){let c=`MDDynamic_${d.imported.replace(/[^A-Za-z0-9_$]/g,"_")}`;u=c;let g=1;for(;n.has(u);)u=`${c}${g++}`;n.add(u),r.set(d.key,u);let x={type:"component",key:d.key,props:[...d.props],objectProps:d.objectProps,acceptsUnknownProps:d.acceptsUnknownProps,hasWholeDefault:d.hasWholeDefault,listLightweight:d.listLightweight,delegatedEvents:d.delegatedEvents,renderProps:[...d.renderProps??[]],renderCallbacks:[...d.renderCallbacks??[]],refProps:[...d.refProps??[]],subtreeReads:[...d.subtreeReads??[]]};e.importedComponents.set(u,x),e.componentProps.set(u,Es(x)),o.push(P.importDeclaration(d.imported==="default"?[P.importDefaultSpecifier(P.identifier(u))]:[P.importSpecifier(P.identifier(u),P.isValidIdentifier(d.imported)?P.identifier(d.imported):P.stringLiteral(d.imported))],P.stringLiteral(d.source)))}a.push(u)}let l=[...new Set(a)];e.state.has(i)?e.stateComponentCandidates.set(i,l):e.functionComponentCandidates.set(i,l)}for(let i of o.reverse())t.unshiftContainer("body",i);t.scope.crawl()}function Un(e){let t=e;for(;P.isTSAsExpression(t)||P.isTSTypeAssertion(t)||P.isTSNonNullExpression(t);)t=t.expression;return t}function ao(e){return P.isJSXIdentifier(e)?P.identifier(e.name):P.memberExpression(ao(e.object),P.identifier(e.property.name))}function lo(e,t){let n=ye(t);if(n===null)return null;let[r,...o]=n.split(".");if(r===void 0||o.length===0)return null;let i=e.scope.getBinding(r);if(!i?.path.isVariableDeclarator())return null;let s=i.path.node.init;if(s==null)return null;for(let a of o){if(s=Un(s),!P.isObjectExpression(s))return null;let l=s.properties.find(d=>!P.isObjectProperty(d)||d.computed?!1:(P.isIdentifier(d.key)?d.key.name:P.isStringLiteral(d.key)?d.key.value:null)===a);if(l===void 0||!P.isObjectProperty(l)||!P.isExpression(l.value))return null;s=l.value}return s}function ys(e,t){let n=e.scope.getBinding(t);if(n===void 0)return[];let r=null;return n.path.isFunctionDeclaration()?r=n.path.node:n.path.isVariableDeclarator()&&(P.isFunctionExpression(n.path.node.init)||P.isArrowFunctionExpression(n.path.node.init))&&(r=n.path.node.init),r===null?[]:co(r)}function co(e){if(P.isExpression(e.body))return[e.body];let t=[],n=r=>{if(!P.isFunction(r)){if(P.isReturnStatement(r)){P.isExpression(r.argument)&&t.push(r.argument);return}for(let o of P.VISITOR_KEYS[r.type]??[]){let i=r[o];if(Array.isArray(i))for(let s of i)s!=null&&typeof s=="object"&&"type"in s&&n(s);else i!=null&&typeof i=="object"&&"type"in i&&n(i)}}};for(let r of e.body.body)n(r);return t}function yt(e,t,n,r=new Set){let o=Un(t);if(!r.has(o)){if(r.add(o),P.isIdentifier(o)&&(e.comps.has(o.name)||e.importedComponents.has(o.name))){n.add(o.name);return}if(P.isIdentifier(o)){for(let i of e.stateComponentCandidates.get(o.name)??e.functionComponentCandidates.get(o.name)??[])n.add(i);return}if(P.isConditionalExpression(o)){yt(e,o.consequent,n,r),yt(e,o.alternate,n,r);return}if(P.isLogicalExpression(o)){yt(e,o.right,n,r);return}if(P.isObjectExpression(o)){for(let i of o.properties)P.isObjectProperty(i)&&P.isExpression(i.value)&&yt(e,i.value,n,r);return}if(P.isArrayExpression(o)){for(let i of o.elements)i!=null&&!P.isSpreadElement(i)&&yt(e,i,n,r);return}if(P.isCallExpression(o)&&P.isIdentifier(o.callee)){for(let i of e.functionComponentCandidates.get(o.callee.name)??[])n.add(i);return}if(P.isMemberExpression(o)){let i=we(o);if(i!==null)for(let s of e.stateComponentCandidates.get(i)??[])n.add(s)}}}function uo(e,t){for(let r of t.node.body){let o=P.isExportNamedDeclaration(r)?r.declaration:r;if(P.isVariableDeclaration(o))for(let i of o.declarations){if(!P.isIdentifier(i.id)||i.init==null)continue;let s=new Set;yt(e,i.init,s),s.size>0&&e.state.has(i.id.name)&&e.stateComponentCandidates.set(i.id.name,[...s])}}let n=!0;for(;n;){n=!1;for(let[r,o]of e.helpers){let i=new Set(e.functionComponentCandidates.get(r)??[]),s=[],a=o.node;(P.isFunctionDeclaration(a)||P.isFunctionExpression(a)||P.isArrowFunctionExpression(a))&&(s=co(a));for(let l of s)yt(e,l,i);i.size>0&&i.size!==(e.functionComponentCandidates.get(r)?.length??0)&&(e.functionComponentCandidates.set(r,[...i]),n=!0)}}}function Ze(e,t,n,r,o=new Set){let i=Un(n);if(!o.has(i)){if(o.add(i),P.isConditionalExpression(i)){Ze(e,t,i.consequent,r,o),Ze(e,t,i.alternate,r,o);return}if(P.isStringLiteral(i)){if(!/^[A-Za-z][A-Za-z0-9:_-]*$/.test(i.value))throw t.buildCodeFrameError(`memo-dom: '${i.value}' is not a valid dynamic intrinsic tag name`);r.push({compare:P.cloneNode(i),tag:P.jsxIdentifier(i.value)});return}if(P.isIdentifier(i)){if(e.comps.has(i.name)||e.importedComponents.has(i.name)){r.push({compare:P.cloneNode(i),tag:P.jsxIdentifier(i.name)});return}let s=e.stateTagCandidates.get(i.name);if(s!==void 0)for(let l of s)Ze(e,t,P.stringLiteral(l),r,o);let a=t.scope.getBinding(i.name);a?.path.isVariableDeclarator()&&a.path.node.init!=null&&Ze(e,t,a.path.node.init,r,o);return}if(P.isCallExpression(i)&&P.isIdentifier(i.callee)){for(let s of e.functionTagCandidates.get(i.callee.name)??[])Ze(e,t,P.stringLiteral(s),r,o);for(let s of ys(t,i.callee.name))Ze(e,t,s,r,o);for(let s of e.functionComponentCandidates.get(i.callee.name)??[])Ze(e,t,P.identifier(s),r,o);return}if(P.isMemberExpression(i)){let s=lo(t,i);if(s!==null){Ze(e,t,s,r,o);return}let a=we(i);if(a===null)return;let l=t.scope.getBinding(a);if(l?.path.isVariableDeclarator()&&l.path.node.init!=null){let d=new Set;yt(e,l.path.node.init,d);for(let u of d)Ze(e,t,P.identifier(u),r,o)}for(let d of e.stateTagCandidates.get(a)??[])Ze(e,t,P.stringLiteral(d),r,o);for(let d of e.stateComponentCandidates.get(a)??[])Ze(e,t,P.identifier(d),r,o)}}}function Ss(e){return P.isStringLiteral(e.compare)?`string:${e.compare.value}`:P.isIdentifier(e.compare)?`component:${e.compare.name}`:JSON.stringify(e.compare)}function xs(e,t){if(P.isIdentifier(t)){let n=e.scope.getBinding(t.name);return n?.path.isVariableDeclarator()?[...n.path.node.init==null?[]:[n.path.node.init],...n.constantViolations.flatMap(r=>r.isAssignmentExpression()&&r.node.operator==="="&&P.isExpression(r.node.right)?[r.node.right]:[])]:[]}if(P.isMemberExpression(t)){let n=lo(e,t),r=ye(t),o=[];return r!==null&&(e.getFunctionParent()??e.findParent(a=>a.isProgram()))?.traverse({AssignmentExpression(a){a.node.operator==="="&&P.isMemberExpression(a.node.left)&&ye(a.node.left)===r&&P.isExpression(a.node.right)&&o.push(a.node.right)}}),[...n===null?[]:[n],...o]}return[]}function po(e,t){let n=P.cloneNode(e,!0);n.openingElement.name=P.cloneNode(t);let r=n.closingElement;return r!=null&&(r.name=P.cloneNode(t)),n}function Cs(e,t,n){let r=P.nullLiteral();for(let o=n.length-1;o>=0;o--){let i=n[o];r=P.conditionalExpression(P.binaryExpression("===",P.cloneNode(e,!0),P.cloneNode(i.compare,!0)),po(t,i.tag),r)}return r}function ws(e){return P.isIdentifier(e)?e.name:P.isMemberExpression(e)?ye(e)??"<member expression>":"<expression>"}function fo(e){let t=new Map;for(let[,n]of e.compPaths){n.scope.crawl();let r=[];n.traverse({JSXElement(o){r.push(o)}});for(let o of r.reverse()){if(o.removed)continue;let i=o.node.openingElement.name;if(P.isJSXNamespacedName(i))throw o.buildCodeFrameError("memo-dom: namespaced JSX tags are not supported");if(P.isJSXIdentifier(i)&&(!/^[A-Z]/.test(i.name)||e.comps.has(i.name)||e.importedComponents.has(i.name)))continue;let s=ao(i),a=xs(o,s),l=[];for(let u of a)Ze(e,o,u,l);let d=[...new Map(l.map(u=>[Ss(u),u])).values()];if(d.length===0)throw o.buildCodeFrameError(`memo-dom: dynamic JSX tag '${ws(s)}' has no finite string or linked-component candidates`);for(let u of d){if(!P.isJSXIdentifier(u.tag))continue;let c=e.componentProps.get(u.tag.name);if(c===void 0||c.renderProps.length===0)continue;let g=t.get(u.tag.name);g===void 0&&(g=new Map,t.set(u.tag.name,g));for(let x of o.node.openingElement.attributes){if(P.isJSXSpreadAttribute(x)||!P.isJSXIdentifier(x.name)||!c.renderProps.includes(x.name.name))continue;let y=$e(x.value),f=g.get(x.name.name)??{scalar:!1,jsx:!1,at:o};y!==null&&ce(y)?f.jsx=!0:f.scalar=!0,g.set(x.name.name,f)}}if(d.length===1){o.replaceWith(po(o.node,d[0].tag));continue}o.replaceWith(P.jsxFragment(P.jsxOpeningFragment(),P.jsxClosingFragment(),[P.jsxExpressionContainer(Cs(s,o.node,d))]))}n.scope.crawl()}for(let[n,r]of t){let o=e.componentProps.get(n);for(let[i,s]of r){if(s.scalar&&s.jsx)throw s.at.buildCodeFrameError(`memo-dom: dynamic component prop '${i}' is used as both scalar data and JSX content`);s.scalar&&(o.renderProps=o.renderProps.filter(a=>a!==i))}}}import*as ne from"@babel/types";function Hn(e){return ne.isExportNamedDeclaration(e)?e.declaration??null:ne.isDeclaration(e)?e:null}function mo(e){let t=new Map;for(let n of e.body){let r=Hn(n);ne.isTSTypeAliasDeclaration(r)&&t.set(r.id.name,r.typeAnnotation)}return t}function ct(e,t,n=new Set){if(ne.isTSLiteralType(e)&&ne.isStringLiteral(e.literal))return[e.literal.value];if(ne.isTSUnionType(e))return e.types.flatMap(r=>ct(r,t,n));if(ne.isTSIntersectionType(e))return e.types.flatMap(r=>ct(r,t,n));if(ne.isTSParenthesizedType(e))return ct(e.typeAnnotation,t,n);if(ne.isTSTypeLiteral(e))return e.members.flatMap(r=>(ne.isTSPropertySignature(r)||ne.isTSIndexSignature(r))&&ne.isTSTypeAnnotation(r.typeAnnotation)&&ne.isTSType(r.typeAnnotation.typeAnnotation)?ct(r.typeAnnotation.typeAnnotation,t,n):[]);if(ne.isTSMappedType(e)&&e.typeAnnotation!=null&&ne.isTSType(e.typeAnnotation))return ct(e.typeAnnotation,t,n);if(ne.isTSTypeReference(e)&&ne.isIdentifier(e.typeName)){let r=e.typeName.name;if((r==="Record"||r==="Readonly"||r==="Partial")&&ne.isTSTypeParameterInstantiation(e.typeArguments)){let s=r==="Record"?e.typeArguments.params[1]:e.typeArguments.params[0];if(s!==void 0&&ne.isTSType(s))return ct(s,t,n)}if(n.has(r))return[];let o=t.get(r);if(o===void 0)return[];let i=new Set(n);return i.add(r),ct(o,t,i)}return[]}function xn(e){let t=mo(e),n=new Map;for(let r of e.body){let o=Hn(r);if(ne.isVariableDeclaration(o))for(let i of o.declarations){if(!ne.isIdentifier(i.id)||!ne.isTSTypeAnnotation(i.id.typeAnnotation))continue;let s=[...new Set(ct(i.id.typeAnnotation.typeAnnotation,t))];s.length>0&&n.set(i.id.name,s)}}return n}function _n(e){let t=mo(e),n=new Map,r=(o,i)=>{if(!ne.isTSTypeAnnotation(i)||!ne.isTSType(i.typeAnnotation))return;let s=[...new Set(ct(i.typeAnnotation,t))];s.length>0&&n.set(o,s)};for(let o of e.body){let i=Hn(o);if(ne.isFunctionDeclaration(i)&&i.id!=null){r(i.id.name,i.returnType);continue}if(ne.isVariableDeclaration(i))for(let s of i.declarations)ne.isIdentifier(s.id)&&(ne.isArrowFunctionExpression(s.init)||ne.isFunctionExpression(s.init))&&r(s.id.name,s.init.returnType)}return n}import*as it from"@babel/types";import*as Ee from"@babel/types";function Ht(e,t){let n=[],r=[],o=-1;for(let s=0;s<e.length;s++)Ee.isJSXSpreadAttribute(e[s])&&(o=s);let i=[];for(let s=0;s<e.length;s++){let a=e[s];if(Ee.isJSXSpreadAttribute(a)){n.push(Ee.spreadElement(Ee.cloneNode(a.argument))),r.push(Ee.cloneNode(a.argument));continue}let l=Ae(a.name);if(l==="key"&&t.skipKey)continue;let d=Ps(a,t.fail),u=t.attributeValue?.(l,d)??d,c=/^on[A-Z]/.test(l)&&t.eventValue!==void 0?t.eventValue(l,u):u;n.push(Ee.objectProperty(Ee.isValidIdentifier(l)?Ee.identifier(l):Ee.stringLiteral(l),c,!1,Ee.isIdentifier(c)&&c.name===l)),r.push(Ee.cloneNode(d)),/^on[A-Z]/.test(l)&&s>o&&i.push(l)}return{expression:Ee.objectExpression(n),sources:r,safeEventKeys:i}}function Ae(e){return Ee.isJSXIdentifier(e)?e.name:`${e.namespace.name}:${e.name.name}`}function Ps(e,t){return e.value==null?Ee.booleanLiteral(!0):Ee.isStringLiteral(e.value)?Ee.cloneNode(e.value):Ee.isJSXExpressionContainer(e.value)&&Ee.isExpression(e.value.expression)?Ee.cloneNode(e.value.expression):t(`memo-dom: attribute '${Ae(e.name)}' must contain a JavaScript expression`)}function Cn(e,t,n=new Set){let r=e.importedComponents.get(t);if(r!==void 0)return new Set(r.subtreeReads??[]);if(n.has(t))return new Set;n.add(t);let o=new Set(e.compReads.get(t)??[]);for(let s of e.effects.get(t)??[]){for(let a of s.moduleReads)o.add(a);for(let a of s.conditionModuleReads)o.add(a)}let i=e.compPaths.get(t);return i!==void 0&&i.traverse({JSXElement(s){let a=s.node.openingElement.name;if(!(!it.isJSXIdentifier(a)||!/^[A-Z]/.test(a.name)))for(let l of Cn(e,a.name,n))o.add(l)}}),n.delete(t),o}function go(e){for(let[t,n]of e.compPaths){let r=e.compReads.get(t);r!==void 0&&n.traverse({JSXAttribute(o){let i=o.parentPath;if(!i?.isJSXOpeningElement())return;let s=i.node.name;if(!it.isJSXIdentifier(s))return;let a=Ae(o.node.name);if(e.componentProps.get(s.name)?.renderCallbacks.includes(a)!==!0)return;let l=o.node.value;!it.isJSXExpressionContainer(l)||!it.isExpression(l.expression)||Xe(l.expression,d=>{if(it.isJSXOpeningElement(d)&&it.isJSXIdentifier(d.name)&&/^[A-Z]/.test(d.name.name))for(let u of Cn(e,d.name.name))r.add(u)})}})}}import*as St from"@babel/types";function bo(e){for(let[t,n]of e.compPaths){let r=e.componentProps.get(t);n.traverse({JSXAttribute(o){if(Ae(o.node.name)!=="ref")return;let i=o.node.value;if(!(!St.isJSXExpressionContainer(i)||!St.isExpression(i.expression)))for(let s of ho(e,t,i.expression))r.refProps.includes(s)||r.refProps.push(s)}})}}function ho(e,t,n){let r=dt(e,t,n);if(r!==null)return[r];if(!St.isArrayExpression(n))return[];let o=[];for(let i of n.elements)i===null||St.isSpreadElement(i)||o.push(...ho(e,t,i));return o}import*as It from"@babel/types";function wn(e){let t=!1;return Xe(e,n=>{if(t||!It.isJSXOpeningElement(n))return;let r=n.name;!It.isJSXIdentifier(r)||!/^[a-z]/.test(r.name)||(t=n.attributes.some(o=>It.isJSXAttribute(o)&&It.isJSXIdentifier(o.name)&&/^on[A-Z]/.test(o.name.name)))}),t}import*as je from"@babel/types";function qn(e){let t=(r,o)=>{let i=_e(e,r),s=e.readers.get(i);s||e.readers.set(i,s=new Set);for(let a of o)s.add(a)};for(let[r,o]of e.compReads){if(o.size===0)continue;let i=Vn(e,r);for(let s of o)t(s,i)}for(let{owner:r,suffix:o,vars:i}of e.rowReads.values()){let s=Et(e,Ge(e,r).flatMap(a=>[`${a}/${o}/Row[*]`,`${a}/${o}/Row[*]/*`]));for(let a of i)t(a,s)}for(let{owner:r,suffix:o,vars:i}of e.condReads.values()){let s=Et(e,Ge(e,r).flatMap(a=>[`${a}/${o}`,`${a}/${o}/*`]));for(let a of i)t(a,s)}for(let[r,o]of e.effects){let i=Vn(e,r).filter(s=>!s.endsWith("/*"));for(let s of o){let a=i.map(d=>`${d}/$effects/${s.index}`),l=s.condition===null?a:a.map(d=>`${d}/$active`);for(let d of s.moduleReads)t(d,l);for(let d of s.conditionModuleReads)t(d,a)}}for(let r of e.moduleEffects){let o=r.condition===null?r.entityId:`${r.entityId}/$active`;for(let i of r.moduleReads)t(i,[o]);for(let i of r.conditionModuleReads)t(i,[r.entityId])}for(let[r,o]of e.computeds){let i=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#${r}`;for(let s of o.reads)t(s,[i])}for(let r of e.moduleControlFlow)for(let o of r.sources)t(o,[r.entityId]);if(e.readers.size===0)return null;let n=[...e.readers.entries()].sort(([r],[o])=>r<o?-1:1).map(([r,o])=>je.objectProperty(je.stringLiteral(r),je.arrayExpression([...o].sort().map(i=>je.stringLiteral(i)))));return je.expressionStatement(je.callExpression(Z(e,"installAccessTable"),[je.objectExpression([je.objectProperty(je.identifier("readers"),je.objectExpression(n))]),je.stringLiteral(e.rootId)]))}function yo(e,t){let n=t?.parentPath;if(!n?.isJSXAttribute())return!1;let r=n.parentPath;if(!r.isJSXOpeningElement())return!1;let o=r.node.name;if(!k.isJSXIdentifier(o)||!/^[A-Z]/.test(o.name))return!1;let i=n.node.name,s=k.isJSXIdentifier(i)?i.name:i.name.name;return e.componentProps.get(o.name)?.renderProps.includes(s)===!0}function Eo(e,t){let n=t.parentPath,r=n?.parentPath;if(!n?.isJSXExpressionContainer()||!r?.isJSXElement()&&!r?.isJSXFragment()&&!yo(e,n))throw t.buildCodeFrameError("memo-dom: conditional rendering must be a direct JSX child: <div>{cond ? <A/> : <B/>}</div>");t.skip()}function vs(e,t){for(let n of t.get("body"))if(!(!n.isImportDeclaration()||n.node.importKind==="type"))for(let r of n.node.specifiers){if(k.isImportSpecifier(r)&&r.importKind==="type")continue;let o=r.local.name;if(!(e.importedState.has(o)||e.importedFunctions.has(o)||e.importedComponents.has(o)))throw n.buildCodeFrameError(`memo-dom: value import '${o}' requires compileModules() so its reactive identity can be linked`)}}function ks(e,t){let n=xn(t.node);for(let r of t.node.body){let o=k.isExportNamedDeclaration(r)?r.declaration:r;if(k.isVariableDeclaration(o)){for(let i of o.declarations)if(k.isIdentifier(i.id)&&(o.kind==="let"||o.kind==="var"?mt(e,i.id.name,"let"):o.kind==="const"&&(Pt(i.init)?mt(e,i.id.name,"store"):vt(i.init)&&mt(e,i.id.name,"const")),e.state.has(i.id.name))){let s=n.get(i.id.name);s!==void 0&&e.stateTagCandidates.set(i.id.name,[...s])}}}}function Ns(e,t){t.traverse({FunctionDeclaration(n){let r=n.node.id?.name;if(r&&!e.comps.has(r)&&!e.helpers.has(r)&&!e.jsxHelpers.has(r))if(De(n))if(/^[A-Z]/.test(r)){e.comps.set(r,{parents:new Set,jsxCount:0}),e.compPaths.set(r,n),wn(n.node.body)&&e.componentsWithHostEvents.add(r);try{e.componentProps.set(r,rn(n.node.params))}catch(o){throw n.buildCodeFrameError(`memo-dom: invalid props for component '${r}': ${o instanceof Error?o.message:String(o)}`)}}else e.jsxHelpers.set(r,n);else e.helpers.set(r,n);n.skip()},VariableDeclarator(n){if(!n.scope.path.isProgram()||!k.isIdentifier(n.node.id))return;let r=n.get("init");(r.isArrowFunctionExpression()||r.isFunctionExpression())&&(ce(r.node.body)?/^[A-Z]/.test(n.node.id.name)||e.jsxHelpers.set(n.node.id.name,r):e.helpers.set(n.node.id.name,r),r.skip())}});for(let n of t.get("body")){let r=n.isExportNamedDeclaration()?n.get("declaration"):n;if(!(Array.isArray(r)||!r.isVariableDeclaration()))for(let o of r.get("declarations")){if(!o.isVariableDeclarator())continue;let i=o.node.id,s=o.get("init");!k.isIdentifier(i)||/^[A-Z]/.test(i.name)||Array.isArray(s)||!s.isArrowFunctionExpression()&&!s.isFunctionExpression()||!ce(s.node.body)||(e.helpers.delete(i.name),e.jsxHelpers.set(i.name,s))}}}function Pn(e,t,n=new Set){if(k.isTSStringKeyword(e)||k.isTSNumberKeyword(e)||k.isTSBooleanKeyword(e)||k.isTSBigIntKeyword(e)||k.isTSSymbolKeyword(e)||k.isTSNullKeyword(e)||k.isTSUndefinedKeyword(e)||k.isTSLiteralType(e))return!0;if(k.isTSParenthesizedType(e))return Pn(e.typeAnnotation,t,n);if(k.isTSUnionType(e))return e.types.every(r=>Pn(r,t,n));if(k.isTSTypeReference(e)&&k.isIdentifier(e.typeName)){let r=e.typeName.name;if(n.has(r))return!1;let o=new Set(n);o.add(r);for(let i of t.body){let s=k.isExportNamedDeclaration(i)?i.declaration:i;if(k.isTSTypeAliasDeclaration(s)&&s.id.name===r)return Pn(s.typeAnnotation,t,o)}}return!1}function Is(e,t){let n=l=>k.isStringLiteral(l)||k.isNumericLiteral(l)||k.isBooleanLiteral(l)||k.isBigIntLiteral(l)||k.isUnaryExpression(l)&&(l.operator==="+"||l.operator==="-")&&k.isNumericLiteral(l.argument);for(let l of e.node.params){if(k.isTSParameterProperty(l))continue;if(k.isAssignmentPattern(l)&&k.isIdentifier(l.left,{name:t})&&n(l.right))return!0;if(k.isAssignmentPattern(l)&&k.isObjectPattern(l.left)&&k.isObjectExpression(l.right)){let u=l.right.properties.find(c=>!k.isObjectProperty(c)||c.computed?!1:(k.isIdentifier(c.key)?c.key.name:k.isStringLiteral(c.key)?c.key.value:null)===t);if(k.isObjectProperty(u)&&k.isExpression(u.value)&&n(u.value))return!0}let d=k.isAssignmentPattern(l)?l.left:l;if(k.isObjectPattern(d))for(let u of d.properties){if(!k.isObjectProperty(u)||u.computed)continue;if((k.isIdentifier(u.key)?u.key.name:k.isStringLiteral(u.key)?u.key.value:null)===t&&k.isAssignmentPattern(u.value)&&n(u.value.right))return!0}}let r=e.node.params[0];if(r==null||k.isTSParameterProperty(r))return!1;let o=k.isAssignmentPattern(r)?r.left:r;if(!k.isIdentifier(o)&&!k.isObjectPattern(o)&&!k.isArrayPattern(o))return!1;let i=o.typeAnnotation;if(!k.isTSTypeAnnotation(i))return!1;let s=e.findParent(l=>l.isProgram());if(!s?.isProgram())return!1;let a=i.typeAnnotation;if(k.isTSTypeReference(a)&&k.isIdentifier(a.typeName)){let l=a.typeName.name,d=s.node.body.map(u=>k.isExportNamedDeclaration(u)?u.declaration:u).find(u=>(k.isTSInterfaceDeclaration(u)||k.isTSTypeAliasDeclaration(u))&&u.id.name===l);k.isTSInterfaceDeclaration(d)?a=k.tsTypeLiteral(d.body.body):k.isTSTypeAliasDeclaration(d)&&(a=d.typeAnnotation)}if(!k.isTSTypeLiteral(a))return!1;for(let l of a.members){if(!k.isTSPropertySignature(l)||l.computed)continue;if((k.isIdentifier(l.key)?l.key.name:k.isStringLiteral(l.key)?l.key.value:null)===t&&k.isTSTypeAnnotation(l.typeAnnotation))return Pn(l.typeAnnotation.typeAnnotation,s.node)}return!1}function Gn(e,t=new Set){if(ce(e.node))return!0;if(t.has(e.node))return!1;if(t.add(e.node),e.isIdentifier()){let n=e.scope.getBinding(e.node.name);if(n?.path.isVariableDeclarator()){let r=n.path.get("init");return!Array.isArray(r)&&r.node!=null?Gn(r,t):!1}}if(e.isMemberExpression()){let n=e.get("object");return!Array.isArray(n)&&Gn(n,t)}return!1}function Fs(e){let t=new Map;for(let[o,i]of e.compPaths){let s=new Set;if(t.set(o,s),i.traverse({JSXExpressionContainer(a){if(!a.parentPath?.isJSXElement()&&!a.parentPath?.isJSXFragment())return;let l=a.node.expression;if(!k.isExpression(l))return;let d=dt(e,o,l);d!==null&&(Is(i,d)||s.add(d))}}),(i.parentPath?.isExportNamedDeclaration()||i.parentPath?.isExportDefaultDeclaration())&&!e.linkedComponentRenderProps.has(o)){let a=e.componentProps.get(o);for(let l of s)a.renderProps.includes(l)||a.renderProps.push(l)}}let n=new Map;for(let[o,i]of e.compPaths)i.traverse({JSXElement(s){let a=s.node.openingElement.name;if(!k.isJSXIdentifier(a)||!e.comps.has(a.name))return;let l=e.componentProps.get(a.name),d=t.get(a.name);if(d===void 0)return;let u=n.get(a.name);u===void 0&&(u=new Map,n.set(a.name,u)),d.has("children")&&s.node.children.some(c=>!k.isJSXText(c)||c.value.trim()!=="")&&!l.renderProps.includes("children")&&(l.renderProps.push("children"),u.set("children",{scalar:!1,jsx:!0,at:s}));for(let c of s.get("openingElement").get("attributes")){if(!c.isJSXAttribute())continue;let g=c.node.name,x=k.isJSXIdentifier(g)?g.name:g.name.name;if(!d.has(x))continue;let y=u.get(x)??{scalar:!1,jsx:!1,at:c},f=c.get("value"),m=!1;if(f.isJSXExpressionContainer()&&k.isExpression(f.node.expression)){let w=f.get("expression");!Array.isArray(w)&&(Gn(w)||k.isExpression(w.node)&&dt(e,o,w.node)!==null)&&(m=!0)}m?y.jsx=!0:y.scalar=!0,u.set(x,y)}}});for(let[o,i]of n){let s=e.componentProps.get(o);for(let[a,l]of i){if(l.scalar&&l.jsx){if(a==="children"){s.renderProps.includes(a)||s.renderProps.push(a);continue}throw l.at.buildCodeFrameError(`memo-dom: prop '${a}' on <${o}> is used as both scalar data and JSX content`)}l.jsx?s.renderProps.includes(a)||s.renderProps.push(a):l.scalar&&(s.renderProps=s.renderProps.filter(d=>d!==a))}}let r=!0;for(;r;){r=!1;for(let[o,i]of e.compPaths){let s=e.componentProps.get(o);i.traverse({JSXAttribute(a){let l=a.get("value");if(!l.isJSXExpressionContainer()||!k.isExpression(l.node.expression))return;let d=dt(e,o,l.node.expression);if(d===null||s.renderProps.includes(d))return;let u=a.parentPath;if(!u.isJSXOpeningElement())return;let c=u.node.name;if(!k.isJSXIdentifier(c)||!/^[A-Z]/.test(c.name))return;let g=e.componentProps.get(c.name),x=a.node.name,y=k.isJSXIdentifier(x)?x.name:x.name.name;g?.renderProps.includes(y)===!0&&(s.renderProps.push(d),r=!0)}})}}for(let[o,i]of e.linkedComponentRenderProps){let s=e.componentProps.get(o);s!==void 0&&(s.renderProps=[...i])}}function Rs(e,t){let n=e.compPaths.get(t),r=e.comps.get(t);n.traverse({JSXElement(o){let i=o.node.openingElement;if(!k.isJSXIdentifier(i.name))throw o.buildCodeFrameError("memo-dom: namespaced or member-expression JSX tags are not supported (L1)");for(let a of i.attributes)if(!k.isJSXSpreadAttribute(a)&&a.name.name==="key"){if(Pr(e,o))continue;throw o.buildCodeFrameError("memo-dom: key={...} is only meaningful on list rows: items.map(item => <Row key={item.id} />)")}let s=i.name.name;if(/^[A-Z]/.test(s)){let a=e.comps.has(s);if(!a&&!e.importedComponents.has(s))throw o.buildCodeFrameError(`memo-dom: <${s} /> is not a linked component factory`);a&&e.comps.get(s).parents.add(t);let l=e.childRefCounts.get(t);l||e.childRefCounts.set(t,l=new Map),l.set(s,(l.get(s)??0)+1),(o.node.children.some(d=>!k.isJSXText(d)||d.value.trim()!=="")||i.attributes.some(d=>{if(k.isJSXSpreadAttribute(d)||e.componentProps.get(s)?.renderProps.includes(k.isJSXIdentifier(d.name)?d.name.name:d.name.name.name)!==!0)return!1;let u=$e(d.value);return u!==null&&ce(u)}))&&e.renderSlotOwners.add(t);return}r.jsxCount++},ConditionalExpression(o){De(o)&&Eo(e,o)},LogicalExpression(o){if(De(o)){if(o.node.operator!=="&&"&&o.node.operator!=="||")throw o.buildCodeFrameError("memo-dom: only && / || conditionals are supported (R8 L1), not ??");Eo(e,o)}},CallExpression(o){let i=Oe(o.node);if(i&&(De(o)||Rt(e,t,i)!==null)){let s=o.parentPath,a=s?.parentPath;if(!s?.isJSXExpressionContainer()||!a?.isJSXElement()&&!a?.isJSXFragment()&&!yo(e,s))throw o.buildCodeFrameError("memo-dom: list rendering must be a direct JSX child: <ul>{items.map(item => <Row />)}</ul>");o.skip()}}})}function Ds(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}function Ms(e,t){let n=ye(t.node);if(!n||!n.includes("."))return null;let r=n.split(".")[0];if(e.state.get(r)!=="store"||t.scope.getBinding(r)?.scope.path.isProgram()!==!0)return null;let o=t.parentPath;return o.isAssignmentExpression({operator:"="})&&o.node.left===t.node||Ds(t)?null:n}function Ls(e){for(let[a]of e.comps){let g=function(S,I,$){let F=Oe(S.node);if(F===null||!De(S))return;let N=kt(e,F,S,a,$),K=`${I}/${N.suffix}`;if(N.form==="component"){let _=e.listedSites.get(N.rowComp)??[];_.some(V=>V.owner===a&&V.suffix===K)||_.push({owner:a,suffix:K,itemParam:N.itemParam,keyExpr:N.keyExpr,sourceKey:N.sourceKey,sourceLocal:N.sourceLocal}),e.listedSites.set(N.rowComp,_)}else m(S,N,K);S.skip()},x=function(S,I,$){let F=S.node.openingElement.name;if(!k.isJSXIdentifier(F)||!/^[A-Z]/.test(F.name))return;if(!e.comps.has(F.name)&&!e.importedComponents.has(F.name))throw S.buildCodeFrameError(`memo-dom: <${F.name} /> is not a linked component factory`);let N=$.get(F.name)??0;$.set(F.name,N+1);let K=N===0?F.name:`${F.name}[${N}]`,_=`${I}/${K}`,V=e.conditionalComponentSites.get(F.name)??[];V.some(O=>O.owner===a&&O.suffix===_)||V.push({owner:a,suffix:_}),e.conditionalComponentSites.set(F.name,V)},y=function(S,I,$){let F=S.node.openingElement.name;if(!k.isJSXIdentifier(F)||!/^[A-Z]/.test(F.name))return;if(!e.comps.has(F.name)&&!e.importedComponents.has(F.name))throw S.buildCodeFrameError(`memo-dom: <${F.name} /> is not a linked component factory`);let N=$.get(F.name)??0;$.set(F.name,N+1);let K=N===0?F.name:`${F.name}[${N}]`,_=`${I}/Row[*]/${K}`,V=e.rowComponentSites.get(F.name)??[];V.some(O=>O.owner===a&&O.suffix===_)||V.push({owner:a,suffix:_}),e.rowComponentSites.set(F.name,V)},f=function(S,I){let $=e.listedSites.get(S.rowComp)??[];$.some(F=>F.owner===a&&F.suffix===I)||$.push({owner:a,suffix:I,itemParam:S.itemParam,keyExpr:S.keyExpr,sourceKey:S.sourceKey,sourceLocal:S.sourceLocal}),e.listedSites.set(S.rowComp,$)},m=function(S,I,$){let F=S.get("arguments")[0];if(F===void 0)return;let N=new Set,K=new Map,_=new Map;F.traverse({Identifier(V){V.node.name!==I.itemParam&&e.state.has(V.node.name)&&V.scope.getBinding(V.node.name)?.scope.path.isProgram()===!0&&N.add(V.node.name)},JSXElement(V){y(V,$,K)},CallExpression(V){let O=Oe(V.node);if(O!==null&&De(V)){let te=kt(e,O,V,a,_,I),q=`${$}/Row[*]/${te.suffix}`;te.form==="component"?f(te,q):m(V,te,q),V.skip();return}let le=V.node.callee;if(k.isIdentifier(le)&&(e.helpers.has(le.name)||e.importedFunctions.has(le.name))){let te=e.importedFunctions.get(le.name)??We(e,le.name);for(let q of te.reads)N.add(q)}}}),N.size>0&&e.rowReads.set(`${a}/${$}`,{owner:a,suffix:$,vars:N})},w=function(S,I=null){let $=S.node;if(!De(S))return;let F=ln($,S,c),N=I===null?F.suffix:`${I}/${F.suffix}`,K=[];if(S.isConditionalExpression()){let V=S;for(;V.isConditionalExpression();)K.push(V.get("consequent")),V=V.get("alternate");K.push(V)}else K.push(S.get("right"));for(let V of K){let O=new Map,le=new Map;if((V.isConditionalExpression()||V.isLogicalExpression())&&De(V)){w(V,N);continue}V.isJSXElement()&&x(V,N,le),V.traverse({ConditionalExpression(te){De(te)&&(w(te,N),te.skip())},LogicalExpression(te){De(te)&&(w(te,N),te.skip())},JSXElement(te){x(te,N,le)},CallExpression(te){g(te,N,O)}})}let _=tn(e,$);_.size>0&&I===null&&e.condReads.set(`${a}/${N}`,{owner:a,suffix:N,vars:_}),S.skip()};var t=g,n=x,r=y,o=f,i=m,s=w;let l=e.compPaths.get(a),d=new Set,u=new Map,c={count:0};l.traverse({JSXAttribute(S){let I=S.node.name;(k.isJSXIdentifier(I,{name:"ref"})||k.isJSXNamespacedName(I)&&I.namespace.name==="ref")&&S.skip()},ConditionalExpression(S){w(S)},LogicalExpression(S){w(S)},CallExpression(S){if(k.isIdentifier(S.node.callee,{name:"effect"})&&S.scope.getBinding("effect")===void 0){S.skip();return}let I=Oe(S.node);if(I&&(De(S)||Rt(e,a,I)!==null)){let F=kt(e,I,S,a,u),N=so(F,e.instanceState.get(a)??new Set);if(N.length>0&&k.isIdentifier(F.sourceExpr)){let K=F.sourceExpr.name;e.targetedListDependencies.set(I,N.map(V=>({source:K,value:V}))),e.targetedListComponents.add(a);let _=new Set([...e.instanceReasonIds.get(a)?.keys()??[],K,...N]);e.instanceReasonIds.set(a,new Map([..._].sort().map((V,O)=>[V,O])))}if(F.sourceLocal||d.add(F.sourceKey),F.form==="component"){for(let _ of F.jsx.openingElement.attributes){if(k.isJSXSpreadAttribute(_))continue;let V=_,O=k.isJSXIdentifier(V.name)?V.name.name:`${V.name.namespace.name}:${V.name.name.name}`;if(O==="key"||O==="ref"||e.componentProps.get(F.rowComp)?.refProps.includes(O)===!0)continue;let le=$e(V.value);le&&Xe(le,te=>{if(k.isIdentifier(te)&&e.state.has(te.name)&&S.scope.getBinding(te.name)?.scope.path.isProgram()===!0&&d.add(te.name),k.isMemberExpression(te)){let q=ye(te);if(q!==null&&q.includes(".")){let Q=q.split(".")[0];e.state.get(Q)==="store"&&S.scope.getBinding(Q)?.scope.path.isProgram()===!0&&d.add(q)}}})}let K=e.listedSites.get(F.rowComp)??[];K.some(_=>_.owner===a&&_.suffix===F.suffix)||K.push({owner:a,suffix:F.suffix,itemParam:F.itemParam,keyExpr:F.keyExpr,sourceKey:F.sourceKey,sourceLocal:F.sourceLocal}),e.listedSites.set(F.rowComp,K)}else m(S,F,F.suffix);S.skip();return}let $=S.node.callee;if(k.isIdentifier($)&&(e.helpers.has($.name)||e.importedFunctions.has($.name))&&S.scope.getBinding($.name)?.scope.path.isProgram()===!0){let F=e.importedFunctions.get($.name)??We(e,$.name);for(let N of F.reads)d.add(N)}},Identifier(S){if(!e.state.has(S.node.name)||S.scope.getBinding(S.node.name)?.scope.path.isProgram()!==!0)return;let I=S.parentPath;I.isAssignmentExpression({operator:"="})&&I.node.left===S.node||d.add(S.node.name)},MemberExpression(S){let I=Ms(e,S);I!==null&&d.add(I)}}),e.compReads.set(a,d)}}function vn(e,t){vs(e,t),ks(e,t),Ns(e,t),bo(e),vr(e),ro(e),uo(e,t),Fs(e),Qr(e),fo(e),oo(e),Ur(e),Kr(e,t),zr(e,t,Bn),Hr(e),qr(e),Gr(e),$r(e,t);for(let[r]of e.comps)Rs(e,r);Ls(e),go(e);for(let[r]of e.comps)Ge(e,r);let n=new Set([...e.listedSites.keys(),...e.linkedComponentRows.keys()]);for(let r of n){if(e.importedComponents.has(r))continue;let o=e.listedSites.get(r)??[],i=e.compPaths.get(r);if((o.length>0||e.linkedComponentRows.has(r))&&(e.comps.get(r).parents.size>0||(e.conditionalComponentSites.get(r)?.length??0)>0))throw i.buildCodeFrameError(`memo-dom: <${r}> is used both as a list row and as a static child \u2014 split it into two components (R7 L1)`)}}import*as D from"@babel/types";import*as h from"@babel/types";import*as Ce from"@babel/types";import*as se from"@babel/types";function Ft(){return{writes:new Set,rootFallback:!1,rowLocal:!1,rowOwnerLocal:!1,instanceLocal:!1,instanceWrites:new Set,eventOrigin:null}}function ut(e,t){e.instanceLocal=!0,e.instanceWrites.add(t)}function At(e,t,n,r){let o=t.rowLocal&&r!==void 0?se.expressionStatement(r.refreshVar!==void 0?se.callExpression(se.identifier(r.refreshVar),[]):se.callExpression(Z(e,"markDirty"),[se.identifier(r.rowIdVar)])):null,i=null;if(t.instanceLocal&&n!==null){let d=e.instanceReasonIds.get(n),u=[...t.instanceWrites].map(g=>d?.get(g)).filter(g=>g!==void 0).sort((g,x)=>g-x),c=t.instanceWrites.size>0&&u.length===t.instanceWrites.size;i=se.expressionStatement(se.callExpression(Z(e,"markDirty"),[Le(e,n),...c?[u.length===1?se.numericLiteral(u[0]):hr(e,u)]:[]]))}let s=t.rowOwnerLocal&&r?.ownerIdVar!==void 0?se.expressionStatement(se.callExpression(Z(e,"markDirty"),[se.identifier(r.ownerIdVar)])):null,a=d=>{let u=[];return t.eventOrigin!==null&&u.push(t.eventOrigin),o!==null&&u.push(o),s!==null&&u.push(s),i!==null&&u.push(i),d!==null&&u.push(d),u.length===0?null:u.length===1?u[0]:se.blockStatement(u)};if(t.rootFallback)return a(se.expressionStatement(se.callExpression(Z(e,"markDirtySubtree"),[se.stringLiteral(e.rootId)])));if(t.writes.size===0)return a(null);let l=[...t.writes].sort();return a(se.expressionStatement(se.callExpression(Z(e,"commitWrites"),[Tt(e,l)])))}function So(e,t,n){if(se.isBlockStatement(t.body)){Zn(t.body,n),t.body.body.push(n);return}let r=j(e,"returnValue");t.body=se.blockStatement([se.variableDeclaration("const",[se.variableDeclarator(r,t.body)]),n,se.returnStatement(se.cloneNode(r))])}function Zn(e,t){if(!se.isFunction(e))for(let n of se.VISITOR_KEYS[e.type]??[]){let r=e[n];if(Array.isArray(r))for(let o=0;o<r.length;o++){let i=r[o];!i||typeof i!="object"||!("type"in i)||se.isFunction(i)||(se.isReturnStatement(i)?(r.splice(o,0,se.cloneNode(t)),o++):Zn(i,t))}else if(r&&typeof r=="object"&&"type"in r){if(se.isFunction(r))continue;se.isReturnStatement(r)?e[n]=se.blockStatement([se.cloneNode(t),r]):Zn(r,t)}}}import*as Se from"@babel/types";function xt(e,t,n,r){if(r===void 0&&n?.refreshVar!==void 0)return Se.expressionStatement(Se.callExpression(Se.identifier(n.refreshVar),[]));let o=r??(n!==void 0?Se.identifier(n.rowIdVar):t!==null?Le(e,t):Se.stringLiteral(e.rootId));return Se.expressionStatement(Se.callExpression(Z(e,"markDirty"),[Se.cloneNode(o)]))}function jt(e,t,n){let r=j(e,"event"),o=j(e,"returnValue");return Se.arrowFunctionExpression([r],Se.blockStatement([Se.variableDeclaration("const",[Se.variableDeclarator(o,Se.callExpression(Se.cloneNode(t),[Se.cloneNode(r)]))]),n,Se.returnStatement(Se.cloneNode(o))]))}import wo from"@babel/traverse";import*as Y from"@babel/types";function As(e,t,n){if(n.key===null)return null;let r=e.componentProps.get(t);if(r===void 0)return null;let o=Ve(r);if(n.root===o){let[s,...a]=n.key.split(".").slice(1);return s===void 0?null:{name:s,path:a}}let i=He(r,n.root);return i===null?null:{name:i,path:n.key.split(".").slice(1)}}function Yn(e,t,n,r,o){let i=As(e,t,r);if(i===null)return!1;n===void 0?ut(o,r.root):o.rowLocal=!0;let s=e.linkedComponentPropSources.get(t)?.get(i.name);if(s===void 0)return o.rootFallback=!0,!0;o.rootFallback||=s.rootFallback;let a=i.path.length===0?"":`.${i.path.join(".")}`;for(let l of s.keys)o.writes.add(`${l}${a}`);return!0}import*as he from"@babel/types";function kn(e){return he.isIdentifier(e)||he.isObjectPattern(e)||he.isArrayPattern(e)||he.isAssignmentPattern(e)||he.isRestElement(e)}function js(e){let t=e;for(;he.isTSAsExpression(t)||he.isTSTypeAssertion(t)||he.isTSNonNullExpression(t)||he.isTSSatisfiesExpression(t);)t=t.expression;return t}function _t(e,t,n){if(he.isIdentifier(t)){e.set(t.name,n);return}if(he.isAssignmentPattern(t)){kn(t.left)&&_t(e,t.left,n);return}if(!he.isRestElement(t)){if(he.isArrayPattern(t)){for(let r=0;r<t.elements.length;r++){let o=t.elements[r];kn(o)&&_t(e,o,bt(n,[String(r)]))}return}if(he.isObjectPattern(t))for(let r of t.properties){if(he.isRestElement(r))continue;if(r.computed||!he.isIdentifier(r.key)&&!he.isStringLiteral(r.key)&&!he.isNumericLiteral(r.key)){kn(r.value)&&_t(e,r.value,{...n,key:null});continue}let o=he.isIdentifier(r.key)?r.key.name:String(r.key.value);kn(r.value)&&_t(e,r.value,bt(n,[o]))}}}function xo(e,t,n,r){let o=js(r),i=e.componentProps.get(t);if(i===void 0)return null;if(he.isIdentifier(o)){let d=n.get(o.name);return d!==void 0?d:Ve(i)===o.name?{locality:"prop",root:o.name,key:o.name}:He(i,o.name)===null?null:{locality:"prop",root:o.name,key:o.name}}if(!he.isMemberExpression(o))return null;let s=we(o),a=ye(o);if(s===null)return null;let l=xo(e,t,n,he.identifier(s));return l===null?null:a===null?{...l,key:null}:bt(l,a.split(".").slice(1))}function Co(e,t){let n=new Map;for(let r of e.instanceDerivations.get(t)??[]){let o=xo(e,t,n,r.source);o!==null&&_t(n,r.target,o)}return n}var Po=wo.default??wo;function Js(e,t){let n=new Set;for(let[r,o]of e.compReads)o.has(t)&&n.add(r);for(let r of e.rowReads.values())r.vars.has(t)&&n.add("__rows__");for(let r of e.condReads.values())r.vars.has(t)&&n.add("__regions__");return n}function vo(e,t,n){if(n.sourceLocal)return!0;let r=n.sourceKey;if(r==="")return!0;for(let i of e.computeds.values())if(i.reads.has(r))return!0;let o=new Set((e.listedSites.get(t??"")??[]).map(i=>i.owner));o.size===0&&t!==null&&o.add(t);for(let i of Js(e,r))if(i==="__rows__"||i==="__regions__"||!o.has(i))return!0;return!1}function qt(e,t,n,r,o=!1,i,s=!1){let a=Y.cloneNode(t),l=a,d=Y.file(Y.program([Y.isFunctionDeclaration(a)?a:Y.expressionStatement(a)])),u=n!==null?e.instanceState.get(n):void 0,c=n!==null?e.instanceDerivedBindings.get(n):void 0,g=n===null?new Map:Co(e,n),x=n!==null?new Set(e.componentProps.get(n)?.bindings??[]):new Set,y=new Set([...x,...u??[],...c??[]]);if(n!==null)for(let E of e.compPaths.get(n)?.node.body.body??[])if(Y.isVariableDeclaration(E))for(let C of E.declarations)for(let M of Object.keys(Y.getBindingIdentifiers(C.id)))y.add(M);else Y.isFunctionDeclaration(E)&&E.id&&y.add(E.id.name);let f=new Dt((E,C)=>{if(C!==void 0)return null;let M=g.get(E);if(M!==void 0)return M;if(r!==void 0&&E===r.itemParam)return{locality:"row",root:E,key:E};if(u?.has(E)===!0)return{locality:"instance",root:E,key:E};if(x.has(E))return{locality:"prop",root:E,key:E};if(y.has(E))return null;let ie=e.state.get(E);return ie===void 0?null:dn(E,ie)}),m=E=>E.stateKind==="computed"||e.state.get(E.root)==="computed",w=new Set;for(let E of a.params)Y.isIdentifier(E)&&w.add(E.name);Po(d,{VariableDeclarator(E){Y.isIdentifier(E.node.id)&&(w.add(E.node.id.name),E.parentPath.isVariableDeclaration()&&f.trackDeclarator(E.scope,E.node))},Function(E){for(let C of E.node.params)Y.isIdentifier(C)&&w.add(C.name)}});let S=new Map,I=new Map,$=E=>{let C=E.getFunctionParent()?.node??l,M=S.get(C);return M||S.set(C,M=Ft()),M},F=(E,C)=>{if(C($(E)),!s||E.getFunctionParent()?.node!==l)return;let M=I.get(E.node);M===void 0&&(M={path:E,writes:Ft()},I.set(E.node,M)),C(M.writes)},N=E=>{F(E,C=>{r?.sourceLocal?C.rowOwnerLocal=!0:r!==void 0&&C.writes.add(r.sourceKey)})},K=E=>{if(r===void 0)return null;let C=E.split(".").slice(1);return r.itemPath.some((M,ie)=>C[ie]!==M)?null:C.slice(r.itemPath.length)},_=(E,C)=>{F(E,M=>{C!==void 0&&n!==null&&Yn(e,n,r,C,M)||(M.rowLocal=!0,M.rootFallback=!0)})},V=(E,C)=>{F(E,M=>{(n===null||!Yn(e,n,r,C,M))&&(r===void 0?(n!==null&&ut(M,C.root),M.rootFallback=!0):(M.rowLocal=!0,M.rootFallback=!0))})},O=(E,C)=>{if(r===void 0||we(C)!==r.itemParam)return!1;let M=ye(C);if(M===null)return r.itemPath.length===0?N(E):_(E),!0;let ie=M.split(".").slice(1);return r.itemPath.some((Je,Re)=>ie[Re]!==Je)?!1:(ie.splice(0,r.itemPath.length),Mn(ie,r.keyPath)?N(E):(F(E,Je=>{Je.rowLocal=!0}),vo(e,n,r)&&N(E)),!0)},le=(E,C)=>{if(C.locality==="instance"){F(E,M=>{ut(M,C.root)});return}if(C.locality==="row"){if(r===void 0){F(E,ie=>{ie.rootFallback=!0});return}if(C.key===null){r.itemPath.length===0?N(E):_(E);return}let M=K(C.key);if(M===null){_(E,C);return}Mn(M,r.keyPath)?N(E):(F(E,ie=>{ie.rowLocal=!0}),vo(e,n,r)&&N(E));return}if(C.locality==="prop"){V(E,C);return}if(C.stateKind==="computed")throw E.buildCodeFrameError(`memo-dom: cannot mutate computed '${C.root}' (R13) - it is derived; write its SOURCE state instead`);if(C.stateKind!=="store"){F(E,M=>{M.writes.add(C.root)});return}C.key!==null&&C.key.includes(".")?F(E,M=>{M.writes.add(C.key)}):F(E,M=>{M.writes.add(C.root)})},te=(E,C)=>{if(C.locality==="instance"){F(E,M=>{ut(M,C.root)});return}if(C.locality==="row"){if(r===void 0){F(E,Je=>{Je.rootFallback=!0});return}if(C.key===null){r.itemPath.length===0?N(E):_(E);return}let M=K(C.key);if(M===null){_(E,C);return}M.length===0&&(r.keyPath===null||r.keyPath.length>0)?N(E):le(E,C);return}if(C.locality==="prop"){V(E,C);return}if(C.stateKind==="computed")throw E.buildCodeFrameError(`memo-dom: cannot mutate computed '${C.root}' (R13) - write its SOURCE state instead`);F(E,M=>{M.writes.add(C.key??C.root)})},q=(E,C)=>{if(!(s&&E.getFunctionParent()?.node===l))for(let M of un(C)){if(!Y.isIdentifier(M))continue;let ie=f.resolveExpression(E.scope,M);ie!==null&&(m(ie)||te(E,ie))}},Q=(E,C)=>{let M=we(C);if(M!==void 0&&u?.has(M??"")===!0){F(E,Re=>{ut(Re,M)});return}if(M!==null&&c?.has(M)&&!g.has(M))throw E.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${M}' (R14) \u2014 write its source instead`);if(O(E,C))return;let ie=f.resolveExpression(E.scope,C);if(ie!==null){le(E,ie);return}if(M!==null&&x.has(M)){V(E,{locality:"prop",root:M,key:ye(C)});return}if(M!==null&&y.has(M)||!M||!e.state.has(M))return;let Je=e.state.get(M);if(Je==="computed")throw E.buildCodeFrameError(`memo-dom: cannot mutate computed '${M}' (R13) \u2014 it is derived; write its SOURCE state instead`);F(E,Re=>{if(Je!=="store"){Re.writes.add(M);return}let rt=ye(C);rt!==null&&rt.includes(".")?Re.writes.add(rt):Re.writes.add(M)})};Po(d,{VariableDeclarator(E){if(!Y.isIdentifier(E.node.id)&&E.node.init!==null)for(let C of f.referencedOrigins(E.scope,E.node.init))te(E,C)},AssignmentExpression(E){let C=E.node.left;if(Y.isIdentifier(C)){if(w.has(C.name)){if(Y.isIdentifier(E.node.right)){let ie=f.resolveExpression(E.scope,E.node.right);ie!==null&&te(E,ie)}return}if(c?.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot assign per-instance derivation '${C.name}' (R14) \u2014 write its source instead`);if(u?.has(C.name)===!0){F(E,ie=>{ut(ie,C.name)});return}if(x.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot assign prop '${C.name}' \u2014 copy it to component-local let state first`);if(y.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot assign component-local const '${C.name}'`);let M=e.state.get(C.name);if(!M)throw E.buildCodeFrameError(`memo-dom: handler assigns '${C.name}', which is neither module state nor a handler local \u2014 declare it at module level (let) or inside the handler`);if(e.importedState.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot reassign imported state '${C.name}' - ES module imports are read-only; export a mutator or mutate an imported store property`);if(M==="store")throw E.buildCodeFrameError(`memo-dom: cannot reassign store '${C.name}' \u2014 assign a property (${C.name}.field = \u2026) instead`);if(M==="const")throw E.buildCodeFrameError(`memo-dom: cannot reassign mutable const root '${C.name}' - mutate the object instead`);if(M==="computed")throw E.buildCodeFrameError(`memo-dom: cannot assign computed '${C.name}' (R13) \u2014 it is derived; write its SOURCE state instead and the derivation recomputes`);F(E,ie=>{ie.writes.add(C.name)})}else if(Y.isMemberExpression(C))Q(E,C);else for(let M of f.referencedOrigins(E.scope,E.node.right))te(E,M)},UpdateExpression(E){let C=E.node.argument;if(Y.isIdentifier(C)){if(w.has(C.name))return;if(c?.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot update per-instance derivation '${C.name}' (R14) \u2014 write its source instead`);if(u?.has(C.name)===!0){F(E,ie=>{ut(ie,C.name)});return}if(x.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot update prop '${C.name}' \u2014 copy it to component-local let state first`);if(y.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot update component-local const '${C.name}'`);let M=e.state.get(C.name);if(!M)throw E.buildCodeFrameError(`memo-dom: handler updates '${C.name}', which is neither module state nor a handler local`);if(e.importedState.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot update imported state '${C.name}' - ES module imports are read-only; call an exported mutator instead`);if(M!=="let")throw E.buildCodeFrameError(M==="computed"?`memo-dom: cannot update computed '${C.name}' (R13) \u2014 it is derived; write its SOURCE state instead`:`memo-dom: cannot update '${C.name}' \u2014 it is a const binding; mutate its contents instead`);F(E,ie=>{ie.writes.add(C.name)})}else Y.isMemberExpression(C)&&Q(E,C)},UnaryExpression(E){E.node.operator==="delete"&&Y.isMemberExpression(E.node.argument)&&Q(E,E.node.argument)},CallExpression(E){let C=E.node.callee;if(Y.isMemberExpression(C)){if(pn(C)==="assign"&&Y.isIdentifier(C.object,{name:"Object"})){let Re=E.node.arguments[0],rt=Re!==void 0&&Y.isExpression(Re)?f.resolveExpression(E.scope,Re):null;if(rt!==null)if(rt.locality==="module"&&rt.stateKind==="store"){let br=cn(rt,E.node.arguments.slice(1));br===null?te(E,rt):F(E,vi=>{for(let ki of br)vi.writes.add(ki)})}else le(E,rt);return}let ie=Y.isIdentifier(C.object)?C.object.name:Y.isMemberExpression(C.object)?we(C.object):null;if(ie!==null&&c?.has(ie)&&!g.has(ie))throw E.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${ie}' (R14) - write its source instead`);let Je=Y.isExpression(C.object)?f.resolveExpression(E.scope,C.object):null;Je!==null?te(E,Je):q(E,E.node.arguments);return}if(Y.isIdentifier(C)&&!y.has(C.name)&&(e.helpers.has(C.name)||e.importedFunctions.has(C.name))){let M=e.importedFunctions.get(C.name)??We(e,C.name);F(E,ie=>{for(let Re of M.writes)ie.writes.add(Re);for(let Re of M.boundedWrites)ie.writes.add(Re);let Je=s&&E.getFunctionParent()?.node===l;M.unbounded&&!Je&&(ie.rootFallback=!0)});for(let ie of M.parameterWrites){let Je=E.node.arguments[ie.index];if(Je===void 0||!Y.isExpression(Je))continue;let Re=f.resolveExpression(E.scope,Je);if(Re!==null){if(m(Re))continue;te(E,bt(Re,ie.path))}}return}q(E,E.node.arguments)}});let ee=S.has(l);if(e.handlerHasRootCommit.set(t,ee),o&&!S.has(l)){let E=Ft();E.eventOrigin=xt(e,n,r,i),S.set(l,E)}let oe=[];if(s)for(let E of I.values()){let C=At(e,E.writes,n,r);C!==null&&oe.push({...E,commit:C})}for(let E of oe)E.flag=j(e,"didWrite");oe.sort((E,C)=>ko(C.path)-ko(E.path)).forEach(E=>$s(E.path,E.flag));for(let[E,C]of S){let M=s&&E===l?oe.length===0?null:Y.blockStatement(oe.map(ie=>Y.ifStatement(Y.cloneNode(ie.flag),Y.cloneNode(ie.commit)))):At(e,C,n,r);M&&So(e,E,M)}if(oe.length>0){if(!Y.isBlockStatement(a.body))throw new Error("memo-dom: execution-aware callback commit did not produce a block body");a.body.body.unshift(Y.variableDeclaration("let",oe.map(E=>Y.variableDeclarator(Y.cloneNode(E.flag),Y.booleanLiteral(!1)))))}t.body=a.body}function ko(e){let t=0,n=e;for(;n.parentPath!==null;)t++,n=n.parentPath;return t}function $s(e,t){let n=Y.assignmentExpression("=",Y.cloneNode(t),Y.booleanLiteral(!0));if(e.isVariableDeclarator()){let r=e.node.init;if(r===null||!Y.isExpression(r))throw new Error("memo-dom: execution-aware variable site has no expression initializer");e.node.init=Y.sequenceExpression([n,r]);return}if(!e.isExpression())throw new Error(`memo-dom: unsupported execution-aware write site '${e.node.type}'`);e.replaceWith(Y.sequenceExpression([n,e.node]))}import*as st from"@babel/types";function No(e,t){let n=!1,r=!0,o=i=>{if(r&&!(i!==e&&st.isFunction(i))){if((st.isCallExpression(i)||st.isOptionalCallExpression(i))&&(n=!0,!st.isIdentifier(i.callee)||!t(i.callee.name))){r=!1;return}for(let s of st.VISITOR_KEYS[i.type]??[]){let a=i[s];if(Array.isArray(a))for(let l of a)l!==null&&typeof l=="object"&&"type"in l&&o(l);else a!==null&&typeof a=="object"&&"type"in a&&o(a)}}};return o(e),n&&r}function pt(e,t){let r=e.scope.getBinding(t)?.path;if(!r||r.getFunctionParent()!==e)return null;if(r.isFunctionDeclaration())return r.node;if(!r.isVariableDeclarator())return null;let o=r.node.init;return o&&(Ce.isArrowFunctionExpression(o)||Ce.isFunctionExpression(o))?o:null}function nt(e,t,n,r,o,i=!1){e.analyzedFunctions.has(n)||(Qn(e,t,n,r,o),e.analyzedFunctions.add(n),qt(e,n,r,o,!1,void 0,i))}function Gt(e,t,n=!1){e.analyzedFunctions.has(t)||(e.analyzedFunctions.add(t),qt(e,t,null,void 0,!1,void 0,n))}function Qn(e,t,n,r,o){let i=new Set;Xe(n.body,s=>{Ce.isCallExpression(s)&&Ce.isIdentifier(s.callee)&&i.add(s.callee.name)});for(let s of i){let a=pt(t,s);a===null||e.analyzedFunctions.has(a)||(e.analyzedFunctions.add(a),Qn(e,t,a,r,o),qt(e,a,r,o,!1))}}function er(e,t,n,r,o,i,s){let a=null,l=!1,d=e.componentProps.get(o),u=d===void 0?null:Ve(d);if(d!==void 0&&(Ce.isIdentifier(n)&&He(d,n.name)!==null||Ce.isMemberExpression(n)&&u!==null&&we(n)===u))return jt(e,n,xt(e,o,i,s));if(Ce.isArrowFunctionExpression(n)||Ce.isFunctionExpression(n))a=n;else if(Ce.isIdentifier(n)){let g=e.importedFunctions.get(n.name);if(g!==void 0){let f=Ft();for(let m of g.writes)f.writes.add(m);for(let m of g.boundedWrites)f.writes.add(m);return f.rootFallback=g.unbounded,jt(e,n,At(e,f,null)??xt(e,o,i,s))}let x=t.scope.getBinding(n.name),y=x?.path;if(y&&y.isVariableDeclarator()){let f=y.node.init;f&&(Ce.isArrowFunctionExpression(f)||Ce.isFunctionExpression(f))&&(a=f,l=x?.scope.path.isProgram()===!0&&e.helpers.has(n.name))}else y&&y.isFunctionDeclaration()&&(e.helpers.has(n.name)?(a=y.node,l=!0):a=pt(t,n.name));if(!a)throw t.buildCodeFrameError(`memo-dom: cannot resolve handler '${n.name}' \u2014 use an inline arrow, a component-local const, or a module-level function (L1)`)}else throw t.buildCodeFrameError(`memo-dom: unsupported ${r} handler form \u2014 expected an arrow function or a function reference (L1)`);if(Ce.isBlockStatement(a.body)||(a.body=Ce.blockStatement([Ce.expressionStatement(a.body)])),!e.analyzedFunctions.has(a)){l||Qn(e,t,a,o,i);let g=!l&&!Ce.isIdentifier(n)&&No(a,x=>{let y=pt(t,x);return y!==null&&e.handlerHasRootCommit.get(y)===!0});e.analyzedFunctions.add(a),qt(e,a,l?null:o,l?void 0:i,!l&&!Ce.isIdentifier(n)&&!g,s)}if(l){let g=We(e,n.name);if(a.async){let x=Ft();for(let y of g.writes)x.writes.add(y);for(let y of g.boundedWrites)x.writes.add(y);return x.rootFallback=g.unbounded,jt(e,n,At(e,x,null)??xt(e,o,i,s))}if(g.writes.size===0&&g.boundedWrites.size===0&&!g.unbounded)return jt(e,n,xt(e,o,i,s))}return Ce.isIdentifier(n)&&!l&&(e.handlerHasRootCommit.get(a)===!1||a.async)?jt(e,n,xt(e,o,i,s)):Ce.isIdentifier(n)?n:a}import*as ve from"@babel/types";function tr(e,t){let n=[];for(let r of e){if(ve.isJSXText(r)){let a=Xn(r.value);a!==""&&n.push({type:"node",variable:t.emitText(ve.stringLiteral(a))});continue}if(ve.isJSXElement(r)||ve.isJSXFragment(r)){n.push({type:"node",variable:t.emitNode(r)});continue}if(ve.isJSXExpressionContainer(r)||t.fail("memo-dom: spread children are not supported"),ve.isJSXEmptyExpression(r.expression))continue;ve.isExpression(r.expression)||t.fail("memo-dom: unsupported expression in JSX child position");let o=r.expression;if(t.isForwarded(o)){n.push({type:"slot",expression:ve.cloneNode(o)});continue}if(ve.isNullLiteral(o)||ve.isBooleanLiteral(o)||ve.isIdentifier(o,{name:"undefined"}))continue;let i=Oe(o);if(i!==null){n.push({type:"list",expression:i});continue}let s=an(o);if(s!==null&&ce(s)){n.push({type:"condition",expression:s});continue}n.push({type:"node",variable:t.emitText(ve.cloneNode(o))})}return n}import*as T from"@babel/types";var Xs=new Set(["innerHTML","checked","value","selected","disabled","hidden","multiple","required","readOnly","muted","open","controls","loop","autoFocus","autoPlay","tabIndex"]),Io={htmlFor:"for",crossOrigin:"crossorigin"};function nr(e,t){return!t&&Xs.has(e)?e:null}function rr(e,t){return!t&&e in Io}function or(e,t,n){let r=T.identifier(e);if(t==="tabIndex")return T.isStringLiteral(n)?T.expressionStatement(T.assignmentExpression("=",T.memberExpression(r,T.identifier(t)),T.cloneNode(n))):T.expressionStatement(T.conditionalExpression(T.binaryExpression("==",T.cloneNode(n),T.nullLiteral()),T.callExpression(T.memberExpression(T.cloneNode(r),T.identifier("removeAttribute")),[T.stringLiteral("tabindex")]),T.assignmentExpression("=",T.memberExpression(T.cloneNode(r),T.identifier(t)),T.cloneNode(n))));let o=t==="value"||t==="innerHTML"?T.stringLiteral(""):T.booleanLiteral(!1),i=T.isStringLiteral(n)?T.cloneNode(n):T.conditionalExpression(T.binaryExpression("==",T.cloneNode(n),T.nullLiteral()),o,T.cloneNode(n));return T.expressionStatement(T.assignmentExpression("=",T.memberExpression(r,T.identifier(t)),i))}function Nn(e,t,n){let r=T.identifier(e),o=Io[t]??t;return T.isStringLiteral(n)?T.expressionStatement(T.callExpression(T.memberExpression(r,T.identifier("setAttribute")),[T.stringLiteral(o),T.cloneNode(n)])):T.expressionStatement(T.conditionalExpression(T.logicalExpression("||",T.binaryExpression("==",T.cloneNode(n),T.nullLiteral()),T.binaryExpression("===",T.cloneNode(n),T.booleanLiteral(!1))),T.callExpression(T.memberExpression(T.cloneNode(r),T.identifier("removeAttribute")),[T.stringLiteral(o)]),T.callExpression(T.memberExpression(r,T.identifier("setAttribute")),[T.stringLiteral(o),T.conditionalExpression(T.binaryExpression("===",T.cloneNode(n),T.booleanLiteral(!0)),T.stringLiteral(""),T.callExpression(T.identifier("String"),[T.cloneNode(n)]))])))}import*as Ke from"@babel/types";var Os="http://www.w3.org/2000/svg",Ts=new Set(["animate","animateMotion","animateTransform","circle","clipPath","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","switch","symbol","text","textPath","tspan","use","view"]);function Fo(e,t){return t||e==="svg"||Ts.has(e)}function Ro(e,t){return t?Ke.callExpression(Ke.memberExpression(Ke.identifier("document"),Ke.identifier("createElementNS")),[Ke.stringLiteral(Os),Ke.stringLiteral(e)]):Ke.callExpression(Ke.memberExpression(Ke.identifier("document"),Ke.identifier("createElement")),[Ke.stringLiteral(e)])}import*as me from"@babel/types";function In(e,t,n){let r=e.componentProps.get(t);if(r?.mode==="object"){if(!r.acceptsUnknown){for(let s of n)if(!r.names.includes(s.name))throw new Error(`memo-dom: unknown prop '${s.name}' on <${t}> - declared props: ${r.names.length>0?r.names.join(", "):"(none)"}`)}return n.length===0&&r.hasWholeDefault?[me.identifier("undefined")]:[me.objectExpression(n.map(s=>me.objectProperty(me.identifier(s.name),s.value,!1,me.isIdentifier(s.value)&&s.value.name===s.name)))]}let o=r?.names;if(o===void 0)return n.map(s=>s.value);let i=new Map(n.map(s=>[s.name,s.value]));for(let s of i.keys())if(!o.includes(s))throw new Error(`memo-dom: unknown prop '${s}' on <${t}> - declared props: ${o.length>0?o.join(", "):"(none)"}`);return o.map(s=>i.get(s)??me.identifier("undefined"))}function Jt(e,t,n){let r=e.componentProps.get(t);return r?.mode==="object"?[me.cloneNode(n)]:(r?.names??[]).map(o=>me.memberExpression(me.cloneNode(n),me.isValidIdentifier(o)?me.identifier(o):me.stringLiteral(o),!me.isValidIdentifier(o)))}function Do(e,t,n,r,o){let i=j(e,`${t}Props`);return me.blockStatement([me.variableDeclaration("const",[me.variableDeclarator(me.cloneNode(i),me.cloneNode(o))]),me.expressionStatement(me.callExpression(Z(e,"setProps"),[me.binaryExpression("+",me.cloneNode(n),me.stringLiteral(r)),me.arrayExpression(Jt(e,t,i))]))])}import*as Ne from"@babel/types";function $t(e){return(Ne.isArrowFunctionExpression(e)||Ne.isFunctionExpression(e))&&!Bs(e.body)}function ir(e,t,n,r="callback"){let o=j(e,r);return t.creation.push(Ne.variableDeclaration("const",[Ne.variableDeclarator(Ne.cloneNode(o),Ne.cloneNode(n,!0))])),o}function sr(e,t,n,r="callback"){let o=j(e,r);return t.push(Ne.variableDeclaration("const",[Ne.variableDeclarator(Ne.cloneNode(o),Ne.cloneNode(n,!0))])),o}function Bs(e){let t=!1;return Ne.traverseFast(e,n=>{if(Ne.isJSXElement(n)||Ne.isJSXFragment(n))return t=!0,Ne.traverseFast.stop}),t}import*as U from"@babel/types";function Mo(e,t,n,r,o,i,s,a=!1,l=Le(e,o),d=!1){let u=ln(n,i,t.usedConds),c=j(e,u.suffix).name,g=U.binaryExpression("+",U.cloneNode(l),U.stringLiteral(`/${u.suffix}`)),x=U.arrowFunctionExpression([],U.cloneNode(u.pickExpr)),y=u.branches.map(f=>f!==null?ar(e,f,o,i,g,s,a,g,!1,t.usedConds):U.nullLiteral());t.creation.push(ht(e,U.cloneNode(g),U.cloneNode(l),U.arrowFunctionExpression([],U.callExpression(U.memberExpression(U.identifier(c),U.identifier("update")),[])))),t.creation.push(U.variableDeclaration("const",[U.variableDeclarator(U.identifier(c),U.callExpression(Z(e,"createCondRegion"),[U.identifier(r),U.cloneNode(g),x,U.arrayExpression(y)]))])),(d||Er(e,n,o))&&t.updaters.push(()=>U.expressionStatement(U.callExpression(U.memberExpression(U.identifier(c),U.identifier("update")),[]))),t.disposableRegions.push(c),t.disposableEntities.push(U.cloneNode(g))}function ar(e,t,n,r,o,i,s=!1,a=o,l=!1,d){let u=Ye(e,!0);d!==void 0&&(u.usedConds=d);let c=i(e,u,t,n,r,l?null:"cond",void 0,o,s,a),g=[U.objectProperty(U.identifier("nodes"),U.callExpression(Z(e,"rootNodes"),[U.identifier(c)])),U.objectProperty(U.identifier("update"),U.identifier(u.updateVar))];if(u.disposableRegions.length>0||u.disposableEntities.length>0||u.disposableCallbacks.length>0){let x=[...[...u.disposableCallbacks].reverse().map(y=>U.ifStatement(U.binaryExpression("!==",U.cloneNode(y),U.nullLiteral()),U.expressionStatement(U.callExpression(U.cloneNode(y),[])))),...u.disposableRegions.map(y=>U.expressionStatement(U.callExpression(U.memberExpression(U.identifier(y),U.identifier("dispose")),[]))),...u.disposableEntities.map(y=>U.expressionStatement(U.callExpression(Z(e,"unregisterSubtree"),[U.cloneNode(y)])))];g.push(U.objectProperty(U.identifier("dispose"),U.arrowFunctionExpression([],U.blockStatement(x))))}return U.arrowFunctionExpression([],U.blockStatement([Qe(u),et(u),...u.creation,...u.mounts,U.returnStatement(U.objectExpression(g))]))}import*as p from"@babel/types";import*as X from"@babel/types";function ft(e,t,n,r){return X.isArrayExpression(r)?X.arrayExpression(r.elements.map(o=>{if(o===null)return null;if(X.isSpreadElement(o))throw t.buildCodeFrameError("memo-dom: ref arrays must have a static shape; nested arrays are supported but array spreads are not");return ft(e,t,n,o)})):Vs(e,n,r)?X.cloneNode(r,!0):Ws(t,r)||X.isMemberExpression(r)?Lo(e,r):X.cloneNode(r,!0)}function lr(e,t,n,r,o){let i=j(e,"refDispose");t.mounts.push(X.variableDeclaration("const",[X.variableDeclarator(X.cloneNode(i),X.callExpression(Z(e,"mountRef"),[X.cloneNode(n,!0),X.cloneNode(o,!0)]))])),t.manualDisposal?t.disposableCallbacks.push(i):t.mounts.push(X.expressionStatement(X.callExpression(Z(e,"cleanup"),[X.cloneNode(r,!0),X.cloneNode(i)])))}function Vs(e,t,n){let r=dt(e,t,n);return r!==null&&e.componentProps.get(t)?.refProps.includes(r)===!0}function Ws(e,t){if(!X.isIdentifier(t)||t.name==="undefined")return!1;let n=e.scope.getBinding(t.name);if(n===void 0||n.path.isFunctionDeclaration()||n.path.isImportSpecifier()||n.path.isImportDefaultSpecifier()||n.path.isImportNamespaceSpecifier())return!1;if(n.path.isVariableDeclarator()){if(n.path.parentPath.isVariableDeclaration({kind:"const"}))return!1;let o=n.path.node.init;if(X.isFunctionExpression(o)||X.isArrowFunctionExpression(o))return!1}return n.kind!=="param"}function Lo(e,t){let n=j(e,"refNode");if(X.isMemberExpression(t)){let r=j(e,"refTarget"),o=t.computed?j(e,"refKey"):null,i=()=>X.memberExpression(X.cloneNode(r),o===null?X.cloneNode(t.property,!0):X.cloneNode(o),t.computed);return X.arrowFunctionExpression([X.cloneNode(n)],X.blockStatement([X.variableDeclaration("const",[X.variableDeclarator(X.cloneNode(r),X.cloneNode(t.object,!0)),...o===null?[]:[X.variableDeclarator(X.cloneNode(o),X.cloneNode(t.property,!0))]]),X.expressionStatement(X.assignmentExpression("=",i(),X.cloneNode(n))),X.returnStatement(X.arrowFunctionExpression([],X.blockStatement([X.ifStatement(X.binaryExpression("===",i(),X.cloneNode(n)),X.expressionStatement(X.assignmentExpression("=",i(),X.identifier("undefined"))))])))]))}return X.arrowFunctionExpression([X.cloneNode(n)],X.blockStatement([X.expressionStatement(X.assignmentExpression("=",X.cloneNode(t,!0),X.cloneNode(n))),X.returnStatement(X.arrowFunctionExpression([],X.blockStatement([X.ifStatement(X.binaryExpression("===",X.cloneNode(t,!0),X.cloneNode(n)),X.expressionStatement(X.assignmentExpression("=",X.cloneNode(t,!0),X.identifier("undefined"))))])))]))}import*as A from"@babel/types";var zs=new Set(["setClassValue","setStyleValue","setDomValue"]);function Xt(e,t,n){if(t.mounts.length!==0||t.disposableRegions.length!==0||t.disposableEntities.length!==0||t.disposableCallbacks.length!==0)return!1;let r=[],o=new Set;for(let f of t.creation){if(!A.isVariableDeclaration(f))continue;let m=Ks(f);if(m===null)return!1;r.push(m),o.add(m.name)}if(!o.has(n)||r.length<2)return!1;let i=new Map,s=new Map;for(let f of t.creation){let m=Ao(f);if(m===null)continue;if(!o.has(m.parent)||!o.has(m.child))return!1;let w=s.get(m.parent)??0;s.set(m.parent,w+1),i.set(m.child,{parent:m.parent,index:w})}let a=new Map;for(let f of o){let m=Us(f,n,i);if(m===null)return!1;a.set(f,m)}let l=[],d=[];for(let f of t.creation)A.isVariableDeclaration(f)||_s(f,o)?l.push(A.cloneNode(f,!0)):d.push(f);let u=j(e,`${n}Template`);e.header.push(A.variableDeclaration("let",[A.variableDeclarator(A.cloneNode(u))]));let c=A.callExpression(A.arrowFunctionExpression([],A.blockStatement([...l,A.returnStatement(A.identifier(n))])),[]),g=A.conditionalExpression(A.binaryExpression("===",A.cloneNode(u),A.unaryExpression("void",A.numericLiteral(0))),A.assignmentExpression("=",A.cloneNode(u),c),A.cloneNode(u)),x=A.callExpression(A.memberExpression(g,A.identifier("cloneNode")),[A.booleanLiteral(!0)]),y=[...r].sort((f,m)=>a.get(f.name).length-a.get(m.name).length).map(({name:f})=>A.variableDeclaration("const",[A.variableDeclarator(A.identifier(f),f===n?A.cloneNode(x,!0):Hs(n,a.get(f)))]));return t.creation=[...y,...d],!0}function Ks(e){if(e.declarations.length!==1)return null;let t=e.declarations[0];if(!A.isIdentifier(t.id)||!A.isCallExpression(t.init)||!A.isMemberExpression(t.init.callee)||!A.isIdentifier(t.init.callee.object,{name:"document"})||!A.isIdentifier(t.init.callee.property))return null;let n=t.init.callee.property.name;if(n!=="createElement"&&n!=="createElementNS"&&n!=="createTextNode")return null;let r=t.init.arguments.at(-1);return(n==="createElement"||n==="createElementNS")&&A.isStringLiteral(r)&&r.value.includes("-")?null:{name:t.id.name,statement:e}}function Ao(e){return!A.isExpressionStatement(e)||!A.isCallExpression(e.expression)||!A.isMemberExpression(e.expression.callee)||!A.isIdentifier(e.expression.callee.object)||!A.isIdentifier(e.expression.callee.property,{name:"appendChild"})||e.expression.arguments.length!==1||!A.isIdentifier(e.expression.arguments[0])?null:{parent:e.expression.callee.object.name,child:e.expression.arguments[0].name}}function Us(e,t,n){if(e===t)return[];let r=[],o=new Set,i=e;for(;i!==t;){if(o.has(i))return null;o.add(i);let s=n.get(i);if(s===void 0)return null;r.push(s.index),i=s.parent}return r.reverse(),r}function Hs(e,t){let n=A.identifier(e);for(let r of t){n=A.memberExpression(n,A.identifier("firstChild"));for(let o=0;o<r;o++)n=A.memberExpression(n,A.identifier("nextSibling"))}return n}function _s(e,t){let n=Ao(e);if(n!==null)return t.has(n.parent)&&t.has(n.child);if(!A.isExpressionStatement(e))return!1;let r=e.expression;return!!(A.isCallExpression(r)&&A.isMemberExpression(r.callee)&&(A.isIdentifier(r.callee.object)&&t.has(r.callee.object.name)&&A.isIdentifier(r.callee.property,{name:"setAttribute"})&&r.arguments.every(o=>A.isExpression(o)&&Fn(o))||A.isIdentifier(r.callee.object)&&A.isIdentifier(r.callee.property)&&zs.has(r.callee.property.name)&&r.arguments.length>=2&&A.isIdentifier(r.arguments[0])&&t.has(r.arguments[0].name)&&r.arguments.slice(1).every(o=>A.isExpression(o)&&Fn(o))))}function Fn(e){return A.isStringLiteral(e)||A.isNumericLiteral(e)||A.isBooleanLiteral(e)||A.isNullLiteral(e)?!0:A.isArrayExpression(e)?e.elements.every(t=>t===null||A.isExpression(t)&&Fn(t)):A.isObjectExpression(e)?e.properties.every(t=>A.isObjectProperty(t)&&!t.computed&&A.isExpression(t.value)&&Fn(t.value)):!1}function $o(e,t,n,r,o,i,s,a,l=!1,d=Le(e,o),u){let c=kt(e,n,i,o,t.usedPrefixes,u===void 0?void 0:{itemParam:u.itemParam,sourceKey:u.sourceKey,sourceLocal:u.sourceLocal??!1}),g=j(e,`region${t.regionCounter++}`).name,x=c.form==="callback"?Gs(e,c,r):c.form==="component"?Zs(e,c,r,o,i,a,l,d):Ys(e,c,r,o,i,s,l,d),y=[p.identifier(r),p.binaryExpression("+",p.cloneNode(d),p.stringLiteral(`/${c.suffix}`)),x];if(c.form==="callback"){let S=p.memberExpression(p.cloneNode(c.renderCallback,!0),p.identifier("key"));y.push(p.arrowFunctionExpression([p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]],p.conditionalExpression(p.binaryExpression("==",p.cloneNode(S),p.nullLiteral()),p.cloneNode(c.itemPattern,!0),p.callExpression(p.cloneNode(S),[p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]]))))}else c.keyExpr!==null&&y.push(p.arrowFunctionExpression([p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]],p.cloneNode(c.keyExpr)));t.creation.push(p.variableDeclaration("const",[p.variableDeclarator(p.identifier(g),p.callExpression(Z(e,"createListRegion"),y))])),t.disposableRegions.push(g);let m=(e.targetedListDependencies.get(n)??[]).map(S=>({dependency:S,cache:j(e,`${S.value}ListKey`).name}));m.length>0&&t.creation.push(p.variableDeclaration("let",m.map(({dependency:S,cache:I})=>p.variableDeclarator(p.identifier(I),p.identifier(S.value)))));let w=()=>p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(g),p.identifier("reconcile")),[p.cloneNode(c.sourceExpr)]));t.creation.push(w()),m.length===0||t.reasonVar===null?t.updaters.push(w):t.updaters.push(()=>qs(e,o,t.reasonVar,g,c.sourceExpr,m))}function jo(e,t){let n=()=>p.identifier(e);return p.logicalExpression("||",p.binaryExpression("===",n(),p.numericLiteral(t)),p.logicalExpression("&&",p.binaryExpression("!==",n(),p.nullLiteral()),p.logicalExpression("&&",p.binaryExpression("!==",p.unaryExpression("typeof",n()),p.stringLiteral("number")),p.callExpression(p.memberExpression(n(),p.identifier("has")),[p.numericLiteral(t)]))))}function Jo(e,t){return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(e),p.identifier("refreshKey")),[t]))}function qs(e,t,n,r,o,i){let s=e.instanceReasonIds.get(t);if(s===void 0)return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(r),p.identifier("reconcile")),[p.cloneNode(o)]));let a=s.get(i[0].dependency.source);if(a===void 0)return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(r),p.identifier("reconcile")),[p.cloneNode(o)]));let l=[p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(r),p.identifier("reconcile")),[p.cloneNode(o)])),...i.map(({dependency:u,cache:c})=>p.expressionStatement(p.assignmentExpression("=",p.identifier(c),p.identifier(u.value))))],d=[];for(let{dependency:u,cache:c}of i){let g=s.get(u.value);if(g===void 0)continue;let x=j(e,"previousListKey");d.push(p.ifStatement(jo(n,g),p.blockStatement([p.variableDeclaration("const",[p.variableDeclarator(x,p.identifier(c))]),p.expressionStatement(p.assignmentExpression("=",p.identifier(c),p.identifier(u.value))),Jo(r,p.cloneNode(x)),p.ifStatement(p.unaryExpression("!",p.callExpression(p.memberExpression(p.identifier("Object"),p.identifier("is")),[p.cloneNode(x),p.identifier(c)])),Jo(r,p.identifier(c)))])))}return p.ifStatement(p.logicalExpression("||",p.binaryExpression("===",p.identifier(n),p.nullLiteral()),jo(n,a)),p.blockStatement(l),d.length===0?void 0:p.blockStatement(d))}function Gs(e,t,n){let r=j(e,"renderRowId");return p.arrowFunctionExpression([p.cloneNode(t.itemPattern,!0),p.cloneNode(r),...t.indexParam===null?[]:[p.identifier(t.indexParam)]],p.callExpression(p.memberExpression(p.cloneNode(t.renderCallback,!0),p.identifier("create")),[p.cloneNode(t.itemPattern,!0),p.cloneNode(r),...t.indexParam===null?[]:[p.identifier(t.indexParam)],p.identifier(n)]))}function Zs(e,t,n,r,o,i,s=!1,a=Le(e,r)){let l=t.rowComp,d=j(e,"rowId"),u=j(e,"nextItem"),c=t.indexParam===null?null:j(e,"nextIndex"),g=j(e,"refreshRow"),x=Ye(e),y=Mt(e,l),f=e.importedComponents.get(l)?.delegatedEvents===!0||e.componentsWithHostEvents.has(l),m={itemParam:t.itemParam,itemPath:[],rowIdVar:d.name,refreshVar:g.name,keyPath:lt(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal&&p.isIdentifier(a)?{ownerIdVar:a.name}:{}},w=t.jsx.openingElement.attributes.filter(q=>p.isJSXSpreadAttribute(q)||Ae(q.name)!=="key"),S=w.some(q=>p.isJSXSpreadAttribute(q)),I=[],$=[],F=null,N=e.componentProps.get(l),K=q=>{let Q=p.isJSXElement(q)||p.isJSXFragment(q)?[q]:[p.jsxExpressionContainer(q)];return i(e,x,Q,r,o,"row",m,d,s,d)};if(S){F=Ht(w,{attributeValue:(q,Q)=>q==="ref"||N?.refProps.includes(q)===!0?ft(e,o,r,Q):Q,fail:q=>{throw o.buildCodeFrameError(q)}}).expression;for(let q of F.properties){if(!p.isObjectProperty(q)||q.computed||!p.isExpression(q.value))continue;let Q=p.isIdentifier(q.key)?q.key.name:p.isStringLiteral(q.key)?q.key.value:null;if(Q!==null)if(N?.renderProps.includes(Q)===!0){if(tt(e,r,q.value))continue;if(!ce(q.value))throw o.buildCodeFrameError(`memo-dom: render prop '${Q}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);q.value=K(q.value)}else{if(ce(q.value))throw o.buildCodeFrameError(`memo-dom: JSX prop '${Q}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);Q!=="ref"&&N?.refProps.includes(Q)!==!0&&$t(q.value)&&(nt(e,o,q.value,r,m,!0),q.value=sr(e,$,q.value,`${Q}Callback`))}}}else for(let q of w){let Q=q,ee=Ae(Q.name),oe=Q.value==null?p.booleanLiteral(!0):$e(Q.value);if(oe===null)throw o.buildCodeFrameError(`memo-dom: prop '${Ae(Q.name)}' on <${l}> must be an expression`);if(N?.renderProps.includes(ee)===!0){if(tt(e,r,oe)){I.push({name:ee,value:p.cloneNode(oe)});continue}if(!ce(oe))throw o.buildCodeFrameError(`memo-dom: render prop '${ee}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);I.push({name:ee,value:K(oe)});continue}if(ee==="ref"||N?.refProps.includes(ee)===!0){I.push({name:ee,value:ft(e,o,r,oe)});continue}if(ce(oe))throw o.buildCodeFrameError(`memo-dom: JSX prop '${ee}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);let E=$t(oe);if(E)nt(e,o,oe,r,m,!0);else if(p.isIdentifier(oe)){let C=pt(o,oe.name);C!==null&&!ce(C.body)&&nt(e,o,C,r,m,!0)}I.push({name:ee,value:E?sr(e,$,oe,`${ee}Callback`):p.cloneNode(oe)})}if(Wt(t.jsx.children)){if(w.some(Q=>p.isJSXAttribute(Q)&&Ae(Q.name)==="children"))throw o.buildCodeFrameError(`memo-dom: <${l}> cannot use both a children prop and nested JSX children`);let q=i(e,x,t.jsx.children,r,o,"row",m,d,s,d);F!==null?F.properties.push(p.objectProperty(p.identifier("children"),p.cloneNode(q))):I.push({name:"children",value:p.cloneNode(q)})}let _;if(F!==null){let q=j(e,`${l}Props`);$.push(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(q),p.cloneNode(F))])),_=Jt(e,l,q)}else _=In(e,l,I);let V=[p.expressionStatement(p.assignmentExpression("=",p.cloneNode(t.itemPattern,!0),p.cloneNode(u)))];c!==null&&t.indexParam!==null&&V.push(p.expressionStatement(p.assignmentExpression("=",p.identifier(t.indexParam),p.cloneNode(c))));let O=_.map(q=>p.cloneNode(q));if(F!==null){let q=j(e,`next${l}Props`);V.push(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(q),p.cloneNode(F))])),O=Jt(e,l,q)}let le=j(e,y?"entry":"rowElement");y?V.push(p.expressionStatement(p.callExpression(p.memberExpression(p.cloneNode(le),p.identifier("updateProps")),O))):V.push(p.expressionStatement(p.callExpression(Z(e,"setProps"),[p.cloneNode(d),p.arrayExpression(O)])),p.expressionStatement(p.callExpression(Z(e,"markDirty"),[p.cloneNode(d)]))),x.updaters.length>0&&V.push(p.expressionStatement(p.callExpression(p.identifier(x.updateVar),[])));let te=y?[p.objectProperty(p.identifier("nodes"),p.memberExpression(p.cloneNode(le),p.identifier("nodes"))),p.objectProperty(p.identifier("entities"),p.arrayExpression([])),p.objectProperty(p.identifier("update"),p.memberExpression(p.cloneNode(le),p.identifier("update"))),p.objectProperty(p.identifier("dispose"),p.memberExpression(p.cloneNode(le),p.identifier("dispose")))]:[p.objectProperty(p.identifier("nodes"),p.callExpression(Z(e,"rootNodes"),[p.cloneNode(le)])),p.objectProperty(p.identifier("entities"),p.arrayExpression([p.cloneNode(d)]))];return(_.length>0||x.updaters.length>0)&&te.push(p.objectProperty(p.identifier("updateProps"),p.arrowFunctionExpression([p.cloneNode(u),...c===null?[]:[p.cloneNode(c)]],p.blockStatement(V)))),p.arrowFunctionExpression([p.cloneNode(t.itemPattern,!0),p.cloneNode(d),...t.indexParam===null?[]:[p.identifier(t.indexParam)]],p.blockStatement([...x.updaters.length>0?[Qe(x),et(x)]:[],...x.creation,...x.mounts,...$,p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(le),y?p.callExpression(p.identifier(l),[..._.map(q=>p.cloneNode(q)),p.cloneNode(d),...t.sourceLocal?[p.cloneNode(a)]:[],...f?[p.identifier(n)]:[]]):p.callExpression(p.identifier(l),[p.cloneNode(d),p.cloneNode(a),..._.length>0?[p.arrayExpression(_)]:[]]))]),...x.updaters.length>0?[p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(g),p.arrowFunctionExpression([],p.blockStatement([p.expressionStatement(y?p.callExpression(p.memberExpression(p.cloneNode(le),p.identifier("update")),[]):p.callExpression(Z(e,"markDirty"),[p.cloneNode(d)])),p.expressionStatement(p.callExpression(p.identifier(x.updateVar),[]))])))])]:[],p.returnStatement(p.objectExpression(te))]))}function Ys(e,t,n,r,o,i,s=!1,a=Le(e,r)){t.jsx.openingElement.attributes=t.jsx.openingElement.attributes.filter(f=>p.isJSXSpreadAttribute(f)||f.name.name!=="key");let l=Ye(e);l.delegatedEventRootVar=n;let d=j(e,"rowId").name,u=j(e,"nextItem"),c=t.indexParam===null?null:j(e,"nextIndex"),g={itemParam:t.itemParam,itemPath:[],rowIdVar:d,keyPath:lt(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal?{ownerIdVar:p.isIdentifier(a)?a.name:Le(e,r).name}:{}},x=i(e,l,t.jsx,r,o,"row",g,p.identifier(d),s,p.identifier(d));Xt(e,l,x);let y=[p.expressionStatement(p.assignmentExpression("=",p.cloneNode(t.itemPattern,!0),p.cloneNode(u)))];return c!==null&&t.indexParam!==null&&y.push(p.expressionStatement(p.assignmentExpression("=",p.identifier(t.indexParam),p.cloneNode(c)))),p.arrowFunctionExpression([p.cloneNode(t.itemPattern,!0),p.identifier(d),...t.indexParam===null?[]:[p.identifier(t.indexParam)]],p.blockStatement([Qe(l),et(l),ht(e,p.identifier(d),p.cloneNode(a),p.identifier(l.updateVar)),...l.creation,...l.mounts,p.returnStatement(p.objectExpression([p.objectProperty(p.identifier("nodes"),p.arrayExpression([p.identifier(x)])),p.objectProperty(p.identifier("entities"),p.arrayExpression([p.identifier(d)])),p.objectProperty(p.identifier("updateProps"),p.arrowFunctionExpression([p.cloneNode(u),...c===null?[]:[p.cloneNode(c)]],p.blockStatement(y))),p.objectProperty(p.identifier("update"),p.identifier(l.updateVar))]))]))}import*as v from"@babel/types";function Qs(e){return v.isJSXElement(e.body)?e.body:v.isBlockStatement(e.body)&&e.body.body.length===1&&v.isReturnStatement(e.body.body[0])&&v.isJSXElement(e.body.body[0].argument)?e.body.body[0].argument:null}function dr(e,t,n,r,o,i,s,a){if(!v.isArrowFunctionExpression(n)&&!v.isFunctionExpression(n)||n.async||n.generator)throw o.buildCodeFrameError("memo-dom: render callbacks must be synchronous inline arrows or function expressions");let l=Qs(n),d=n.params[0],u=n.params[1];if(l===null||n.params.length<1||n.params.length>2||!v.isIdentifier(d)&&!v.isObjectPattern(d)&&!v.isArrayPattern(d)||u!==void 0&&!v.isIdentifier(u))throw o.buildCodeFrameError("memo-dom: render callbacks take an item binding pattern and optional index, then return one JSX element");let c=nn(d),g=Object.keys(v.getBindingIdentifiers(c));if(g.length===0)throw o.buildCodeFrameError("memo-dom: render callback item patterns must bind at least one name");let x=v.isIdentifier(c)?c.name:g[0],y=u===void 0?null:u.name,f=null;l.openingElement.attributes=l.openingElement.attributes.filter(Q=>{if(v.isJSXSpreadAttribute(Q)||!v.isJSXIdentifier(Q.name)||Q.name.name!=="key")return!0;if(f=$e(Q.value),f===null)throw o.buildCodeFrameError("memo-dom: key={...} needs an expression");return!1});let m=j(e,"renderCallback"),w=j(e,"renderRows"),S=j(e,"renderNextUpdate"),I=j(e,"renderRowId"),$=j(e,"renderEventRoot"),F=j(e,"refreshRenderRow"),N=j(e,"renderNextItem"),K=y===null?null:j(e,"renderNextIndex"),_=Ye(e);_.delegatedEventRootVar=$.name;let V={itemParam:x,itemPath:[],rowIdVar:I.name,keyPath:lt(f,x),sourceKey:"$render-callback",sourceLocal:!0,...v.isIdentifier(a)?{ownerIdVar:a.name}:{}},O=i(e,_,l,r,o,"row",V,I,s,I);Xt(e,_,O),t.creation.push(v.variableDeclaration("const",[v.variableDeclarator(v.cloneNode(w),v.newExpression(v.identifier("Set"),[]))])),t.updaters.push(()=>v.forOfStatement(v.variableDeclaration("const",[v.variableDeclarator(v.cloneNode(S))]),v.cloneNode(w),v.expressionStatement(v.callExpression(v.cloneNode(S),[]))));let le=[v.expressionStatement(v.assignmentExpression("=",v.cloneNode(c,!0),v.cloneNode(N)))];K!==null&&y!==null&&le.push(v.expressionStatement(v.assignmentExpression("=",v.identifier(y),v.cloneNode(K))));let te=v.arrowFunctionExpression([v.cloneNode(c,!0),v.cloneNode(I),...y===null?[]:[v.identifier(y)],v.cloneNode($)],v.blockStatement([Qe(_),et(_),v.variableDeclaration("const",[v.variableDeclarator(v.cloneNode(F),v.arrowFunctionExpression([],v.blockStatement([v.expressionStatement(v.callExpression(v.identifier(_.updateVar),[])),v.expressionStatement(v.callExpression(Z(e,"renderDescendants"),[v.cloneNode(I)]))])))]),ht(e,v.cloneNode(I),v.cloneNode(a,!0),v.cloneNode(F)),..._.creation,..._.mounts,v.expressionStatement(v.callExpression(v.memberExpression(v.cloneNode(w),v.identifier("add")),[v.cloneNode(F)])),v.returnStatement(v.objectExpression([v.objectProperty(v.identifier("nodes"),v.callExpression(Z(e,"rootNodes"),[v.identifier(O)])),v.objectProperty(v.identifier("entities"),v.arrayExpression([v.cloneNode(I)])),v.objectProperty(v.identifier("updateProps"),v.arrowFunctionExpression([v.cloneNode(N),...K===null?[]:[v.cloneNode(K)]],v.blockStatement(le))),v.objectProperty(v.identifier("update"),v.cloneNode(F)),v.objectProperty(v.identifier("dispose"),v.arrowFunctionExpression([],v.callExpression(v.memberExpression(v.cloneNode(w),v.identifier("delete")),[v.cloneNode(F)])))]))])),q=f===null?v.nullLiteral():v.arrowFunctionExpression([v.cloneNode(c,!0),...y===null?[]:[v.identifier(y)]],v.cloneNode(f));return t.creation.push(v.variableDeclaration("const",[v.variableDeclarator(v.cloneNode(m),v.objectExpression([v.objectProperty(v.identifier("create"),te),v.objectProperty(v.identifier("key"),q)]))])),m}function ea(e){return h.conditionalExpression(h.logicalExpression("||",h.binaryExpression("==",h.cloneNode(e),h.nullLiteral()),h.binaryExpression("===",h.unaryExpression("typeof",h.cloneNode(e),!0),h.stringLiteral("boolean"))),h.stringLiteral(""),h.callExpression(h.identifier("String"),[h.cloneNode(e)]))}function ta(e,t,n,r){return()=>Nt(e,t,h.cloneNode(r),o=>h.expressionStatement(h.assignmentExpression("=",h.memberExpression(h.identifier(n),h.identifier("data")),ea(o))))}function cr(e,t,n){let r=j(e,`text${t.textCounter++}`).name;if(h.isStringLiteral(n))return t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(r),h.callExpression(h.memberExpression(h.identifier("document"),h.identifier("createTextNode")),[h.stringLiteral(n.value)]))])),r;let o=Jn(e,t);t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(r),h.callExpression(h.memberExpression(h.identifier("document"),h.identifier("createTextNode")),[h.stringLiteral("")]))]));let i=ta(t,o,r,n);return t.creation.push(i()),t.updaters.push(i),r}function Xo(e,t){let n=!1;return h.traverseFast(e,r=>{h.isIdentifier(r,{name:t})&&(n=!0)}),n}function at(e,t,n,r,o,i=null,s,a,l=!1,d=Le(e,r)){return h.isJSXFragment(n)?na(e,t,n,r,o,i,s,a,l,d):ra(e,t,n,r,o,i,s,a,l,d)}function na(e,t,n,r,o,i,s,a,l=!1,d=Le(e,r)){let u=tr(n.children,{emitText:g=>cr(e,t,g),emitNode:g=>at(e,t,g,r,o,i,s,a,l,d),isForwarded:g=>tt(e,r,g),fail:g=>{throw o.buildCodeFrameError(g)}}),c=$n(e,t,"fragment");return t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(c),h.callExpression(h.memberExpression(h.identifier("document"),h.identifier("createDocumentFragment")),[]))])),To(e,t,u,c,r,o,i,s,l,d),c}function To(e,t,n,r,o,i,s=null,a,l=!1,d=Le(e,o)){for(let u of n)u.type==="node"?t.creation.push(h.expressionStatement(h.callExpression(h.memberExpression(h.identifier(r),h.identifier("appendChild")),[h.identifier(u.variable)]))):u.type==="slot"?On(e,t,u.expression,r,d):u.type==="list"?Bo(e,t,u.expression,r,o,i,l,d,a):Vo(e,t,u.expression,r,o,i,l,d,s!==null)}function ur(e,t,n,r,o,i,s,a,l,d){return Nr(e,t,d,(u,c,g)=>{Ir(u,n,c.name,{emitText:x=>cr(e,u,x),emitNode:x=>at(e,u,x,r,o,i,s,a,l,g),emitList:(x,y)=>Bo(e,u,x,y,r,o,l,g,s),emitCondition:(x,y)=>Vo(e,u,x,y,r,o,l,g,i!==null),isForwarded:x=>tt(e,r,x),emitForwarded:(x,y)=>On(e,u,x,y,g),fail:x=>{throw o.buildCodeFrameError(x)}})})}function Oo(e,t,n,r,o,i,s,a,l,d){let u=h.isJSXElement(n)||h.isJSXFragment(n)?[n]:[h.jsxExpressionContainer(n)];return ur(e,t,u,r,o,i,s,a,l,d)}function ra(e,t,n,r,o,i=null,s,a,l=!1,d=Le(e,r)){let u=n.openingElement,c=u.name.name;if(/^[A-Z]/.test(c)){let S=t.childCounts.get(c)??0;t.childCounts.set(c,S+1);let I=c.charAt(0).toLowerCase()+c.slice(1),$=S===0?I:`${I}${S}`,F=j(e,$).name,N=S===0?`/${c}`:`/${c}[${S}]`,K=[],_=e.componentProps.get(c);if(Wt(n.children)&&u.attributes.some(Q=>h.isJSXAttribute(Q)&&Ae(Q.name)==="children"))throw o.buildCodeFrameError(`memo-dom: <${c}> cannot use both a children prop and nested JSX children`);let V=u.attributes.some(Q=>h.isJSXSpreadAttribute(Q)),O=null,le=!1;if(V){O=Ht(u.attributes,{attributeValue:(ee,oe)=>ee==="ref"||_?.refProps.includes(ee)===!0?ft(e,o,r,oe):oe,fail:ee=>{throw o.buildCodeFrameError(ee)}}).expression;for(let ee of O.properties){if(!h.isObjectProperty(ee)||ee.computed||!h.isExpression(ee.value))continue;let oe=h.isIdentifier(ee.key)?ee.key.name:h.isStringLiteral(ee.key)?ee.key.value:null;if(oe!==null)if(_?.renderCallbacks.includes(oe)===!0)ee.value=dr(e,t,ee.value,r,o,at,l,d);else if(_?.renderProps.includes(oe)===!0){if(tt(e,r,ee.value))continue;if(!ce(ee.value))throw o.buildCodeFrameError(`memo-dom: render prop '${oe}' on <${c}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);ee.value=Oo(e,t,ee.value,r,o,i,s,a,l,d)}else{if(ce(ee.value))throw o.buildCodeFrameError(`memo-dom: JSX prop '${oe}' on <${c}> is not rendered by the callee; interpolate that prop in <${c}> to declare a render slot`);oe!=="ref"&&_?.refProps.includes(oe)!==!0&&$t(ee.value)&&(nt(e,o,ee.value,r,s,!0),ee.value=ir(e,t,ee.value,`${oe}Callback`))}}le=Ln(e,O,r)||s!==void 0&&Xo(O,s.itemParam)}else for(let Q of u.attributes){let ee=Q,oe=Ae(ee.name),E=ee.value==null?h.booleanLiteral(!0):$e(ee.value);if(E==null)throw o.buildCodeFrameError(`memo-dom: prop '${Ae(ee.name)}' on <${c}> must be an expression`);if(_?.renderCallbacks.includes(oe)===!0){K.push({name:oe,value:dr(e,t,E,r,o,at,l,d)});continue}if(oe==="ref"||_?.refProps.includes(oe)===!0){K.push({name:oe,value:ft(e,o,r,E)});continue}if(_?.renderProps.includes(oe)===!0){if(tt(e,r,E)){K.push({name:oe,value:h.cloneNode(E)});continue}if(!ce(E))throw o.buildCodeFrameError(`memo-dom: render prop '${oe}' on <${c}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);K.push({name:oe,value:Oo(e,t,E,r,o,i,s,a,l,d)});continue}if(ce(E))throw o.buildCodeFrameError(`memo-dom: JSX prop '${oe}' on <${c}> is not rendered by the callee; interpolate that prop in <${c}> to declare a render slot`);let C=$t(E);if(!C&&(Ln(e,E,r)||s!==void 0&&Xo(E,s.itemParam))&&(le=!0),C)nt(e,o,E,r,s,!0);else if(h.isIdentifier(E)){let M=pt(o,E.name);M!==null&&!ce(M.body)&&nt(e,o,M,r,s,!0)}K.push({name:oe,value:C?ir(e,t,E,`${oe}Callback`):h.cloneNode(E)})}if(Wt(n.children)){if(u.attributes.some(ee=>h.isJSXAttribute(ee)&&Ae(ee.name)==="children"))throw o.buildCodeFrameError(`memo-dom: <${c}> cannot use both a children prop and nested JSX children`);let Q=ur(e,t,n.children,r,o,i,s,a,l,d);O!==null?O.properties.push(h.objectProperty(h.identifier("children"),h.cloneNode(Q))):K.push({name:"children",value:h.cloneNode(Q)})}let te;if(O!==null){let Q=j(e,`${I}Props`);t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(Q),h.cloneNode(O))])),te=Jt(e,c,Q)}else te=In(e,c,K);let q=h.binaryExpression("+",h.cloneNode(d),h.stringLiteral(N));return t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(F),h.callExpression(h.identifier(c),[q,h.cloneNode(d),...te.length>0?[h.arrayExpression(te)]:[]]))])),t.disposableEntities.push(h.cloneNode(q)),le&&t.updaters.push(()=>O===null?h.expressionStatement(h.callExpression(Z(e,"setProps"),[h.binaryExpression("+",h.cloneNode(d),h.stringLiteral(N)),h.arrayExpression(te.map(Q=>h.cloneNode(Q)))])):Do(e,c,d,N,O)),F}let g=Fo(c,l),x=g&&c!=="foreignObject";if(u.attributes.find(S=>h.isJSXAttribute(S)&&Ae(S.name)==="innerHTML")!==void 0){if(g)throw o.buildCodeFrameError("memo-dom: innerHTML is only supported on HTML elements");if(n.children.some(I=>!h.isJSXText(I)||I.value.trim()!==""))throw o.buildCodeFrameError("memo-dom: an element using innerHTML cannot also have JSX children")}let f=tr(n.children,{emitText:S=>cr(e,t,S),emitNode:S=>at(e,t,S,r,o,i,s,a,x,d),isForwarded:S=>tt(e,r,S),fail:S=>{throw o.buildCodeFrameError(S)}}),m=$n(e,t,c);if(t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(m),Ro(c,g))])),u.attributes.some(S=>h.isJSXSpreadAttribute(S))){let S=Ht(u.attributes,{attributeValue:(F,N)=>F==="ref"?ft(e,o,r,N):N,eventValue:(F,N)=>{let K=er(e,o,N,F,r,s,a),_=j(e,`${F}Handler`);return t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(_),K)])),_},fail:F=>{throw o.buildCodeFrameError(F)}}),I=j(e,`${c}Props`);t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(I),h.cloneNode(S.expression))]));let $=F=>h.expressionStatement(h.callExpression(Z(e,"patchDomProps"),[h.identifier(m),h.cloneNode(F),h.stringLiteral(e.rootId),h.arrayExpression(S.safeEventKeys.map(N=>h.stringLiteral(N)))]));t.creation.push($(I)),lr(e,t,h.identifier(m),d,h.memberExpression(h.cloneNode(I),h.identifier("ref"))),t.updaters.push(()=>$(S.expression))}else for(let S of u.attributes){let I=S,$=Ae(I.name);if($==="ref"){let O=$e(I.value);if(O===null)throw o.buildCodeFrameError("memo-dom: ref needs an expression");lr(e,t,h.identifier(m),d,ft(e,o,r,O));continue}if($==="key")throw o.buildCodeFrameError("memo-dom: key={...} is only meaningful on list rows: items.map(item => <Row key={item.id} />)");if(/^on[A-Z]/.test($)){let O=$e(I.value);if(O==null)throw o.buildCodeFrameError(`memo-dom: ${$} needs a handler expression (L1)`);let le=er(e,o,O,$,r,s,a);t.creation.push(t.delegatedEventRootVar===null?h.expressionStatement(h.assignmentExpression("=",h.memberExpression(h.identifier(m),h.identifier($.toLowerCase())),le)):h.expressionStatement(h.callExpression(Z(e,"setDelegatedEvent"),[h.identifier(t.delegatedEventRootVar),h.identifier(m),h.stringLiteral($),le])));continue}if(h.isStringLiteral(I.value)){$==="class"||$==="className"?t.creation.push(h.expressionStatement(h.callExpression(Z(e,"setClassValue"),[h.identifier(m),h.stringLiteral(I.value.value)]))):$==="style"?t.creation.push(h.expressionStatement(h.callExpression(Z(e,"setStyleValue"),[h.identifier(m),h.stringLiteral(I.value.value)]))):nr($,g)!==null?t.creation.push(or(m,$,h.stringLiteral(I.value.value))):rr($,g)?t.creation.push(Nn(m,$,h.stringLiteral(I.value.value))):g?t.creation.push(h.expressionStatement(h.callExpression(Z(e,"setDomValue"),[h.identifier(m),h.stringLiteral($),h.stringLiteral(I.value.value)]))):t.creation.push(h.expressionStatement(h.callExpression(h.memberExpression(h.identifier(m),h.identifier("setAttribute")),[h.stringLiteral($),h.stringLiteral(I.value.value)])));continue}let F=I.value==null?h.booleanLiteral(!0):$e(I.value);if(F==null||h.isStringLiteral(F))throw o.buildCodeFrameError(`memo-dom: attribute '${$}' needs a string or an expression (L1)`);let N=h.cloneNode(F);if($==="style"){let O=()=>h.expressionStatement(h.callExpression(Z(e,"setStyleValue"),[h.identifier(m),h.cloneNode(N)]));t.creation.push(O()),t.updaters.push(O);continue}let K=Jn(e,t),_=nr($,g),V=()=>$==="class"||$==="className"?Nt(t,K,h.callExpression(Z(e,"classValue"),[h.cloneNode(N)]),O=>h.expressionStatement(h.callExpression(Z(e,"setClassValue"),[h.identifier(m),O]))):_!==null?Nt(t,K,h.cloneNode(N),O=>or(m,_,O)):rr($,g)?Nt(t,K,h.cloneNode(N),O=>Nn(m,$,O)):g?Nt(t,K,h.cloneNode(N),O=>h.expressionStatement(h.callExpression(Z(e,"setDomValue"),[h.identifier(m),h.stringLiteral($),O]))):Nt(t,K,h.cloneNode(N),O=>Nn(m,$,O));t.creation.push(V()),t.updaters.push(V)}return To(e,t,f,m,r,o,i,s,x,d),m}function Bo(e,t,n,r,o,i,s=!1,a=Le(e,o),l){$o(e,t,n,r,o,i,at,ur,s,a,l)}function Vo(e,t,n,r,o,i,s=!1,a=Le(e,o),l=!1){Mo(e,t,n,r,o,i,at,s,a,l)}function Wo(e,t,n,r,o,i=!1,s=o,a=!1,l){return ar(e,t,n,r,o,at,i,s,a,l)}import*as Ie from"@babel/types";function Uo(e){if(e.isFunctionDeclaration())return e.node;if(!e.isVariableDeclarator())return null;let t=e.node.init;return t&&(Ie.isArrowFunctionExpression(t)||Ie.isFunctionExpression(t))?t:null}function Ho(e,t,n,r,o,i=!1){let s=pt(t,n);if(s!==null){nt(e,t,s,r,o,i);return}let a=t.scope.getBinding(n);if(a===void 0||a.scope.path.isProgram()!==!0||!e.helpers.has(n))return;let l=Uo(a.path);l!==null&&Gt(e,l,i)}function zo(e,t,n,r,o,i=!1){if(Ie.isArrowFunctionExpression(n)||Ie.isFunctionExpression(n)){if(ce(n.body))return;nt(e,t,n,r,o,i)}else Ie.isIdentifier(n)&&Ho(e,t,n.name,r,o,i)}function _o(e,t,n,r=!1){let o=t.scope.getBinding(n);if(o===void 0||o.scope.path.isProgram()!==!0||!e.helpers.has(n))return;let i=Uo(o.path);i!==null&&Gt(e,i,r)}function Ko(e,t,n,r=!1){if(Ie.isArrowFunctionExpression(n)||Ie.isFunctionExpression(n)){if(ce(n.body))return;Gt(e,n,r)}else Ie.isIdentifier(n)&&_o(e,t,n.name,r)}function qo(e,t,n,r,o){t.traverse({CallExpression(i){let s=i.getFunctionParent()===t,a=i.node.callee,l=Ie.isIdentifier(a,{name:"effect"})&&i.scope.getBinding("effect")===void 0;if(Ie.isIdentifier(a,{name:"cleanup"})&&i.scope.getBinding("cleanup")===void 0){if(!s)throw i.buildCodeFrameError("memo-dom: cleanup(disposer) must run directly during component factory initialization");let d=i.node.arguments[0];if(i.node.arguments.length!==1||d===void 0||!Ie.isExpression(d))throw i.buildCodeFrameError("memo-dom: cleanup(disposer) requires exactly one disposer expression");i.node.callee=Z(e,"cleanup"),i.node.arguments.unshift(Ie.identifier(r))}if(s){Ie.isIdentifier(a)&&Ho(e,t,a.name,n,o);for(let d of i.node.arguments)zo(e,t,d,n,o,l)}},NewExpression(i){if(i.getFunctionParent()===t)for(let s of i.node.arguments)zo(e,t,s,n,o)}})}function Go(e,t){t.traverse({CallExpression(n){if(n.getFunctionParent()!==null)return;let r=Ie.isIdentifier(n.node.callee,{name:"effect"})&&n.scope.getBinding("effect")===void 0;Ie.isIdentifier(n.node.callee)&&_o(e,t,n.node.callee.name);for(let o of n.node.arguments)Ko(e,t,o,r)},NewExpression(n){if(n.getFunctionParent()===null)for(let r of n.node.arguments)Ko(e,t,r)}})}function Zo(e){for(let t of e.helpers.values())t.node.async&&Gt(e,t.node)}function Yo(e){e.traverse({CallExpression(t){if(Ie.isIdentifier(t.node.callee,{name:"cleanup"})&&t.scope.getBinding("cleanup")===void 0)throw t.buildCodeFrameError("memo-dom: cleanup(disposer) is only valid directly inside a component factory")}})}import*as Be from"@babel/types";import*as Pe from"@babel/types";function Qo(e){return e.reduce((t,n)=>Pe.logicalExpression("||",t,n))}function ei(e,t){let n=()=>Pe.identifier(e),r=Qo(t.map(i=>Pe.binaryExpression("===",n(),Pe.numericLiteral(i)))),o=Qo(t.map(i=>Pe.callExpression(Pe.memberExpression(n(),Pe.identifier("has")),[Pe.numericLiteral(i)])));return Pe.logicalExpression("||",Pe.binaryExpression("===",n(),Pe.nullLiteral()),Pe.conditionalExpression(Pe.binaryExpression("===",Pe.unaryExpression("typeof",n()),Pe.stringLiteral("number")),r,o))}function ti(e,t,n,r,o,i){let s=new Map(r.map((c,g)=>[c,g])),a=0,l=[...o.map(c=>({order:s.get(c.declaration)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:c.sources,statement:Sr(c)})),...i.map(c=>({order:s.get(c.statement)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:c.sources,statement:Be.blockStatement([...c.resets.map(g=>Be.expressionStatement(Be.assignmentExpression("=",Be.identifier(g.binding),Be.cloneNode(g.source,!0)))),Be.cloneNode(c.statement,!0)])}))].sort((c,g)=>c.order-g.order||c.sequence-g.sequence),d=e.instanceReasonIds.get(t),u=[];for(let c of l){let g=n===null||d===void 0?null:c.sources.map(w=>d.get(w)).filter(w=>w!==void 0).sort((w,S)=>w-S),x=g===null||g.length===c.sources.length?g:null,y=x?.join(" ")??"*",f=u.at(-1),m=f?.reasons?.join(" ")??"*";f!==void 0&&m===y?f.statements.push(c.statement):u.push({reasons:x,statements:[c.statement]})}return Be.blockStatement(u.map(c=>c.reasons===null||n===null?Be.blockStatement(c.statements):Be.ifStatement(ei(n,c.reasons),Be.blockStatement(c.statements))))}import*as B from"@babel/types";function Zt(e){return!B.isReturnStatement(e)||!B.isJSXElement(e.argument)&&!B.isJSXFragment(e.argument)?null:{jsx:e.argument,statement:e}}function pr(e){return B.isBlockStatement(e)?e.body.length===1?Zt(e.body[0]):null:Zt(e)}function oa(e){let t=[];return e.get("body").traverse({ReturnStatement(n){t.push(n.node)},Function(n){n.skip()}}),t}function ia(e){if(B.isFunctionDeclaration(e))return!0;if(B.isVariableDeclaration(e))return e.declarations.every(t=>t.init==null||B.isFunction(t.init)||sa(t.init));if(B.isSwitchStatement(e)||B.isIfStatement(e)){let t=!0;return B.traverseFast(e,n=>{(B.isCallExpression(n)||B.isOptionalCallExpression(n)||B.isNewExpression(n)||B.isAwaitExpression(n)||B.isYieldExpression(n)||B.isThrowStatement(n)||B.isTaggedTemplateExpression(n)||B.isUpdateExpression(n))&&(t=!1)}),t}return B.isTypeScript(e)}function sa(e){let t=!0;return B.traverseFast(e,n=>{(B.isCallExpression(n)||B.isOptionalCallExpression(n)||B.isNewExpression(n)||B.isAwaitExpression(n)||B.isYieldExpression(n)||B.isTaggedTemplateExpression(n)||B.isAssignmentExpression(n)||B.isUpdateExpression(n))&&(t=!1)}),t}function aa(e){if(!e.cases.some(r=>r.test==null))return null;let t=[],n=[];for(let r of e.cases){if(r.consequent.length!==1)return null;let o=Zt(r.consequent[0]);if(o===null)return null;let i=t.length;t.push(o.jsx),n.push(B.switchCase(r.test===null?null:B.cloneNode(r.test),[B.returnStatement(B.numericLiteral(i))]))}return{pick:B.arrowFunctionExpression([],B.blockStatement([B.switchStatement(B.cloneNode(e.discriminant),n)])),branches:t,statements:new Set([e])}}function ni(e,t){let n=e.node.body.body,r=oa(e),o=n.at(-1);if(r.length===1&&o!==void 0){let s=Zt(o);if(s!==null)return s}if(o&&B.isIfStatement(o)&&o.alternate!=null){let s=o.alternate,a=pr(o.consequent),l=pr(s);if(a!==null&&l!==null&&r.length===2)return{pick:B.arrowFunctionExpression([],B.conditionalExpression(B.cloneNode(o.test),B.numericLiteral(0),B.numericLiteral(1))),branches:[a.jsx,l.jsx],statements:new Set([o])}}if(o&&B.isSwitchStatement(o)){let s=aa(o);if(s!==null&&s.branches.length===r.length)return s}let i=o===void 0?null:Zt(o);if(i!==null){let s=[],a=[],l=new Set([o]),d=-1,u=!0;for(let c=0;c<n.length-1;c++){let g=n[c];if(B.isIfStatement(g)&&g.alternate==null){let x=pr(g.consequent);if(x!==null){d===-1&&(d=c),s.push(B.cloneNode(g.test)),a.push(x.jsx),l.add(g);continue}}if(d!==-1&&!ia(g)){u=!1;break}}if(a.push(i.jsx),u&&a.length===r.length&&a.length>1){let c=B.numericLiteral(a.length-1);for(let g=s.length-1;g>=0;g--)c=B.conditionalExpression(s[g],B.numericLiteral(g),c);return{pick:B.arrowFunctionExpression([],c),branches:a,statements:l}}}throw e.buildCodeFrameError(`memo-dom: component '${t}' has unsupported JSX return control flow; use a tail chain of JSX early returns, a terminal JSX if/else, or an exhaustive JSX switch`)}function ri(e,t,n){let r=t.node,o=ni(t,n),i=e.componentProps.get(n),s=i.params.length,a=e.listedSites.get(n)??[],l=e.linkedComponentRows.get(n)??[],d=a.some(O=>O.sourceLocal===!0)||l.some(O=>O.sourceLocal),u=Mt(e,n),c=Ye(e,u),g=e.instanceDerivations.get(n),x=e.instanceControlFlow.get(n),y=e.effects.get(n),f=y?.some(O=>O.localReads.size>0||O.localDerivationReads.size>0||O.conditionLocalReads.size>0||O.conditionLocalDerivationReads.size>0)===!0;(e.selectiveDerivationComponents.has(n)||e.targetedListComponents.has(n)||f)&&(c.reasonVar=j(e,"reasons").name);let m=j(e,"id").name,w=u?null:j(e,"parent").name,S=u&&d?j(e,"owner").name:null,I=u&&e.componentsWithHostEvents.has(n)?j(e,"eventRoot").name:null;c.delegatedEventRootVar=I;let $=s>0&&!u?j(e,"props").name:null;wt(e).registerComponentId(n,m);let F;if((a.length>0||l.length>0)&&i.bindings.length>0){let O=[...a.map(ee=>lt(ee.keyExpr??null,ee.itemParam??"")),...l.map(ee=>ee.keyPath)],le=JSON.stringify(O[0]),te=O.every(ee=>JSON.stringify(ee)===le)?O[0]:null,q=on(i,"item"),Q=Ve(i);F={itemParam:q??Q??i.bindings[0],itemPath:q===null&&Q!==null?["item"]:[],rowIdVar:m,...u?{refreshVar:c.updateVar}:{},keyPath:te,sourceKey:a[0]?.sourceKey??l[0]?.sourceKey??"",sourceLocal:d,...d?{ownerIdVar:S??w}:{}}}qo(e,t,n,m,F);let N="jsx"in o?at(e,c,o.jsx,n,t,null,F):la(e,c,o,n,t,m);if(u&&Xt(e,c,N),g!==void 0)for(let O of g)O.declaration.kind="let";(g!==void 0||x!==void 0)&&c.updaters.unshift(()=>ti(e,n,c.reasonVar,r.body.body,g??[],x??[])),y!==void 0&&f&&c.updaters.push(()=>Xr(e,n,m,c.reasonVar,y,c));let K=new Set(y?.map(O=>O.statement)??[]),_=r.body.body.filter(O=>!("jsx"in o?O===o.statement:o.statements.has(O))&&!K.has(O));s>0&&!u&&c.updaters.unshift(()=>D.blockStatement(An(i,i.params.map((O,le)=>D.memberExpression(D.identifier($),D.numericLiteral(le),!0)))));let V=[Qe(c)];if(s>0&&!u){let O=yr(i,i.params.map((le,te)=>D.memberExpression(D.identifier($),D.numericLiteral(te),!0)));O!==null&&V.push(O)}if(V.push(..._,et(c),...u?[]:[ht(e,D.identifier(m),D.identifier(w),D.identifier(c.updateVar))]),s>0&&!u&&V.push(D.expressionStatement(D.callExpression(Z(e,"registerProps"),[D.identifier(m),D.identifier($)]))),V.push(...c.creation,...c.mounts),y!==void 0&&V.push(...Or(e,m,y)),u){let O=i.params.map((le,te)=>j(e,`nextProp${te}`));V.push(D.returnStatement(D.objectExpression([D.objectProperty(D.identifier("nodes"),D.callExpression(Z(e,"rootNodes"),[D.identifier(N)])),D.objectProperty(D.identifier("entities"),D.arrayExpression([])),D.objectProperty(D.identifier("update"),D.identifier(c.updateVar)),...s>0?[D.objectProperty(D.identifier("updateProps"),D.arrowFunctionExpression(O,D.blockStatement(An(i,O))))]:[],...c.disposableCallbacks.length>0?[D.objectProperty(D.identifier("dispose"),D.arrowFunctionExpression([],D.blockStatement([...c.disposableCallbacks].reverse().map(le=>D.ifStatement(D.binaryExpression("!==",D.cloneNode(le),D.nullLiteral()),D.expressionStatement(D.callExpression(D.cloneNode(le),[])))))))]:[]])))}else V.push(D.returnStatement(D.identifier(N)));r.params=u?[...i.params.map(xr),D.identifier(m),...S===null?[]:[D.identifier(S)],...I===null?[]:[D.identifier(I)]]:s>0?[D.identifier(m),D.identifier(w),D.identifier($)]:[D.identifier(m),D.identifier(w)],r.body=D.blockStatement(V)}function la(e,t,n,r,o,i){let s=j(e,"returnRoot").name,a=j(e,"returnRegion").name,l=D.identifier(i),d=D.binaryExpression("+",D.cloneNode(l),D.stringLiteral("/$return"));return t.creation.push(D.variableDeclaration("const",[D.variableDeclarator(D.identifier(s),D.callExpression(D.memberExpression(D.identifier("document"),D.identifier("createDocumentFragment")),[]))])),t.creation.push(D.variableDeclaration("const",[D.variableDeclarator(D.identifier(a),D.callExpression(Z(e,"createCondRegion"),[D.identifier(s),D.cloneNode(d),D.cloneNode(n.pick),D.arrayExpression(n.branches.map(u=>Wo(e,u,r,o,d,!1,l,!0,t.usedConds)))]))])),t.updaters.push(()=>D.expressionStatement(D.callExpression(D.memberExpression(D.identifier(a),D.identifier("update")),[]))),s}import*as de from"@babel/types";function da(e){return!de.isIdentifier(e.id)||!/^[A-Z]/.test(e.id.name)||!de.isArrowFunctionExpression(e.init)&&!de.isFunctionExpression(e.init)||!ce(e.init.body)?null:e.init}function ca(e,t,n){if(t.async||t.generator)throw n.buildCodeFrameError(`memo-dom: component '${e}' must be synchronous`);if(de.isFunctionExpression(t)&&t.id!=null&&t.id.name!==e)throw n.buildCodeFrameError(`memo-dom: named component function expression '${t.id.name}' must match binding '${e}'`);let r=de.functionDeclaration(de.identifier(e),t.params.map(o=>de.cloneNode(o,!0)),de.isBlockStatement(t.body)?de.cloneNode(t.body,!0):de.blockStatement([de.returnStatement(de.cloneNode(t.body,!0))]));return r.returnType=t.returnType==null?null:de.cloneNode(t.returnType,!0),r.typeParameters=t.typeParameters==null?null:de.cloneNode(t.typeParameters,!0),r.loc=t.loc,r}function oi(e,t,n){if(e.kind!=="const")return[t?de.exportNamedDeclaration(de.cloneNode(e,!0)):de.cloneNode(e,!0)];let r=[];for(let o of e.declarations){let i=da(o),s;i===null?s=de.variableDeclaration("const",[de.cloneNode(o,!0)]):s=ca(o.id.name,i,n),r.push(t?de.exportNamedDeclaration(s):s)}return r.length>0&&de.inheritsComments(r[0],e),r}function Yt(e){let t=[],n=!1;for(let r of e.get("body")){let o=r.node;if(de.isVariableDeclaration(o)){let i=oi(o,!1,r);n||=i.some(s=>de.isFunctionDeclaration(s)),t.push(...i);continue}if(de.isExportNamedDeclaration(o)&&de.isVariableDeclaration(o.declaration)){let i=oi(o.declaration,!0,r);n||=i.some(s=>de.isExportNamedDeclaration(s)&&de.isFunctionDeclaration(s.declaration)),t.push(...i);continue}t.push(o)}n&&(e.set("body",t),e.scope.crawl())}function ua(e,t){let n=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#`;for(let r of t.get("body")){let o=r.node;if(J.isExportNamedDeclaration(o)&&(o=o.declaration),!(!J.isVariableDeclaration(o)||o.kind!=="const"))for(let i of o.declarations){if(!J.isIdentifier(i.id)||i.init==null)continue;let s=i.id.name;if(!e.computeds.has(s))continue;o.kind="let";let a=J.cloneNode(i.init),l=j(e,`${s}Next`),d=J.expressionStatement(J.callExpression(Z(e,"register"),[J.objectExpression([J.objectProperty(J.identifier("id"),J.stringLiteral(`${n}${s}`)),J.objectProperty(J.identifier("parent"),J.nullLiteral()),J.objectProperty(J.identifier("depth"),J.unaryExpression("-",J.numericLiteral(1))),J.objectProperty(J.identifier("render"),J.arrowFunctionExpression([],J.blockStatement([J.variableDeclaration("const",[J.variableDeclarator(l,a)]),J.ifStatement(J.callExpression(Z(e,"computedChanged"),[J.identifier(s),J.cloneNode(l)]),J.blockStatement([J.expressionStatement(J.assignmentExpression("=",J.identifier(s),J.cloneNode(l))),J.expressionStatement(J.callExpression(Z(e,"commitWrites"),[Tt(e,[s])]))]))])))])]));r.insertAfter(d)}}}function pa(e,t){let n=new Map(t.get("body").map(r=>[r.node,r]));for(let r of e.moduleControlFlow){let o=n.get(r.statement);if(o===void 0)continue;let i=new Map(r.bindings.map(a=>[a,j(e,`${a}Previous`)])),s=[J.variableDeclaration("const",r.bindings.map(a=>J.variableDeclarator(J.cloneNode(i.get(a)),J.identifier(a)))),J.cloneNode(r.statement,!0),...r.bindings.map(a=>J.ifStatement(J.callExpression(Z(e,"computedChanged"),[J.cloneNode(i.get(a)),J.identifier(a)]),J.blockStatement([J.expressionStatement(J.callExpression(Z(e,"commitWrites"),[Tt(e,[a])]))])))];o.insertAfter(J.expressionStatement(J.callExpression(Z(e,"register"),[J.objectExpression([J.objectProperty(J.identifier("id"),J.stringLiteral(r.entityId)),J.objectProperty(J.identifier("parent"),J.nullLiteral()),J.objectProperty(J.identifier("depth"),J.unaryExpression("-",J.numericLiteral(1))),J.objectProperty(J.identifier("render"),J.arrowFunctionExpression([],J.blockStatement(s)))])])))}}function fr(e,t={}){let n=Qt(t),r=new WeakSet;return{name:"memo-dom",visitor:{Program:{enter(i){Yt(i),Sn(n,i),en(n,i),vn(n,i),Go(n,i),Zo(n)},exit(i){Tr(n,i),Yo(i),Br(i),i.traverse({JSXElement(a){throw a.buildCodeFrameError("memo-dom: JSX outside a component function \u2014 components must be top-level function declarations (L1)")},JSXFragment(a){throw a.buildCodeFrameError("memo-dom: JSX outside a component function - components must be top-level function declarations")}});let s=qn(n);n.computeds.size>0&&ua(n,i),n.moduleControlFlow.length>0&&pa(n,i),s&&n.header.push(s);for(let a=n.header.length-1;a>=0;a--)i.unshiftContainer("body",n.header[a]);i.unshiftContainer("body",J.importDeclaration([J.importNamespaceSpecifier(J.identifier(wt(n).runtimeId))],J.stringLiteral(n.runtimePath)))}},FunctionDeclaration(i){let s=i.node.id?.name;!s||!n.comps.has(s)||r.has(i.node)||(r.add(i.node),ri(n,i,s),i.skip())}}}}function mr(e,t={}){let n=fa(e,{filename:t.moduleId??"./component.tsx",plugins:[[ma,{}],[fr,t],[ga,{isTSX:!0}]],configFile:!1,babelrc:!1});if(!n||n.code==null)throw new Error("memo-dom: compilation produced no output");return n.code}import{posix as Ot}from"node:path";import{transformSync as hi}from"@babel/core";import Ei from"@babel/plugin-syntax-jsx";import yi from"@babel/plugin-transform-typescript";import*as W from"@babel/types";function ba(e,t,n){let r=e.get(t);r===void 0&&(r=new Map,e.set(t,r));let o=r.get(n);return o===void 0&&(o={keys:new Set,rootFallback:!1},r.set(n,o)),o}function ha(e,t,n,r){if(n.type==="state"){r.keys.add(n.key);return}if(n.type==="root"){r.rootFallback=!0;return}if(n.type==="local")return;let o=e.get(t)?.get(n.name);if(o===void 0){r.rootFallback=!0;return}r.rootFallback||=o.rootFallback;let i=n.path.length===0?"":`.${n.path.join(".")}`;for(let s of o.keys)r.keys.add(`${s}${i}`)}function ii(e,t){let n=new Map;for(let s of e.values())for(let a of s.edges)n.set(a.target,(n.get(a.target)??0)+1);let r=new Map,o=new Map(n),i=[...t];for(;i.length>0;){let s=i.shift();for(let a of e.get(s)?.edges??[]){for(let[d,u]of Object.entries(a.propSources??{})){let c=ba(r,a.target,d);for(let g of u)ha(r,s,g,c)}let l=(o.get(a.target)??1)-1;o.set(a.target,l),l===0&&i.push(a.target)}}return new Map([...r].map(([s,a])=>[s,new Map([...a].map(([l,d])=>[l,{keys:[...d.keys].sort(),rootFallback:d.rootFallback}]))]))}function Ea(e){let t=new Set,n=new Set,r=o=>{if(n.has(o))throw new Error(`memo-dom: recursive cross-module component graph at '${o}'`);if(!t.has(o)){n.add(o);for(let i of e.get(o)?.edges??[])r(i.target);n.delete(o),t.add(o)}};for(let o of e.keys())r(o)}function si(e,t){let n=new Map(e.map(u=>[u.key,u]));Ea(n);let r=new Map,o=new Map;for(let u of n.values())for(let c of u.edges){if(!n.has(c.target))throw new Error(`memo-dom: component '${u.key}' references unknown factory '${c.target}'`);let g=r.get(c.target)??new Set;if(g.add(c.mode),r.set(c.target,g),c.mode==="row"){let x=o.get(c.target)??[];x.push({keyPath:c.keyPath===void 0||c.keyPath===null?null:[...c.keyPath],sourceKey:c.sourceKey??"",sourceLocal:c.sourceLocal??!1}),o.set(c.target,x)}}for(let[u,c]of r)if(c.size>1)throw new Error(`memo-dom: component '${u}' is used both as a keyed row and a static child`);let i=new Map,s=[...n.keys()].filter(u=>!r.has(u));for(let u of s)i.set(u,new Set([t]));let a=[...s];for(;a.length>0;){let u=a.shift(),c=i.get(u);if(c!==void 0)for(let g of n.get(u)?.edges??[]){let x=i.get(g.target)??new Set,y=x.size;for(let f of c)x.add(`${f}${g.suffix}`);i.set(g.target,x),x.size!==y&&a.push(g.target)}}let l=new Map;for(let u of n.keys())l.set(u,[...i.get(u)??[]].sort());let d=ii(n,s);return{paths:l,rows:o,propSources:d}}import"@babel/types";import*as be from"@babel/types";function ai(e){let t=e;for(;be.isTSAsExpression(t)||be.isTSTypeAssertion(t)||be.isTSNonNullExpression(t)||be.isTSSatisfiesExpression(t);)t=t.expression;return t}function ya(e,t,n){let r=ai(n);if(be.isIdentifier(r))return!e.state.has(r.name)||t.getBinding(r.name)?.scope.path.isProgram()!==!0?null:_e(e,r.name);if(!be.isMemberExpression(r))return null;let o=we(r);return o===null||!e.state.has(o)||t.getBinding(o)?.scope.path.isProgram()!==!0?null:_e(e,ye(r)??o)}function Sa(e,t){let n=ai(t);if(be.isIdentifier(n)){let a=He(e,n.name);return a===null?null:{type:"prop",name:a,path:[]}}if(!be.isMemberExpression(n))return null;let r=we(n),o=ye(n);if(r===null||o===null)return null;if(Ve(e)===r){let[a,...l]=o.split(".").slice(1);return a===void 0?null:{type:"prop",name:a,path:l}}let s=He(e,r);return s===null?null:{type:"prop",name:s,path:o.split(".").slice(1)}}function xa(e,t){let n=!1,r=Ve(e);return Xe(t,o=>{be.isIdentifier(o)&&(o.name===r||He(e,o.name)!==null)&&(n=!0)}),n}function Ca(e){return be.isStringLiteral(e)||be.isNumericLiteral(e)||be.isBooleanLiteral(e)||be.isNullLiteral(e)||be.isBigIntLiteral(e)||be.isTemplateLiteral(e)}function wa(e,t,n,r){let o=ya(e,n,r);if(o!==null)return{type:"state",key:o};let i=e.componentProps.get(t),s=Sa(i,r);if(s!==null)return s;let a=be.isIdentifier(r)?r.name:be.isMemberExpression(r)?we(r):null;return a!==null&&(e.instanceState.get(t)?.has(a)===!0||e.instanceDerivedBindings.get(t)?.has(a)===!0)||tn(e,r).size>0||xa(i,r)?{type:"root"}:Ca(r)?{type:"local"}:{type:"root"}}function gr(e,t,n,r){let o=e.get(t)??{},i=o[n]??[],s=JSON.stringify(r);i.some(a=>JSON.stringify(a)===s)||(i.push(r),i.sort((a,l)=>JSON.stringify(a).localeCompare(JSON.stringify(l)))),o[n]=i,e.set(t,o)}function Pa(e){return be.isJSXIdentifier(e.name)?e.name.name:null}function li(e,t){let n=new Map;return e.compPaths.get(t).traverse({JSXOpeningElement(r){let o=r.node.name;if(!be.isJSXIdentifier(o)||!/^[A-Z]/.test(o.name))return;let i=e.componentProps.get(o.name);for(let s of r.get("attributes")){if(s.isJSXSpreadAttribute()){for(let d of i?.names??[])d==="ref"||i?.refProps.includes(d)||gr(n,o.name,d,{type:"root"});continue}if(!s.isJSXAttribute())continue;let a=Pa(s.node);if(a===null||a==="key"||a==="ref"||i?.refProps.includes(a)===!0)continue;let l=s.node.value;if(!be.isJSXExpressionContainer(l)||!be.isExpression(l.expression)){gr(n,o.name,a,{type:"local"});continue}gr(n,o.name,a,wa(e,t,s.scope,l.expression))}}}),n}function di(e,t){let n=new Map;return e.traverse({FunctionDeclaration(r){let o=r.node.id?.name;if(o!==void 0&&/^[A-Z]/.test(o)&&r.scope.parent?.path.isProgram()===!0&&De(r)){let i=rn(r.node.params);n.set(o,{key:`${t}#${o}`,props:[...i.names],objectProps:i.mode==="object",acceptsUnknownProps:i.acceptsUnknown,hasWholeDefault:i.hasWholeDefault,listLightweight:!1,delegatedEvents:wn(r.node.body),renderProps:[],renderCallbacks:[],refProps:[],subtreeReads:[]})}r.skip()}}),n}function ci(e,t,n){let r=e.componentProps.get(n);return{key:`${t}#${n}`,props:[...r.names],objectProps:r.mode==="object",acceptsUnknownProps:r.acceptsUnknown,hasWholeDefault:r.hasWholeDefault,listLightweight:hn(e,n),delegatedEvents:e.componentsWithHostEvents.has(n),renderProps:[...r.renderProps],renderCallbacks:[...r.renderCallbacks],refProps:[...r.refProps],subtreeReads:[...Cn(e,n)].map(o=>_e(e,o)).sort()}}function Rn(e,t){return e.importedComponents.get(t)?.key??`${e.moduleId}#${t}`}function ui(e,t){let n=[];for(let r of t.comps.keys()){let o=[],i=li(t,r);for(let[s,a]of t.childRefCounts.get(r)??[]){let l=Rn(t,s),d=i.get(s);o.push({target:l,suffix:`/${s}`,mode:"static",...d===void 0?{}:{propSources:d}}),a>1&&o.push({target:l,suffix:`/${s}[*]`,mode:"static",...d===void 0?{}:{propSources:d}})}for(let[s,a]of t.conditionalComponentSites)for(let l of a){if(l.owner!==r)continue;let d=i.get(s);o.push({target:Rn(t,s),suffix:`/${l.suffix}`,mode:"static",...d===void 0?{}:{propSources:d}})}for(let[s,a]of t.rowComponentSites)for(let l of a){if(l.owner!==r)continue;let d=i.get(s);o.push({target:Rn(t,s),suffix:`/${l.suffix}`,mode:"static",...d===void 0?{}:{propSources:d}})}for(let[s,a]of t.listedSites)for(let l of a)l.owner===r&&o.push({target:Rn(t,s),suffix:`/${l.suffix}/Row[*]`,mode:"row",keyPath:lt(l.keyExpr??null,l.itemParam??""),sourceKey:l.sourceLocal===!0?l.sourceKey??"":_e(t,l.sourceKey??""),sourceLocal:l.sourceLocal??!1,...i.get(s)===void 0?{}:{propSources:i.get(s)}});n.push({key:`${e}#${r}`,moduleId:e,local:r,edges:o})}return n}function Si(e){let t=e.replace(/\\/g,"/"),n=Ot.normalize(t);return t.startsWith("./")&&!n.startsWith("../")?`./${n}`:n}function xi(e){return{...e.runtimePath===void 0?{}:{runtimePath:e.runtimePath},...e.rootId===void 0?{}:{rootId:e.rootId}}}function va(e){let t=new Map,n=(r,o,i)=>{t.set(`${r}\0${o}\0${i}`,{target:r,prop:o,kind:i})};for(let[r,o]of e.compPaths)o.traverse({JSXElement(i){let s=i.node.openingElement,a=s.name;if(!W.isJSXIdentifier(a)||!/^[A-Z]/.test(a.name))return;let l=e.importedComponents.get(a.name)?.key??(e.comps.has(a.name)?`${e.moduleId}#${a.name}`:null);if(l!==null){for(let d of s.attributes){if(!W.isJSXAttribute(d))continue;let u=W.isJSXIdentifier(d.name)?d.name.name:d.name.name.name,c=d.value;W.isJSXElement(c)||W.isJSXFragment(c)||W.isJSXExpressionContainer(c)&&W.isExpression(c.expression)&&(ce(c.expression)||tt(e,r,c.expression))?n(l,u,"jsx"):n(l,u,"scalar")}i.node.children.some(d=>!W.isJSXText(d)||d.value.trim()!=="")&&n(l,"children","jsx")}}});return[...t.values()].sort((r,o)=>r.target.localeCompare(o.target)||r.prop.localeCompare(o.prop)||r.kind.localeCompare(o.kind))}function pi(e,t){return[...new Set(t.flatMap(n=>{let r=e.importedComponents.get(n);return r!==void 0?[r.key]:e.comps.has(n)?[`${e.moduleId}#${n}`]:[]}))].sort()}function Ct(e,t,n){for(;W.isTSAsExpression(e)||W.isTSTypeAssertion(e)||W.isTSNonNullExpression(e);)e=e.expression;if(W.isIdentifier(e)){t.has(e.name)&&n.add(e.name);return}if(W.isConditionalExpression(e)){Ct(e.consequent,t,n),Ct(e.alternate,t,n);return}if(W.isLogicalExpression(e)){Ct(e.right,t,n);return}if(W.isObjectExpression(e)){for(let r of e.properties)W.isObjectProperty(r)&&W.isExpression(r.value)&&Ct(r.value,t,n);return}if(W.isArrayExpression(e))for(let r of e.elements)r!=null&&!W.isSpreadElement(r)&&Ct(r,t,n)}function fi(e,t){let n=new Set;if(W.isExpression(e.body))return Ct(e.body,t,n),[...n];let r=o=>{if(!W.isFunction(o)){if(W.isReturnStatement(o)){W.isExpression(o.argument)&&Ct(o.argument,t,n);return}for(let i of W.VISITOR_KEYS[o.type]??[]){let s=o[i];if(Array.isArray(s))for(let a of s)a!=null&&typeof a=="object"&&"type"in a&&r(a);else s!=null&&typeof s=="object"&&"type"in s&&r(s)}}};for(let o of e.body.body)r(o);return[...n]}function Ci(e){let t=[];for(let n of e.body)if(!(!W.isImportDeclaration(n)||n.importKind==="type"))for(let r of n.specifiers)if(W.isImportSpecifier(r)){if(r.importKind==="type")continue;let o=W.isIdentifier(r.imported)?r.imported.name:r.imported.value;t.push({local:r.local.name,imported:o,source:n.source.value})}else W.isImportDefaultSpecifier(r)?t.push({local:r.local.name,imported:"default",source:n.source.value}):t.push({local:r.local.name,imported:"*",source:n.source.value});return t}function wi(e){let t=new Map;for(let n of e.body){if(W.isExportDefaultDeclaration(n)){(W.isFunctionDeclaration(n.declaration)||W.isClassDeclaration(n.declaration))&&n.declaration.id!=null?t.set("default",n.declaration.id.name):W.isIdentifier(n.declaration)&&t.set("default",n.declaration.name);continue}if(!W.isExportNamedDeclaration(n))continue;if(n.source!==null)throw new Error("memo-dom: re-export-from declarations are not supported by compileModules(); import then export the binding explicitly");let r=n.declaration;if(W.isVariableDeclaration(r))for(let o of r.declarations)W.isIdentifier(o.id)&&t.set(o.id.name,o.id.name);else W.isFunctionDeclaration(r)&&r.id!=null&&t.set(r.id.name,r.id.name);for(let o of n.specifiers){if(!W.isExportSpecifier(o))continue;let i=o.local.name,s=W.isIdentifier(o.exported)?o.exported.name:o.exported.value;t.set(s,i)}}return t}function ka(e,t,n){let r,o=()=>({visitor:{Program(i){Yt(i);let s=Ci(i.node),a=Qt({...xi(n),moduleId:e.id,linkedImports:t});Sn(a,i),en(a,i),vn(a,i);let l={},d=_n(i.node);for(let[u,c]of wi(i.node)){if(a.comps.has(c)){l[u]={type:"component",...ci(a,e.id,c)};continue}let g=a.state.get(c);if(g!==void 0){l[u]={type:"state",kind:g,key:a.stateKeys.get(c)??`${e.id}#${c}`,tagCandidates:[...a.stateTagCandidates.get(c)??[]],componentCandidates:pi(a,a.stateComponentCandidates.get(c)??[])};continue}let x=a.importedFunctions.get(c)??(a.helpers.has(c)?We(a,c):void 0);x!==void 0&&(l[u]={type:"function",tagCandidates:[...d.get(c)??a.functionTagCandidates.get(c)??[]],componentCandidates:pi(a,a.functionComponentCandidates.get(c)??[]),reads:[...x.reads].map(y=>_e(a,y)).sort(),writes:[...x.writes].map(y=>_e(a,y)).sort(),boundedWrites:[...x.boundedWrites].map(y=>_e(a,y)).sort(),parameterWrites:x.parameterWrites.map(y=>({index:y.index,path:[...y.path]})).sort((y,f)=>y.index-f.index||y.path.join(".").localeCompare(f.path.join("."))),unbounded:x.unbounded})}r={exports:l,imports:s,components:ui(e.id,a),componentUsages:va(a)}}}});if(hi(e.source,{filename:e.id,plugins:[[Ei,{}],o,[yi,{isTSX:!0}]],configFile:!1,babelrc:!1}),r===void 0)throw new Error(`memo-dom: failed to analyze module '${e.id}'`);return r}function Na(e){let t,n=()=>({visitor:{Program(r){Yt(r);let o=new Map,i=xn(r.node),s=_n(r.node),a=di(r,e.id),l=new Set(a.keys());for(let[u,c]of a)o.set(u,{type:"component",...c});for(let u of r.node.body){let c=W.isExportNamedDeclaration(u)?u.declaration:u;if(W.isVariableDeclaration(c))for(let g of c.declarations){if(!W.isIdentifier(g.id))continue;if(W.isArrowFunctionExpression(g.init)||W.isFunctionExpression(g.init)){let y=fi(g.init,l).map(f=>`${e.id}#${f}`);o.set(g.id.name,{type:"function",tagCandidates:[...s.get(g.id.name)??[]],componentCandidates:y,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0});continue}let x;if(c.kind==="let"||c.kind==="var"?x="let":Pt(g.init)?x="store":vt(g.init)&&(x="const"),x!==void 0){let y=new Set;W.isExpression(g.init)&&Ct(g.init,l,y),o.set(g.id.name,{type:"state",kind:x,key:`${e.id}#${g.id.name}`,tagCandidates:[...i.get(g.id.name)??[]],componentCandidates:[...y].map(f=>`${e.id}#${f}`)})}}else if(W.isFunctionDeclaration(c)&&c.id!=null&&!a.has(c.id.name)){let g=fi(c,l).map(x=>`${e.id}#${x}`);o.set(c.id.name,{type:"function",tagCandidates:[...s.get(c.id.name)??[]],componentCandidates:g,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0})}}let d={};for(let[u,c]of wi(r.node)){let g=o.get(c);g!==void 0&&(d[u]=g)}t={exports:d,imports:Ci(r.node),components:[],componentUsages:[]}}}});if(hi(e.source,{filename:e.id,plugins:[[Ei,{}],n,[yi,{isTSX:!0}]],configFile:!1,babelrc:!1}),t===void 0)throw new Error(`memo-dom: failed to discover module '${e.id}'`);return t}function Pi(e,t,n,r){let i=r.resolveImport?.(t,e);if(i===void 0){let l=Object.entries(r.aliases??{}).sort(([d],[u])=>u.length-d.length);for(let[d,u]of l)if(d.endsWith("/")?t.startsWith(d):t===d||t.startsWith(`${d}/`)){i=`${u}${t.slice(d.length)}`;break}}if(i===void 0)if(t.startsWith(".")){let l=Ot.normalize(Ot.join(Ot.dirname(e),t));i=e.startsWith("./")&&!l.startsWith("../")?`./${l}`:l}else i=t;let s=Si(i??t),a=[s,`${s}.ts`,`${s}.tsx`,`${s}.js`,`${s}.jsx`,`${s}/index.ts`,`${s}/index.tsx`,`${s}/index.js`,`${s}/index.jsx`];for(let l of a){let d=n.get(l);if(d!==void 0)return d}}function Ia(e,t){if(!t.startsWith("."))return t;let n=Ot.relative(Ot.dirname(e),t);return n.startsWith(".")?n:`./${n}`}function mi(e,t,n){return t.map(r=>{for(let[o,i]of n)for(let[s,a]of Object.entries(i.exports))if(!(a.type!=="component"||a.key!==r))return{key:a.key,source:Ia(e.id,o),imported:s,props:[...a.props],objectProps:a.objectProps,acceptsUnknownProps:a.acceptsUnknownProps,hasWholeDefault:a.hasWholeDefault,listLightweight:a.listLightweight,delegatedEvents:a.delegatedEvents,renderProps:[...a.renderProps],renderCallbacks:[...a.renderCallbacks],refProps:[...a.refProps],subtreeReads:[...a.subtreeReads]};throw new Error(`memo-dom: dynamic component candidate '${r}' is not exported; export the component so consuming modules can link it`)})}function gi(e,t,n,r,o,i){let s={};for(let a of t.imports){let l=Pi(e.id,a.source,r,o);if(l===void 0){s[a.local]={type:"function",tagCandidates:[],componentCandidates:[],reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}if(a.imported==="*")throw new Error(`memo-dom: namespace import '${a.local}' from '${a.source}' cannot identify a reactive export; use named imports`);let d=n.get(l.id)?.exports[a.imported];if(d===void 0){s[a.local]={type:"function",tagCandidates:[],componentCandidates:[],reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}if(d.type==="state")s[a.local]={type:"state",kind:d.kind,key:d.key,tagCandidates:[...d.tagCandidates],componentCandidates:mi(e,d.componentCandidates,n)};else if(d.type==="component"){let u=i?.get(d.key),c=d.renderProps.filter(g=>u?.scalar.has(g)!==!0||u.jsx.has(g));s[a.local]={type:"component",key:d.key,props:[...d.props],objectProps:d.objectProps,acceptsUnknownProps:d.acceptsUnknownProps,hasWholeDefault:d.hasWholeDefault,listLightweight:d.listLightweight,delegatedEvents:d.delegatedEvents,renderProps:c,renderCallbacks:[...d.renderCallbacks],refProps:[...d.refProps],subtreeReads:[...d.subtreeReads]}}else s[a.local]={type:"function",tagCandidates:[...d.tagCandidates],componentCandidates:mi(e,d.componentCandidates,n),reads:[...d.reads],writes:[...d.writes],boundedWrites:[...d.boundedWrites],parameterWrites:[...d.parameterWrites],unbounded:d.unbounded}}return s}function bi(e){return JSON.stringify(e)}function Fa(e,t={}){let n=new Map;for(let[a,l]of Object.entries(e)){let d=Si(a);if(n.has(d))throw new Error(`memo-dom: duplicate module id after normalization: '${d}'`);n.set(d,{originalId:a,id:d,source:l})}let r=new Map;for(let a of n.values())r.set(a.id,Na(a));for(let a=0;a<=n.size;a++){let l=!1,d=new Map;for(let u of n.values()){let c=r.get(u.id),g=gi(u,c,r,n,t),x=ka(u,g,t);d.set(u.id,x),bi(x)!==bi(c)&&(l=!0)}if(r=d,!l)break;if(a===n.size)throw new Error("memo-dom: cross-module export summaries did not converge")}let o=new Map;for(let a of r.values())for(let l of a.componentUsages){let d=o.get(l.target);d===void 0&&(d={jsx:new Set,scalar:new Set},o.set(l.target,d)),d[l.kind].add(l.prop)}for(let[a,l]of o)for(let d of l.jsx)if(l.scalar.has(d))throw new Error(`memo-dom: component '${a}' prop '${d}' is used as both scalar data and JSX content; split the prop or component contract`);let i=si([...r.values()].flatMap(a=>a.components),t.rootId??"App"),s={};for(let a of n.values()){let l=r.get(a.id),d=gi(a,l,r,n,t,o);for(let y of l.imports){let f=Pi(a.id,y.source,n,t);if(f!==void 0&&r.get(f.id)?.exports[y.imported]===void 0)throw new Error(`memo-dom: '${y.imported}' is not a linkable state, function, or component export of '${y.source}'`)}let u={},c={},g={},x={};for(let y of l.components){u[y.local]=[...i.paths.get(y.key)??[]];let f=i.rows.get(y.key);f!==void 0&&(c[y.local]=f.map(S=>({keyPath:S.keyPath===null?null:[...S.keyPath],sourceKey:S.sourceKey,sourceLocal:S.sourceLocal})));let m=i.propSources.get(y.key);m!==void 0&&(g[y.local]=Object.fromEntries([...m].map(([S,I])=>[S,{keys:[...I.keys],rootFallback:I.rootFallback}])));let w=Object.values(l.exports).find(S=>S.type==="component"&&S.key===y.key);if(w?.type==="component"){let S=o.get(y.key);x[y.local]=w.renderProps.filter(I=>S?.scalar.has(I)!==!0||S.jsx.has(I))}}s[a.originalId]=mr(a.source,{...xi(t),moduleId:a.id,linkedImports:d,linkedComponentPaths:u,linkedComponentRows:c,linkedComponentPropSources:g,linkedComponentRenderProps:x})}return s}export{mr as compile,Fa as compileModules};
1
+ import{transformSync as wa}from"@babel/core";import va from"@babel/plugin-syntax-jsx";import ka from"@babel/plugin-transform-typescript";import*as $ from"@babel/types";import"@babel/types";function ln(e={}){let t=e.moduleId??"./component.tsx",n=new Map,r=new Map,o=new Map,i=new Map,s=new Map,a=new Map,l=new Map,d=new Set,p=new Map,u=new Map;for(let[x,f]of Object.entries(e.linkedImports??{}))f.type==="state"?(n.set(x,f.kind),r.set(x,f.key),f.tagCandidates!==void 0&&o.set(x,[...f.tagCandidates]),f.componentCandidates!==void 0&&l.set(x,f.componentCandidates.map(m=>({...m}))),d.add(x)):f.type==="function"?(f.tagCandidates!==void 0&&i.set(x,[...f.tagCandidates]),f.componentCandidates!==void 0&&l.set(x,f.componentCandidates.map(m=>({...m}))),p.set(x,{reads:new Set(f.reads),writes:new Set(f.writes),boundedWrites:new Set(f.boundedWrites),parameterWrites:f.parameterWrites.map(m=>({index:m.index,path:[...m.path]})),unbounded:f.unbounded})):u.set(x,{...f,props:[...f.props]});let g=new Map;for(let[x,f]of u)g.set(x,{mode:f.objectProps?"object":"positional",names:[...f.props],acceptsUnknown:f.acceptsUnknownProps,bindings:[],params:[],hasWholeDefault:f.hasWholeDefault,renderProps:[...f.renderProps??[]],renderCallbacks:[...f.renderCallbacks??[]],refProps:[...f.refProps??[]]});let S=new Map(Object.entries(e.linkedComponentRenderProps??{}).map(([x,f])=>[x,[...f]]));return{runtimePath:e.runtimePath??"@memoized-dom/runtime",rootId:e.rootId??"App",moduleId:t,state:n,stateKeys:r,stateTagCandidates:o,functionTagCandidates:i,stateComponentCandidates:s,functionComponentCandidates:a,linkedDynamicComponentCandidates:l,importedState:d,importedFunctions:p,importedComponents:u,linkedComponentPaths:new Map(Object.entries(e.linkedComponentPaths??{}).map(([x,f])=>[x,[...f]])),linkedComponentRows:new Map(Object.entries(e.linkedComponentRows??{}).map(([x,f])=>[x,f.map(m=>({keyPath:m.keyPath===null?null:[...m.keyPath],sourceKey:m.sourceKey,sourceLocal:m.sourceLocal}))])),linkedComponentPropSources:new Map(Object.entries(e.linkedComponentPropSources??{}).map(([x,f])=>[x,new Map(Object.entries(f).map(([m,C])=>[m,{keys:[...C.keys],rootFallback:C.rootFallback}]))])),comps:new Map,compPaths:new Map,helpers:new Map,jsxHelpers:new Map,helperSummaries:new Map,compReads:new Map,childRefCounts:new Map,renderSlotOwners:new Set,listedSites:new Map,componentsWithHostEvents:new Set,componentHostEvents:new Map,conditionalComponentSites:new Map,rowComponentSites:new Map,componentProps:g,linkedComponentRenderProps:S,lightweightCache:new Map,rowReads:new Map,condReads:new Map,targetedListDependencies:new WeakMap,targetedListComponents:new Set,keyedListMutations:new WeakMap,keyedListMutationSources:new Map,disabledKeyedListMutationSources:new Set,instanceState:new Map,instanceDerivations:new Map,instanceControlFlow:new Map,instanceDerivedBindings:new Map,instanceReasonIds:new Map,selectiveDerivationComponents:new Set,effects:new Map,moduleEffects:[],computeds:new Map,moduleControlFlow:[],header:[],readers:new Map,writeConstCounter:0,writeConsts:new Map,reasonConstCounter:0,reasonConsts:new Map,analyzedFunctions:new WeakSet,handlerHasRootCommit:new WeakMap,identifiers:null}}import*as Z from"@babel/types";import*as lt from"@babel/types";var Xn=class{constructor(t,n){this.scope=t;Di(n.node,r=>this.reserved.add(r)),this.runtimeId=this.generate("MD").name}scope;runtimeId;reserved=new Set;componentIds=new Map;generate(t){let n;do n=this.scope.generateUidIdentifier(t);while(this.reserved.has(n.name));return this.reserved.add(n.name),n}registerComponentId(t,n){this.componentIds.set(t,n)}componentId(t){let n=this.componentIds.get(t);if(n===void 0)throw new Error(`memo-dom: missing generated factory id for '${t}'`);return lt.identifier(n)}runtimeMember(t){return lt.memberExpression(lt.identifier(this.runtimeId),lt.identifier(t))}};function dn(e,t){let n=new Xn(t.scope,t);return e.identifiers=n,n}function A(e,t){return Nt(e).generate(t)}function $e(e,t){return Nt(e).componentId(t)}function Y(e,t){return Nt(e).runtimeMember(t)}function Nt(e){if(e.identifiers===null)throw new Error("memo-dom: generated identifier allocator was not initialized");return e.identifiers}function Di(e,t){let n=r=>{lt.isIdentifier(r)&&t(r.name);for(let o of lt.VISITOR_KEYS[r.type]??[]){let i=r[o];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&"type"in s&&n(s);else i&&typeof i=="object"&&"type"in i&&n(i)}};n(e)}function ht(e,t,n){e.state.set(t,n),e.stateKeys.has(t)||e.stateKeys.set(t,`${e.moduleId}#${t}`)}function Ye(e,t){if(t.includes("#"))return t;let n=t.indexOf("."),r=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n);return`${e.stateKeys.get(r)??r}${o}`}function Ht(e,t){let n=[...new Set(t.map(s=>Ye(e,s)))].sort(),r=n.join(" "),o=e.writeConsts.get(r);if(o!==void 0)return Z.identifier(o);let i=A(e,`WRITES_${e.writeConstCounter++}`);return e.writeConsts.set(r,i.name),e.header.push(Z.variableDeclaration("const",[Z.variableDeclarator(i,Z.arrayExpression(n.map(s=>Z.stringLiteral(s))))])),i}function Pr(e,t){let n=[...new Set(t)].sort((s,a)=>s-a),r=n.join(" "),o=e.reasonConsts.get(r);if(o!==void 0)return Z.identifier(o);let i=A(e,`REASONS_${e.reasonConstCounter++}`);return e.reasonConsts.set(r,i.name),e.header.push(Z.variableDeclaration("const",[Z.variableDeclarator(i,Z.arrayExpression(n.map(s=>Z.numericLiteral(s))))])),i}function xe(e){let t=[],n=e;for(;Z.isMemberExpression(n);){if(n.computed){if(!Z.isStringLiteral(n.property))return null;t.unshift(n.property.value)}else{if(!Z.isIdentifier(n.property))return null;t.unshift(n.property.name)}if(Z.isSuper(n.object))return null;n=n.object}for(;Z.isTSNonNullExpression(n)||Z.isTSAsExpression(n);)n=n.expression;return Z.isIdentifier(n)?(t.unshift(n.name),t.join(".")):null}function nt(e,t){if(e===null)return[];let n=[],r=e;for(;Z.isMemberExpression(r)&&!r.computed;){if(!Z.isIdentifier(r.property)||(n.unshift(r.property.name),Z.isSuper(r.object)))return null;r=r.object}return!Z.isIdentifier(r,{name:t})||n.length===0?null:n}function jt(e,t){return t===null?!0:t.length===0||e.length>t.length?!1:e.every((n,r)=>t[r]===n)}function ke(e){let t=e;for(;;){if(Z.isMemberExpression(t)){if(Z.isSuper(t.object))return null;t=t.object;continue}if(Z.isTSNonNullExpression(t)||Z.isTSAsExpression(t)){t=t.expression;continue}break}return Z.isIdentifier(t)?t.name:null}function It(e){return!e||!Z.isObjectExpression(e)?!1:e.properties.every(t=>Z.isObjectProperty(t)&&!t.computed&&(Z.isIdentifier(t.key)||Z.isStringLiteral(t.key)))}function Rt(e){return e?Z.isArrayExpression(e)||Z.isNewExpression(e):!1}function Ve(e){return e==null?null:Z.isStringLiteral(e)?e:Z.isJSXExpressionContainer(e)?Z.isJSXEmptyExpression(e.expression)?null:e.expression:null}function Tn(e,t,n){let r=n!==void 0?e.instanceState.get(n):void 0,o=n!==void 0?e.instanceDerivedBindings.get(n):void 0,i=n!==void 0?e.componentProps.get(n)?.bindings:void 0,s=!1,a=l=>{if(!s){if(Z.isIdentifier(l)&&(e.state.has(l.name)||r?.has(l.name)===!0||o?.has(l.name)===!0||i?.includes(l.name)===!0)){s=!0;return}for(let d of Z.VISITOR_KEYS[l.type]??[]){let p=l[d];if(Array.isArray(p))for(let u of p)u&&typeof u=="object"&&"type"in u&&a(u);else p&&typeof p=="object"&&"type"in p&&a(p)}}};return a(t),s}function wr(e,t,n){let r=new Set([...e.instanceState.get(n)??[],...e.instanceDerivedBindings.get(n)??[],...e.componentProps.get(n)?.bindings??[]]);if(r.size===0)return!1;let o=!1;return Ae(t,i=>Z.isIdentifier(i)&&r.has(i.name)?(o=!0,!1):o?!1:void 0),o}function Ae(e,t){let n=(r,o)=>{if(t(r,o)!==!1)for(let i of Z.VISITOR_KEYS[r.type]??[]){let s=r[i];if(Array.isArray(s))for(let a of s)a&&typeof a=="object"&&"type"in a&&n(a,r);else s&&typeof s=="object"&&"type"in s&&n(s,r)}};n(e,null)}function de(e){let t=!1;return Ae(e,n=>{(Z.isJSXElement(n)||Z.isJSXFragment(n))&&(t=!0)}),t}function cn(e,t){let n=new Set;return Ae(t,r=>{if(Z.isJSXAttribute(r)&&Z.isJSXIdentifier(r.name,{name:"ref"}))return!1;Z.isIdentifier(r)&&e.state.has(r.name)&&n.add(r.name)}),n}import*as w from"@babel/types";import*as ce from"@babel/types";import*as Ge from"@babel/types";function un(e){let t=Ge.cloneNode(e,!0);return Ge.traverseFast(t,n=>{(Ge.isIdentifier(n)||Ge.isObjectPattern(n)||Ge.isArrayPattern(n)||Ge.isRestElement(n)||Ge.isAssignmentPattern(n))&&(n.typeAnnotation=null)}),t}import*as we from"@babel/types";import*as K from"@babel/types";function pn(e){if(e.mode!=="object"||e.params.length!==1||e.hasWholeDefault)return null;let t=e.params[0];if(!K.isObjectPattern(t))return null;let n=[];for(let r of t.properties){if(!K.isObjectProperty(r)||r.computed||!K.isIdentifier(r.value))return null;let o=K.isIdentifier(r.key)?r.key.name:K.isStringLiteral(r.key)?r.key.value:null;if(o===null)return null;n.push({name:o,local:r.value.name})}return n}function fn(e){if(e.some(i=>K.isTSParameterProperty(i)))throw new Error("TypeScript parameter properties are not valid component props");let t=e;if(t.length===0)return{mode:"positional",names:[],acceptsUnknown:!1,bindings:[],params:[],hasWholeDefault:!1,renderProps:[],renderCallbacks:[],refProps:[]};let n=Et(t[0]);if(t.length===1&&(K.isObjectPattern(n)||K.isIdentifier(n)&&n.name==="props"))return{mode:"object",names:K.isObjectPattern(n)?Li(n):[],acceptsUnknown:K.isIdentifier(n)||n.properties.some(s=>K.isRestElement(s)),bindings:_t(n),params:t.map(s=>K.cloneNode(s)),hasWholeDefault:K.isAssignmentPattern(t[0]),renderProps:[],renderCallbacks:[],refProps:[]};let o=[];for(let i of t){let s=Et(i);if(!K.isIdentifier(s))throw new Error("object-destructured props must be the component's only parameter");o.push(s.name)}return{mode:"positional",names:o,acceptsUnknown:!1,bindings:t.flatMap(i=>_t(Et(i))),params:t.map(i=>K.cloneNode(i)),hasWholeDefault:!1,renderProps:[],renderCallbacks:[],refProps:[]}}function vr(e,t){return e.params.length===0?null:K.variableDeclaration("let",e.params.map((n,r)=>K.variableDeclarator(Ai(Et(n)),Ir(n,t[r]??K.identifier("undefined")))))}function Bn(e,t){return e.params.map((n,r)=>K.expressionStatement(K.assignmentExpression("=",Rr(Et(n)),Ir(n,t[r]??K.identifier("undefined")))))}function kr(e){return K.expressionStatement(K.assignmentExpression("=",Rr(e.target),K.cloneNode(e.source)))}function _t(e){return Object.keys(K.getBindingIdentifiers(e))}function Ue(e){if(e.mode!=="object"||e.params.length!==1)return null;let t=Et(e.params[0]);return K.isIdentifier(t)?t.name:null}function mn(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=Et(e.params[0]);if(!K.isObjectPattern(n))return null;for(let r of n.properties){if(!K.isObjectProperty(r)||r.computed||(K.isIdentifier(r.key)?r.key.name:K.isStringLiteral(r.key)?r.key.value:null)!==t)continue;let i=K.isAssignmentPattern(r.value)?r.value.left:r.value;return K.isIdentifier(i)?i.name:null}return null}function Ze(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=Et(e.params[0]);if(!K.isObjectPattern(n))return null;for(let r of n.properties)if(!(!K.isObjectProperty(r)||r.computed)&&Object.keys(K.getBindingIdentifiers(r.value)).includes(t)){if(K.isIdentifier(r.key))return r.key.name;if(K.isStringLiteral(r.key))return r.key.value}return null}function Et(e){if(K.isRestElement(e))throw new Error("rest component parameters are not supported");let t=K.isAssignmentPattern(e)?e.left:e;if(!K.isIdentifier(t)&&!K.isObjectPattern(t)&&!K.isArrayPattern(t))throw new Error("unsupported component parameter target");return t}function Nr(e){let t=K.cloneNode(e);return qt(t),t}function Ir(e,t){return K.isAssignmentPattern(e)?K.conditionalExpression(K.binaryExpression("===",K.cloneNode(t),K.identifier("undefined")),K.cloneNode(e.right),K.cloneNode(t)):K.cloneNode(t)}function Li(e){let t=[];for(let n of e.properties)if(!K.isRestElement(n)){if(n.computed)throw new Error("computed keys are not supported in component prop patterns");if(K.isIdentifier(n.key))t.push(n.key.name);else if(K.isStringLiteral(n.key))t.push(n.key.value);else throw new Error("component prop pattern keys must be identifiers or strings")}return t}function Ai(e){let t=K.cloneNode(e);return qt(t),t}function Rr(e){let t=K.cloneNode(e);return qt(t),t}function qt(e){let t=e;"typeAnnotation"in t&&(t.typeAnnotation=null),"optional"in t&&(t.optional=null);for(let n of K.VISITOR_KEYS[e.type]??[]){let r=e[n];if(Array.isArray(r))for(let o of r)o&&typeof o=="object"&&"type"in o&&qt(o);else r&&typeof r=="object"&&"type"in r&&qt(r)}}function Fr(e,t){let n=t.findParent(d=>d.isArrowFunctionExpression()||d.isFunctionExpression());if(n===null||!n.isArrowFunctionExpression()&&!n.isFunctionExpression())return!1;let r=n.get("body");if(!(r.isJSXElement()&&r.node===t.node||r.isBlockStatement()&&r.node.body.length===1&&we.isReturnStatement(r.node.body[0])&&r.node.body[0].argument===t.node))return!1;let i=n.parentPath,s=i?.parentPath,a=s?.parentPath;if(!i?.isJSXExpressionContainer()||!s?.isJSXAttribute()||!a?.isJSXOpeningElement()||!we.isJSXIdentifier(a.node.name))return!1;let l=we.isJSXIdentifier(s.node.name)?s.node.name.name:s.node.name.name.name;return e.componentProps.get(a.node.name.name)?.renderCallbacks.includes(l)===!0||/^[A-Z]/.test(a.node.name.name)}function ji(e){return we.isMemberExpression(e.callee)&&!e.callee.computed&&we.isIdentifier(e.callee.property,{name:"map"})}function Ji(e,t,n){let r=e.componentProps.get(t);if(r===void 0)return null;let o=Ue(r);return o!==null&&we.isMemberExpression(n)&&!n.computed&&we.isIdentifier(n.object,{name:o})&&we.isIdentifier(n.property)?n.property.name:we.isIdentifier(n)?Ze(r,n.name)??(mn(r,n.name)!==null?n.name:null):null}function $i(e){return we.isExpression(e.body)?e.body:e.body.body.length===1&&we.isReturnStatement(e.body.body[0])&&we.isExpression(e.body.body[0].argument)?e.body.body[0].argument:null}function Jt(e,t,n){if(!ji(n)||n.arguments.length!==1)return null;let r=n.arguments[0];if(!we.isArrowFunctionExpression(r))return null;let o=$i(r);if(o===null||!we.isCallExpression(o)||!we.isExpression(o.callee)||o.arguments.some(s=>!we.isExpression(s)))return null;let i=Ji(e,t,o.callee);return i===null?null:{propName:i,target:we.cloneNode(o.callee,!0),arguments:o.arguments.map(s=>we.cloneNode(s,!0))}}function Mr(e){for(let[t,n]of e.compPaths){let r=e.componentProps.get(t);n.traverse({CallExpression(o){let i=Jt(e,t,o.node);i!==null&&!r.renderCallbacks.includes(i.propName)&&r.renderCallbacks.push(i.propName)}})}}import*as Fe from"@babel/types";function Ft(e){for(;Fe.isTSAsExpression(e)||Fe.isTSTypeAssertion(e)||Fe.isTSNonNullExpression(e)||Fe.isTSInstantiationExpression(e);)e=e.expression;return e}function gn(e){let t=Ft(e);return Fe.isArrayExpression(t)&&t.elements.every(n=>n!==null&&!Fe.isSpreadElement(n)&&(Fe.isStringLiteral(n)||Fe.isNumericLiteral(n)||Fe.isBooleanLiteral(n)||Fe.isNullLiteral(n)||Fe.isBigIntLiteral(n)))}function We(e){if(!ce.isCallExpression(e))return null;let t=e.callee;return ce.isMemberExpression(t)&&!t.computed&&ce.isIdentifier(t.property,{name:"map"})?e:null}function je(e){let t=!1;return e.traverse({JSXElement(){t=!0},JSXFragment(){t=!0}}),t}function Mt(e,t,n,r,o,i){let s=g=>{throw n.buildCodeFrameError(g)},a=t.callee,l=Oi(e,a.object,r,i,s),d=Bi(e,t,r,s),p=Vi(e,d,s),u=Ki(l.suffixBase,o);return{sourceKey:l.key,sourceExpr:ce.cloneNode(l.expression),sourceLocal:l.local,itemPattern:d.itemPattern,itemParam:d.itemParam,indexParam:d.indexParam,keyExpr:zi(d.jsx?.openingElement??null,s),jsx:d.jsx,form:p.form,rowComp:p.rowComp,renderCallback:p.renderCallback,owner:r,suffix:u,prefix:`${r}/${u}`}}function Oi(e,t,n,r,o){return ce.isIdentifier(t)?Xi(e,t,n,o):ce.isMemberExpression(t)?Ti(e,t,n,r,o):ce.isExpression(t)&&gn(t)?{expression:t,key:"$static-list",local:!0,suffixBase:"$static-list"}:o("memo-dom: assign an ordered collection view to reactive state or a local derivation before mapping it")}function Xi(e,t,n,r){let o=e.componentProps.get(n)?.bindings??[],i=e.instanceState.get(n)?.has(t.name)===!0||e.instanceDerivedBindings.get(n)?.has(t.name)===!0||o.includes(t.name),s=e.state.get(t.name);return!i&&s!=="let"&&s!=="const"&&s!=="computed"?r("memo-dom: list views must come from reactive module state, component props, component state, or a local derivation"):{expression:t,key:t.name,local:i,suffixBase:t.name}}function Ti(e,t,n,r,o){let i=ke(t),s=xe(t),a=e.componentProps.get(n)?.bindings??[],l=i!==null&&(e.instanceState.get(n)?.has(i)===!0||a.includes(i)),d=i!==null&&s!==null&&r!==void 0&&i===r.itemParam;return i===null||s===null||!s.includes(".")||!d&&!l&&e.state.get(i)!=="store"?o("memo-dom: list member views must be a static path on reactive module state, component props, or component state"):{expression:t,key:d?r.sourceKey:s,local:d?r.sourceLocal:l,suffixBase:s.slice(s.lastIndexOf(".")+1)}}function Bi(e,t,n,r){if(t.arguments.length!==1||!ce.isArrowFunctionExpression(t.arguments[0]))return r("memo-dom: list rendering expects items.map(item => <JSX />) \u2014 R7 L1");let o=t.arguments[0],i=o.params[0],s=o.params[1];if(o.params.length<1||o.params.length>2||!ce.isIdentifier(i)&&!ce.isObjectPattern(i)&&!ce.isArrayPattern(i)||s!==void 0&&!ce.isIdentifier(s))return r("memo-dom: list callback must take an item binding pattern and optional index identifier \u2014 R7 L1");let a=un(i),l=Object.keys(ce.getBindingIdentifiers(a));if(l.length===0)return r("memo-dom: list callback item pattern must bind at least one name \u2014 R7 L1");let d=ce.isIdentifier(a)?a.name:l[0],p=ce.isIdentifier(s)?s.name:null,u=ce.isBlockStatement(o.body)&&o.body.body.length===1&&ce.isReturnStatement(o.body.body[0])?o.body.body[0].argument:null,g=ce.isJSXElement(o.body)?o.body:ce.isJSXElement(u)?u:null,S=Jt(e,n,t);return g===null&&S===null?r("memo-dom: list callback body must be one JSX element or a block containing only return <JSX /> \u2014 R7 L1"):{itemPattern:a,itemParam:d,indexParam:p,jsx:g,renderInvocation:S}}function Vi(e,t,n){let r=t.jsx?.openingElement??null;if(r!==null&&!ce.isJSXIdentifier(r.name))return n("memo-dom: namespaced JSX tags are not supported (L1)");let o=r!==null&&ce.isJSXIdentifier(r.name)?r.name.name:null;return t.renderInvocation!==null?(Wi(t,n),{form:"callback",rowComp:null,renderCallback:ce.cloneNode(t.renderInvocation.target,!0)}):o!==null&&/^[A-Z]/.test(o)?!e.comps.has(o)&&!e.importedComponents.has(o)?n(`memo-dom: <${o} /> is not a linked component factory`):{form:"component",rowComp:o,renderCallback:null}:{form:"inline",rowComp:null,renderCallback:null}}function Wi(e,t){let n=e.renderInvocation;(!ce.isIdentifier(e.itemPattern)||n.arguments.length<1||n.arguments.length>2||!ce.isIdentifier(n.arguments[0],{name:e.itemPattern.name})||n.arguments.length===2&&(e.indexParam===null||!ce.isIdentifier(n.arguments[1],{name:e.indexParam})))&&t("memo-dom: render callback maps must pass their item and optional index bindings directly")}function zi(e,t){let n=null;for(let r of e?.attributes??[])if(ce.isJSXAttribute(r)&&ce.isJSXIdentifier(r.name,{name:"key"})&&(n=Ve(r.value),n===null))return t("memo-dom: key={...} needs an expression");return n}function Ki(e,t){let n=t.get(e)??0;return t.set(e,n+1),n===0?e:`${e}${n}`}import*as oe from"@babel/types";function bn(e){return oe.isConditionalExpression(e)||oe.isLogicalExpression(e)&&(e.operator==="&&"||e.operator==="||")?e:null}function Ui(e){return oe.isNullLiteral(e)||oe.isBooleanLiteral(e,{value:!1})||oe.isIdentifier(e,{name:"undefined"})}function Hi(e,t){let n=[e];for(;n.length>0;){let r=n.pop();if(oe.isJSXElement(r)){for(let o of r.openingElement.attributes)!oe.isJSXSpreadAttribute(o)&&o.name.name==="key"&&t("memo-dom: key={...} is only meaningful on list rows");n.push(...r.children)}else if(oe.isJSXFragment(r))n.push(...r.children);else if(oe.isJSXExpressionContainer(r)&&oe.isExpression(r.expression)){let o=r.expression;if(We(o)!==null&&de(o))continue}}}function hn(e,t,n){let r=l=>{throw t.buildCodeFrameError(l)},o,i;if(oe.isConditionalExpression(e)){let l=[];i=[];let d=e;for(;oe.isConditionalExpression(d);)l.push(oe.cloneNode(d.test)),i.push(d.consequent),d=d.alternate;i.push(d),o=oe.numericLiteral(i.length-1);for(let p=l.length-1;p>=0;p--)o=oe.conditionalExpression(l[p],oe.numericLiteral(p),o)}else e.operator==="&&"?(o=oe.conditionalExpression(oe.cloneNode(e.left),oe.numericLiteral(0),oe.numericLiteral(1)),i=[e.right,null]):(o=oe.conditionalExpression(oe.cloneNode(e.left),oe.numericLiteral(1),oe.numericLiteral(0)),i=[e.right,null]);let s=l=>l===null||Ui(l)?null:oe.isJSXElement(l)||oe.isJSXFragment(l)?l:oe.isExpression(l)?oe.jsxFragment(oe.jsxOpeningFragment(),oe.jsxClosingFragment(),[oe.jsxExpressionContainer(oe.cloneNode(l,!0))]):r("memo-dom: conditional branches must be JSX, renderable text expressions, or null/false"),a=i.map(s);for(let l of a)l!==null&&Hi(l,r);return{pickExpr:o,branches:a,suffix:`when${n.count++}`}}import*as Le from"@babel/types";import*as ge from"@babel/types";var $t=class{constructor(t){this.fallback=t}fallback;origins=new WeakMap;trackDeclarator(t,n){if(!ge.isIdentifier(n.id)||n.init===null)return;let r=this.resolveExpression(t,n.init);if(r===null)return;let o=t.getBinding(n.id.name);o!==void 0&&this.origins.set(o.identifier,r)}referencedOrigins(t,n){let r=new Map,o=i=>{if(ge.isIdentifier(i)||ge.isMemberExpression(i)){let s=this.resolveExpression(t,i);if(s!==null){let a=[s.locality,s.root,s.key??"*"].join(":");r.set(a,s);return}}for(let s of ge.VISITOR_KEYS[i.type]??[]){let a=i[s];if(Array.isArray(a))for(let l of a)l&&typeof l=="object"&&"type"in l&&o(l);else a&&typeof a=="object"&&"type"in a&&o(a)}};return o(n),[...r.values()]}resolveName(t,n){let r=t.getBinding(n);if(r!==void 0){let o=this.origins.get(r.identifier);if(o!==void 0)return o}return this.fallback(n,r)}resolveExpression(t,n){let r=Dr(n);if(ge.isIdentifier(r))return this.resolveName(t,r.name);if(!ge.isMemberExpression(r))return null;let o=_i(r);if(o===null)return null;let i=this.resolveName(t,o);if(i===null)return null;let s=xe(r);if(i.key===null||s===null)return{...i,key:null};let a=s.split(".").slice(1);return{...i,key:[i.key,...a].join(".")}}};function En(e,t){return{locality:"module",root:e,key:e,stateKind:t}}function yt(e,t){return e.key===null?e:{...e,key:[e.key,...t].join(".")}}function yn(e,t){if(e.key===null)return null;let n=[];for(let r of t){if(!ge.isObjectExpression(r))return null;for(let o of r.properties){if(!ge.isObjectProperty(o)||o.computed||!ge.isIdentifier(o.key)&&!ge.isStringLiteral(o.key))return null;let i=ge.isIdentifier(o.key)?o.key.name:o.key.value;n.push(`${e.key}.${i}`)}}return n}function Sn(e){let t=[];for(let n of e)ge.isExpression(n)?t.push(n):ge.isSpreadElement(n)&&t.push(n.argument);return t}function xn(e){return!e.computed&&ge.isIdentifier(e.property)?e.property.name:e.computed&&ge.isStringLiteral(e.property)?e.property.value:null}function _i(e){let t=e;for(;ge.isMemberExpression(t);){if(ge.isSuper(t.object))return null;t=Dr(t.object)}return ge.isIdentifier(t)?t.name:null}function Dr(e){let t=e;for(;ge.isTSAsExpression(t)||ge.isTSTypeAssertion(t)||ge.isTSNonNullExpression(t)||ge.isTypeCastExpression(t)||ge.isTSSatisfiesExpression(t);)t=t.expression;return t}function He(e,t,n=new Set){let r=e.helperSummaries.get(t);if(r)return r;if(n.has(t))return{reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!0};let o=e.helpers.get(t),i=new Set,s=new Map(o.node.params.flatMap((f,m)=>Le.isIdentifier(f)?[[f.name,m]]:[])),a={reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!1},l=new $t((f,m)=>{if(s.has(f)&&m?.scope.block===o.node)return{locality:"prop",root:f,key:f};let C=e.state.get(f);return C===void 0||m!==void 0&&!m.scope.path.isProgram()?null:En(f,C)}),d=f=>f.stateKind==="computed"||e.state.get(f.root)==="computed";n.add(t),o.traverse({VariableDeclarator(f){Le.isIdentifier(f.node.id)&&(i.add(f.node.id.name),f.parentPath.isVariableDeclaration()&&l.trackDeclarator(f.scope,f.node))},Function(f){for(let m of f.node.params)Le.isIdentifier(m)&&i.add(m.name)}});let p=(f,m)=>{a.parameterWrites.some(C=>C.index===f&&C.path.length===m.length&&C.path.every((b,v)=>b===m[v]))||a.parameterWrites.push({index:f,path:m})},u=f=>{if(!d(f)){if(f.locality==="module"){a.boundedWrites.add(f.key??f.root);return}if(f.locality==="prop"){let m=s.get(f.root);if(m!==void 0){let C=f.key===null?[]:f.key.split(".").slice(1);p(m,C);return}}a.unbounded=!0}},g=f=>{f.locality==="prop"?u(f):f.locality!=="module"?a.unbounded=!0:f.stateKind!=="store"?a.writes.add(f.root):f.key!==null&&f.key.includes(".")?a.writes.add(f.key):a.boundedWrites.add(f.root)},S=(f,m)=>{let C=l.resolveExpression(f.scope,m);C!==null&&g(C)},x=(f,m)=>{for(let C of Sn(m)){if(!Le.isIdentifier(C))continue;let b=l.resolveExpression(f.scope,C);b!==null&&!d(b)&&u(b)}};return o.traverse({VariableDeclarator(f){if(!Le.isIdentifier(f.node.id)&&f.node.init!==null)for(let m of l.referencedOrigins(f.scope,f.node.init))u(m)},AssignmentExpression(f){let m=f.node.left;if(Le.isIdentifier(m))if(i.has(m.name)){if(Le.isIdentifier(f.node.right)){let C=l.resolveExpression(f.scope,f.node.right);C!==null&&u(C)}}else e.state.has(m.name)&&a.writes.add(m.name);else if(Le.isMemberExpression(m))S(f,m);else for(let C of l.referencedOrigins(f.scope,f.node.right))u(C)},UpdateExpression(f){let m=f.node.argument;Le.isIdentifier(m)?!i.has(m.name)&&e.state.has(m.name)&&a.writes.add(m.name):Le.isMemberExpression(m)&&S(f,m)},UnaryExpression(f){f.node.operator==="delete"&&Le.isMemberExpression(f.node.argument)&&S(f,f.node.argument)},CallExpression(f){let m=f.node.callee;if(Le.isMemberExpression(m)){if(xn(m)==="assign"&&Le.isIdentifier(m.object,{name:"Object"})){let v=f.node.arguments[0],F=v!==void 0&&Le.isExpression(v)?l.resolveExpression(f.scope,v):null;if(F!==null){let R=yn(F,f.node.arguments.slice(1));if(R===null)u(F);else for(let k of R)g({...F,key:k})}return}let b=Le.isExpression(m.object)?l.resolveExpression(f.scope,m.object):null;b!==null?u(b):x(f,f.node.arguments);return}if(Le.isIdentifier(m)&&(e.helpers.has(m.name)||e.importedFunctions.has(m.name))){let C=e.importedFunctions.get(m.name)??He(e,m.name,n);for(let b of C.reads)a.reads.add(b);for(let b of C.writes)a.writes.add(b);for(let b of C.boundedWrites)a.boundedWrites.add(b);for(let b of C.parameterWrites){let v=f.node.arguments[b.index];if(v===void 0||!Le.isExpression(v))continue;let F=l.resolveExpression(f.scope,v);F!==null&&u(yt(F,b.path))}C.unbounded&&(a.unbounded=!0);return}x(f,f.node.arguments)},Identifier(f){let m=f.node.name;if(!e.state.has(m)||i.has(m))return;let C=f.parentPath;C.isAssignmentExpression({operator:"="})&&C.node.left===f.node||a.reads.add(m)},MemberExpression(f){let m=qi(e,f);m!==null&&a.reads.add(m)}}),n.delete(t),e.helperSummaries.set(t,a),a}function qi(e,t){let n=xe(t.node);if(!n||!n.includes("."))return null;let r=n.split(".")[0];if(e.state.get(r)!=="store"||t.scope.getBinding(r)?.scope.path.isProgram()!==!0)return null;let o=t.parentPath;return o.isAssignmentExpression({operator:"="})&&o.node.left===t.node||Gi(t)?null:n}function Gi(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}import*as h from"@babel/types";import*as ae from"@babel/types";function rt(e,t=!1){return{slots:[],tempVar:A(e,"value").name,updateVar:A(e,"update").name,reasonVar:null,delegatedEventBindings:new Map,creation:[],mounts:[],updaters:[],tagCounters:new Map,childCounts:new Map,usedPrefixes:new Map,usedConds:{count:0},textCounter:0,regionCounter:0,disposableRegions:[],disposableEntities:[],disposableCallbacks:[],forwardedSlotCounter:0,manualDisposal:t}}function ot(e){return ae.variableDeclaration("let",[...e.slots.map(t=>ae.variableDeclarator(ae.identifier(t))),ae.variableDeclarator(ae.identifier(e.tempVar))])}function Vn(e,t){let n=A(e,`slot${t.slots.length}`).name;return t.slots.push(n),n}function Wn(e,t,n){let r=t.tagCounters.get(n)??0;return t.tagCounters.set(n,r+1),A(e,`${n}${r}`).name}function Dt(e,t,n,r){let o=()=>ae.identifier(e.tempVar),i=()=>ae.identifier(t);return ae.ifStatement(ae.binaryExpression("!==",i(),ae.assignmentExpression("=",o(),n)),ae.blockStatement([ae.expressionStatement(ae.assignmentExpression("=",i(),o())),r(o())]))}function it(e){return ae.variableDeclaration("const",[ae.variableDeclarator(ae.identifier(e.updateVar),ae.arrowFunctionExpression(e.reasonVar===null?[]:[ae.assignmentPattern(ae.identifier(e.reasonVar),ae.nullLiteral())],ae.blockStatement(e.updaters.map(t=>t()))))])}function St(e,t,n,r){return ae.expressionStatement(ae.callExpression(Y(e,"register"),[ae.objectExpression([ae.objectProperty(ae.identifier("id"),t),ae.objectProperty(ae.identifier("parent"),n),ae.objectProperty(ae.identifier("render"),r)])]))}function zn(e){let t=e.replace(/\s+/g," ");return/^\s*\n/.test(e)&&(t=t.replace(/^ /,"")),/\n\s*$/.test(e)&&(t=t.replace(/ $/,"")),t}function Gt(e){return e.some(t=>!h.isJSXText(t)||t.value.trim()!=="")}function ft(e,t,n){let r=e.componentProps.get(t);if(r===void 0)return null;let o=Ue(r);if(o!==null&&h.isMemberExpression(n)&&!n.computed&&h.isIdentifier(n.object,{name:o})&&h.isIdentifier(n.property))return n.property.name;if(h.isIdentifier(n)){let i=Ze(r,n.name);if(i!==null)return i;if(n.name==="children"&&e.instanceDerivedBindings.get(t)?.has("children")===!0)return"children"}return null}function st(e,t,n){let r=ft(e,t,n);return r!==null&&e.componentProps.get(t)?.renderProps.includes(r)===!0}function Lr(e,t,n,r){let o=rt(e,!0);o.childCounts=t.childCounts,o.usedPrefixes=t.usedPrefixes,o.usedConds=t.usedConds;let i=A(e,"childrenUpdate"),s=A(e,"childrenUpdates"),a=A(e,"childrenMountSequence"),l=A(e,"children"),d=A(e,"childrenParent"),p=A(e,"childrenOwner"),u=A(e,"childrenKey"),g=A(e,"childrenSlot"),S=A(e,"childrenNextUpdate"),x=A(e,"childrenActive"),f=A(e,"childrenDispose");return r(o,d,g),t.creation.push(h.variableDeclaration("let",[h.variableDeclarator(h.cloneNode(i),h.nullLiteral()),h.variableDeclarator(h.cloneNode(s),h.nullLiteral()),h.variableDeclarator(h.cloneNode(a),h.numericLiteral(0))]),h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(l),h.arrowFunctionExpression([h.cloneNode(d),h.cloneNode(p),h.cloneNode(u)],h.blockStatement([h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(g),h.conditionalExpression(h.binaryExpression("===",h.cloneNode(a),h.numericLiteral(0)),h.cloneNode(n,!0),h.binaryExpression("+",h.binaryExpression("+",h.cloneNode(n,!0),h.stringLiteral("/$slot[")),h.binaryExpression("+",h.cloneNode(a),h.stringLiteral("]")))))]),h.expressionStatement(h.updateExpression("++",h.cloneNode(a))),h.variableDeclaration("let",[h.variableDeclarator(h.cloneNode(x),h.booleanLiteral(!0))]),ot(o),it(o),...o.creation,...o.mounts,h.ifStatement(h.binaryExpression("===",h.cloneNode(i),h.nullLiteral()),h.expressionStatement(h.assignmentExpression("=",h.cloneNode(i),h.identifier(o.updateVar))),h.blockStatement([h.ifStatement(h.binaryExpression("===",h.cloneNode(s),h.nullLiteral()),h.expressionStatement(h.assignmentExpression("=",h.cloneNode(s),h.newExpression(h.identifier("Set"),[])))),h.expressionStatement(h.callExpression(h.memberExpression(h.cloneNode(s),h.identifier("add")),[h.identifier(o.updateVar)]))])),h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(f),h.arrowFunctionExpression([],h.blockStatement([h.ifStatement(h.unaryExpression("!",h.cloneNode(x)),h.returnStatement()),h.expressionStatement(h.assignmentExpression("=",h.cloneNode(x),h.booleanLiteral(!1))),h.ifStatement(h.binaryExpression("===",h.cloneNode(i),h.identifier(o.updateVar)),h.expressionStatement(h.assignmentExpression("=",h.cloneNode(i),h.nullLiteral())),h.ifStatement(h.binaryExpression("!==",h.cloneNode(s),h.nullLiteral()),h.expressionStatement(h.callExpression(h.memberExpression(h.cloneNode(s),h.identifier("delete")),[h.identifier(o.updateVar)])))),...o.disposableRegions.map(m=>h.expressionStatement(h.callExpression(h.memberExpression(h.identifier(m),h.identifier("dispose")),[]))),...[...o.disposableCallbacks].reverse().map(m=>h.ifStatement(h.binaryExpression("!==",h.cloneNode(m),h.nullLiteral()),h.expressionStatement(h.callExpression(h.cloneNode(m),[])))),...o.disposableEntities.map(m=>h.expressionStatement(h.callExpression(Y(e,"unregisterSubtree"),[h.cloneNode(m,!0)])))])))]),h.expressionStatement(h.callExpression(Y(e,"cleanup"),[h.cloneNode(p),h.cloneNode(f)])),h.returnStatement(h.cloneNode(f))])))])),t.updaters.push(()=>h.blockStatement([h.ifStatement(h.binaryExpression("!==",h.cloneNode(i),h.nullLiteral()),h.expressionStatement(h.callExpression(h.cloneNode(i),[]))),h.ifStatement(h.binaryExpression("!==",h.cloneNode(s),h.nullLiteral()),h.forOfStatement(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(S))]),h.cloneNode(s),h.expressionStatement(h.callExpression(h.cloneNode(S),[]))))])),l}function Kn(e,t,n,r,o){let i=A(e,"slotDispose"),s=t.forwardedSlotCounter++;t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(i),h.conditionalExpression(h.binaryExpression("==",h.cloneNode(n,!0),h.nullLiteral()),h.nullLiteral(),h.callExpression(h.cloneNode(n,!0),[h.identifier(r),h.cloneNode(o,!0),h.stringLiteral(String(s))])))])),t.disposableCallbacks.push(i)}function Ar(e,t,n,r){let o=i=>{e.creation.push(h.expressionStatement(h.callExpression(h.memberExpression(h.identifier(n),h.identifier("appendChild")),[h.identifier(i)])))};for(let i of t){if(h.isJSXText(i)){let d=zn(i.value);d!==""&&o(r.emitText(h.stringLiteral(d)));continue}if(h.isJSXElement(i)||h.isJSXFragment(i)){o(r.emitNode(i));continue}if(h.isJSXExpressionContainer(i)||r.fail("memo-dom: spread children are not supported (L1)"),h.isJSXEmptyExpression(i.expression))continue;h.isExpression(i.expression)||r.fail("memo-dom: unsupported expression in component children");let s=i.expression;if(h.isNullLiteral(s)||h.isBooleanLiteral(s)||h.isIdentifier(s,{name:"undefined"}))continue;if(r.isForwarded(s)){r.emitForwarded(s,n);continue}let a=We(s);if(a!==null){r.emitList(a,n);continue}let l=bn(s);if(l!==null&&de(l)){r.emitCondition(l,n);continue}o(r.emitText(h.cloneNode(s)))}}import*as j from"@babel/types";function wn(e){return j.isIdentifier(e.node.callee,{name:"effect"})&&e.scope.getBinding("effect")===void 0}function Pn(e,t){return j.binaryExpression("+",j.identifier(e),j.stringLiteral(`/$effects/${t}`))}function Zi(e,t){return j.binaryExpression("+",Pn(e,t),j.stringLiteral("/$active"))}function Yi(e){if(e.isFunctionDeclaration())return e;if(!e.isVariableDeclarator())return null;let t=e.get("init");return t.isArrowFunctionExpression()||t.isFunctionExpression()?t:null}function Xr(e,t){let n=t.get("arguments"),r=n[0];if(n.length!==1||r===void 0)throw t.buildCodeFrameError("memo-dom: effect() requires exactly one callback");if(r.isArrowFunctionExpression()||r.isFunctionExpression()){if(r.node.async||r.node.generator)throw r.buildCodeFrameError("memo-dom: effect callback must be synchronous; start async work inside it and return a synchronous teardown");return{expression:r.node,path:r,importedReads:new Set}}if(!r.isIdentifier())throw r.buildCodeFrameError("memo-dom: effect callback must be an inline function or a resolvable function identifier");if(e.importedFunctions.get(r.node.name)!==void 0)throw r.buildCodeFrameError(`memo-dom: imported named effect callback '${r.node.name}' is not supported yet; define a local synchronous wrapper so its cleanup and writes can be instrumented`);let i=r.scope.getBinding(r.node.name),s=i===void 0?null:Yi(i.path);if(s===null)throw r.buildCodeFrameError(`memo-dom: cannot resolve effect callback '${r.node.name}' \u2014 use an inline function or a local/module-level function declaration or const`);if(s.node.async||s.node.generator)throw s.buildCodeFrameError("memo-dom: effect callback must be synchronous; start async work inside it and return a synchronous teardown");if(de(s.node.body))throw s.buildCodeFrameError("memo-dom: a JSX component cannot be used as an effect callback");return{expression:j.cloneNode(r.node),path:s,importedReads:new Set}}function jr(e,t,n,r){let o=new Set,i=new Set,s=new Map,a=new Set([...e.componentProps.get(t)?.bindings??[],...e.instanceState.get(t)??[]]),l=new Map;for(let m of e.instanceDerivations.get(t)??[])for(let C of m.bindings)l.set(C,m.sources);for(let m of e.instanceControlFlow.get(t)??[])for(let C of m.bindings)l.set(C,m.sources);for(let m of a){let C=n.scope.getBinding(m);C!==void 0&&s.set(C,{source:m,local:!0})}for(let m of l.keys()){let C=n.scope.getBinding(m);C!==void 0&&s.set(C,{source:m,local:!0})}for(let m of e.state.keys()){let C=n.scope.getBinding(m);C?.scope.path.isProgram()===!0&&s.set(C,{source:m,local:!1})}let d=m=>{let C=m.scope.getBinding(m.node.name),b=C===void 0?void 0:s.get(C);if(b===void 0)return;let v=m.parentPath;!b.local&&e.state.get(b.source)==="store"&&v?.isMemberExpression()&&v.node.object===m.node||(b.local?i.add(b.source):o.add(b.source))},p=m=>{let C=xe(m.node),b=ke(m.node);C===null||b===null||e.state.get(b)!=="store"||m.scope.getBinding(b)?.scope.path.isProgram()!==!0||o.add(C)},u=m=>{let C=m.node.callee;if(!j.isIdentifier(C)||m.scope.getBinding(C.name)?.scope.path.isProgram()!==!0||!e.helpers.has(C.name)&&!e.importedFunctions.has(C.name))return;let b=e.importedFunctions.get(C.name)??He(e,C.name);for(let v of b.reads)o.add(v)};r.isIdentifier()&&r.isReferencedIdentifier()&&d(r),r.isMemberExpression()&&p(r),r.isCallExpression()&&u(r),r.traverse({Function(m){m.skip()},ReferencedIdentifier(m){m.isIdentifier()&&d(m)},MemberExpression(m){p(m)},CallExpression(m){u(m)}});let g=new Set,S=new Set,x=new Set;for(let m of i)a.has(m)&&x.add(m);let f=(m,C)=>{if(C.has(m))return;let b=l.get(m);if(b===void 0){a.has(m)?g.add(m):e.state.has(m)&&o.add(m);return}C.add(m),b.some(F=>x.has(F))||S.add(m);for(let F of b)f(F,C);C.delete(m)};for(let m of i)f(m,new Set);return{moduleReads:o,localReads:g,localDerivationReads:S}}function Jr(e,t){let n=new Set,r=s=>{let a=s.node.name;if(!e.state.has(a)||s.scope.getBinding(a)?.scope.path.isProgram()!==!0)return;let l=s.parentPath;e.state.get(a)==="store"&&l?.isMemberExpression()&&l.node.object===s.node||n.add(a)},o=s=>{let a=xe(s.node),l=ke(s.node);a!==null&&l!==null&&e.state.get(l)==="store"&&s.scope.getBinding(l)?.scope.path.isProgram()===!0&&n.add(a)},i=s=>{let a=s.node.callee;if(!j.isIdentifier(a)||s.scope.getBinding(a.name)?.scope.path.isProgram()!==!0||!e.helpers.has(a.name)&&!e.importedFunctions.has(a.name))return;let l=e.importedFunctions.get(a.name)??He(e,a.name);for(let d of l.reads)n.add(d)};return t.isIdentifier()&&t.isReferencedIdentifier()&&r(t),t.isMemberExpression()&&o(t),t.isCallExpression()&&i(t),t.traverse({Function(s){s.skip()},ReferencedIdentifier(s){s.isIdentifier()&&r(s)},MemberExpression(s){o(s)},CallExpression(s){i(s)}}),n}function Un(e){if(!e.isExpressionStatement())return null;let t=e.get("expression");return t.isCallExpression()&&wn(t)?t:null}function Tr(e){if(Un(e)!==null)return!0;let t=!1;return e.traverse({Function(n){n.skip()},CallExpression(n){wn(n)&&(t=!0,n.stop())}}),t}function Cn(e,t,n,r){let o=Un(e);if(o!==null){r.push({callPath:o,rootStatement:t,conditions:[...n]});return}if(!e.isEmptyStatement()){if(e.isBlockStatement()){for(let i of e.get("body"))if(!i.isEmptyStatement()){if(!Tr(i))throw i.buildCodeFrameError("memo-dom: a conditional effect branch may contain only effect() calls, nested if statements, or empty statements");Cn(i,t,n,r)}return}if(e.isIfStatement()){let i=e.get("test");Cn(e.get("consequent"),t,[...n,{path:i,negated:!1}],r);let s=e.get("alternate");s.node!==null&&Cn(s,t,[...n,{path:i,negated:!0}],r);return}throw e.buildCodeFrameError("memo-dom: conditional effect() calls must be controlled by top-level if statements")}}function Br(e){let t=[];for(let n of e){let r=Un(n);if(r!==null){t.push({callPath:r,rootStatement:n.node,conditions:[]});continue}!n.isIfStatement()||!Tr(n)||Cn(n,n.node,[],t)}return t}function Vr(e){return e.length===0?null:e.map(({path:n,negated:r})=>r?j.unaryExpression("!",j.cloneNode(n.node,!0)):j.cloneNode(n.node,!0)).reduce((n,r)=>j.logicalExpression("&&",n,r))}function Qi(e,t){let n=[],r=Br(t.get("body"));for(let o of r){let i=Xr(e,o.callPath),s=i.path===null?i.importedReads:Jr(e,i.path),a=new Set;for(let d of o.conditions)for(let p of Jr(e,d.path))a.add(p);let l=n.length;n.push({index:l,statement:o.rootStatement,callback:i.expression,moduleReads:s,condition:Vr(o.conditions),conditionModuleReads:a,entityId:`${e.rootId}/$module-effects/${encodeURIComponent(e.moduleId)}/${l}`})}e.moduleEffects.push(...n)}function Wr(e,t){Qi(e,t);for(let[n,r]of e.compPaths){let o=[],i=new Set,s=Br(r.get("body").get("body"));for(let l of s){let d=Xr(e,l.callPath),p=d.path===null?{moduleReads:d.importedReads,localReads:new Set,localDerivationReads:new Set}:jr(e,n,r,d.path),u=new Set,g=new Set,S=new Set;for(let x of l.conditions){let f=jr(e,n,r,x.path);for(let m of f.moduleReads)u.add(m);for(let m of f.localReads)g.add(m);for(let m of f.localDerivationReads)S.add(m)}o.push({index:o.length,statement:l.rootStatement,callback:d.expression,...p,condition:Vr(l.conditions),conditionModuleReads:u,conditionLocalReads:g,conditionLocalDerivationReads:S}),i.add(l.callPath.node)}if(r.traverse({CallExpression(l){if(!(!wn(l)||i.has(l.node)))throw l.buildCodeFrameError("memo-dom: effect() must be a direct top-level statement in a component body")}}),o.length===0)continue;e.effects.set(n,o);let a=new Set([...e.instanceReasonIds.get(n)?.keys()??[],...e.instanceState.get(n)??[],...e.componentProps.get(n)?.bindings??[],...o.flatMap(l=>[...l.localReads]),...o.flatMap(l=>[...l.conditionLocalReads])]);a.size>0&&e.instanceReasonIds.set(n,new Map([...a].sort().map((l,d)=>[l,d])))}}function $r(e){return e.reduce((t,n)=>j.logicalExpression("||",t,n))}function es(e,t,n,r){let o=e.instanceReasonIds.get(t);if(o===void 0)return null;let i=[...r].map(d=>o.get(d)).filter(d=>d!==void 0).sort((d,p)=>d-p);if(i.length===0||i.length!==r.size)return null;let s=()=>j.identifier(n),a=$r(i.map(d=>j.binaryExpression("===",s(),j.numericLiteral(d)))),l=$r(i.map(d=>j.callExpression(j.memberExpression(s(),j.identifier("has")),[j.numericLiteral(d)])));return j.logicalExpression("||",j.binaryExpression("===",s(),j.nullLiteral()),j.conditionalExpression(j.binaryExpression("===",j.unaryExpression("typeof",s()),j.stringLiteral("number")),a,l))}function zr(e,t,n,r,o,i){let s=(l,d,p,u,g)=>{if(p.size===0&&u.size===0)return null;let S=j.expressionStatement(j.callExpression(Y(e,"markDirty"),[d]));if(u.size>0&&i!==void 0){let f=[],m=[];for(let b of u){let v=A(e,`eff${l.index}_${g}_${b}`).name;i.creation.push(j.variableDeclaration("let",[j.variableDeclarator(j.identifier(v),j.identifier(b))])),f.push(j.binaryExpression("!==",j.identifier(v),j.identifier(b))),m.push(j.expressionStatement(j.assignmentExpression("=",j.identifier(v),j.identifier(b))))}let C=f.length===1?f[0]:f.reduce((b,v)=>j.logicalExpression("||",b,v));S=j.ifStatement(C,j.blockStatement([...m,S]))}if(r===null)return S;let x=es(e,t,r,p);return x===null?S:j.ifStatement(x,S)},a=o.flatMap(l=>{let d=l.condition===null?null:s(l,Pn(n,l.index),l.conditionLocalReads,l.conditionLocalDerivationReads,"condition"),p=s(l,l.condition===null?Pn(n,l.index):Zi(n,l.index),l.localReads,l.localDerivationReads,"callback");return[d,p].filter(u=>u!==null)});return j.blockStatement(a)}function Kr(e,t,n){return n.map(r=>j.expressionStatement(j.callExpression(Y(e,r.condition===null?"registerEffect":"registerConditionalEffect"),[Pn(t,r.index),j.identifier(t),...r.condition===null?[]:[j.arrowFunctionExpression([],j.cloneNode(r.condition,!0))],j.cloneNode(r.callback,!0)])))}function Or(){return j.memberExpression(j.metaProperty(j.identifier("import"),j.identifier("meta")),j.identifier("hot"))}function Ur(e,t){if(e.moduleEffects.length===0)return;let n=new Map(t.get("body").map(o=>[o.node,o])),r=new Map;for(let o of e.moduleEffects){let i=r.get(o.statement)??[];i.push(o),r.set(o.statement,i)}for(let[o,i]of r){let s=n.get(o);if(s===void 0)continue;let a=[];for(let l of i)a.push(j.expressionStatement(j.callExpression(Y(e,l.condition===null?"registerEffect":"registerConditionalEffect"),[j.stringLiteral(l.entityId),j.nullLiteral(),...l.condition===null?[]:[j.arrowFunctionExpression([],j.cloneNode(l.condition,!0))],j.cloneNode(l.callback,!0)])),j.ifStatement(Or(),j.expressionStatement(j.callExpression(j.memberExpression(Or(),j.identifier("dispose")),[j.arrowFunctionExpression([],j.callExpression(Y(e,"unregisterSubtree"),[j.stringLiteral(l.entityId)]))]))));s.replaceWithMultiple(a)}}function Hr(e){e.traverse({CallExpression(t){if(wn(t))throw t.buildCodeFrameError("memo-dom: effect() must be a direct top-level statement or be controlled by a top-level effect-only if branch in a component or module")}})}import*as Qe from"@babel/types";function _r(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function qr(e){let t=new Set,n=[];for(let r of e){let o=vn(r);if(o===null)return null;for(let i of o.bindings){if(t.has(i))return null;t.add(i)}n.push(...o.expressions)}return t.size===0?null:{bindings:t,expressions:n}}function vn(e){if(Qe.isExpressionStatement(e)&&Qe.isAssignmentExpression(e.expression,{operator:"="})&&Qe.isIdentifier(e.expression.left))return{bindings:new Set([e.expression.left.name]),expressions:[e.expression.right]};if(Qe.isBlockStatement(e))return qr(e.body);if(Qe.isIfStatement(e)){let t=e.alternate;if(t==null)return null;let n=vn(e.consequent),r=vn(t);return n===null||r===null||!_r(n.bindings,r.bindings)?null:{bindings:n.bindings,expressions:[e.test,...n.expressions,...r.expressions]}}return null}function ts(e){if(!e.cases.some(o=>o.test==null))return null;let t=null,n=!1,r=[e.discriminant];for(let o of e.cases){o.test!=null&&r.push(o.test);let i=[...o.consequent];if(i.length===0){n=!0;continue}if(i.at(-1)&&Qe.isBreakStatement(i.at(-1))&&i.pop(),i.some(a=>Qe.isBreakStatement(a)))return null;let s=qr(i);if(s===null)return null;if(n=!1,t===null)t=s.bindings;else if(!_r(t,s.bindings))return null;r.push(...s.expressions)}return t===null||n?null:{bindings:t,expressions:r}}function ns(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function rs(e,t){let n=e;for(;n?.parentPath!==t;)n=n?.parentPath??null;return n}function Gr(e,t,n){let r=t.get("body"),o=new Map(r.map((i,s)=>[i.node,s]));for(let i of r){if(!i.isIfStatement()&&!i.isSwitchStatement())continue;let s=i.node,a=i.isIfStatement()?vn(s):ts(s);if(a===null)continue;let l=!0,d=[];for(let x of a.bindings){let f=t.scope.getBinding(x),m=f?.path,C=m?.parentPath,b=m===void 0?null:rs(m,t);if(f===void 0||!m?.isVariableDeclarator()||!C?.isVariableDeclaration()||C.node.kind!=="let"&&C.node.kind!=="var"||b===null||(o.get(b.node)??Number.MAX_SAFE_INTEGER)>=(o.get(s)??-1)){l=!1;break}d.push(...f.constantViolations.filter(v=>!ns(v,s)))}if(!l)continue;let p=new Set,u=null;for(let x of a.expressions){let f=n(e,x);for(let m of f.reads)p.add(m);f.impure&&u===null&&(u=f.reason??"cannot be analyzed")}if(p.size===0)continue;if(u!==null)throw i.buildCodeFrameError(`memo-dom: module control-flow derivation ${u}`);for(let x of a.bindings)if(p.has(x))throw i.buildCodeFrameError(`memo-dom: module control-flow derivation '${x}' reads its own previous value`);if(d.length>0)throw d[0].buildCodeFrameError(`memo-dom: cannot assign module control-flow computed '${[...a.bindings].sort().join(", ")}' outside its derivation`);let g=e.moduleControlFlow.length,S=[...a.bindings].sort();for(let x of S)ht(e,x,"computed");e.moduleControlFlow.push({statement:s,bindings:S,sources:[...p].sort(),entityId:`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#$flow${g}`})}}import*as pe from"@babel/types";function Hn(e,t){let n=new Set,r=!1,o,i=new Set,s=l=>{r||(r=!0,o=l)},a=l=>{pe.isIdentifier(l)?i.add(l.name):Ae(l,d=>{pe.isIdentifier(d)&&i.add(d.name)})};return Ae(t,(l,d)=>{if(pe.isFunction(l)){if(!(d!==null&&(pe.isCallExpression(d)||pe.isNewExpression(d))))return!1;for(let u of l.params)pe.isLVal(u)&&a(u);return}if(pe.isVariableDeclarator(l)&&pe.isLVal(l.id)){a(l.id);return}if(pe.isAssignmentExpression(l)){let p=pe.isIdentifier(l.left)?l.left.name:pe.isMemberExpression(l.left)?ke(l.left):null;(p===null||!i.has(p))&&s("contains an assignment \u2014 writes belong in handlers, not derivations");return}if(pe.isUpdateExpression(l)){let p=l.argument,u=pe.isIdentifier(p)?p.name:pe.isMemberExpression(p)?ke(p):null;(u===null||!i.has(u))&&s("contains an update (++/--) \u2014 writes belong in handlers, not derivations");return}if(pe.isAwaitExpression(l)||pe.isYieldExpression(l)){s("uses await/yield \u2014 derivations must be synchronous");return}if(pe.isCallExpression(l)){let p=l.callee;if(pe.isIdentifier(p)&&(e.helpers.has(p.name)||e.importedFunctions.has(p.name))){let u=e.importedFunctions.get(p.name)??He(e,p.name);for(let g of u.reads)n.add(g);if(u.writes.size>0){for(let g of u.writes)n.add(g);s(`calls helper '${p.name}' which writes state \u2014 writes belong in handlers`)}else u.unbounded&&e.helpers.has(p.name)&&s(`calls recursive helper '${p.name}' which cannot be analyzed`)}return}if(pe.isIdentifier(l)){!i.has(l.name)&&e.state.has(l.name)&&n.add(l.name);return}if(pe.isMemberExpression(l)&&!l.computed){let p=xe(l);if(p!==null&&p.includes(".")){let u=p.split(".")[0];!i.has(u)&&e.state.get(u)==="store"&&n.add(p)}}}),{reads:n,impure:r,reason:o}}function Zr(e,t){for(let n of t.node.body){let r=pe.isExportNamedDeclaration(n)?n.declaration:n;if(!(!pe.isVariableDeclaration(r)||r.kind!=="const"))for(let o of r.declarations){if(!pe.isIdentifier(o.id)||o.init==null)continue;let i=o.id.name;if(e.state.get(i)==="let"||e.state.get(i)==="computed"||pe.isFunction(o.init)||pe.isJSX(o.init))continue;let s=Hn(e,o.init);if(s.impure){if(s.reads.size>0)throw new Error(`memo-dom: const '${i}' is a state derivation but ${s.reason??"cannot be analyzed"}. Fix the derivation, or make it a 'let' you update in handlers.`);continue}s.reads.size!==0&&(ht(e,i,"computed"),e.computeds.set(i,{reads:s.reads}))}}}import*as Je from"@babel/types";function Yr(e){for(let[t,n]of e.compPaths){let r=new Set;for(let o of n.node.body.body)if(Je.isVariableDeclaration(o)&&!(o.kind!=="let"&&o.kind!=="var"&&o.kind!=="const"))for(let i of o.declarations)Je.isIdentifier(i.id)&&(o.kind==="let"||o.kind==="var"||It(i.init)||Rt(i.init))&&r.add(i.id.name);r.size>0&&e.instanceState.set(t,r)}}function Qr(e){for(let[t,n]of e.compPaths){let r=new Map;for(let u of e.componentProps.get(t)?.bindings??[]){let g=n.scope.getBinding(u);g&&r.set(g,u)}for(let u of e.instanceState.get(t)??[]){let g=n.scope.getBinding(u);g&&r.set(g,u)}for(let u of e.state.keys()){let g=n.scope.getBinding(u);g?.scope.path.isProgram()&&r.set(g,u)}let o=[],i=new Set,s=new Map,a=n.get("body").get("body");for(let u of a)if(u.isVariableDeclaration({kind:"const"}))for(let g of u.get("declarations")){let S=g.node;if(!Je.isIdentifier(S.id)&&!Je.isObjectPattern(S.id)&&!Je.isArrayPattern(S.id)||S.init==null||Je.isFunction(S.init)||Je.isIdentifier(S.id)&&e.instanceState.get(t)?.has(S.id.name)===!0&&(It(S.init)||Rt(S.init)))continue;let x=g.get("init");if(!x.isExpression())continue;let f=new Set,m=null,C=(k,W)=>{let B=W.scope.getBinding(k);return B!==void 0&&r.has(B)},b=k=>{if(!Je.isIdentifier(k.node))return;let W=k.scope.getBinding(k.node.name),B=W===void 0?void 0:r.get(W);B!==void 0&&f.add(B)},v=k=>Je.isIdentifier(k)?k.name:Je.isMemberExpression(k)?ke(k):null;if(x.isReferencedIdentifier()&&b(x),x.isAssignmentExpression()){let k=v(x.node.left);k!==null&&C(k,x)&&(m="contains an assignment to reactive state")}else if(x.isUpdateExpression()){let k=v(x.node.argument);k!==null&&C(k,x)&&(m="contains an update (++/--) to reactive state")}else x.isAwaitExpression()?m="uses await; per-instance derivations must be synchronous":x.isYieldExpression()&&(m="uses yield; per-instance derivations must be synchronous");if(x.traverse({Function(k){k.skip()},ReferencedIdentifier(k){b(k)},AssignmentExpression(k){let W=v(k.node.left);W!==null&&C(W,k)&&(m="contains an assignment to reactive state")},UpdateExpression(k){let W=v(k.node.argument);W!==null&&C(W,k)&&(m="contains an update (++/--) to reactive state")},AwaitExpression(){m="uses await; per-instance derivations must be synchronous"},YieldExpression(){m="uses yield; per-instance derivations must be synchronous"}}),f.size===0)continue;if(x.traverse({ReferencedIdentifier(k){b(k)},AssignmentExpression(k){let W=v(k.node.left);W!==null&&C(W,k)&&(m="contains an assignment to reactive state")},UpdateExpression(k){let W=v(k.node.argument);W!==null&&C(W,k)&&(m="contains an update (++/--) to reactive state")}}),m!==null){let k=_t(S.id);throw g.buildCodeFrameError(`memo-dom: local const '${k.join(", ")||"<pattern>"}' is a per-instance derivation but ${m}`)}let F=_t(S.id),R=new Set;for(let k of f){let W=s.get(k);if(W===void 0)R.add(k);else for(let B of W)R.add(B)}o.push({declaration:u.node,target:Je.cloneNode(S.id),source:Je.cloneNode(S.init),bindings:F,sources:[...R].sort()});for(let k of F){i.add(k),s.set(k,new Set(R));let W=n.scope.getBinding(k);W&&r.set(W,k),e.instanceState.get(t)?.delete(k)}}if(o.length===0)continue;e.instanceDerivations.set(t,o),e.instanceDerivedBindings.set(t,i);let l=new Set([...e.instanceState.get(t)??[],...e.componentProps.get(t)?.bindings??[]]);if(![...l].some(u=>o.some(g=>!g.sources.includes(u))))continue;let p=new Set([...l,...o.flatMap(u=>u.sources)]);e.instanceReasonIds.set(t,new Map([...p].sort().map((u,g)=>[u,g]))),e.selectiveDerivationComponents.add(t)}}import*as fe from"@babel/types";function Yt(e){let t=!0;return fe.traverseFast(e,n=>{if(fe.isAssignmentExpression(n)||fe.isUpdateExpression(n)||fe.isAwaitExpression(n)||fe.isYieldExpression(n)||fe.isNewExpression(n)||fe.isTaggedTemplateExpression(n)||fe.isFunction(n)){t=!1;return}if(fe.isCallExpression(n)||fe.isOptionalCallExpression(n)){let r=n.callee;t=t&&fe.isMemberExpression(r)&&!r.computed&&fe.isIdentifier(r.object,{name:"Math"})&&fe.isIdentifier(r.property)}}),t}function os(e){return!fe.isExpressionStatement(e)||!fe.isAssignmentExpression(e.expression,{operator:"="})||!fe.isIdentifier(e.expression.left)||!Yt(e.expression.right)?null:e.expression.left.name}function eo(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function Zt(e){if(fe.isExpressionStatement(e)){let t=os(e);return t===null?null:{bindings:new Set([t]),partial:new Set}}if(fe.isBlockStatement(e)){let t=new Set,n=new Set;for(let r of e.body){let o=Zt(r);if(o===null)return null;for(let i of o.bindings){if(t.has(i))return null;t.add(i)}for(let i of o.partial)n.add(i)}return t.size===0?null:{bindings:t,partial:n}}if(fe.isIfStatement(e)){if(!Yt(e.test))return null;let t=Zt(e.consequent);if(t===null)return null;if(e.alternate==null)return{bindings:t.bindings,partial:new Set([...t.bindings,...t.partial])};let n=Zt(e.alternate);return n===null||!eo(t.bindings,n.bindings)?null:{bindings:t.bindings,partial:new Set([...t.partial,...n.partial])}}return null}function is(e){if(!Yt(e.discriminant))return null;let t=null;for(let n of e.cases){if(n.test!=null&&!Yt(n.test))return null;let r=[...n.consequent];if(r.at(-1)&&fe.isBreakStatement(r.at(-1))&&r.pop(),r.some(i=>fe.isBreakStatement(i)))return null;let o=Zt(fe.blockStatement(r));if(o===null)return null;if(t===null)t=o;else{if(!eo(t.bindings,o.bindings))return null;for(let i of o.partial)t.partial.add(i)}}if(t!==null&&!e.cases.some(n=>n.test===null))for(let n of t.bindings)t.partial.add(n);return t}function ss(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function to(e){for(let[t,n]of e.compPaths){let r=new Map;for(let s of e.componentProps.get(t)?.bindings??[]){let a=n.scope.getBinding(s);a&&r.set(a,s)}for(let s of e.instanceState.get(t)??[]){let a=n.scope.getBinding(s);a&&r.set(a,s)}for(let s of e.instanceDerivedBindings.get(t)??[]){let a=n.scope.getBinding(s);a&&r.set(a,s)}for(let s of e.state.keys()){let a=n.scope.getBinding(s);a?.scope.path.isProgram()&&r.set(a,s)}let o=[],i=e.instanceDerivedBindings.get(t)??new Set;for(let s of n.get("body").get("body")){if(!s.isIfStatement()&&!s.isSwitchStatement())continue;let a=s,l=a.isIfStatement()?Zt(a.node):is(a.node);if(l===null)continue;let d=!0,p=[],u=[];for(let f of l.bindings){let m=n.scope.getBinding(f),C=m?.path,b=C?.parentPath;if(m===void 0||!C?.isVariableDeclarator()||!b?.isVariableDeclaration()||b.node.kind!=="let"&&b.node.kind!=="var"||m.constantViolations.some(v=>!ss(v,a.node))){d=!1;break}if(l.partial.has(f)){let v=C.get("init");if(!v.isExpression()||!Yt(v.node)){d=!1;break}p.push({binding:f,source:v.node}),u.push(v)}}if(!d)continue;let g=new Set,S=f=>{let m=f.scope.getBinding(f.node.name),C=m===void 0?void 0:r.get(m);C!==void 0&&g.add(C)},x={Function(f){f.skip()},ReferencedIdentifier(f){f.isIdentifier()&&S(f)}};a.traverse(x);for(let f of u)f.isReferencedIdentifier()&&S(f),f.traverse(x);if(g.size!==0){for(let f of l.bindings)if(g.has(f))throw a.buildCodeFrameError(`memo-dom: reactive control-flow derivation '${f}' reads its own previous value`);o.push({statement:a.node,bindings:[...l.bindings].sort(),resets:p,sources:[...g].sort()});for(let f of l.bindings){i.add(f);let m=n.scope.getBinding(f);m&&r.set(m,f),e.instanceState.get(t)?.delete(f)}}}o.length>0&&(e.instanceControlFlow.set(t,o),e.instanceDerivedBindings.set(t,i))}}function no(e){for(let[t]of e.compPaths){let n=e.instanceDerivations.get(t)??[],r=e.instanceControlFlow.get(t)??[];if(n.length===0&&r.length===0)continue;let o=new Map;for(let p of n)for(let u of p.bindings)o.set(u,new Set(p.sources));for(let p of r)for(let u of p.bindings)o.set(u,new Set(p.sources));let i=(p,u=new Set)=>{let g=o.get(p);if(g===void 0)return new Set([p]);if(u.has(p))return new Set([p]);let S=new Set(u).add(p),x=new Set;for(let f of g)for(let m of i(f,S))x.add(m);return x};for(let p of n)p.sources=[...new Set(p.sources.flatMap(u=>[...i(u)]))].sort();for(let p of r)p.sources=[...new Set(p.sources.flatMap(u=>[...i(u)]))].sort();let s=new Set([...e.instanceState.get(t)??[],...e.componentProps.get(t)?.bindings??[]]),a=[...n,...r],l=[...s].some(p=>a.some(u=>!u.sources.includes(p)));if(e.selectiveDerivationComponents.delete(t),e.instanceReasonIds.delete(t),!l)continue;let d=new Set([...s,...a.flatMap(p=>p.sources)]);e.instanceReasonIds.set(t,new Map([...d].sort().map((p,u)=>[p,u]))),e.selectiveDerivationComponents.add(t)}}import*as Qt from"@babel/types";function as(e){let t=e.indexOf("[");return t<0?e:e.slice(0,t)}function xt(e,t){let n=new Set;for(let r of t){let o=r.split("/"),i=[[]];for(let s=0;s<o.length;s++){let a=o[s],l=i.map(d=>[...d,a]);if(s<o.length-1&&e.renderSlotOwners.has(as(a)))for(let d of i)l.push([...d,a,"$slot[*]"]);i=l}for(let s of i)n.add(s.join("/"))}return[...n]}function et(e,t,n=new Set){let r=e.linkedComponentPaths.get(t);if(r!==void 0)return[...r];if(n.has(t))throw e.compPaths.get(t).buildCodeFrameError(`memo-dom: recursive component '${t}' \u2014 components cannot render themselves (L1)`);let o=e.listedSites.get(t);if(o!==void 0&&o.length>0){n.add(t);let d=o.flatMap(p=>et(e,p.owner,n).map(u=>`${u}/${p.suffix}/Row[*]`));return n.delete(t),[...new Set(d)]}let i=e.comps.get(t),s=e.conditionalComponentSites.get(t)??[],a=e.rowComponentSites.get(t)??[];if(i.parents.size===0&&s.length===0&&a.length===0)return[e.rootId];n.add(t);let l=[];for(let d of s)for(let p of et(e,d.owner,n))l.push(`${p}/${d.suffix}`);for(let d of a)for(let p of et(e,d.owner,n))l.push(`${p}/${d.suffix}`);for(let d of i.parents){let p=e.childRefCounts.get(d)?.get(t)??1;for(let u of et(e,d,n))p>1?l.push(`${u}/${t}`,`${u}/${t}[*]`):l.push(`${u}/${t}`)}return n.delete(t),l}function _n(e,t){let n=e.linkedComponentPaths.get(t);if(n!==void 0)return xt(e,n.flatMap(i=>[i,`${i}/*`]));let r=e.listedSites.get(t),o=[];if(r&&r.length>0){if(Ct(e,t)){for(let i of r){let s=i.suffix.lastIndexOf("/"),a=s<0?"":`/${i.suffix.slice(0,s)}`;for(let l of et(e,i.owner))o.push(`${l}${a}`,`${l}${a}/*`)}return xt(e,o)}for(let i of r)for(let s of et(e,i.owner))o.push(`${s}/${i.suffix}/Row[*]`,`${s}/${i.suffix}/Row[*]/*`);return xt(e,o)}for(let i of et(e,t))o.push(i,`${i}/*`);return xt(e,o)}function Ct(e,t){let n=e.importedComponents.get(t);if(n!==void 0)return n.listLightweight;let r=e.lightweightCache.get(t);if(r!==void 0)return r;let o=!1,i=e.listedSites.get(t),s=e.linkedComponentRows.get(t);return(i!==void 0&&i.length>0||s!==void 0&&s.length>0)&&e.comps.get(t).parents.size===0&&kn(e,t)&&(o=!0),e.lightweightCache.set(t,o),o}function kn(e,t){if((e.instanceState.get(t)?.size??0)>0)return!1;let n=!0;return e.compPaths.get(t).traverse({JSXElement(o){let i=o.node.openingElement.name;Qt.isJSXIdentifier(i)&&/^[A-Z]/.test(i.name)&&(n=!1)},CallExpression(o){(Qt.isIdentifier(o.node.callee,{name:"cleanup"})&&o.scope.getBinding("cleanup")===void 0||Qt.isIdentifier(o.node.callee,{name:"effect"})&&o.scope.getBinding("effect")===void 0)&&(n=!1),We(o.node)&&je(o)&&(n=!1)},ConditionalExpression(o){je(o)&&(n=!1)},LogicalExpression(o){je(o)&&(n=!1)}}),n}import*as U from"@babel/types";function ro(e,t){let n=e.findParent(r=>r.isFunctionDeclaration()||r.isFunctionExpression()||r.isArrowFunctionExpression());return n===t?!0:n?.findParent(r=>r===t)!==null}function qn(e,t){let n=e;for(;n!==null;){let r=n.parentPath;if(r===null||r.isJSXAttribute()||r.isJSXSpreadAttribute())return!1;if(r.isJSXExpressionContainer()){if(r.parentPath?.isJSXAttribute()===!0){let o=r.parentPath.node,i=r.parentPath.parentPath;if(!i?.isJSXOpeningElement())return!1;let s=i.node.name;if(!U.isJSXIdentifier(s)||!/^[A-Z]/.test(s.name))return!1;let a=U.isJSXIdentifier(o.name)?o.name.name:o.name.name.name;return t.componentProps.get(s.name)?.renderProps.includes(a)===!0}return r.parentPath?.isJSXElement()===!0||r.parentPath?.isJSXFragment()===!0}if(r.isReturnStatement()&&r.node.argument===n.node||r.isArrowFunctionExpression()&&r.node.body===n.node||r.isVariableDeclarator()&&r.node.init===n.node)return!0;n=r}return!1}function ls(e,t){if(U.isArrayExpression(e))return e;if(!U.isIdentifier(e))return null;let n=t.scope.getBinding(e.name);return n?.path.isVariableDeclarator()&&U.isArrayExpression(n.path.node.init)?n.path.node.init:null}function Gn(e,t,n=new Set){if(n.has(e))throw t.buildCodeFrameError("memo-dom: cyclic JSX array spread");n.add(e);let r=[];try{for(let o of e.elements)if(!(o==null||U.isNullLiteral(o)||U.isBooleanLiteral(o))){if(U.isSpreadElement(o)){if(!U.isExpression(o.argument))throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");let i=ls(o.argument,t);if(i===null)throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");r.push(...Gn(i,t,n));continue}if(U.isArrayExpression(o)){r.push(...Gn(o,t,n));continue}if(U.isJSXElement(o)||U.isJSXFragment(o)){r.push(U.cloneNode(o,!0));continue}if(!U.isExpression(o))throw t.buildCodeFrameError("memo-dom: JSX arrays require renderable expression entries");r.push(U.jsxExpressionContainer(U.cloneNode(o,!0)))}}finally{n.delete(e)}return r}function oo(e,t){return U.jsxFragment(U.jsxOpeningFragment(),U.jsxClosingFragment(),Gn(e,t))}function ds(e,t){return U.isArrayExpression(e)?e.elements.map((n,r)=>{if(n==null||U.isSpreadElement(n))throw t.buildCodeFrameError("memo-dom: JSX arrays cannot contain holes or spread elements");return{key:U.numericLiteral(r),value:n}}):e.properties.map(n=>{if(!U.isObjectProperty(n)||n.computed||!U.isExpression(n.value))throw t.buildCodeFrameError("memo-dom: JSX objects require static data properties without spreads");let r=U.isIdentifier(n.key)?U.stringLiteral(n.key.name):U.isStringLiteral(n.key)||U.isNumericLiteral(n.key)?U.cloneNode(n.key):null;if(r===null)throw t.buildCodeFrameError("memo-dom: JSX objects require identifier, string, or numeric keys");return{key:r,value:n.value}})}function cs(e,t){let n=e.node,r=null;if(!n.computed&&U.isIdentifier(n.property)?r=n.property.name:n.computed&&(U.isStringLiteral(n.property)||U.isNumericLiteral(n.property))&&(r=n.property.value),r!==null){let i=t.find(s=>(U.isStringLiteral(s.key)||U.isNumericLiteral(s.key))&&s.key.value===r);if(i===void 0)throw e.buildCodeFrameError(`memo-dom: JSX collection has no entry for '${r}'`);return U.cloneNode(i.value,!0)}if(!n.computed||!U.isExpression(n.property))throw e.buildCodeFrameError("memo-dom: JSX collection selection requires a static or expression key");let o=U.nullLiteral();for(let i=t.length-1;i>=0;i--){let s=t[i];o=U.conditionalExpression(U.binaryExpression("===",U.cloneNode(n.property,!0),U.cloneNode(s.key,!0)),U.cloneNode(s.value,!0),o)}return o}function io(e){for(let[,t]of e.compPaths){let n=!1;t.traverse({JSXExpressionContainer(o){if(!o.parentPath?.isJSXElement()&&!o.parentPath?.isJSXFragment())return;let i=o.get("expression");Array.isArray(i)||!i.isArrayExpression()||!de(i.node)||(o.replaceWith(oo(i.node,i)),n=!0)}});let r=!0;for(;r;){r=!1,t.scope.crawl();let o=t.get("body").get("body");for(let i of o)if(i.isVariableDeclaration({kind:"const"})){for(let s of i.get("declarations")){let a=s.node,l=a.init;if(!U.isIdentifier(a.id)||l==null||!de(l))continue;let d=s.scope.getBinding(a.id.name);if(d?.path!==s)continue;let p=[...d.referencePaths];if(U.isObjectExpression(l)||U.isArrayExpression(l))for(let u of p){if(!u.isIdentifier()||!ro(u,t))throw u.buildCodeFrameError(`memo-dom: JSX collection '${a.id.name}' is used outside its component`);if(u.parentPath?.isMemberExpression()&&u.parentPath.node.object===u.node){let g=u.parentPath;if(!qn(g,e))throw g.buildCodeFrameError(`memo-dom: JSX collection '${a.id.name}' is used outside a render position`);g.replaceWith(cs(g,ds(l,s)));continue}if(U.isArrayExpression(l)&&u.parentPath?.isSpreadElement()&&u.parentPath.parentPath?.isArrayExpression()){u.replaceWith(U.cloneNode(l,!0));continue}if(U.isArrayExpression(l)&&qn(u,e)){u.replaceWith(oo(l,u));continue}throw u.buildCodeFrameError(U.isArrayExpression(l)?`memo-dom: JSX collection '${a.id.name}' must be rendered directly or selected with a direct index access`:`memo-dom: JSX collection '${a.id.name}' is used outside a render position`)}else for(let u of p)if(!(!u.isIdentifier()||!ro(u,t))){if(!qn(u,e))throw u.buildCodeFrameError(`memo-dom: JSX value '${a.id.name}' is used outside a render position`);u.replaceWith(U.cloneNode(l,!0))}i.node.declarations.length===1?i.remove():s.remove(),n=!0,r=!0;break}if(r)break}}n&&(t.traverse({JSXExpressionContainer(o){let i=o.node.expression;(o.parentPath?.isJSXElement()===!0||o.parentPath?.isJSXFragment()===!0)&&(U.isJSXElement(i)||U.isJSXFragment(i))&&o.replaceWith(i)}}),t.scope.crawl())}}import*as L from"@babel/types";function Zn(e){return L.isReturnStatement(e)&&L.isExpression(e.argument)?e.argument:L.isBlockStatement(e)&&e.body.length===1?Zn(e.body[0]):null}function Ot(e){let t=Zn(e);if(t!==null)return t;if(L.isIfStatement(e)&&e.alternate!=null){let n=Ot(e.consequent),r=Ot(e.alternate);return n===null||r===null?null:L.conditionalExpression(L.cloneNode(e.test,!0),L.cloneNode(n,!0),L.cloneNode(r,!0))}if(L.isSwitchStatement(e)){let n=e.cases.find(o=>o.test==null);if(n===void 0||n.consequent.length!==1)return null;let r=Ot(n.consequent[0]);if(r===null)return null;for(let o=e.cases.length-1;o>=0;o--){let i=e.cases[o];if(i.test==null)continue;if(i.consequent.length!==1)return null;let s=Ot(i.consequent[0]);if(s===null)return null;r=L.conditionalExpression(L.binaryExpression("===",L.cloneNode(e.discriminant,!0),L.cloneNode(i.test,!0)),L.cloneNode(s,!0),r)}return r}return null}function us(e,t){if(L.isExpression(e.body))return{expression:L.cloneNode(e.body,!0),locals:new Map};let n=new Map,r=[];for(let s of e.body.body){if(L.isVariableDeclaration(s,{kind:"const"})){for(let a of s.declarations)(!L.isIdentifier(a.id)||a.init==null||!L.isExpression(a.init))&&t("memo-dom: JSX render functions require identifier const declarations with expression initializers"),n.set(a.id.name,L.cloneNode(a.init,!0));continue}L.isTypeScript(s)||L.isEmptyStatement(s)||r.push(s)}if(r.length===1){let s=Ot(r[0]);if(s!==null)return{expression:s,locals:n}}let o=r.at(-1),i=o===void 0?null:Zn(o);if(i!==null){let s=L.cloneNode(i,!0);for(let a=r.length-2;a>=0;a--){let l=r[a];if(L.isIfStatement(l)&&l.alternate==null){let d=Ot(l.consequent);if(d!==null){s=L.conditionalExpression(L.cloneNode(l.test,!0),L.cloneNode(d,!0),s);continue}}t("memo-dom: JSX render functions support pure const setup, JSX return expressions, tail early-return if statements, exhaustive return if/else, or exhaustive return switch statements")}return{expression:s,locals:n}}return t("memo-dom: JSX render function does not have supported exhaustive return control flow")}function ps(e,t){return(L.isMemberExpression(e)||L.isOptionalMemberExpression(e))&&t==="property"&&!e.computed||(L.isObjectProperty(e)||L.isObjectMethod(e)||L.isClassMethod(e))&&t==="key"&&!e.computed||L.isVariableDeclarator(e)&&t==="id"||(L.isFunction(e)||L.isCatchClause(e))&&(t==="params"||t==="param"||t==="id")||L.isLabeledStatement(e)&&t==="label"}function so(e,t,n=new Set){let r=L.cloneNode(e,!0),o=(i,s,a,l)=>{if(L.isIdentifier(i)&&!l.has(i.name)&&t.has(i.name)&&(s===null||!ps(s,a)))return L.cloneNode(t.get(i.name),!0);let d=l;if(L.isFunction(i)&&i!==r){let p=i.params.flatMap(u=>Object.keys(L.getBindingIdentifiers(u)));d=new Set([...l,...p])}for(let p of L.VISITOR_KEYS[i.type]??[]){let u=i[p];Array.isArray(u)?i[p]=u.map(g=>g!=null&&typeof g=="object"&&"type"in g?o(g,i,p,d):g):u!=null&&typeof u=="object"&&"type"in u&&(i[p]=o(u,i,p,d))}return L.isObjectProperty(i)&&i.shorthand&&!L.isIdentifier(i.value,{name:L.isIdentifier(i.key)?i.key.name:""})&&(i.shorthand=!1),i};return o(r,null,"",n)}function fs(e,t){let n=a=>{throw t.buildCodeFrameError(a)},r=e.node;(r.async||r.generator)&&n("memo-dom: JSX render functions must be synchronous"),t.node.arguments.some(a=>L.isSpreadElement(a))&&n("memo-dom: JSX render function calls do not support spread arguments"),t.node.arguments.length>r.params.length&&n("memo-dom: JSX render function received more arguments than parameters");let o=new Map;for(let a=0;a<r.params.length;a++){let l=r.params[a],d=t.node.arguments[a],p=d!==void 0&&L.isExpression(d)?d:L.identifier("undefined");if(L.isIdentifier(l)){o.set(l.name,L.cloneNode(p,!0));continue}if(L.isAssignmentPattern(l)&&L.isIdentifier(l.left)){o.set(l.left.name,L.conditionalExpression(L.binaryExpression("===",L.cloneNode(p,!0),L.identifier("undefined")),L.cloneNode(l.right,!0),L.cloneNode(p,!0)));continue}n("memo-dom: JSX render functions currently require identifier parameters with optional defaults")}let i=us(r,n);for(let[a,l]of i.locals)o.set(a,so(l,o));let s=so(i.expression,o);return de(s)||n("memo-dom: JSX render function expansion did not produce JSX"),s}function ms(e,t){let n=t.get("callee");return Array.isArray(n)||!n.isIdentifier()?null:ao(e,n)}function ao(e,t){let n=t.node.name,r=e.jsxHelpers.get(n);if(r!==void 0)return{node:r.node,bindingPath:r};let o=t.scope.getBinding(n);if(o?.path.isFunctionDeclaration()&&de(o.path.node))return{node:o.path.node,bindingPath:o.path};if(o?.path.isVariableDeclarator()){let i=o.path.node.init;if((L.isFunctionExpression(i)||L.isArrowFunctionExpression(i))&&de(i.body))return{node:i,bindingPath:o.path}}return null}function lo(e){return L.isMemberExpression(e.callee)&&!e.callee.computed&&L.isIdentifier(e.callee.property,{name:"map"})}function gs(e){let t=e.parentPath;return t?.isCallExpression()===!0&&(t.node.callee===e.node||lo(t.node)&&t.node.arguments[0]===e.node)}function bs(e,t){let n=e.node;if(n.async||n.generator)throw t.buildCodeFrameError("memo-dom: JSX render callbacks must be synchronous");return L.arrowFunctionExpression(n.params.map(r=>L.cloneNode(r,!0)),L.cloneNode(n.body,!0))}function Nn(e){if(!e.removed){if(e.isFunctionDeclaration()){e.parentPath?.isExportNamedDeclaration()?e.parentPath.remove():e.remove();return}if(e.isVariableDeclarator()){let t=e.parentPath;if(!t?.isVariableDeclaration())return;t.node.declarations.length===1?t.parentPath?.isExportNamedDeclaration()?t.parentPath.remove():t.remove():e.remove();return}if(e.isArrowFunctionExpression()||e.isFunctionExpression()){let t=e.parentPath;t?.isVariableDeclarator()&&Nn(t)}}}function hs(e,t){let n=t.findParent(r=>r.isProgram());if(n===null||!n.isProgram()){Nn(t);return}for(let r of n.get("body")){let o=r.isExportNamedDeclaration()?r.get("declaration"):r;if(Array.isArray(o)||o==null)continue;if(o.isFunctionDeclaration()&&o.node.id?.name===e){r.remove();return}if(!o.isVariableDeclaration())continue;let i=o.get("declarations"),s=i.find(a=>a.isVariableDeclarator()&&L.isIdentifier(a.node.id,{name:e}));if(s!==void 0){i.length===1?r.remove():s.remove();return}}Nn(t)}function Es(e,t){let n=e.parentPath,r=n?.parentPath;if((L.isJSXElement(t)||L.isJSXFragment(t))&&n?.isJSXExpressionContainer()&&(r?.isJSXElement()||r?.isJSXFragment())&&r.node.children.includes(n.node)){n.replaceWith(t);return}e.replaceWith(t)}function co(e){let t=new Set;for(let[n,r]of e.jsxHelpers)if((r.scope.parent?.getBinding(n)??r.parentPath?.scope.getBinding(n))?.referencePaths.some(i=>i.isIdentifier()&&!gs(i)))throw r.buildCodeFrameError("memo-dom: JSX render functions may only be called in local render composition or passed directly to collection map()");for(let[,n]of e.compPaths){n.scope.crawl(),n.traverse({CallExpression(o){if(!lo(o.node)||o.node.arguments.length!==1)return;let i=o.get("arguments")[0];if(i===void 0||Array.isArray(i)||!i.isIdentifier())return;let s=ao(e,i);s!==null&&(i.replaceWith(bs(s,i)),t.add(s.bindingPath))}});let r=!0;for(;r;){r=!1,n.scope.crawl();let o=[];n.traverse({CallExpression(i){o.push(i)}});for(let i of o.reverse()){if(i.removed)continue;let s=ms(e,i);s!==null&&(Es(i,fs(s,i)),t.add(s.bindingPath),r=!0)}}}for(let[n,r]of e.jsxHelpers)hs(n,r);for(let n of t)Nn(n)}import*as _e from"@babel/types";function ys(e){let t=Ft(e);return _e.isIdentifier(t)||_e.isMemberExpression(t)||gn(t)}function Ss(e,t){let n=e,r=t.get("body");for(;n!==null&&n.parentPath!==r;)n=n.parentPath;return n?.isStatement()===!0?n:null}function xs(e,t){return e.findParent(n=>n.isFunctionDeclaration()||n.isFunctionExpression()||n.isArrowFunctionExpression())===t}function uo(e){for(let[,t]of e.compPaths){let n=[];if(t.traverse({CallExpression(s){if(We(s.node)===null||!_e.isMemberExpression(s.node.callee)||!_e.isExpression(s.node.callee.object)||ys(s.node.callee.object)||!xs(s,t))return;let a=Ss(s,t);a!==null&&n.push({path:s,source:_e.cloneNode(s.node.callee.object,!0),statement:a})}}),n.length===0)continue;let r=t.get("body").get("body"),o=new Map(r.map((s,a)=>[s.node,a]));n.sort((s,a)=>(o.get(s.statement.node)??0)-(o.get(a.statement.node)??0));let i=[];for(let s of n){let a=A(e,"listView");i.push(_e.variableDeclarator(_e.cloneNode(a),s.source));let l=s.path.get("callee");if(Array.isArray(l)||!l.isMemberExpression())continue;let d=l.get("object");Array.isArray(d)||d.replaceWith(_e.cloneNode(a))}n[0].statement.insertBefore(_e.variableDeclaration("const",i)),t.scope.crawl()}}import*as ze from"@babel/types";var Cs=new Set(["==","==="]);function In(e,t,n){if(n(e,t),!ze.isFunction(e))for(let r of ze.VISITOR_KEYS[e.type]??[]){let o=e[r];if(Array.isArray(o))for(let i of o)i&&In(i,e,n);else o&&In(o,e,n)}}function po(e,t,n){if(!ze.isBinaryExpression(t)||!Cs.has(t.operator))return!1;let r=t.left===e?t.right:t.left;return ze.isExpression(r)&&ze.isNodesEquivalent(r,n)}function fo(e,t){if(e.jsx===null||e.keyExpr===null||!e.sourceLocal||!ze.isIdentifier(e.sourceExpr)||!t.has(e.sourceExpr.name))return[];let n=e.sourceExpr.name,r=new Set;if(In(e.jsx,null,(i,s)=>{ze.isIdentifier(i)&&t.has(i.name)&&i.name!==n&&po(i,s,e.keyExpr)&&r.add(i.name)}),r.size===0)return[];let o=new Set;return In(e.jsx,null,(i,s)=>{ze.isIdentifier(i)&&r.has(i.name)&&ze.isReferenced(i,s)&&!po(i,s,e.keyExpr)&&o.add(i.name)}),[...r].filter(i=>!o.has(i)).sort()}import*as N from"@babel/types";function Ps(e){return{mode:e.objectProps?"object":"positional",names:[...e.props],acceptsUnknown:e.acceptsUnknownProps,bindings:[],params:[],hasWholeDefault:e.hasWholeDefault,renderProps:[...e.renderProps??[]],renderCallbacks:[...e.renderCallbacks??[]],refProps:[...e.refProps??[]]}}function Rn(e,t){if(e.linkedDynamicComponentCandidates.size===0)return;t.scope.crawl();let n=new Set(Object.keys(t.scope.bindings)),r=new Map([...e.importedComponents].map(([i,s])=>[s.key,i])),o=[];for(let[i,s]of e.linkedDynamicComponentCandidates){let a=[];for(let d of s){let p=r.get(d.key);if(p===void 0){let u=`MDDynamic_${d.imported.replace(/[^A-Za-z0-9_$]/g,"_")}`;p=u;let g=1;for(;n.has(p);)p=`${u}${g++}`;n.add(p),r.set(d.key,p);let S={type:"component",key:d.key,props:[...d.props],objectProps:d.objectProps,acceptsUnknownProps:d.acceptsUnknownProps,hasWholeDefault:d.hasWholeDefault,listLightweight:d.listLightweight,delegatedEvents:d.delegatedEvents,renderProps:[...d.renderProps??[]],renderCallbacks:[...d.renderCallbacks??[]],refProps:[...d.refProps??[]],subtreeReads:[...d.subtreeReads??[]]};e.importedComponents.set(p,S),e.componentProps.set(p,Ps(S)),o.push(N.importDeclaration(d.imported==="default"?[N.importDefaultSpecifier(N.identifier(p))]:[N.importSpecifier(N.identifier(p),N.isValidIdentifier(d.imported)?N.identifier(d.imported):N.stringLiteral(d.imported))],N.stringLiteral(d.source)))}a.push(p)}let l=[...new Set(a)];e.state.has(i)?e.stateComponentCandidates.set(i,l):e.functionComponentCandidates.set(i,l)}for(let i of o.reverse())t.unshiftContainer("body",i);t.scope.crawl()}function Yn(e){let t=e;for(;N.isTSAsExpression(t)||N.isTSTypeAssertion(t)||N.isTSNonNullExpression(t);)t=t.expression;return t}function mo(e){return N.isJSXIdentifier(e)?N.identifier(e.name):N.memberExpression(mo(e.object),N.identifier(e.property.name))}function go(e,t){let n=xe(t);if(n===null)return null;let[r,...o]=n.split(".");if(r===void 0||o.length===0)return null;let i=e.scope.getBinding(r);if(!i?.path.isVariableDeclarator())return null;let s=i.path.node.init;if(s==null)return null;for(let a of o){if(s=Yn(s),!N.isObjectExpression(s))return null;let l=s.properties.find(d=>!N.isObjectProperty(d)||d.computed?!1:(N.isIdentifier(d.key)?d.key.name:N.isStringLiteral(d.key)?d.key.value:null)===a);if(l===void 0||!N.isObjectProperty(l)||!N.isExpression(l.value))return null;s=l.value}return s}function ws(e,t){let n=e.scope.getBinding(t);if(n===void 0)return[];let r=null;return n.path.isFunctionDeclaration()?r=n.path.node:n.path.isVariableDeclarator()&&(N.isFunctionExpression(n.path.node.init)||N.isArrowFunctionExpression(n.path.node.init))&&(r=n.path.node.init),r===null?[]:bo(r)}function bo(e){if(N.isExpression(e.body))return[e.body];let t=[],n=r=>{if(!N.isFunction(r)){if(N.isReturnStatement(r)){N.isExpression(r.argument)&&t.push(r.argument);return}for(let o of N.VISITOR_KEYS[r.type]??[]){let i=r[o];if(Array.isArray(i))for(let s of i)s!=null&&typeof s=="object"&&"type"in s&&n(s);else i!=null&&typeof i=="object"&&"type"in i&&n(i)}}};for(let r of e.body.body)n(r);return t}function Pt(e,t,n,r=new Set){let o=Yn(t);if(!r.has(o)){if(r.add(o),N.isIdentifier(o)&&(e.comps.has(o.name)||e.importedComponents.has(o.name))){n.add(o.name);return}if(N.isIdentifier(o)){for(let i of e.stateComponentCandidates.get(o.name)??e.functionComponentCandidates.get(o.name)??[])n.add(i);return}if(N.isConditionalExpression(o)){Pt(e,o.consequent,n,r),Pt(e,o.alternate,n,r);return}if(N.isLogicalExpression(o)){Pt(e,o.right,n,r);return}if(N.isObjectExpression(o)){for(let i of o.properties)N.isObjectProperty(i)&&N.isExpression(i.value)&&Pt(e,i.value,n,r);return}if(N.isArrayExpression(o)){for(let i of o.elements)i!=null&&!N.isSpreadElement(i)&&Pt(e,i,n,r);return}if(N.isCallExpression(o)&&N.isIdentifier(o.callee)){for(let i of e.functionComponentCandidates.get(o.callee.name)??[])n.add(i);return}if(N.isMemberExpression(o)){let i=ke(o);if(i!==null)for(let s of e.stateComponentCandidates.get(i)??[])n.add(s)}}}function ho(e,t){for(let r of t.node.body){let o=N.isExportNamedDeclaration(r)?r.declaration:r;if(N.isVariableDeclaration(o))for(let i of o.declarations){if(!N.isIdentifier(i.id)||i.init==null)continue;let s=new Set;Pt(e,i.init,s),s.size>0&&e.state.has(i.id.name)&&e.stateComponentCandidates.set(i.id.name,[...s])}}let n=!0;for(;n;){n=!1;for(let[r,o]of e.helpers){let i=new Set(e.functionComponentCandidates.get(r)??[]),s=[],a=o.node;(N.isFunctionDeclaration(a)||N.isFunctionExpression(a)||N.isArrowFunctionExpression(a))&&(s=bo(a));for(let l of s)Pt(e,l,i);i.size>0&&i.size!==(e.functionComponentCandidates.get(r)?.length??0)&&(e.functionComponentCandidates.set(r,[...i]),n=!0)}}}function tt(e,t,n,r,o=new Set){let i=Yn(n);if(!o.has(i)){if(o.add(i),N.isConditionalExpression(i)){tt(e,t,i.consequent,r,o),tt(e,t,i.alternate,r,o);return}if(N.isStringLiteral(i)){if(!/^[A-Za-z][A-Za-z0-9:_-]*$/.test(i.value))throw t.buildCodeFrameError(`memo-dom: '${i.value}' is not a valid dynamic intrinsic tag name`);r.push({compare:N.cloneNode(i),tag:N.jsxIdentifier(i.value)});return}if(N.isIdentifier(i)){if(e.comps.has(i.name)||e.importedComponents.has(i.name)){r.push({compare:N.cloneNode(i),tag:N.jsxIdentifier(i.name)});return}let s=e.stateTagCandidates.get(i.name);if(s!==void 0)for(let l of s)tt(e,t,N.stringLiteral(l),r,o);let a=t.scope.getBinding(i.name);a?.path.isVariableDeclarator()&&a.path.node.init!=null&&tt(e,t,a.path.node.init,r,o);return}if(N.isCallExpression(i)&&N.isIdentifier(i.callee)){for(let s of e.functionTagCandidates.get(i.callee.name)??[])tt(e,t,N.stringLiteral(s),r,o);for(let s of ws(t,i.callee.name))tt(e,t,s,r,o);for(let s of e.functionComponentCandidates.get(i.callee.name)??[])tt(e,t,N.identifier(s),r,o);return}if(N.isMemberExpression(i)){let s=go(t,i);if(s!==null){tt(e,t,s,r,o);return}let a=ke(i);if(a===null)return;let l=t.scope.getBinding(a);if(l?.path.isVariableDeclarator()&&l.path.node.init!=null){let d=new Set;Pt(e,l.path.node.init,d);for(let p of d)tt(e,t,N.identifier(p),r,o)}for(let d of e.stateTagCandidates.get(a)??[])tt(e,t,N.stringLiteral(d),r,o);for(let d of e.stateComponentCandidates.get(a)??[])tt(e,t,N.identifier(d),r,o)}}}function vs(e){return N.isStringLiteral(e.compare)?`string:${e.compare.value}`:N.isIdentifier(e.compare)?`component:${e.compare.name}`:JSON.stringify(e.compare)}function ks(e,t){if(N.isIdentifier(t)){let n=e.scope.getBinding(t.name);return n?.path.isVariableDeclarator()?[...n.path.node.init==null?[]:[n.path.node.init],...n.constantViolations.flatMap(r=>r.isAssignmentExpression()&&r.node.operator==="="&&N.isExpression(r.node.right)?[r.node.right]:[])]:[]}if(N.isMemberExpression(t)){let n=go(e,t),r=xe(t),o=[];return r!==null&&(e.getFunctionParent()??e.findParent(a=>a.isProgram()))?.traverse({AssignmentExpression(a){a.node.operator==="="&&N.isMemberExpression(a.node.left)&&xe(a.node.left)===r&&N.isExpression(a.node.right)&&o.push(a.node.right)}}),[...n===null?[]:[n],...o]}return[]}function Eo(e,t){let n=N.cloneNode(e,!0);n.openingElement.name=N.cloneNode(t);let r=n.closingElement;return r!=null&&(r.name=N.cloneNode(t)),n}function Ns(e,t,n){let r=N.nullLiteral();for(let o=n.length-1;o>=0;o--){let i=n[o];r=N.conditionalExpression(N.binaryExpression("===",N.cloneNode(e,!0),N.cloneNode(i.compare,!0)),Eo(t,i.tag),r)}return r}function Is(e){return N.isIdentifier(e)?e.name:N.isMemberExpression(e)?xe(e)??"<member expression>":"<expression>"}function yo(e){let t=new Map;for(let[,n]of e.compPaths){n.scope.crawl();let r=[];n.traverse({JSXElement(o){r.push(o)}});for(let o of r.reverse()){if(o.removed)continue;let i=o.node.openingElement.name;if(N.isJSXNamespacedName(i))throw o.buildCodeFrameError("memo-dom: namespaced JSX tags are not supported");if(N.isJSXIdentifier(i)&&(!/^[A-Z]/.test(i.name)||e.comps.has(i.name)||e.importedComponents.has(i.name)))continue;let s=mo(i),a=ks(o,s),l=[];for(let p of a)tt(e,o,p,l);let d=[...new Map(l.map(p=>[vs(p),p])).values()];if(d.length===0)throw o.buildCodeFrameError(`memo-dom: dynamic JSX tag '${Is(s)}' has no finite string or linked-component candidates`);for(let p of d){if(!N.isJSXIdentifier(p.tag))continue;let u=e.componentProps.get(p.tag.name);if(u===void 0||u.renderProps.length===0)continue;let g=t.get(p.tag.name);g===void 0&&(g=new Map,t.set(p.tag.name,g));for(let S of o.node.openingElement.attributes){if(N.isJSXSpreadAttribute(S)||!N.isJSXIdentifier(S.name)||!u.renderProps.includes(S.name.name))continue;let x=Ve(S.value),f=g.get(S.name.name)??{scalar:!1,jsx:!1,at:o};x!==null&&de(x)?f.jsx=!0:f.scalar=!0,g.set(S.name.name,f)}}if(d.length===1){o.replaceWith(Eo(o.node,d[0].tag));continue}o.replaceWith(N.jsxFragment(N.jsxOpeningFragment(),N.jsxClosingFragment(),[N.jsxExpressionContainer(Ns(s,o.node,d))]))}n.scope.crawl()}for(let[n,r]of t){let o=e.componentProps.get(n);for(let[i,s]of r){if(s.scalar&&s.jsx)throw s.at.buildCodeFrameError(`memo-dom: dynamic component prop '${i}' is used as both scalar data and JSX content`);s.scalar&&(o.renderProps=o.renderProps.filter(a=>a!==i))}}}import*as re from"@babel/types";function Qn(e){return re.isExportNamedDeclaration(e)?e.declaration??null:re.isDeclaration(e)?e:null}function So(e){let t=new Map;for(let n of e.body){let r=Qn(n);re.isTSTypeAliasDeclaration(r)&&t.set(r.id.name,r.typeAnnotation)}return t}function mt(e,t,n=new Set){if(re.isTSLiteralType(e)&&re.isStringLiteral(e.literal))return[e.literal.value];if(re.isTSUnionType(e))return e.types.flatMap(r=>mt(r,t,n));if(re.isTSIntersectionType(e))return e.types.flatMap(r=>mt(r,t,n));if(re.isTSParenthesizedType(e))return mt(e.typeAnnotation,t,n);if(re.isTSTypeLiteral(e))return e.members.flatMap(r=>(re.isTSPropertySignature(r)||re.isTSIndexSignature(r))&&re.isTSTypeAnnotation(r.typeAnnotation)&&re.isTSType(r.typeAnnotation.typeAnnotation)?mt(r.typeAnnotation.typeAnnotation,t,n):[]);if(re.isTSMappedType(e)&&e.typeAnnotation!=null&&re.isTSType(e.typeAnnotation))return mt(e.typeAnnotation,t,n);if(re.isTSTypeReference(e)&&re.isIdentifier(e.typeName)){let r=e.typeName.name;if((r==="Record"||r==="Readonly"||r==="Partial")&&re.isTSTypeParameterInstantiation(e.typeArguments)){let s=r==="Record"?e.typeArguments.params[1]:e.typeArguments.params[0];if(s!==void 0&&re.isTSType(s))return mt(s,t,n)}if(n.has(r))return[];let o=t.get(r);if(o===void 0)return[];let i=new Set(n);return i.add(r),mt(o,t,i)}return[]}function Fn(e){let t=So(e),n=new Map;for(let r of e.body){let o=Qn(r);if(re.isVariableDeclaration(o))for(let i of o.declarations){if(!re.isIdentifier(i.id)||!re.isTSTypeAnnotation(i.id.typeAnnotation))continue;let s=[...new Set(mt(i.id.typeAnnotation.typeAnnotation,t))];s.length>0&&n.set(i.id.name,s)}}return n}function er(e){let t=So(e),n=new Map,r=(o,i)=>{if(!re.isTSTypeAnnotation(i)||!re.isTSType(i.typeAnnotation))return;let s=[...new Set(mt(i.typeAnnotation,t))];s.length>0&&n.set(o,s)};for(let o of e.body){let i=Qn(o);if(re.isFunctionDeclaration(i)&&i.id!=null){r(i.id.name,i.returnType);continue}if(re.isVariableDeclaration(i))for(let s of i.declarations)re.isIdentifier(s.id)&&(re.isArrowFunctionExpression(s.init)||re.isFunctionExpression(s.init))&&r(s.id.name,s.init.returnType)}return n}import*as dt from"@babel/types";import*as Se from"@babel/types";function en(e,t){let n=[],r=[],o=-1;for(let s=0;s<e.length;s++)Se.isJSXSpreadAttribute(e[s])&&(o=s);let i=[];for(let s=0;s<e.length;s++){let a=e[s];if(Se.isJSXSpreadAttribute(a)){n.push(Se.spreadElement(Se.cloneNode(a.argument))),r.push(Se.cloneNode(a.argument));continue}let l=Oe(a.name);if(l==="key"&&t.skipKey)continue;let d=Rs(a,t.fail),p=t.attributeValue?.(l,d)??d,u=/^on[A-Z]/.test(l)&&t.eventValue!==void 0?t.eventValue(l,p):p;n.push(Se.objectProperty(Se.isValidIdentifier(l)?Se.identifier(l):Se.stringLiteral(l),u,!1,Se.isIdentifier(u)&&u.name===l)),r.push(Se.cloneNode(d)),/^on[A-Z]/.test(l)&&s>o&&i.push(l)}return{expression:Se.objectExpression(n),sources:r,safeEventKeys:i}}function Oe(e){return Se.isJSXIdentifier(e)?e.name:`${e.namespace.name}:${e.name.name}`}function Rs(e,t){return e.value==null?Se.booleanLiteral(!0):Se.isStringLiteral(e.value)?Se.cloneNode(e.value):Se.isJSXExpressionContainer(e.value)&&Se.isExpression(e.value.expression)?Se.cloneNode(e.value.expression):t(`memo-dom: attribute '${Oe(e.name)}' must contain a JavaScript expression`)}function Mn(e,t,n=new Set){let r=e.importedComponents.get(t);if(r!==void 0)return new Set(r.subtreeReads??[]);if(n.has(t))return new Set;n.add(t);let o=new Set(e.compReads.get(t)??[]);for(let s of e.effects.get(t)??[]){for(let a of s.moduleReads)o.add(a);for(let a of s.conditionModuleReads)o.add(a)}let i=e.compPaths.get(t);return i!==void 0&&i.traverse({JSXElement(s){let a=s.node.openingElement.name;if(!(!dt.isJSXIdentifier(a)||!/^[A-Z]/.test(a.name)))for(let l of Mn(e,a.name,n))o.add(l)}}),n.delete(t),o}function xo(e){for(let[t,n]of e.compPaths){let r=e.compReads.get(t);r!==void 0&&n.traverse({JSXAttribute(o){let i=o.parentPath;if(!i?.isJSXOpeningElement())return;let s=i.node.name;if(!dt.isJSXIdentifier(s))return;let a=Oe(o.node.name);if(e.componentProps.get(s.name)?.renderCallbacks.includes(a)!==!0)return;let l=o.node.value;!dt.isJSXExpressionContainer(l)||!dt.isExpression(l.expression)||Ae(l.expression,d=>{if(dt.isJSXOpeningElement(d)&&dt.isJSXIdentifier(d.name)&&/^[A-Z]/.test(d.name.name))for(let p of Mn(e,d.name.name))r.add(p)})}})}}import*as wt from"@babel/types";function Co(e){for(let[t,n]of e.compPaths){let r=e.componentProps.get(t);n.traverse({JSXAttribute(o){if(Oe(o.node.name)!=="ref")return;let i=o.node.value;if(!(!wt.isJSXExpressionContainer(i)||!wt.isExpression(i.expression)))for(let s of Po(e,t,i.expression))r.refProps.includes(s)||r.refProps.push(s)}})}}function Po(e,t,n){let r=ft(e,t,n);if(r!==null)return[r];if(!wt.isArrayExpression(n))return[];let o=[];for(let i of n.elements)i===null||wt.isSpreadElement(i)||o.push(...Po(e,t,i));return o}import*as Lt from"@babel/types";function Xt(e){let t=new Set;return Ae(e,n=>{if(!Lt.isJSXOpeningElement(n))return;let r=n.name;if(!(!Lt.isJSXIdentifier(r)||!/^[a-z]/.test(r.name)))for(let o of n.attributes)Lt.isJSXAttribute(o)&&Lt.isJSXIdentifier(o.name)&&/^on[A-Z]/.test(o.name.name)&&t.add(o.name.name)}),[...t].sort()}import*as Xe from"@babel/types";function tr(e){let t=(r,o)=>{let i=Ye(e,r),s=e.readers.get(i);s||e.readers.set(i,s=new Set);for(let a of o)s.add(a)};for(let[r,o]of e.compReads){if(o.size===0)continue;let i=_n(e,r);for(let s of o)t(s,i)}for(let{owner:r,suffix:o,vars:i}of e.rowReads.values()){let s=xt(e,et(e,r).flatMap(a=>[`${a}/${o}/Row[*]`,`${a}/${o}/Row[*]/*`]));for(let a of i)t(a,s)}for(let{owner:r,suffix:o,vars:i}of e.condReads.values()){let s=xt(e,et(e,r).flatMap(a=>[`${a}/${o}`,`${a}/${o}/*`]));for(let a of i)t(a,s)}for(let[r,o]of e.effects){let i=_n(e,r).filter(s=>!s.endsWith("/*"));for(let s of o){let a=i.map(d=>`${d}/$effects/${s.index}`),l=s.condition===null?a:a.map(d=>`${d}/$active`);for(let d of s.moduleReads)t(d,l);for(let d of s.conditionModuleReads)t(d,a)}}for(let r of e.moduleEffects){let o=r.condition===null?r.entityId:`${r.entityId}/$active`;for(let i of r.moduleReads)t(i,[o]);for(let i of r.conditionModuleReads)t(i,[r.entityId])}for(let[r,o]of e.computeds){let i=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#${r}`;for(let s of o.reads)t(s,[i])}for(let r of e.moduleControlFlow)for(let o of r.sources)t(o,[r.entityId]);if(e.readers.size===0)return null;let n=[...e.readers.entries()].sort(([r],[o])=>r<o?-1:1).map(([r,o])=>Xe.objectProperty(Xe.stringLiteral(r),Xe.arrayExpression([...o].sort().map(i=>Xe.stringLiteral(i)))));return Xe.expressionStatement(Xe.callExpression(Y(e,"installAccessTable"),[Xe.objectExpression([Xe.objectProperty(Xe.identifier("readers"),Xe.objectExpression(n))]),Xe.stringLiteral(e.rootId)]))}function vo(e,t){let n=t?.parentPath;if(!n?.isJSXAttribute())return!1;let r=n.parentPath;if(!r.isJSXOpeningElement())return!1;let o=r.node.name;if(!w.isJSXIdentifier(o)||!/^[A-Z]/.test(o.name))return!1;let i=n.node.name,s=w.isJSXIdentifier(i)?i.name:i.name.name;return e.componentProps.get(o.name)?.renderProps.includes(s)===!0}function wo(e,t){let n=t.parentPath,r=n?.parentPath;if(!n?.isJSXExpressionContainer()||!r?.isJSXElement()&&!r?.isJSXFragment()&&!vo(e,n))throw t.buildCodeFrameError("memo-dom: conditional rendering must be a direct JSX child: <div>{cond ? <A/> : <B/>}</div>");t.skip()}function Fs(e,t){for(let n of t.get("body"))if(!(!n.isImportDeclaration()||n.node.importKind==="type"))for(let r of n.node.specifiers){if(w.isImportSpecifier(r)&&r.importKind==="type")continue;let o=r.local.name;if(!(e.importedState.has(o)||e.importedFunctions.has(o)||e.importedComponents.has(o)))throw n.buildCodeFrameError(`memo-dom: value import '${o}' requires compileModules() so its reactive identity can be linked`)}}function Ms(e,t){let n=Fn(t.node);for(let r of t.node.body){let o=w.isExportNamedDeclaration(r)?r.declaration:r;if(w.isVariableDeclaration(o)){for(let i of o.declarations)if(w.isIdentifier(i.id)&&(o.kind==="let"||o.kind==="var"?ht(e,i.id.name,"let"):o.kind==="const"&&(It(i.init)?ht(e,i.id.name,"store"):Rt(i.init)&&ht(e,i.id.name,"const")),e.state.has(i.id.name))){let s=n.get(i.id.name);s!==void 0&&e.stateTagCandidates.set(i.id.name,[...s])}}}}function Ds(e,t){t.traverse({FunctionDeclaration(n){let r=n.node.id?.name;if(r&&!e.comps.has(r)&&!e.helpers.has(r)&&!e.jsxHelpers.has(r))if(je(n))if(/^[A-Z]/.test(r)){e.comps.set(r,{parents:new Set,jsxCount:0}),e.compPaths.set(r,n);let o=Xt(n.node.body);e.componentHostEvents.set(r,o),o.length!==0&&e.componentsWithHostEvents.add(r);try{e.componentProps.set(r,fn(n.node.params))}catch(i){throw n.buildCodeFrameError(`memo-dom: invalid props for component '${r}': ${i instanceof Error?i.message:String(i)}`)}}else e.jsxHelpers.set(r,n);else e.helpers.set(r,n);n.skip()},VariableDeclarator(n){if(!n.scope.path.isProgram()||!w.isIdentifier(n.node.id))return;let r=n.get("init");(r.isArrowFunctionExpression()||r.isFunctionExpression())&&(de(r.node.body)?/^[A-Z]/.test(n.node.id.name)||e.jsxHelpers.set(n.node.id.name,r):e.helpers.set(n.node.id.name,r),r.skip())}});for(let n of t.get("body")){let r=n.isExportNamedDeclaration()?n.get("declaration"):n;if(!(Array.isArray(r)||!r.isVariableDeclaration()))for(let o of r.get("declarations")){if(!o.isVariableDeclarator())continue;let i=o.node.id,s=o.get("init");!w.isIdentifier(i)||/^[A-Z]/.test(i.name)||Array.isArray(s)||!s.isArrowFunctionExpression()&&!s.isFunctionExpression()||!de(s.node.body)||(e.helpers.delete(i.name),e.jsxHelpers.set(i.name,s))}}}function Dn(e,t,n=new Set){if(w.isTSStringKeyword(e)||w.isTSNumberKeyword(e)||w.isTSBooleanKeyword(e)||w.isTSBigIntKeyword(e)||w.isTSSymbolKeyword(e)||w.isTSNullKeyword(e)||w.isTSUndefinedKeyword(e)||w.isTSLiteralType(e))return!0;if(w.isTSParenthesizedType(e))return Dn(e.typeAnnotation,t,n);if(w.isTSUnionType(e))return e.types.every(r=>Dn(r,t,n));if(w.isTSTypeReference(e)&&w.isIdentifier(e.typeName)){let r=e.typeName.name;if(n.has(r))return!1;let o=new Set(n);o.add(r);for(let i of t.body){let s=w.isExportNamedDeclaration(i)?i.declaration:i;if(w.isTSTypeAliasDeclaration(s)&&s.id.name===r)return Dn(s.typeAnnotation,t,o)}}return!1}function Ls(e,t){let n=l=>w.isStringLiteral(l)||w.isNumericLiteral(l)||w.isBooleanLiteral(l)||w.isBigIntLiteral(l)||w.isUnaryExpression(l)&&(l.operator==="+"||l.operator==="-")&&w.isNumericLiteral(l.argument);for(let l of e.node.params){if(w.isTSParameterProperty(l))continue;if(w.isAssignmentPattern(l)&&w.isIdentifier(l.left,{name:t})&&n(l.right))return!0;if(w.isAssignmentPattern(l)&&w.isObjectPattern(l.left)&&w.isObjectExpression(l.right)){let p=l.right.properties.find(u=>!w.isObjectProperty(u)||u.computed?!1:(w.isIdentifier(u.key)?u.key.name:w.isStringLiteral(u.key)?u.key.value:null)===t);if(w.isObjectProperty(p)&&w.isExpression(p.value)&&n(p.value))return!0}let d=w.isAssignmentPattern(l)?l.left:l;if(w.isObjectPattern(d))for(let p of d.properties){if(!w.isObjectProperty(p)||p.computed)continue;if((w.isIdentifier(p.key)?p.key.name:w.isStringLiteral(p.key)?p.key.value:null)===t&&w.isAssignmentPattern(p.value)&&n(p.value.right))return!0}}let r=e.node.params[0];if(r==null||w.isTSParameterProperty(r))return!1;let o=w.isAssignmentPattern(r)?r.left:r;if(!w.isIdentifier(o)&&!w.isObjectPattern(o)&&!w.isArrayPattern(o))return!1;let i=o.typeAnnotation;if(!w.isTSTypeAnnotation(i))return!1;let s=e.findParent(l=>l.isProgram());if(!s?.isProgram())return!1;let a=i.typeAnnotation;if(w.isTSTypeReference(a)&&w.isIdentifier(a.typeName)){let l=a.typeName.name,d=s.node.body.map(p=>w.isExportNamedDeclaration(p)?p.declaration:p).find(p=>(w.isTSInterfaceDeclaration(p)||w.isTSTypeAliasDeclaration(p))&&p.id.name===l);w.isTSInterfaceDeclaration(d)?a=w.tsTypeLiteral(d.body.body):w.isTSTypeAliasDeclaration(d)&&(a=d.typeAnnotation)}if(!w.isTSTypeLiteral(a))return!1;for(let l of a.members){if(!w.isTSPropertySignature(l)||l.computed)continue;if((w.isIdentifier(l.key)?l.key.name:w.isStringLiteral(l.key)?l.key.value:null)===t&&w.isTSTypeAnnotation(l.typeAnnotation))return Dn(l.typeAnnotation.typeAnnotation,s.node)}return!1}function nr(e,t=new Set){if(de(e.node))return!0;if(t.has(e.node))return!1;if(t.add(e.node),e.isIdentifier()){let n=e.scope.getBinding(e.node.name);if(n?.path.isVariableDeclarator()){let r=n.path.get("init");return!Array.isArray(r)&&r.node!=null?nr(r,t):!1}}if(e.isMemberExpression()){let n=e.get("object");return!Array.isArray(n)&&nr(n,t)}return!1}function As(e){let t=new Map;for(let[o,i]of e.compPaths){let s=new Set;if(t.set(o,s),i.traverse({JSXExpressionContainer(a){if(!a.parentPath?.isJSXElement()&&!a.parentPath?.isJSXFragment())return;let l=a.node.expression;if(!w.isExpression(l))return;let d=ft(e,o,l);d!==null&&(Ls(i,d)||s.add(d))}}),(i.parentPath?.isExportNamedDeclaration()||i.parentPath?.isExportDefaultDeclaration())&&!e.linkedComponentRenderProps.has(o)){let a=e.componentProps.get(o);for(let l of s)a.renderProps.includes(l)||a.renderProps.push(l)}}let n=new Map;for(let[o,i]of e.compPaths)i.traverse({JSXElement(s){let a=s.node.openingElement.name;if(!w.isJSXIdentifier(a)||!e.comps.has(a.name))return;let l=e.componentProps.get(a.name),d=t.get(a.name);if(d===void 0)return;let p=n.get(a.name);p===void 0&&(p=new Map,n.set(a.name,p)),d.has("children")&&s.node.children.some(u=>!w.isJSXText(u)||u.value.trim()!=="")&&!l.renderProps.includes("children")&&(l.renderProps.push("children"),p.set("children",{scalar:!1,jsx:!0,at:s}));for(let u of s.get("openingElement").get("attributes")){if(!u.isJSXAttribute())continue;let g=u.node.name,S=w.isJSXIdentifier(g)?g.name:g.name.name;if(!d.has(S))continue;let x=p.get(S)??{scalar:!1,jsx:!1,at:u},f=u.get("value"),m=!1;if(f.isJSXExpressionContainer()&&w.isExpression(f.node.expression)){let C=f.get("expression");!Array.isArray(C)&&(nr(C)||w.isExpression(C.node)&&ft(e,o,C.node)!==null)&&(m=!0)}m?x.jsx=!0:x.scalar=!0,p.set(S,x)}}});for(let[o,i]of n){let s=e.componentProps.get(o);for(let[a,l]of i){if(l.scalar&&l.jsx){if(a==="children"){s.renderProps.includes(a)||s.renderProps.push(a);continue}throw l.at.buildCodeFrameError(`memo-dom: prop '${a}' on <${o}> is used as both scalar data and JSX content`)}l.jsx?s.renderProps.includes(a)||s.renderProps.push(a):l.scalar&&(s.renderProps=s.renderProps.filter(d=>d!==a))}}let r=!0;for(;r;){r=!1;for(let[o,i]of e.compPaths){let s=e.componentProps.get(o);i.traverse({JSXAttribute(a){let l=a.get("value");if(!l.isJSXExpressionContainer()||!w.isExpression(l.node.expression))return;let d=ft(e,o,l.node.expression);if(d===null||s.renderProps.includes(d))return;let p=a.parentPath;if(!p.isJSXOpeningElement())return;let u=p.node.name;if(!w.isJSXIdentifier(u)||!/^[A-Z]/.test(u.name))return;let g=e.componentProps.get(u.name),S=a.node.name,x=w.isJSXIdentifier(S)?S.name:S.name.name;g?.renderProps.includes(x)===!0&&(s.renderProps.push(d),r=!0)}})}}for(let[o,i]of e.linkedComponentRenderProps){let s=e.componentProps.get(o);s!==void 0&&(s.renderProps=[...i])}}function js(e,t){let n=e.compPaths.get(t),r=e.comps.get(t);n.traverse({JSXElement(o){let i=o.node.openingElement;if(!w.isJSXIdentifier(i.name))throw o.buildCodeFrameError("memo-dom: namespaced or member-expression JSX tags are not supported (L1)");for(let a of i.attributes)if(!w.isJSXSpreadAttribute(a)&&a.name.name==="key"){if(Fr(e,o))continue;throw o.buildCodeFrameError("memo-dom: key={...} is only meaningful on list rows: items.map(item => <Row key={item.id} />)")}let s=i.name.name;if(/^[A-Z]/.test(s)){let a=e.comps.has(s);if(!a&&!e.importedComponents.has(s))throw o.buildCodeFrameError(`memo-dom: <${s} /> is not a linked component factory`);a&&e.comps.get(s).parents.add(t);let l=e.childRefCounts.get(t);l||e.childRefCounts.set(t,l=new Map),l.set(s,(l.get(s)??0)+1),(o.node.children.some(d=>!w.isJSXText(d)||d.value.trim()!=="")||i.attributes.some(d=>{if(w.isJSXSpreadAttribute(d)||e.componentProps.get(s)?.renderProps.includes(w.isJSXIdentifier(d.name)?d.name.name:d.name.name.name)!==!0)return!1;let p=Ve(d.value);return p!==null&&de(p)}))&&e.renderSlotOwners.add(t);return}r.jsxCount++},ConditionalExpression(o){je(o)&&wo(e,o)},LogicalExpression(o){if(je(o)){if(o.node.operator!=="&&"&&o.node.operator!=="||")throw o.buildCodeFrameError("memo-dom: only && / || conditionals are supported (R8 L1), not ??");wo(e,o)}},CallExpression(o){let i=We(o.node);if(i&&(je(o)||Jt(e,t,i)!==null)){let s=o.parentPath,a=s?.parentPath;if(!s?.isJSXExpressionContainer()||!a?.isJSXElement()&&!a?.isJSXFragment()&&!vo(e,s))throw o.buildCodeFrameError("memo-dom: list rendering must be a direct JSX child: <ul>{items.map(item => <Row />)}</ul>");o.skip()}}})}function Js(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}function $s(e,t){let n=xe(t.node);if(!n||!n.includes("."))return null;let r=n.split(".")[0];if(e.state.get(r)!=="store"||t.scope.getBinding(r)?.scope.path.isProgram()!==!0)return null;let o=t.parentPath;return o.isAssignmentExpression({operator:"="})&&o.node.left===t.node||Js(t)?null:n}function ko(e,t,n){let r=new Set([...e.instanceReasonIds.get(t)?.keys()??[],...n]);e.instanceReasonIds.set(t,new Map([...r].sort().map((o,i)=>[o,i])))}function Os(e,t){let n=[],r=e;for(;r=Ft(r),!!w.isMemberExpression(r);){if(n.unshift(r),w.isSuper(r.object))return null;r=r.object}if(!w.isIdentifier(r,{name:t}))return null;let o=n[0];if(o===void 0||!o.computed||!w.isExpression(o.property)||!(w.isIdentifier(o.property)||w.isNumericLiteral(o.property)||w.isStringLiteral(o.property))||n.length<2)return null;let i=[];for(let s of n.slice(1))if(!s.computed&&w.isIdentifier(s.property))i.push(s.property.name);else if(s.computed&&w.isStringLiteral(s.property))i.push(s.property.value);else return null;return i}function Xs(e,t,n){let r=!1;return Ae(e.node.body,o=>{if(r)return;let i=w.isAssignmentExpression(o)&&w.isMemberExpression(o.left)?o.left:w.isUpdateExpression(o)&&w.isMemberExpression(o.argument)||w.isUnaryExpression(o,{operator:"delete"})&&w.isMemberExpression(o.argument)?o.argument:null;if(i===null)return;let s=Os(i,t);s!==null&&!jt(s,n)&&(r=!0)}),r}function Ts(e,t,n,r){if(!r.sourceLocal||!w.isIdentifier(r.sourceExpr))return;let o=r.sourceExpr.name;if(e.instanceState.get(t)?.has(o)!==!0)return;let i=nt(r.keyExpr,r.itemParam);if(i===null||i.length===0)return;let s=e.compPaths.get(t);if(s===void 0||!Xs(s,o,i))return;let a=`${t}\0${o}`;if(e.disabledKeyedListMutationSources.has(a))return;let l=e.keyedListMutationSources.get(t);l===void 0&&(l=new Map,e.keyedListMutationSources.set(t,l));let d=l.get(o);if(d!==void 0){e.keyedListMutations.delete(d.call),l.delete(o),e.disabledKeyedListMutationSources.add(a);return}let p={source:o,keyPath:i,keysVariable:A(e,`${o}ChangedKeys`).name,targetedReason:`${a}\0content`,topologyReason:`${a}\0topology`,structuralReason:`${a}\0structure`,call:n};l.set(o,p),e.keyedListMutations.set(n,p),e.targetedListComponents.add(t),ko(e,t,[o,p.targetedReason,p.topologyReason,p.structuralReason])}function Bs(e){for(let[a]of e.comps){let g=function(b,v,F){let R=We(b.node);if(R===null||!je(b))return;let k=Mt(e,R,b,a,F),W=`${v}/${k.suffix}`;if(k.form==="component"){let B=e.listedSites.get(k.rowComp)??[];B.some(_=>_.owner===a&&_.suffix===W)||B.push({owner:a,suffix:W,itemParam:k.itemParam,keyExpr:k.keyExpr,sourceKey:k.sourceKey,sourceLocal:k.sourceLocal}),e.listedSites.set(k.rowComp,B)}else m(b,k,W);b.skip()},S=function(b,v,F){let R=b.node.openingElement.name;if(!w.isJSXIdentifier(R)||!/^[A-Z]/.test(R.name))return;if(!e.comps.has(R.name)&&!e.importedComponents.has(R.name))throw b.buildCodeFrameError(`memo-dom: <${R.name} /> is not a linked component factory`);let k=F.get(R.name)??0;F.set(R.name,k+1);let W=k===0?R.name:`${R.name}[${k}]`,B=`${v}/${W}`,_=e.conditionalComponentSites.get(R.name)??[];_.some(Q=>Q.owner===a&&Q.suffix===B)||_.push({owner:a,suffix:B}),e.conditionalComponentSites.set(R.name,_)},x=function(b,v,F){let R=b.node.openingElement.name;if(!w.isJSXIdentifier(R)||!/^[A-Z]/.test(R.name))return;if(!e.comps.has(R.name)&&!e.importedComponents.has(R.name))throw b.buildCodeFrameError(`memo-dom: <${R.name} /> is not a linked component factory`);let k=F.get(R.name)??0;F.set(R.name,k+1);let W=k===0?R.name:`${R.name}[${k}]`,B=`${v}/Row[*]/${W}`,_=e.rowComponentSites.get(R.name)??[];_.some(Q=>Q.owner===a&&Q.suffix===B)||_.push({owner:a,suffix:B}),e.rowComponentSites.set(R.name,_)},f=function(b,v){let F=e.listedSites.get(b.rowComp)??[];F.some(R=>R.owner===a&&R.suffix===v)||F.push({owner:a,suffix:v,itemParam:b.itemParam,keyExpr:b.keyExpr,sourceKey:b.sourceKey,sourceLocal:b.sourceLocal}),e.listedSites.set(b.rowComp,F)},m=function(b,v,F){let R=b.get("arguments")[0];if(R===void 0)return;let k=new Set,W=new Map,B=new Map;R.traverse({Identifier(_){_.node.name!==v.itemParam&&e.state.has(_.node.name)&&_.scope.getBinding(_.node.name)?.scope.path.isProgram()===!0&&k.add(_.node.name)},JSXElement(_){x(_,F,W)},CallExpression(_){let Q=We(_.node);if(Q!==null&&je(_)){let te=Mt(e,Q,_,a,B,v),q=`${F}/Row[*]/${te.suffix}`;te.form==="component"?f(te,q):m(_,te,q),_.skip();return}let be=_.node.callee;if(w.isIdentifier(be)&&(e.helpers.has(be.name)||e.importedFunctions.has(be.name))){let te=e.importedFunctions.get(be.name)??He(e,be.name);for(let q of te.reads)k.add(q)}}}),k.size>0&&e.rowReads.set(`${a}/${F}`,{owner:a,suffix:F,vars:k})},C=function(b,v=null){let F=b.node;if(!je(b))return;let R=hn(F,b,u),k=v===null?R.suffix:`${v}/${R.suffix}`,W=[];if(b.isConditionalExpression()){let _=b;for(;_.isConditionalExpression();)W.push(_.get("consequent")),_=_.get("alternate");W.push(_)}else W.push(b.get("right"));for(let _ of W){let Q=new Map,be=new Map;if((_.isConditionalExpression()||_.isLogicalExpression())&&je(_)){C(_,k);continue}_.isJSXElement()&&S(_,k,be),_.traverse({ConditionalExpression(te){je(te)&&(C(te,k),te.skip())},LogicalExpression(te){je(te)&&(C(te,k),te.skip())},JSXElement(te){S(te,k,be)},CallExpression(te){g(te,k,Q)}})}let B=cn(e,F);B.size>0&&v===null&&e.condReads.set(`${a}/${k}`,{owner:a,suffix:k,vars:B}),b.skip()};var t=g,n=S,r=x,o=f,i=m,s=C;let l=e.compPaths.get(a),d=new Set,p=new Map,u={count:0};l.traverse({JSXAttribute(b){let v=b.node.name;(w.isJSXIdentifier(v,{name:"ref"})||w.isJSXNamespacedName(v)&&v.namespace.name==="ref")&&b.skip()},ConditionalExpression(b){C(b)},LogicalExpression(b){C(b)},CallExpression(b){if(w.isIdentifier(b.node.callee,{name:"effect"})&&b.scope.getBinding("effect")===void 0){b.skip();return}let v=We(b.node);if(v&&(je(b)||Jt(e,a,v)!==null)){let R=Mt(e,v,b,a,p);Ts(e,a,v,R);let k=fo(R,e.instanceState.get(a)??new Set);if(k.length>0&&w.isIdentifier(R.sourceExpr)){let W=R.sourceExpr.name;e.targetedListDependencies.set(v,k.map(B=>({source:W,value:B}))),e.targetedListComponents.add(a),ko(e,a,[W,...k])}if(R.sourceLocal||d.add(R.sourceKey),R.form==="component"){for(let B of R.jsx.openingElement.attributes){if(w.isJSXSpreadAttribute(B))continue;let _=B,Q=w.isJSXIdentifier(_.name)?_.name.name:`${_.name.namespace.name}:${_.name.name.name}`;if(Q==="key"||Q==="ref"||e.componentProps.get(R.rowComp)?.refProps.includes(Q)===!0)continue;let be=Ve(_.value);be&&Ae(be,te=>{if(w.isIdentifier(te)&&e.state.has(te.name)&&b.scope.getBinding(te.name)?.scope.path.isProgram()===!0&&d.add(te.name),w.isMemberExpression(te)){let q=xe(te);if(q!==null&&q.includes(".")){let Ee=q.split(".")[0];e.state.get(Ee)==="store"&&b.scope.getBinding(Ee)?.scope.path.isProgram()===!0&&d.add(q)}}})}let W=e.listedSites.get(R.rowComp)??[];W.some(B=>B.owner===a&&B.suffix===R.suffix)||W.push({owner:a,suffix:R.suffix,itemParam:R.itemParam,keyExpr:R.keyExpr,sourceKey:R.sourceKey,sourceLocal:R.sourceLocal}),e.listedSites.set(R.rowComp,W)}else m(b,R,R.suffix);b.skip();return}let F=b.node.callee;if(w.isIdentifier(F)&&(e.helpers.has(F.name)||e.importedFunctions.has(F.name))&&b.scope.getBinding(F.name)?.scope.path.isProgram()===!0){let R=e.importedFunctions.get(F.name)??He(e,F.name);for(let k of R.reads)d.add(k)}},Identifier(b){if(!e.state.has(b.node.name)||b.scope.getBinding(b.node.name)?.scope.path.isProgram()!==!0)return;let v=b.parentPath;v.isAssignmentExpression({operator:"="})&&v.node.left===b.node||d.add(b.node.name)},MemberExpression(b){let v=$s(e,b);v!==null&&d.add(v)}}),e.compReads.set(a,d)}}function Ln(e,t){Fs(e,t),Ms(e,t),Ds(e,t),Co(e),Mr(e),co(e),ho(e,t),As(e),io(e),yo(e),uo(e),Yr(e),Zr(e,t),Gr(e,t,Hn),Qr(e),to(e),no(e),Wr(e,t);for(let[r]of e.comps)js(e,r);Bs(e),xo(e);for(let[r]of e.comps)et(e,r);let n=new Set([...e.listedSites.keys(),...e.linkedComponentRows.keys()]);for(let r of n){if(e.importedComponents.has(r))continue;let o=e.listedSites.get(r)??[],i=e.compPaths.get(r);if((o.length>0||e.linkedComponentRows.has(r))&&(e.comps.get(r).parents.size>0||(e.conditionalComponentSites.get(r)?.length??0)>0))throw i.buildCodeFrameError(`memo-dom: <${r}> is used both as a list row and as a static child \u2014 split it into two components (R7 L1)`)}}import*as M from"@babel/types";import*as y from"@babel/types";import*as ve from"@babel/types";import*as ie from"@babel/types";function At(){return{writes:new Set,rootFallback:!1,rowLocal:!1,rowOwnerLocal:!1,instanceLocal:!1,instanceWrites:new Set,eventOrigin:null}}function Tt(e,t){e.instanceLocal=!0,e.instanceWrites.add(t)}function Bt(e,t,n,r){let o=t.rowLocal&&r!==void 0?ie.expressionStatement(r.refreshVar!==void 0?ie.callExpression(ie.identifier(r.refreshVar),[]):ie.callExpression(Y(e,"markDirty"),[ie.identifier(r.rowIdVar)])):null,i=null;if(t.instanceLocal&&n!==null){let d=e.instanceReasonIds.get(n),p=[...t.instanceWrites].map(g=>d?.get(g)).filter(g=>g!==void 0).sort((g,S)=>g-S),u=t.instanceWrites.size>0&&p.length===t.instanceWrites.size;i=ie.expressionStatement(ie.callExpression(Y(e,"markDirty"),[$e(e,n),...u?[p.length===1?ie.numericLiteral(p[0]):Pr(e,p)]:[]]))}let s=t.rowOwnerLocal&&r?.ownerIdVar!==void 0?ie.expressionStatement(ie.callExpression(Y(e,"markDirty"),[ie.identifier(r.ownerIdVar)])):null,a=d=>{let p=[];return t.eventOrigin!==null&&p.push(t.eventOrigin),o!==null&&p.push(o),s!==null&&p.push(s),i!==null&&p.push(i),d!==null&&p.push(d),p.length===0?null:p.length===1?p[0]:ie.blockStatement(p)};if(t.rootFallback)return a(ie.expressionStatement(ie.callExpression(Y(e,"markDirtySubtree"),[ie.stringLiteral(e.rootId)])));if(t.writes.size===0)return a(null);let l=[...t.writes].sort();return a(ie.expressionStatement(ie.callExpression(Y(e,"commitWrites"),[Ht(e,l)])))}function No(e,t,n){if(ie.isBlockStatement(t.body)){rr(t.body,n),t.body.body.push(n);return}let r=A(e,"returnValue");t.body=ie.blockStatement([ie.variableDeclaration("const",[ie.variableDeclarator(r,t.body)]),n,ie.returnStatement(ie.cloneNode(r))])}function rr(e,t){if(!ie.isFunction(e))for(let n of ie.VISITOR_KEYS[e.type]??[]){let r=e[n];if(Array.isArray(r))for(let o=0;o<r.length;o++){let i=r[o];!i||typeof i!="object"||!("type"in i)||ie.isFunction(i)||(ie.isReturnStatement(i)?(r.splice(o,0,ie.cloneNode(t)),o++):rr(i,t))}else if(r&&typeof r=="object"&&"type"in r){if(ie.isFunction(r))continue;ie.isReturnStatement(r)?e[n]=ie.blockStatement([ie.cloneNode(t),r]):rr(r,t)}}}import*as Ce from"@babel/types";function vt(e,t,n,r){if(r===void 0&&n?.refreshVar!==void 0)return Ce.expressionStatement(Ce.callExpression(Ce.identifier(n.refreshVar),[]));let o=r??(n!==void 0?Ce.identifier(n.rowIdVar):t!==null?$e(e,t):Ce.stringLiteral(e.rootId));return Ce.expressionStatement(Ce.callExpression(Y(e,"markDirty"),[Ce.cloneNode(o)]))}function Vt(e,t,n){let r=A(e,"event"),o=A(e,"returnValue");return Ce.arrowFunctionExpression([r],Ce.blockStatement([Ce.variableDeclaration("const",[Ce.variableDeclarator(o,Ce.callExpression(Ce.cloneNode(t),[Ce.cloneNode(r)]))]),n,Ce.returnStatement(Ce.cloneNode(o))]))}import Fo from"@babel/traverse";import*as O from"@babel/types";function Vs(e,t,n){if(n.key===null)return null;let r=e.componentProps.get(t);if(r===void 0)return null;let o=Ue(r);if(n.root===o){let[s,...a]=n.key.split(".").slice(1);return s===void 0?null:{name:s,path:a}}let i=Ze(r,n.root);return i===null?null:{name:i,path:n.key.split(".").slice(1)}}function or(e,t,n,r,o){let i=Vs(e,t,r);if(i===null)return!1;n===void 0?Tt(o,r.root):o.rowLocal=!0;let s=e.linkedComponentPropSources.get(t)?.get(i.name);if(s===void 0)return o.rootFallback=!0,!0;o.rootFallback||=s.rootFallback;let a=i.path.length===0?"":`.${i.path.join(".")}`;for(let l of s.keys)o.writes.add(`${l}${a}`);return!0}import*as ye from"@babel/types";function An(e){return ye.isIdentifier(e)||ye.isObjectPattern(e)||ye.isArrayPattern(e)||ye.isAssignmentPattern(e)||ye.isRestElement(e)}function Ws(e){let t=e;for(;ye.isTSAsExpression(t)||ye.isTSTypeAssertion(t)||ye.isTSNonNullExpression(t)||ye.isTSSatisfiesExpression(t);)t=t.expression;return t}function tn(e,t,n){if(ye.isIdentifier(t)){e.set(t.name,n);return}if(ye.isAssignmentPattern(t)){An(t.left)&&tn(e,t.left,n);return}if(!ye.isRestElement(t)){if(ye.isArrayPattern(t)){for(let r=0;r<t.elements.length;r++){let o=t.elements[r];An(o)&&tn(e,o,yt(n,[String(r)]))}return}if(ye.isObjectPattern(t))for(let r of t.properties){if(ye.isRestElement(r))continue;if(r.computed||!ye.isIdentifier(r.key)&&!ye.isStringLiteral(r.key)&&!ye.isNumericLiteral(r.key)){An(r.value)&&tn(e,r.value,{...n,key:null});continue}let o=ye.isIdentifier(r.key)?r.key.name:String(r.key.value);An(r.value)&&tn(e,r.value,yt(n,[o]))}}}function Io(e,t,n,r){let o=Ws(r),i=e.componentProps.get(t);if(i===void 0)return null;if(ye.isIdentifier(o)){let d=n.get(o.name);return d!==void 0?d:Ue(i)===o.name?{locality:"prop",root:o.name,key:o.name}:Ze(i,o.name)===null?null:{locality:"prop",root:o.name,key:o.name}}if(!ye.isMemberExpression(o))return null;let s=ke(o),a=xe(o);if(s===null)return null;let l=Io(e,t,n,ye.identifier(s));return l===null?null:a===null?{...l,key:null}:yt(l,a.split(".").slice(1))}function Ro(e,t){let n=new Map;for(let r of e.instanceDerivations.get(t)??[]){let o=Io(e,t,n,r.source);o!==null&&tn(n,r.target,o)}return n}var Mo=Fo.default??Fo,zs=new Set(["copyWithin","fill","pop","push","reverse","shift","sort","splice","unshift"]);function Ks(e,t){let n=[],r=e;for(;r=Ft(r),!!O.isMemberExpression(r);){if(n.unshift(r),O.isSuper(r.object))return null;r=r.object}if(!O.isIdentifier(r,{name:t.source}))return null;let o=n[0];if(o===void 0||!o.computed||!O.isExpression(o.property)||!(O.isIdentifier(o.property)||O.isNumericLiteral(o.property)||O.isStringLiteral(o.property))||n.length<2)return null;let i=[];for(let a of n.slice(1))if(!a.computed&&O.isIdentifier(a.property))i.push(a.property.name);else if(a.computed&&O.isStringLiteral(a.property))i.push(a.property.value);else return null;if(jt(i,t.keyPath))return null;let s=O.cloneNode(o,!0);for(let a of t.keyPath)s=O.memberExpression(s,O.identifier(a));return s}function Us(e,t){let n=new Set;for(let[r,o]of e.compReads)o.has(t)&&n.add(r);for(let r of e.rowReads.values())r.vars.has(t)&&n.add("__rows__");for(let r of e.condReads.values())r.vars.has(t)&&n.add("__regions__");return n}function Do(e,t,n){if(n.sourceLocal)return!0;let r=n.sourceKey;if(r==="")return!0;for(let i of e.computeds.values())if(i.reads.has(r))return!0;let o=new Set((e.listedSites.get(t??"")??[]).map(i=>i.owner));o.size===0&&t!==null&&o.add(t);for(let i of Us(e,r))if(i==="__rows__"||i==="__regions__"||!o.has(i))return!0;return!1}function nn(e,t,n,r,o=!1,i,s=!1){let a=O.cloneNode(t),l=a,d=O.file(O.program([O.isFunctionDeclaration(a)?a:O.expressionStatement(a)])),p=n!==null?e.instanceState.get(n):void 0,u=n!==null?e.instanceDerivedBindings.get(n):void 0,g=n===null?new Map:Ro(e,n),S=n!==null?new Set(e.componentProps.get(n)?.bindings??[]):new Set,x=new Set([...S,...p??[],...u??[]]);if(n!==null)for(let E of e.compPaths.get(n)?.node.body.body??[])if(O.isVariableDeclaration(E))for(let P of E.declarations)for(let D of Object.keys(O.getBindingIdentifiers(P.id)))x.add(D);else O.isFunctionDeclaration(E)&&E.id&&x.add(E.id.name);let f=new $t((E,P)=>{if(P!==void 0)return null;let D=g.get(E);if(D!==void 0)return D;if(r!==void 0&&E===r.itemParam)return{locality:"row",root:E,key:E};if(p?.has(E)===!0)return{locality:"instance",root:E,key:E};if(S.has(E))return{locality:"prop",root:E,key:E};if(x.has(E))return null;let ee=e.state.get(E);return ee===void 0?null:En(E,ee)}),m=E=>E.stateKind==="computed"||e.state.get(E.root)==="computed",C=n===null?void 0:e.keyedListMutationSources.get(n),b=(E,P,D="structural")=>{Tt(E,P);let ee=C?.get(P);ee!==void 0&&Tt(E,D==="targeted"?ee.targetedReason:D==="topology"?ee.topologyReason:ee.structuralReason)},v=(E,P,D)=>{E.isExpression()&&(E.replaceWith(O.sequenceExpression([O.callExpression(O.memberExpression(O.identifier(P.keysVariable),O.identifier("add")),[D]),E.node])),E.skip())},F=new Set;for(let E of a.params)O.isIdentifier(E)&&F.add(E.name);Mo(d,{VariableDeclarator(E){O.isIdentifier(E.node.id)&&(F.add(E.node.id.name),E.parentPath.isVariableDeclaration()&&f.trackDeclarator(E.scope,E.node))},Function(E){for(let P of E.node.params)O.isIdentifier(P)&&F.add(P.name)}});let R=new Map,k=new Map,W=E=>{let P=E.getFunctionParent()?.node??l,D=R.get(P);return D||R.set(P,D=At()),D},B=(E,P)=>{if(P(W(E)),!s||E.getFunctionParent()?.node!==l)return;let D=k.get(E.node);D===void 0&&(D={path:E,writes:At()},k.set(E.node,D)),P(D.writes)},_=E=>{B(E,P=>{r?.sourceLocal?P.rowOwnerLocal=!0:r!==void 0&&P.writes.add(r.sourceKey)})},Q=E=>{if(r===void 0)return null;let P=E.split(".").slice(1);return r.itemPath.some((D,ee)=>P[ee]!==D)?null:P.slice(r.itemPath.length)},be=(E,P)=>{B(E,D=>{P!==void 0&&n!==null&&or(e,n,r,P,D)||(D.rowLocal=!0,D.rootFallback=!0)})},te=(E,P)=>{B(E,D=>{(n===null||!or(e,n,r,P,D))&&(r===void 0?(n!==null&&Tt(D,P.root),D.rootFallback=!0):(D.rowLocal=!0,D.rootFallback=!0))})},q=(E,P)=>{if(r===void 0||ke(P)!==r.itemParam)return!1;let D=xe(P);if(D===null)return r.itemPath.length===0?_(E):be(E),!0;let ee=D.split(".").slice(1);return r.itemPath.some((Te,Ie)=>ee[Ie]!==Te)?!1:(ee.splice(0,r.itemPath.length),jt(ee,r.keyPath)?_(E):(B(E,Te=>{Te.rowLocal=!0}),Do(e,n,r)&&_(E)),!0)},Ee=(E,P)=>{if(P.locality==="instance"){B(E,D=>{b(D,P.root)});return}if(P.locality==="row"){if(r===void 0){B(E,ee=>{ee.rootFallback=!0});return}if(P.key===null){r.itemPath.length===0?_(E):be(E);return}let D=Q(P.key);if(D===null){be(E,P);return}jt(D,r.keyPath)?_(E):(B(E,ee=>{ee.rowLocal=!0}),Do(e,n,r)&&_(E));return}if(P.locality==="prop"){te(E,P);return}if(P.stateKind==="computed")throw E.buildCodeFrameError(`memo-dom: cannot mutate computed '${P.root}' (R13) - it is derived; write its SOURCE state instead`);if(P.stateKind!=="store"){B(E,D=>{D.writes.add(P.root)});return}P.key!==null&&P.key.includes(".")?B(E,D=>{D.writes.add(P.key)}):B(E,D=>{D.writes.add(P.root)})},ne=(E,P)=>{if(P.locality==="instance"){B(E,D=>{b(D,P.root)});return}if(P.locality==="row"){if(r===void 0){B(E,Te=>{Te.rootFallback=!0});return}if(P.key===null){r.itemPath.length===0?_(E):be(E);return}let D=Q(P.key);if(D===null){be(E,P);return}D.length===0&&(r.keyPath===null||r.keyPath.length>0)?_(E):Ee(E,P);return}if(P.locality==="prop"){te(E,P);return}if(P.stateKind==="computed")throw E.buildCodeFrameError(`memo-dom: cannot mutate computed '${P.root}' (R13) - write its SOURCE state instead`);B(E,D=>{D.writes.add(P.key??P.root)})},ue=(E,P)=>{if(!(s&&E.getFunctionParent()?.node===l))for(let D of Sn(P)){if(!O.isIdentifier(D))continue;let ee=f.resolveExpression(E.scope,D);ee!==null&&(m(ee)||ne(E,ee))}},Pe=(E,P)=>{let D=ke(P);if(D!==void 0&&p?.has(D??"")===!0){let Ie=C?.get(D),Be=Ie===void 0?null:Ks(P,Ie);B(E,an=>{b(an,D,Be===null?"structural":"targeted")}),Ie!==void 0&&Be!==null&&v(E,Ie,Be);return}if(D!==null&&u?.has(D)&&!g.has(D))throw E.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${D}' (R14) \u2014 write its source instead`);if(q(E,P))return;let ee=f.resolveExpression(E.scope,P);if(ee!==null){Ee(E,ee);return}if(D!==null&&S.has(D)){te(E,{locality:"prop",root:D,key:xe(P)});return}if(D!==null&&x.has(D)||!D||!e.state.has(D))return;let Te=e.state.get(D);if(Te==="computed")throw E.buildCodeFrameError(`memo-dom: cannot mutate computed '${D}' (R13) \u2014 it is derived; write its SOURCE state instead`);B(E,Ie=>{if(Te!=="store"){Ie.writes.add(D);return}let Be=xe(P);Be!==null&&Be.includes(".")?Ie.writes.add(Be):Ie.writes.add(D)})};Mo(d,{VariableDeclarator(E){if(!O.isIdentifier(E.node.id)&&E.node.init!==null)for(let P of f.referencedOrigins(E.scope,E.node.init))ne(E,P)},AssignmentExpression(E){let P=E.node.left;if(O.isIdentifier(P)){if(F.has(P.name)){if(O.isIdentifier(E.node.right)){let ee=f.resolveExpression(E.scope,E.node.right);ee!==null&&ne(E,ee)}return}if(u?.has(P.name))throw E.buildCodeFrameError(`memo-dom: cannot assign per-instance derivation '${P.name}' (R14) \u2014 write its source instead`);if(p?.has(P.name)===!0){B(E,ee=>{b(ee,P.name)});return}if(S.has(P.name))throw E.buildCodeFrameError(`memo-dom: cannot assign prop '${P.name}' \u2014 copy it to component-local let state first`);if(x.has(P.name))throw E.buildCodeFrameError(`memo-dom: cannot assign component-local const '${P.name}'`);let D=e.state.get(P.name);if(!D)throw E.buildCodeFrameError(`memo-dom: handler assigns '${P.name}', which is neither module state nor a handler local \u2014 declare it at module level (let) or inside the handler`);if(e.importedState.has(P.name))throw E.buildCodeFrameError(`memo-dom: cannot reassign imported state '${P.name}' - ES module imports are read-only; export a mutator or mutate an imported store property`);if(D==="store")throw E.buildCodeFrameError(`memo-dom: cannot reassign store '${P.name}' \u2014 assign a property (${P.name}.field = \u2026) instead`);if(D==="const")throw E.buildCodeFrameError(`memo-dom: cannot reassign mutable const root '${P.name}' - mutate the object instead`);if(D==="computed")throw E.buildCodeFrameError(`memo-dom: cannot assign computed '${P.name}' (R13) \u2014 it is derived; write its SOURCE state instead and the derivation recomputes`);B(E,ee=>{ee.writes.add(P.name)})}else if(O.isMemberExpression(P))Pe(E,P);else for(let D of f.referencedOrigins(E.scope,E.node.right))ne(E,D)},UpdateExpression(E){let P=E.node.argument;if(O.isIdentifier(P)){if(F.has(P.name))return;if(u?.has(P.name))throw E.buildCodeFrameError(`memo-dom: cannot update per-instance derivation '${P.name}' (R14) \u2014 write its source instead`);if(p?.has(P.name)===!0){B(E,ee=>{b(ee,P.name)});return}if(S.has(P.name))throw E.buildCodeFrameError(`memo-dom: cannot update prop '${P.name}' \u2014 copy it to component-local let state first`);if(x.has(P.name))throw E.buildCodeFrameError(`memo-dom: cannot update component-local const '${P.name}'`);let D=e.state.get(P.name);if(!D)throw E.buildCodeFrameError(`memo-dom: handler updates '${P.name}', which is neither module state nor a handler local`);if(e.importedState.has(P.name))throw E.buildCodeFrameError(`memo-dom: cannot update imported state '${P.name}' - ES module imports are read-only; call an exported mutator instead`);if(D!=="let")throw E.buildCodeFrameError(D==="computed"?`memo-dom: cannot update computed '${P.name}' (R13) \u2014 it is derived; write its SOURCE state instead`:`memo-dom: cannot update '${P.name}' \u2014 it is a const binding; mutate its contents instead`);B(E,ee=>{ee.writes.add(P.name)})}else O.isMemberExpression(P)&&Pe(E,P)},UnaryExpression(E){E.node.operator==="delete"&&O.isMemberExpression(E.node.argument)&&Pe(E,E.node.argument)},CallExpression(E){let P=E.node.callee;if(O.isMemberExpression(P)){let D=xn(P);if(D==="assign"&&O.isIdentifier(P.object,{name:"Object"})){let Ie=E.node.arguments[0],Be=Ie!==void 0&&O.isExpression(Ie)?f.resolveExpression(E.scope,Ie):null;if(Be!==null)if(Be.locality==="module"&&Be.stateKind==="store"){let an=yn(Be,E.node.arguments.slice(1));an===null?ne(E,Be):B(E,Fi=>{for(let Mi of an)Fi.writes.add(Mi)})}else Ee(E,Be);return}if(D!==null&&zs.has(D)&&O.isIdentifier(P.object)&&p?.has(P.object.name)===!0&&C?.has(P.object.name)===!0){let Ie=P.object.name;B(E,Be=>{b(Be,Ie,"topology")});return}let ee=O.isIdentifier(P.object)?P.object.name:O.isMemberExpression(P.object)?ke(P.object):null;if(ee!==null&&u?.has(ee)&&!g.has(ee))throw E.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${ee}' (R14) - write its source instead`);let Te=O.isExpression(P.object)?f.resolveExpression(E.scope,P.object):null;Te!==null?ne(E,Te):ue(E,E.node.arguments);return}if(O.isIdentifier(P)&&!x.has(P.name)&&(e.helpers.has(P.name)||e.importedFunctions.has(P.name))){let D=e.importedFunctions.get(P.name)??He(e,P.name);B(E,ee=>{for(let Ie of D.writes)ee.writes.add(Ie);for(let Ie of D.boundedWrites)ee.writes.add(Ie);let Te=s&&E.getFunctionParent()?.node===l;D.unbounded&&!Te&&(ee.rootFallback=!0)});for(let ee of D.parameterWrites){let Te=E.node.arguments[ee.index];if(Te===void 0||!O.isExpression(Te))continue;let Ie=f.resolveExpression(E.scope,Te);if(Ie!==null){if(m(Ie))continue;ne(E,yt(Ie,ee.path))}}return}ue(E,E.node.arguments)}});let G=R.has(l);if(e.handlerHasRootCommit.set(t,G),o&&!R.has(l)){let E=At();E.eventOrigin=vt(e,n,r,i),R.set(l,E)}let se=[];if(s)for(let E of k.values()){let P=Bt(e,E.writes,n,r);P!==null&&se.push({...E,commit:P})}for(let E of se)E.flag=A(e,"didWrite");se.sort((E,P)=>Lo(P.path)-Lo(E.path)).forEach(E=>Hs(E.path,E.flag));for(let[E,P]of R){let D=s&&E===l?se.length===0?null:O.blockStatement(se.map(ee=>O.ifStatement(O.cloneNode(ee.flag),O.cloneNode(ee.commit)))):Bt(e,P,n,r);D&&No(e,E,D)}if(se.length>0){if(!O.isBlockStatement(a.body))throw new Error("memo-dom: execution-aware callback commit did not produce a block body");a.body.body.unshift(O.variableDeclaration("let",se.map(E=>O.variableDeclarator(O.cloneNode(E.flag),O.booleanLiteral(!1)))))}t.body=a.body}function Lo(e){let t=0,n=e;for(;n.parentPath!==null;)t++,n=n.parentPath;return t}function Hs(e,t){let n=O.assignmentExpression("=",O.cloneNode(t),O.booleanLiteral(!0));if(e.isVariableDeclarator()){let r=e.node.init;if(r===null||!O.isExpression(r))throw new Error("memo-dom: execution-aware variable site has no expression initializer");e.node.init=O.sequenceExpression([n,r]);return}if(!e.isExpression())throw new Error(`memo-dom: unsupported execution-aware write site '${e.node.type}'`);e.replaceWith(O.sequenceExpression([n,e.node]))}import*as ct from"@babel/types";function Ao(e,t){let n=!1,r=!0,o=i=>{if(r&&!(i!==e&&ct.isFunction(i))){if((ct.isCallExpression(i)||ct.isOptionalCallExpression(i))&&(n=!0,!ct.isIdentifier(i.callee)||!t(i.callee.name))){r=!1;return}for(let s of ct.VISITOR_KEYS[i.type]??[]){let a=i[s];if(Array.isArray(a))for(let l of a)l!==null&&typeof l=="object"&&"type"in l&&o(l);else a!==null&&typeof a=="object"&&"type"in a&&o(a)}}};return o(e),n&&r}function gt(e,t){let r=e.scope.getBinding(t)?.path;if(!r||r.getFunctionParent()!==e)return null;if(r.isFunctionDeclaration())return r.node;if(!r.isVariableDeclarator())return null;let o=r.node.init;return o&&(ve.isArrowFunctionExpression(o)||ve.isFunctionExpression(o))?o:null}function at(e,t,n,r,o,i=!1){e.analyzedFunctions.has(n)||(ir(e,t,n,r,o),e.analyzedFunctions.add(n),nn(e,n,r,o,!1,void 0,i))}function rn(e,t,n=!1){e.analyzedFunctions.has(t)||(e.analyzedFunctions.add(t),nn(e,t,null,void 0,!1,void 0,n))}function ir(e,t,n,r,o){let i=new Set;Ae(n.body,s=>{ve.isCallExpression(s)&&ve.isIdentifier(s.callee)&&i.add(s.callee.name)});for(let s of i){let a=gt(t,s);a===null||e.analyzedFunctions.has(a)||(e.analyzedFunctions.add(a),ir(e,t,a,r,o),nn(e,a,r,o,!1))}}function sr(e,t,n,r,o,i,s){let a=null,l=!1,d=e.componentProps.get(o),p=d===void 0?null:Ue(d);if(d!==void 0&&(ve.isIdentifier(n)&&Ze(d,n.name)!==null||ve.isMemberExpression(n)&&p!==null&&ke(n)===p))return Vt(e,n,vt(e,o,i,s));if(ve.isArrowFunctionExpression(n)||ve.isFunctionExpression(n))a=n;else if(ve.isIdentifier(n)){let g=e.importedFunctions.get(n.name);if(g!==void 0){let f=At();for(let m of g.writes)f.writes.add(m);for(let m of g.boundedWrites)f.writes.add(m);return f.rootFallback=g.unbounded,Vt(e,n,Bt(e,f,null)??vt(e,o,i,s))}let S=t.scope.getBinding(n.name),x=S?.path;if(x&&x.isVariableDeclarator()){let f=x.node.init;f&&(ve.isArrowFunctionExpression(f)||ve.isFunctionExpression(f))&&(a=f,l=S?.scope.path.isProgram()===!0&&e.helpers.has(n.name))}else x&&x.isFunctionDeclaration()&&(e.helpers.has(n.name)?(a=x.node,l=!0):a=gt(t,n.name));if(!a)throw t.buildCodeFrameError(`memo-dom: cannot resolve handler '${n.name}' \u2014 use an inline arrow, a component-local const, or a module-level function (L1)`)}else throw t.buildCodeFrameError(`memo-dom: unsupported ${r} handler form \u2014 expected an arrow function or a function reference (L1)`);if(ve.isBlockStatement(a.body)||(a.body=ve.blockStatement([ve.expressionStatement(a.body)])),!e.analyzedFunctions.has(a)){l||ir(e,t,a,o,i);let g=!l&&!ve.isIdentifier(n)&&Ao(a,S=>{let x=gt(t,S);return x!==null&&e.handlerHasRootCommit.get(x)===!0});e.analyzedFunctions.add(a),nn(e,a,l?null:o,l?void 0:i,!l&&!ve.isIdentifier(n)&&!g,s)}if(l){let g=He(e,n.name);if(a.async){let S=At();for(let x of g.writes)S.writes.add(x);for(let x of g.boundedWrites)S.writes.add(x);return S.rootFallback=g.unbounded,Vt(e,n,Bt(e,S,null)??vt(e,o,i,s))}if(g.writes.size===0&&g.boundedWrites.size===0&&!g.unbounded)return Vt(e,n,vt(e,o,i,s))}return ve.isIdentifier(n)&&!l&&(e.handlerHasRootCommit.get(a)===!1||a.async)?Vt(e,n,vt(e,o,i,s)):ve.isIdentifier(n)?n:a}import*as Re from"@babel/types";function ar(e,t){let n=[];for(let r of e){if(Re.isJSXText(r)){let a=zn(r.value);a!==""&&n.push({type:"node",variable:t.emitText(Re.stringLiteral(a))});continue}if(Re.isJSXElement(r)||Re.isJSXFragment(r)){n.push({type:"node",variable:t.emitNode(r)});continue}if(Re.isJSXExpressionContainer(r)||t.fail("memo-dom: spread children are not supported"),Re.isJSXEmptyExpression(r.expression))continue;Re.isExpression(r.expression)||t.fail("memo-dom: unsupported expression in JSX child position");let o=r.expression;if(t.isForwarded(o)){n.push({type:"slot",expression:Re.cloneNode(o)});continue}if(Re.isNullLiteral(o)||Re.isBooleanLiteral(o)||Re.isIdentifier(o,{name:"undefined"}))continue;let i=We(o);if(i!==null){n.push({type:"list",expression:i});continue}let s=bn(o);if(s!==null&&de(s)){n.push({type:"condition",expression:s});continue}n.push({type:"node",variable:t.emitText(Re.cloneNode(o))})}return n}import*as T from"@babel/types";var _s=new Set(["innerHTML","checked","value","selected","disabled","hidden","multiple","required","readOnly","muted","open","controls","loop","autoFocus","autoPlay","tabIndex"]),jo={htmlFor:"for",crossOrigin:"crossorigin"};function lr(e,t){return!t&&_s.has(e)?e:null}function dr(e,t){return!t&&e in jo}function cr(e,t,n){let r=T.identifier(e);if(t==="tabIndex")return T.isStringLiteral(n)?T.expressionStatement(T.assignmentExpression("=",T.memberExpression(r,T.identifier(t)),T.cloneNode(n))):T.expressionStatement(T.conditionalExpression(T.binaryExpression("==",T.cloneNode(n),T.nullLiteral()),T.callExpression(T.memberExpression(T.cloneNode(r),T.identifier("removeAttribute")),[T.stringLiteral("tabindex")]),T.assignmentExpression("=",T.memberExpression(T.cloneNode(r),T.identifier(t)),T.cloneNode(n))));let o=t==="value"||t==="innerHTML"?T.stringLiteral(""):T.booleanLiteral(!1),i=T.isStringLiteral(n)?T.cloneNode(n):T.conditionalExpression(T.binaryExpression("==",T.cloneNode(n),T.nullLiteral()),o,T.cloneNode(n));return T.expressionStatement(T.assignmentExpression("=",T.memberExpression(r,T.identifier(t)),i))}function jn(e,t,n){let r=T.identifier(e),o=jo[t]??t;return T.isStringLiteral(n)?T.expressionStatement(T.callExpression(T.memberExpression(r,T.identifier("setAttribute")),[T.stringLiteral(o),T.cloneNode(n)])):T.expressionStatement(T.conditionalExpression(T.logicalExpression("||",T.binaryExpression("==",T.cloneNode(n),T.nullLiteral()),T.binaryExpression("===",T.cloneNode(n),T.booleanLiteral(!1))),T.callExpression(T.memberExpression(T.cloneNode(r),T.identifier("removeAttribute")),[T.stringLiteral(o)]),T.callExpression(T.memberExpression(r,T.identifier("setAttribute")),[T.stringLiteral(o),T.conditionalExpression(T.binaryExpression("===",T.cloneNode(n),T.booleanLiteral(!0)),T.stringLiteral(""),T.callExpression(T.identifier("String"),[T.cloneNode(n)]))])))}import*as qe from"@babel/types";var qs="http://www.w3.org/2000/svg",Gs=new Set(["animate","animateMotion","animateTransform","circle","clipPath","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","switch","symbol","text","textPath","tspan","use","view"]);function Jo(e,t){return t||e==="svg"||Gs.has(e)}function $o(e,t){return t?qe.callExpression(qe.memberExpression(qe.identifier("document"),qe.identifier("createElementNS")),[qe.stringLiteral(qs),qe.stringLiteral(e)]):qe.callExpression(qe.memberExpression(qe.identifier("document"),qe.identifier("createElement")),[qe.stringLiteral(e)])}import*as me from"@babel/types";function Jn(e,t,n){let r=e.componentProps.get(t);if(r?.mode==="object"){if(!r.acceptsUnknown){for(let s of n)if(!r.names.includes(s.name))throw new Error(`memo-dom: unknown prop '${s.name}' on <${t}> - declared props: ${r.names.length>0?r.names.join(", "):"(none)"}`)}return n.length===0&&r.hasWholeDefault?[me.identifier("undefined")]:[me.objectExpression(n.map(s=>me.objectProperty(me.identifier(s.name),s.value,!1,me.isIdentifier(s.value)&&s.value.name===s.name)))]}let o=r?.names;if(o===void 0)return n.map(s=>s.value);let i=new Map(n.map(s=>[s.name,s.value]));for(let s of i.keys())if(!o.includes(s))throw new Error(`memo-dom: unknown prop '${s}' on <${t}> - declared props: ${o.length>0?o.join(", "):"(none)"}`);return o.map(s=>i.get(s)??me.identifier("undefined"))}function Wt(e,t,n){let r=e.componentProps.get(t);return r?.mode==="object"?[me.cloneNode(n)]:(r?.names??[]).map(o=>me.memberExpression(me.cloneNode(n),me.isValidIdentifier(o)?me.identifier(o):me.stringLiteral(o),!me.isValidIdentifier(o)))}function Oo(e,t,n,r,o){let i=A(e,`${t}Props`);return me.blockStatement([me.variableDeclaration("const",[me.variableDeclarator(me.cloneNode(i),me.cloneNode(o))]),me.expressionStatement(me.callExpression(Y(e,"setProps"),[me.binaryExpression("+",me.cloneNode(n),me.stringLiteral(r)),me.arrayExpression(Wt(e,t,i))]))])}import*as Me from"@babel/types";function zt(e){return(Me.isArrowFunctionExpression(e)||Me.isFunctionExpression(e))&&!Zs(e.body)}function ur(e,t,n,r="callback"){let o=A(e,r);return t.creation.push(Me.variableDeclaration("const",[Me.variableDeclarator(Me.cloneNode(o),Me.cloneNode(n,!0))])),o}function pr(e,t,n,r="callback"){let o=A(e,r);return t.push(Me.variableDeclaration("const",[Me.variableDeclarator(Me.cloneNode(o),Me.cloneNode(n,!0))])),o}function Zs(e){let t=!1;return Me.traverseFast(e,n=>{if(Me.isJSXElement(n)||Me.isJSXFragment(n))return t=!0,Me.traverseFast.stop}),t}import*as H from"@babel/types";function Xo(e,t,n,r,o,i,s,a=!1,l=$e(e,o),d=!1){let p=hn(n,i,t.usedConds),u=A(e,p.suffix).name,g=H.binaryExpression("+",H.cloneNode(l),H.stringLiteral(`/${p.suffix}`)),S=H.arrowFunctionExpression([],H.cloneNode(p.pickExpr)),x=p.branches.map(f=>f!==null?fr(e,f,o,i,g,s,a,g,!1,t.usedConds):H.nullLiteral());t.creation.push(St(e,H.cloneNode(g),H.cloneNode(l),H.arrowFunctionExpression([],H.callExpression(H.memberExpression(H.identifier(u),H.identifier("update")),[])))),t.creation.push(H.variableDeclaration("const",[H.variableDeclarator(H.identifier(u),H.callExpression(Y(e,"createCondRegion"),[H.identifier(r),H.cloneNode(g),S,H.arrayExpression(x)]))])),(d||wr(e,n,o))&&t.updaters.push(()=>H.expressionStatement(H.callExpression(H.memberExpression(H.identifier(u),H.identifier("update")),[]))),t.disposableRegions.push(u),t.disposableEntities.push(H.cloneNode(g))}function fr(e,t,n,r,o,i,s=!1,a=o,l=!1,d){let p=rt(e,!0);d!==void 0&&(p.usedConds=d);let u=i(e,p,t,n,r,l?null:"cond",void 0,o,s,a),g=[H.objectProperty(H.identifier("nodes"),H.callExpression(Y(e,"rootNodes"),[H.identifier(u)])),H.objectProperty(H.identifier("update"),H.identifier(p.updateVar))];if(p.disposableRegions.length>0||p.disposableEntities.length>0||p.disposableCallbacks.length>0){let S=[...[...p.disposableCallbacks].reverse().map(x=>H.ifStatement(H.binaryExpression("!==",H.cloneNode(x),H.nullLiteral()),H.expressionStatement(H.callExpression(H.cloneNode(x),[])))),...p.disposableRegions.map(x=>H.expressionStatement(H.callExpression(H.memberExpression(H.identifier(x),H.identifier("dispose")),[]))),...p.disposableEntities.map(x=>H.expressionStatement(H.callExpression(Y(e,"unregisterSubtree"),[H.cloneNode(x)])))];g.push(H.objectProperty(H.identifier("dispose"),H.arrowFunctionExpression([],H.blockStatement(S))))}return H.arrowFunctionExpression([],H.blockStatement([ot(p),it(p),...p.creation,...p.mounts,H.returnStatement(H.objectExpression(g))]))}import*as c from"@babel/types";import*as X from"@babel/types";function bt(e,t,n,r){return X.isArrayExpression(r)?X.arrayExpression(r.elements.map(o=>{if(o===null)return null;if(X.isSpreadElement(o))throw t.buildCodeFrameError("memo-dom: ref arrays must have a static shape; nested arrays are supported but array spreads are not");return bt(e,t,n,o)})):Ys(e,n,r)?X.cloneNode(r,!0):Qs(t,r)||X.isMemberExpression(r)?To(e,r):X.cloneNode(r,!0)}function mr(e,t,n,r,o){let i=A(e,"refDispose");t.mounts.push(X.variableDeclaration("const",[X.variableDeclarator(X.cloneNode(i),X.callExpression(Y(e,"mountRef"),[X.cloneNode(n,!0),X.cloneNode(o,!0)]))])),t.manualDisposal?t.disposableCallbacks.push(i):t.mounts.push(X.expressionStatement(X.callExpression(Y(e,"cleanup"),[X.cloneNode(r,!0),X.cloneNode(i)])))}function Ys(e,t,n){let r=ft(e,t,n);return r!==null&&e.componentProps.get(t)?.refProps.includes(r)===!0}function Qs(e,t){if(!X.isIdentifier(t)||t.name==="undefined")return!1;let n=e.scope.getBinding(t.name);if(n===void 0||n.path.isFunctionDeclaration()||n.path.isImportSpecifier()||n.path.isImportDefaultSpecifier()||n.path.isImportNamespaceSpecifier())return!1;if(n.path.isVariableDeclarator()){if(n.path.parentPath.isVariableDeclaration({kind:"const"}))return!1;let o=n.path.node.init;if(X.isFunctionExpression(o)||X.isArrowFunctionExpression(o))return!1}return n.kind!=="param"}function To(e,t){let n=A(e,"refNode");if(X.isMemberExpression(t)){let r=A(e,"refTarget"),o=t.computed?A(e,"refKey"):null,i=()=>X.memberExpression(X.cloneNode(r),o===null?X.cloneNode(t.property,!0):X.cloneNode(o),t.computed);return X.arrowFunctionExpression([X.cloneNode(n)],X.blockStatement([X.variableDeclaration("const",[X.variableDeclarator(X.cloneNode(r),X.cloneNode(t.object,!0)),...o===null?[]:[X.variableDeclarator(X.cloneNode(o),X.cloneNode(t.property,!0))]]),X.expressionStatement(X.assignmentExpression("=",i(),X.cloneNode(n))),X.returnStatement(X.arrowFunctionExpression([],X.blockStatement([X.ifStatement(X.binaryExpression("===",i(),X.cloneNode(n)),X.expressionStatement(X.assignmentExpression("=",i(),X.identifier("undefined"))))])))]))}return X.arrowFunctionExpression([X.cloneNode(n)],X.blockStatement([X.expressionStatement(X.assignmentExpression("=",X.cloneNode(t,!0),X.cloneNode(n))),X.returnStatement(X.arrowFunctionExpression([],X.blockStatement([X.ifStatement(X.binaryExpression("===",X.cloneNode(t,!0),X.cloneNode(n)),X.expressionStatement(X.assignmentExpression("=",X.cloneNode(t,!0),X.identifier("undefined"))))])))]))}import*as J from"@babel/types";var ea=new Set(["setClassValue","setStyleValue","setDomValue"]);function Kt(e,t,n){if(t.mounts.length!==0||t.disposableRegions.length!==0||t.disposableEntities.length!==0||t.disposableCallbacks.length!==0)return!1;let r=[],o=new Set;for(let C of t.creation){if(!J.isVariableDeclaration(C))continue;let b=na(C);if(b===null)return!1;r.push(b),o.add(b.name)}if(!o.has(n)||r.length<2)return!1;let i=new Map,s=new Map;for(let C of t.creation){let b=Bo(C);if(b===null)continue;if(!o.has(b.parent)||!o.has(b.child))return!1;let v=s.get(b.parent)??0;s.set(b.parent,v+1),i.set(b.child,{parent:b.parent,index:v})}let a=new Map;for(let C of o){let b=ra(C,n,i);if(b===null)return!1;a.set(C,b)}let l=[],d=[];for(let C of t.creation)J.isVariableDeclaration(C)||ia(C,o)?l.push(J.cloneNode(C,!0)):d.push(C);let p=A(e,`${n}Template`);e.header.push(J.variableDeclaration("let",[J.variableDeclarator(J.cloneNode(p))]));let u=J.callExpression(J.arrowFunctionExpression([],J.blockStatement([...l,J.returnStatement(J.identifier(n))])),[]),g=J.conditionalExpression(J.binaryExpression("===",J.cloneNode(p),J.unaryExpression("void",J.numericLiteral(0))),J.assignmentExpression("=",J.cloneNode(p),u),J.cloneNode(p)),S=J.callExpression(J.memberExpression(g,J.identifier("cloneNode")),[J.booleanLiteral(!0)]),x=new Set([n]);for(let C of d)Ae(C,b=>{J.isIdentifier(b)&&o.has(b.name)&&x.add(b.name)});let f=[],m=r.filter(({name:C})=>x.has(C)).sort((C,b)=>a.get(C.name).length-a.get(b.name).length).map(({name:C})=>{let b=a.get(C),v;if(C===n)v=J.cloneNode(S,!0);else{let F=f[0];for(let R of f)R.path.length>F.path.length&&ta(R.path,b)&&(F=R);v=oa(F.name,b.slice(F.path.length))}return f.push({name:C,path:b}),J.variableDeclaration("const",[J.variableDeclarator(J.identifier(C),v)])});return t.creation=[...m,...d],!0}function ta(e,t){return e.length<=t.length&&e.every((n,r)=>t[r]===n)}function na(e){if(e.declarations.length!==1)return null;let t=e.declarations[0];if(!J.isIdentifier(t.id)||!J.isCallExpression(t.init)||!J.isMemberExpression(t.init.callee)||!J.isIdentifier(t.init.callee.object,{name:"document"})||!J.isIdentifier(t.init.callee.property))return null;let n=t.init.callee.property.name;if(n!=="createElement"&&n!=="createElementNS"&&n!=="createTextNode")return null;let r=t.init.arguments.at(-1);return(n==="createElement"||n==="createElementNS")&&J.isStringLiteral(r)&&r.value.includes("-")?null:{name:t.id.name,statement:e}}function Bo(e){return!J.isExpressionStatement(e)||!J.isCallExpression(e.expression)||!J.isMemberExpression(e.expression.callee)||!J.isIdentifier(e.expression.callee.object)||!J.isIdentifier(e.expression.callee.property,{name:"appendChild"})||e.expression.arguments.length!==1||!J.isIdentifier(e.expression.arguments[0])?null:{parent:e.expression.callee.object.name,child:e.expression.arguments[0].name}}function ra(e,t,n){if(e===t)return[];let r=[],o=new Set,i=e;for(;i!==t;){if(o.has(i))return null;o.add(i);let s=n.get(i);if(s===void 0)return null;r.push(s.index),i=s.parent}return r.reverse(),r}function oa(e,t){let n=J.identifier(e);for(let r of t){n=J.memberExpression(n,J.identifier("firstChild"));for(let o=0;o<r;o++)n=J.memberExpression(n,J.identifier("nextSibling"))}return n}function ia(e,t){let n=Bo(e);if(n!==null)return t.has(n.parent)&&t.has(n.child);if(!J.isExpressionStatement(e))return!1;let r=e.expression;return!!(J.isCallExpression(r)&&J.isMemberExpression(r.callee)&&(J.isIdentifier(r.callee.object)&&t.has(r.callee.object.name)&&J.isIdentifier(r.callee.property,{name:"setAttribute"})&&r.arguments.every(o=>J.isExpression(o)&&$n(o))||J.isIdentifier(r.callee.object)&&J.isIdentifier(r.callee.property)&&ea.has(r.callee.property.name)&&r.arguments.length>=2&&J.isIdentifier(r.arguments[0])&&t.has(r.arguments[0].name)&&r.arguments.slice(1).every(o=>J.isExpression(o)&&$n(o))))}function $n(e){return J.isStringLiteral(e)||J.isNumericLiteral(e)||J.isBooleanLiteral(e)||J.isNullLiteral(e)?!0:J.isArrayExpression(e)?e.elements.every(t=>t===null||J.isExpression(t)&&$n(t)):J.isObjectExpression(e)?e.properties.every(t=>J.isObjectProperty(t)&&!t.computed&&J.isExpression(t.value)&&$n(t.value)):!1}function Vo(e,t,n,r,o,i,s,a,l=!1,d=$e(e,o),p){let u=Mt(e,n,i,o,t.usedPrefixes,p===void 0?void 0:{itemParam:p.itemParam,sourceKey:p.sourceKey,sourceLocal:p.sourceLocal??!1}),g=A(e,`region${t.regionCounter++}`).name,S=new Map,x=u.form==="inline"?Xt(u.jsx):u.form==="component"&&Ct(e,u.rowComp)?e.importedComponents.get(u.rowComp)?.delegatedEvents??e.componentHostEvents.get(u.rowComp)??[]:[];for(let R of x){let k=A(e,`${R}Binding`);S.set(R,k),t.creation.push(c.variableDeclaration("const",[c.variableDeclarator(c.cloneNode(k),c.callExpression(Y(e,"createDelegatedEventBinding"),[c.identifier(r),c.stringLiteral(R)]))]))}let f=u.form==="callback"?aa(e,u):u.form==="component"?la(e,u,o,i,a,l,d,S):da(e,u,o,i,s,l,d,S),m=[c.identifier(r),c.binaryExpression("+",c.cloneNode(d),c.stringLiteral(`/${u.suffix}`)),f];if(u.form==="callback"){let R=c.memberExpression(c.cloneNode(u.renderCallback,!0),c.identifier("key"));m.push(c.arrowFunctionExpression([c.cloneNode(u.itemPattern,!0),...u.indexParam===null?[]:[c.identifier(u.indexParam)]],c.conditionalExpression(c.binaryExpression("==",c.cloneNode(R),c.nullLiteral()),c.cloneNode(u.itemPattern,!0),c.callExpression(c.cloneNode(R),[c.cloneNode(u.itemPattern,!0),...u.indexParam===null?[]:[c.identifier(u.indexParam)]]))))}else u.keyExpr!==null&&m.push(c.arrowFunctionExpression([c.cloneNode(u.itemPattern,!0),...u.indexParam===null?[]:[c.identifier(u.indexParam)]],c.cloneNode(u.keyExpr)));u.form==="component"&&Ct(e,u.rowComp)&&(m.length===3&&m.push(c.identifier("undefined")),m.push(c.booleanLiteral(!1))),t.creation.push(c.variableDeclaration("const",[c.variableDeclarator(c.identifier(g),c.callExpression(Y(e,"createListRegion"),m))])),t.disposableRegions.push(g);let C=e.targetedListDependencies.get(n)??[],b=e.keyedListMutations.get(n);b!==void 0&&t.creation.push(c.variableDeclaration("const",[c.variableDeclarator(c.identifier(b.keysVariable),c.newExpression(c.identifier("Set"),[]))]));let v=C.map(R=>({dependency:R,cache:A(e,`${R.value}ListKey`).name}));v.length>0&&t.creation.push(c.variableDeclaration("let",v.map(({dependency:R,cache:k})=>c.variableDeclarator(c.identifier(k),c.identifier(R.value)))));let F=()=>c.expressionStatement(c.callExpression(c.memberExpression(c.identifier(g),c.identifier("reconcile")),[c.cloneNode(u.sourceExpr)]));t.creation.push(F()),v.length===0&&b===void 0||t.reasonVar===null?t.updaters.push(F):t.updaters.push(()=>sa(e,o,t.reasonVar,g,u.sourceExpr,v,b,u.indexParam===null))}function ut(e,t){let n=()=>c.identifier(e);return c.logicalExpression("||",c.binaryExpression("===",n(),c.numericLiteral(t)),c.logicalExpression("&&",c.binaryExpression("!==",n(),c.nullLiteral()),c.logicalExpression("&&",c.binaryExpression("!==",c.unaryExpression("typeof",n()),c.stringLiteral("number")),c.callExpression(c.memberExpression(n(),c.identifier("has")),[c.numericLiteral(t)]))))}function gr(e,t){return c.expressionStatement(c.callExpression(c.memberExpression(c.identifier(e),c.identifier("refreshKey")),[t]))}function sa(e,t,n,r,o,i,s,a){let l=e.instanceReasonIds.get(t);if(l===void 0)return c.expressionStatement(c.callExpression(c.memberExpression(c.identifier(r),c.identifier("reconcile")),[c.cloneNode(o)]));let d=s?.source??i[0]?.dependency.source,p=d===void 0?void 0:l.get(d);if(p===void 0)return c.expressionStatement(c.callExpression(c.memberExpression(c.identifier(r),c.identifier("reconcile")),[c.cloneNode(o)]));let u=[c.expressionStatement(c.callExpression(c.memberExpression(c.identifier(r),c.identifier("reconcile")),[c.cloneNode(o)])),...i.map(({dependency:m,cache:C})=>c.expressionStatement(c.assignmentExpression("=",c.identifier(C),c.identifier(m.value)))),...s===void 0?[]:[c.expressionStatement(c.callExpression(c.memberExpression(c.identifier(s.keysVariable),c.identifier("clear")),[]))]],g=null;if(s!==void 0&&a){let m=l.get(s.topologyReason);if(m!==void 0){let C=ut(n,m);for(let b of[l.get(s.targetedReason),l.get(s.structuralReason),...i.map(({dependency:v})=>l.get(v.value))])b!==void 0&&(C=c.logicalExpression("&&",C,c.unaryExpression("!",ut(n,b))));g=c.ifStatement(C,c.blockStatement([c.expressionStatement(c.callExpression(c.memberExpression(c.identifier(r),c.identifier("reconcile")),[c.cloneNode(o),c.booleanLiteral(!1)]))]))}}let S=[];if(s!==void 0){let m=l.get(s.targetedReason);if(m!==void 0){let C=A(e,"changedListKey");S.push(c.ifStatement(ut(n,m),c.blockStatement([c.forOfStatement(c.variableDeclaration("const",[c.variableDeclarator(c.cloneNode(C))]),c.identifier(s.keysVariable),c.blockStatement([gr(r,c.cloneNode(C))])),c.expressionStatement(c.callExpression(c.memberExpression(c.identifier(s.keysVariable),c.identifier("clear")),[]))])))}}for(let{dependency:m,cache:C}of i){let b=l.get(m.value);if(b===void 0)continue;let v=A(e,"previousListKey");S.push(c.ifStatement(ut(n,b),c.blockStatement([c.variableDeclaration("const",[c.variableDeclarator(v,c.identifier(C))]),c.expressionStatement(c.assignmentExpression("=",c.identifier(C),c.identifier(m.value))),gr(r,c.cloneNode(v)),c.ifStatement(c.unaryExpression("!",c.callExpression(c.memberExpression(c.identifier("Object"),c.identifier("is")),[c.cloneNode(v),c.identifier(C)])),gr(r,c.identifier(C)))])))}let x=c.binaryExpression("===",c.identifier(n),c.nullLiteral());if(s!==void 0){let m=l.get(s.structuralReason),C=l.get(s.topologyReason),b=l.get(s.targetedReason);m!==void 0&&(x=c.logicalExpression("||",x,ut(n,m))),C!==void 0&&(x=c.logicalExpression("||",x,ut(n,C))),x=c.logicalExpression("||",x,b===void 0?ut(n,p):c.logicalExpression("&&",ut(n,p),c.unaryExpression("!",ut(n,b))))}else x=c.logicalExpression("||",x,ut(n,p));let f=c.ifStatement(x,c.blockStatement(u),S.length===0?void 0:c.blockStatement(S));return g===null?f:(g.alternate=f,g)}function aa(e,t){let n=A(e,"renderRowId");return c.arrowFunctionExpression([c.cloneNode(t.itemPattern,!0),c.cloneNode(n),...t.indexParam===null?[]:[c.identifier(t.indexParam)]],c.callExpression(c.memberExpression(c.cloneNode(t.renderCallback,!0),c.identifier("create")),[c.cloneNode(t.itemPattern,!0),c.cloneNode(n),...t.indexParam===null?[]:[c.identifier(t.indexParam)]]))}function la(e,t,n,r,o,i=!1,s=$e(e,n),a=new Map){let l=t.rowComp,d=A(e,"rowId"),p=A(e,"nextItem"),u=t.indexParam===null?null:A(e,"nextIndex"),g=A(e,"refreshRow"),S=rt(e),x=Ct(e,l),f={itemParam:t.itemParam,itemPath:[],rowIdVar:d.name,refreshVar:g.name,keyPath:nt(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal&&c.isIdentifier(s)?{ownerIdVar:s.name}:{}},m=t.jsx.openingElement.attributes.filter(G=>c.isJSXSpreadAttribute(G)||Oe(G.name)!=="key"),C=m.some(G=>c.isJSXSpreadAttribute(G)),b=[],v=[],F=null,R=e.componentProps.get(l),k=x&&(e.linkedComponentRows.get(l)?.length??0)===0&&R!==void 0?pn(R):null,W=()=>{for(let{name:se}of b)if(!k.some(E=>E.name===se))throw r.buildCodeFrameError(`memo-dom: unknown prop '${se}' on <${l}> - declared props: ${k.map(E=>E.name).join(", ")}`);let G=new Map(b.map(({name:se,value:E})=>[se,E]));return k.map(({name:se})=>c.cloneNode(G.get(se)??c.identifier("undefined")))},B=G=>k.map(({name:se})=>c.memberExpression(c.cloneNode(G),c.isValidIdentifier(se)?c.identifier(se):c.stringLiteral(se),!c.isValidIdentifier(se))),_=G=>{let se=c.isJSXElement(G)||c.isJSXFragment(G)?[G]:[c.jsxExpressionContainer(G)];return o(e,S,se,n,r,"row",f,d,i,d)};if(C){F=en(m,{attributeValue:(G,se)=>G==="ref"||R?.refProps.includes(G)===!0?bt(e,r,n,se):se,fail:G=>{throw r.buildCodeFrameError(G)}}).expression;for(let G of F.properties){if(!c.isObjectProperty(G)||G.computed||!c.isExpression(G.value))continue;let se=c.isIdentifier(G.key)?G.key.name:c.isStringLiteral(G.key)?G.key.value:null;if(se!==null)if(R?.renderProps.includes(se)===!0){if(st(e,n,G.value))continue;if(!de(G.value))throw r.buildCodeFrameError(`memo-dom: render prop '${se}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);G.value=_(G.value)}else{if(de(G.value))throw r.buildCodeFrameError(`memo-dom: JSX prop '${se}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);se!=="ref"&&R?.refProps.includes(se)!==!0&&zt(G.value)&&(at(e,r,G.value,n,f,!0),G.value=pr(e,v,G.value,`${se}Callback`))}}}else for(let G of m){let se=G,E=Oe(se.name),P=se.value==null?c.booleanLiteral(!0):Ve(se.value);if(P===null)throw r.buildCodeFrameError(`memo-dom: prop '${Oe(se.name)}' on <${l}> must be an expression`);if(R?.renderProps.includes(E)===!0){if(st(e,n,P)){b.push({name:E,value:c.cloneNode(P)});continue}if(!de(P))throw r.buildCodeFrameError(`memo-dom: render prop '${E}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);b.push({name:E,value:_(P)});continue}if(E==="ref"||R?.refProps.includes(E)===!0){b.push({name:E,value:bt(e,r,n,P)});continue}if(de(P))throw r.buildCodeFrameError(`memo-dom: JSX prop '${E}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);let D=zt(P);if(D)at(e,r,P,n,f,!0);else if(c.isIdentifier(P)){let ee=gt(r,P.name);ee!==null&&!de(ee.body)&&at(e,r,ee,n,f,!0)}b.push({name:E,value:D?pr(e,v,P,`${E}Callback`):c.cloneNode(P)})}if(Gt(t.jsx.children)){if(m.some(se=>c.isJSXAttribute(se)&&Oe(se.name)==="children"))throw r.buildCodeFrameError(`memo-dom: <${l}> cannot use both a children prop and nested JSX children`);let G=o(e,S,t.jsx.children,n,r,"row",f,d,i,d);F!==null?F.properties.push(c.objectProperty(c.identifier("children"),c.cloneNode(G))):b.push({name:"children",value:c.cloneNode(G)})}let Q;if(F!==null){let G=A(e,`${l}Props`);v.push(c.variableDeclaration("const",[c.variableDeclarator(c.cloneNode(G),c.cloneNode(F))])),Q=k===null?Wt(e,l,G):B(G)}else Q=k===null?Jn(e,l,b):W();let be=[c.expressionStatement(c.assignmentExpression("=",c.cloneNode(t.itemPattern,!0),c.cloneNode(p)))];u!==null&&t.indexParam!==null&&be.push(c.expressionStatement(c.assignmentExpression("=",c.identifier(t.indexParam),c.cloneNode(u))));let te=Q.map(G=>c.cloneNode(G));if(F!==null){let G=A(e,`next${l}Props`);be.push(c.variableDeclaration("const",[c.variableDeclarator(c.cloneNode(G),c.cloneNode(F))])),te=k===null?Wt(e,l,G):B(G)}let q=A(e,x?"entry":"rowElement"),Ee=Q.length>0||S.updaters.length>0,ne=x&&Ee,ue=ne?A(e,"pushRowProps"):null;x?be.push(c.expressionStatement(c.callExpression(ue===null?c.memberExpression(c.cloneNode(q),c.identifier("updateProps")):c.cloneNode(ue),te))):be.push(c.expressionStatement(c.callExpression(Y(e,"setProps"),[c.cloneNode(d),c.arrayExpression(te)])),c.expressionStatement(c.callExpression(Y(e,"markDirty"),[c.cloneNode(d)]))),S.updaters.length>0&&be.push(c.expressionStatement(c.callExpression(c.identifier(S.updateVar),[])));let Pe=x?[c.objectProperty(c.identifier("nodes"),c.memberExpression(c.cloneNode(q),c.identifier("nodes"))),c.objectProperty(c.identifier("entities"),c.arrayExpression([])),c.objectProperty(c.identifier("update"),c.memberExpression(c.cloneNode(q),c.identifier("update"))),c.objectProperty(c.identifier("dispose"),c.memberExpression(c.cloneNode(q),c.identifier("dispose")))]:[c.objectProperty(c.identifier("nodes"),c.callExpression(Y(e,"rootNodes"),[c.cloneNode(q)])),c.objectProperty(c.identifier("entities"),c.arrayExpression([c.cloneNode(d)]))];return Ee&&!ne&&Pe.push(c.objectProperty(c.identifier("updateProps"),c.arrowFunctionExpression([c.cloneNode(p),...u===null?[]:[c.cloneNode(u)]],c.blockStatement(be)))),c.arrowFunctionExpression([c.cloneNode(t.itemPattern,!0),c.cloneNode(d),...t.indexParam===null?[]:[c.identifier(t.indexParam)]],c.blockStatement([...S.updaters.length>0?[ot(S),it(S)]:[],...S.creation,...S.mounts,...v,c.variableDeclaration("const",[c.variableDeclarator(c.cloneNode(q),x?c.callExpression(c.identifier(l),[...Q.map(G=>c.cloneNode(G)),c.cloneNode(d),...t.sourceLocal?[c.cloneNode(s)]:[],...[...a.values()].map(G=>c.cloneNode(G))]):c.callExpression(c.identifier(l),[c.cloneNode(d),c.cloneNode(s),...Q.length>0?[c.arrayExpression(Q)]:[]]))]),...S.updaters.length>0?[c.variableDeclaration("const",[c.variableDeclarator(c.cloneNode(g),c.arrowFunctionExpression([],c.blockStatement([c.expressionStatement(x?c.callExpression(c.memberExpression(c.cloneNode(q),c.identifier("update")),[]):c.callExpression(Y(e,"markDirty"),[c.cloneNode(d)])),c.expressionStatement(c.callExpression(c.identifier(S.updateVar),[]))])))])]:[],...ue===null?[]:[c.variableDeclaration("const",[c.variableDeclarator(c.cloneNode(ue),c.memberExpression(c.cloneNode(q),c.identifier("updateProps")))]),c.expressionStatement(c.assignmentExpression("=",c.memberExpression(c.cloneNode(q),c.identifier("updateProps")),c.arrowFunctionExpression([c.cloneNode(p),...u===null?[]:[c.cloneNode(u)]],c.blockStatement(be))))],c.returnStatement(ne?c.cloneNode(q):c.objectExpression(Pe))]))}function da(e,t,n,r,o,i=!1,s=$e(e,n),a=new Map){t.jsx.openingElement.attributes=t.jsx.openingElement.attributes.filter(f=>c.isJSXSpreadAttribute(f)||f.name.name!=="key");let l=rt(e);for(let[f,m]of a)l.delegatedEventBindings.set(f,m.name);let d=A(e,"rowId").name,p=A(e,"nextItem"),u=t.indexParam===null?null:A(e,"nextIndex"),g={itemParam:t.itemParam,itemPath:[],rowIdVar:d,keyPath:nt(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal?{ownerIdVar:c.isIdentifier(s)?s.name:$e(e,n).name}:{}},S=o(e,l,t.jsx,n,r,"row",g,c.identifier(d),i,c.identifier(d));Kt(e,l,S);let x=[c.expressionStatement(c.assignmentExpression("=",c.cloneNode(t.itemPattern,!0),c.cloneNode(p)))];return u!==null&&t.indexParam!==null&&x.push(c.expressionStatement(c.assignmentExpression("=",c.identifier(t.indexParam),c.cloneNode(u)))),c.arrowFunctionExpression([c.cloneNode(t.itemPattern,!0),c.identifier(d),...t.indexParam===null?[]:[c.identifier(t.indexParam)]],c.blockStatement([ot(l),it(l),St(e,c.identifier(d),c.cloneNode(s),c.identifier(l.updateVar)),...l.creation,...l.mounts,c.returnStatement(c.objectExpression([c.objectProperty(c.identifier("nodes"),c.arrayExpression([c.identifier(S)])),c.objectProperty(c.identifier("entities"),c.arrayExpression([c.identifier(d)])),c.objectProperty(c.identifier("updateProps"),c.arrowFunctionExpression([c.cloneNode(p),...u===null?[]:[c.cloneNode(u)]],c.blockStatement(x))),c.objectProperty(c.identifier("update"),c.identifier(l.updateVar))]))]))}import*as I from"@babel/types";function ca(e){return I.isJSXElement(e.body)?e.body:I.isBlockStatement(e.body)&&e.body.body.length===1&&I.isReturnStatement(e.body.body[0])&&I.isJSXElement(e.body.body[0].argument)?e.body.body[0].argument:null}function br(e,t,n,r,o,i,s,a){if(!I.isArrowFunctionExpression(n)&&!I.isFunctionExpression(n)||n.async||n.generator)throw o.buildCodeFrameError("memo-dom: render callbacks must be synchronous inline arrows or function expressions");let l=ca(n),d=n.params[0],p=n.params[1];if(l===null||n.params.length<1||n.params.length>2||!I.isIdentifier(d)&&!I.isObjectPattern(d)&&!I.isArrayPattern(d)||p!==void 0&&!I.isIdentifier(p))throw o.buildCodeFrameError("memo-dom: render callbacks take an item binding pattern and optional index, then return one JSX element");let u=un(d),g=Object.keys(I.getBindingIdentifiers(u));if(g.length===0)throw o.buildCodeFrameError("memo-dom: render callback item patterns must bind at least one name");let S=I.isIdentifier(u)?u.name:g[0],x=p===void 0?null:p.name,f=null;l.openingElement.attributes=l.openingElement.attributes.filter(q=>{if(I.isJSXSpreadAttribute(q)||!I.isJSXIdentifier(q.name)||q.name.name!=="key")return!0;if(f=Ve(q.value),f===null)throw o.buildCodeFrameError("memo-dom: key={...} needs an expression");return!1});let m=A(e,"renderCallback"),C=A(e,"renderRows"),b=A(e,"renderNextUpdate"),v=A(e,"renderRowId"),F=A(e,"refreshRenderRow"),R=A(e,"renderNextItem"),k=x===null?null:A(e,"renderNextIndex"),W=rt(e),B={itemParam:S,itemPath:[],rowIdVar:v.name,keyPath:nt(f,S),sourceKey:"$render-callback",sourceLocal:!0,...I.isIdentifier(a)?{ownerIdVar:a.name}:{}},_=i(e,W,l,r,o,"row",B,v,s,v);Kt(e,W,_),t.creation.push(I.variableDeclaration("const",[I.variableDeclarator(I.cloneNode(C),I.newExpression(I.identifier("Set"),[]))])),t.updaters.push(()=>I.forOfStatement(I.variableDeclaration("const",[I.variableDeclarator(I.cloneNode(b))]),I.cloneNode(C),I.expressionStatement(I.callExpression(I.cloneNode(b),[]))));let Q=[I.expressionStatement(I.assignmentExpression("=",I.cloneNode(u,!0),I.cloneNode(R)))];k!==null&&x!==null&&Q.push(I.expressionStatement(I.assignmentExpression("=",I.identifier(x),I.cloneNode(k))));let be=I.arrowFunctionExpression([I.cloneNode(u,!0),I.cloneNode(v),...x===null?[]:[I.identifier(x)]],I.blockStatement([ot(W),it(W),I.variableDeclaration("const",[I.variableDeclarator(I.cloneNode(F),I.arrowFunctionExpression([],I.blockStatement([I.expressionStatement(I.callExpression(I.identifier(W.updateVar),[])),I.expressionStatement(I.callExpression(Y(e,"renderDescendants"),[I.cloneNode(v)]))])))]),St(e,I.cloneNode(v),I.cloneNode(a,!0),I.cloneNode(F)),...W.creation,...W.mounts,I.expressionStatement(I.callExpression(I.memberExpression(I.cloneNode(C),I.identifier("add")),[I.cloneNode(F)])),I.returnStatement(I.objectExpression([I.objectProperty(I.identifier("nodes"),I.callExpression(Y(e,"rootNodes"),[I.identifier(_)])),I.objectProperty(I.identifier("entities"),I.arrayExpression([I.cloneNode(v)])),I.objectProperty(I.identifier("updateProps"),I.arrowFunctionExpression([I.cloneNode(R),...k===null?[]:[I.cloneNode(k)]],I.blockStatement(Q))),I.objectProperty(I.identifier("update"),I.cloneNode(F)),I.objectProperty(I.identifier("dispose"),I.arrowFunctionExpression([],I.callExpression(I.memberExpression(I.cloneNode(C),I.identifier("delete")),[I.cloneNode(F)])))]))])),te=f===null?I.nullLiteral():I.arrowFunctionExpression([I.cloneNode(u,!0),...x===null?[]:[I.identifier(x)]],I.cloneNode(f));return t.creation.push(I.variableDeclaration("const",[I.variableDeclarator(I.cloneNode(m),I.objectExpression([I.objectProperty(I.identifier("create"),be),I.objectProperty(I.identifier("key"),te)]))])),m}function ua(e){return y.conditionalExpression(y.logicalExpression("||",y.binaryExpression("==",y.cloneNode(e),y.nullLiteral()),y.binaryExpression("===",y.unaryExpression("typeof",y.cloneNode(e),!0),y.stringLiteral("boolean"))),y.stringLiteral(""),y.callExpression(y.identifier("String"),[y.cloneNode(e)]))}function pa(e,t,n,r){return()=>Dt(e,t,y.cloneNode(r),o=>y.expressionStatement(y.assignmentExpression("=",y.memberExpression(y.identifier(n),y.identifier("data")),ua(o))))}function hr(e,t,n){let r=A(e,`text${t.textCounter++}`).name;if(y.isStringLiteral(n))return t.creation.push(y.variableDeclaration("const",[y.variableDeclarator(y.identifier(r),y.callExpression(y.memberExpression(y.identifier("document"),y.identifier("createTextNode")),[y.stringLiteral(n.value)]))])),r;let o=Vn(e,t);t.creation.push(y.variableDeclaration("const",[y.variableDeclarator(y.identifier(r),y.callExpression(y.memberExpression(y.identifier("document"),y.identifier("createTextNode")),[y.stringLiteral("")]))]));let i=pa(t,o,r,n);return t.creation.push(i()),t.updaters.push(i),r}function Wo(e,t){let n=!1;return y.traverseFast(e,r=>{y.isIdentifier(r,{name:t})&&(n=!0)}),n}function pt(e,t,n,r,o,i=null,s,a,l=!1,d=$e(e,r)){return y.isJSXFragment(n)?fa(e,t,n,r,o,i,s,a,l,d):ma(e,t,n,r,o,i,s,a,l,d)}function fa(e,t,n,r,o,i,s,a,l=!1,d=$e(e,r)){let p=ar(n.children,{emitText:g=>hr(e,t,g),emitNode:g=>pt(e,t,g,r,o,i,s,a,l,d),isForwarded:g=>st(e,r,g),fail:g=>{throw o.buildCodeFrameError(g)}}),u=Wn(e,t,"fragment");return t.creation.push(y.variableDeclaration("const",[y.variableDeclarator(y.identifier(u),y.callExpression(y.memberExpression(y.identifier("document"),y.identifier("createDocumentFragment")),[]))])),Ko(e,t,p,u,r,o,i,s,l,d),u}function Ko(e,t,n,r,o,i,s=null,a,l=!1,d=$e(e,o)){for(let p of n)p.type==="node"?t.creation.push(y.expressionStatement(y.callExpression(y.memberExpression(y.identifier(r),y.identifier("appendChild")),[y.identifier(p.variable)]))):p.type==="slot"?Kn(e,t,p.expression,r,d):p.type==="list"?Uo(e,t,p.expression,r,o,i,l,d,a):Ho(e,t,p.expression,r,o,i,l,d,s!==null)}function Er(e,t,n,r,o,i,s,a,l,d){return Lr(e,t,d,(p,u,g)=>{Ar(p,n,u.name,{emitText:S=>hr(e,p,S),emitNode:S=>pt(e,p,S,r,o,i,s,a,l,g),emitList:(S,x)=>Uo(e,p,S,x,r,o,l,g,s),emitCondition:(S,x)=>Ho(e,p,S,x,r,o,l,g,i!==null),isForwarded:S=>st(e,r,S),emitForwarded:(S,x)=>Kn(e,p,S,x,g),fail:S=>{throw o.buildCodeFrameError(S)}})})}function zo(e,t,n,r,o,i,s,a,l,d){let p=y.isJSXElement(n)||y.isJSXFragment(n)?[n]:[y.jsxExpressionContainer(n)];return Er(e,t,p,r,o,i,s,a,l,d)}function ma(e,t,n,r,o,i=null,s,a,l=!1,d=$e(e,r)){let p=n.openingElement,u=p.name.name;if(/^[A-Z]/.test(u)){let b=t.childCounts.get(u)??0;t.childCounts.set(u,b+1);let v=u.charAt(0).toLowerCase()+u.slice(1),F=b===0?v:`${v}${b}`,R=A(e,F).name,k=b===0?`/${u}`:`/${u}[${b}]`,W=[],B=e.componentProps.get(u);if(Gt(n.children)&&p.attributes.some(Ee=>y.isJSXAttribute(Ee)&&Oe(Ee.name)==="children"))throw o.buildCodeFrameError(`memo-dom: <${u}> cannot use both a children prop and nested JSX children`);let _=p.attributes.some(Ee=>y.isJSXSpreadAttribute(Ee)),Q=null,be=!1;if(_){Q=en(p.attributes,{attributeValue:(ne,ue)=>ne==="ref"||B?.refProps.includes(ne)===!0?bt(e,o,r,ue):ue,fail:ne=>{throw o.buildCodeFrameError(ne)}}).expression;for(let ne of Q.properties){if(!y.isObjectProperty(ne)||ne.computed||!y.isExpression(ne.value))continue;let ue=y.isIdentifier(ne.key)?ne.key.name:y.isStringLiteral(ne.key)?ne.key.value:null;if(ue!==null)if(B?.renderCallbacks.includes(ue)===!0)ne.value=br(e,t,ne.value,r,o,pt,l,d);else if(B?.renderProps.includes(ue)===!0){if(st(e,r,ne.value))continue;if(!de(ne.value))throw o.buildCodeFrameError(`memo-dom: render prop '${ue}' on <${u}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);ne.value=zo(e,t,ne.value,r,o,i,s,a,l,d)}else{if(de(ne.value))throw o.buildCodeFrameError(`memo-dom: JSX prop '${ue}' on <${u}> is not rendered by the callee; interpolate that prop in <${u}> to declare a render slot`);ue!=="ref"&&B?.refProps.includes(ue)!==!0&&zt(ne.value)&&(at(e,o,ne.value,r,s,!0),ne.value=ur(e,t,ne.value,`${ue}Callback`))}}be=Tn(e,Q,r)||s!==void 0&&Wo(Q,s.itemParam)}else for(let Ee of p.attributes){let ne=Ee,ue=Oe(ne.name),Pe=ne.value==null?y.booleanLiteral(!0):Ve(ne.value);if(Pe==null)throw o.buildCodeFrameError(`memo-dom: prop '${Oe(ne.name)}' on <${u}> must be an expression`);if(B?.renderCallbacks.includes(ue)===!0){W.push({name:ue,value:br(e,t,Pe,r,o,pt,l,d)});continue}if(ue==="ref"||B?.refProps.includes(ue)===!0){W.push({name:ue,value:bt(e,o,r,Pe)});continue}if(B?.renderProps.includes(ue)===!0){if(st(e,r,Pe)){W.push({name:ue,value:y.cloneNode(Pe)});continue}if(!de(Pe))throw o.buildCodeFrameError(`memo-dom: render prop '${ue}' on <${u}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);W.push({name:ue,value:zo(e,t,Pe,r,o,i,s,a,l,d)});continue}if(de(Pe))throw o.buildCodeFrameError(`memo-dom: JSX prop '${ue}' on <${u}> is not rendered by the callee; interpolate that prop in <${u}> to declare a render slot`);let G=zt(Pe);if(!G&&(Tn(e,Pe,r)||s!==void 0&&Wo(Pe,s.itemParam))&&(be=!0),G)at(e,o,Pe,r,s,!0);else if(y.isIdentifier(Pe)){let se=gt(o,Pe.name);se!==null&&!de(se.body)&&at(e,o,se,r,s,!0)}W.push({name:ue,value:G?ur(e,t,Pe,`${ue}Callback`):y.cloneNode(Pe)})}if(Gt(n.children)){if(p.attributes.some(ne=>y.isJSXAttribute(ne)&&Oe(ne.name)==="children"))throw o.buildCodeFrameError(`memo-dom: <${u}> cannot use both a children prop and nested JSX children`);let Ee=Er(e,t,n.children,r,o,i,s,a,l,d);Q!==null?Q.properties.push(y.objectProperty(y.identifier("children"),y.cloneNode(Ee))):W.push({name:"children",value:y.cloneNode(Ee)})}let te;if(Q!==null){let Ee=A(e,`${v}Props`);t.creation.push(y.variableDeclaration("const",[y.variableDeclarator(y.cloneNode(Ee),y.cloneNode(Q))])),te=Wt(e,u,Ee)}else te=Jn(e,u,W);let q=y.binaryExpression("+",y.cloneNode(d),y.stringLiteral(k));return t.creation.push(y.variableDeclaration("const",[y.variableDeclarator(y.identifier(R),y.callExpression(y.identifier(u),[q,y.cloneNode(d),...te.length>0?[y.arrayExpression(te)]:[]]))])),t.disposableEntities.push(y.cloneNode(q)),be&&t.updaters.push(()=>Q===null?y.expressionStatement(y.callExpression(Y(e,"setProps"),[y.binaryExpression("+",y.cloneNode(d),y.stringLiteral(k)),y.arrayExpression(te.map(Ee=>y.cloneNode(Ee)))])):Oo(e,u,d,k,Q)),R}let g=Jo(u,l),S=g&&u!=="foreignObject";if(p.attributes.find(b=>y.isJSXAttribute(b)&&Oe(b.name)==="innerHTML")!==void 0){if(g)throw o.buildCodeFrameError("memo-dom: innerHTML is only supported on HTML elements");if(n.children.some(v=>!y.isJSXText(v)||v.value.trim()!==""))throw o.buildCodeFrameError("memo-dom: an element using innerHTML cannot also have JSX children")}let f=ar(n.children,{emitText:b=>hr(e,t,b),emitNode:b=>pt(e,t,b,r,o,i,s,a,S,d),isForwarded:b=>st(e,r,b),fail:b=>{throw o.buildCodeFrameError(b)}}),m=Wn(e,t,u);if(t.creation.push(y.variableDeclaration("const",[y.variableDeclarator(y.identifier(m),$o(u,g))])),p.attributes.some(b=>y.isJSXSpreadAttribute(b))){let b=en(p.attributes,{attributeValue:(R,k)=>R==="ref"?bt(e,o,r,k):k,eventValue:(R,k)=>{let W=sr(e,o,k,R,r,s,a),B=A(e,`${R}Handler`);return t.creation.push(y.variableDeclaration("const",[y.variableDeclarator(y.cloneNode(B),W)])),B},fail:R=>{throw o.buildCodeFrameError(R)}}),v=A(e,`${u}Props`);t.creation.push(y.variableDeclaration("const",[y.variableDeclarator(y.cloneNode(v),y.cloneNode(b.expression))]));let F=R=>y.expressionStatement(y.callExpression(Y(e,"patchDomProps"),[y.identifier(m),y.cloneNode(R),y.stringLiteral(e.rootId),y.arrayExpression(b.safeEventKeys.map(k=>y.stringLiteral(k)))]));t.creation.push(F(v)),mr(e,t,y.identifier(m),d,y.memberExpression(y.cloneNode(v),y.identifier("ref"))),t.updaters.push(()=>F(b.expression))}else for(let b of p.attributes){let v=b,F=Oe(v.name);if(F==="ref"){let Q=Ve(v.value);if(Q===null)throw o.buildCodeFrameError("memo-dom: ref needs an expression");mr(e,t,y.identifier(m),d,bt(e,o,r,Q));continue}if(F==="key")throw o.buildCodeFrameError("memo-dom: key={...} is only meaningful on list rows: items.map(item => <Row key={item.id} />)");if(/^on[A-Z]/.test(F)){let Q=Ve(v.value);if(Q==null)throw o.buildCodeFrameError(`memo-dom: ${F} needs a handler expression (L1)`);let be=sr(e,o,Q,F,r,s,a),te=t.delegatedEventBindings.get(F);t.creation.push(te===void 0?y.expressionStatement(y.assignmentExpression("=",y.memberExpression(y.identifier(m),y.identifier(F.toLowerCase())),be)):y.expressionStatement(y.callExpression(Y(e,"setDelegatedEvent"),[y.identifier(te),y.identifier(m),be])));continue}if(y.isStringLiteral(v.value)){F==="class"||F==="className"?t.creation.push(y.expressionStatement(y.callExpression(Y(e,"setClassValue"),[y.identifier(m),y.stringLiteral(v.value.value)]))):F==="style"?t.creation.push(y.expressionStatement(y.callExpression(Y(e,"setStyleValue"),[y.identifier(m),y.stringLiteral(v.value.value)]))):lr(F,g)!==null?t.creation.push(cr(m,F,y.stringLiteral(v.value.value))):dr(F,g)?t.creation.push(jn(m,F,y.stringLiteral(v.value.value))):g?t.creation.push(y.expressionStatement(y.callExpression(Y(e,"setDomValue"),[y.identifier(m),y.stringLiteral(F),y.stringLiteral(v.value.value)]))):t.creation.push(y.expressionStatement(y.callExpression(y.memberExpression(y.identifier(m),y.identifier("setAttribute")),[y.stringLiteral(F),y.stringLiteral(v.value.value)])));continue}let R=v.value==null?y.booleanLiteral(!0):Ve(v.value);if(R==null||y.isStringLiteral(R))throw o.buildCodeFrameError(`memo-dom: attribute '${F}' needs a string or an expression (L1)`);let k=y.cloneNode(R);if(F==="style"){let Q=()=>y.expressionStatement(y.callExpression(Y(e,"setStyleValue"),[y.identifier(m),y.cloneNode(k)]));t.creation.push(Q()),t.updaters.push(Q);continue}let W=Vn(e,t),B=lr(F,g),_=()=>F==="class"||F==="className"?Dt(t,W,y.callExpression(Y(e,"classValue"),[y.cloneNode(k)]),Q=>y.expressionStatement(y.callExpression(Y(e,"setClassValue"),[y.identifier(m),Q]))):B!==null?Dt(t,W,y.cloneNode(k),Q=>cr(m,B,Q)):dr(F,g)?Dt(t,W,y.cloneNode(k),Q=>jn(m,F,Q)):g?Dt(t,W,y.cloneNode(k),Q=>y.expressionStatement(y.callExpression(Y(e,"setDomValue"),[y.identifier(m),y.stringLiteral(F),Q]))):Dt(t,W,y.cloneNode(k),Q=>jn(m,F,Q));t.creation.push(_()),t.updaters.push(_)}return Ko(e,t,f,m,r,o,i,s,S,d),m}function Uo(e,t,n,r,o,i,s=!1,a=$e(e,o),l){Vo(e,t,n,r,o,i,pt,Er,s,a,l)}function Ho(e,t,n,r,o,i,s=!1,a=$e(e,o),l=!1){Xo(e,t,n,r,o,i,pt,s,a,l)}function _o(e,t,n,r,o,i=!1,s=o,a=!1,l){return fr(e,t,n,r,o,pt,i,s,a,l)}import*as De from"@babel/types";function Zo(e){if(e.isFunctionDeclaration())return e.node;if(!e.isVariableDeclarator())return null;let t=e.node.init;return t&&(De.isArrowFunctionExpression(t)||De.isFunctionExpression(t))?t:null}function Yo(e,t,n,r,o,i=!1){let s=gt(t,n);if(s!==null){at(e,t,s,r,o,i);return}let a=t.scope.getBinding(n);if(a===void 0||a.scope.path.isProgram()!==!0||!e.helpers.has(n))return;let l=Zo(a.path);l!==null&&rn(e,l,i)}function qo(e,t,n,r,o,i=!1){if(De.isArrowFunctionExpression(n)||De.isFunctionExpression(n)){if(de(n.body))return;at(e,t,n,r,o,i)}else De.isIdentifier(n)&&Yo(e,t,n.name,r,o,i)}function Qo(e,t,n,r=!1){let o=t.scope.getBinding(n);if(o===void 0||o.scope.path.isProgram()!==!0||!e.helpers.has(n))return;let i=Zo(o.path);i!==null&&rn(e,i,r)}function Go(e,t,n,r=!1){if(De.isArrowFunctionExpression(n)||De.isFunctionExpression(n)){if(de(n.body))return;rn(e,n,r)}else De.isIdentifier(n)&&Qo(e,t,n.name,r)}function ei(e,t,n,r,o){t.traverse({CallExpression(i){let s=i.getFunctionParent()===t,a=i.node.callee,l=De.isIdentifier(a,{name:"effect"})&&i.scope.getBinding("effect")===void 0;if(De.isIdentifier(a,{name:"cleanup"})&&i.scope.getBinding("cleanup")===void 0){if(!s)throw i.buildCodeFrameError("memo-dom: cleanup(disposer) must run directly during component factory initialization");let d=i.node.arguments[0];if(i.node.arguments.length!==1||d===void 0||!De.isExpression(d))throw i.buildCodeFrameError("memo-dom: cleanup(disposer) requires exactly one disposer expression");i.node.callee=Y(e,"cleanup"),i.node.arguments.unshift(De.identifier(r))}if(s){De.isIdentifier(a)&&Yo(e,t,a.name,n,o);for(let d of i.node.arguments)qo(e,t,d,n,o,l)}},NewExpression(i){if(i.getFunctionParent()===t)for(let s of i.node.arguments)qo(e,t,s,n,o)}})}function ti(e,t){t.traverse({CallExpression(n){if(n.getFunctionParent()!==null)return;let r=De.isIdentifier(n.node.callee,{name:"effect"})&&n.scope.getBinding("effect")===void 0;De.isIdentifier(n.node.callee)&&Qo(e,t,n.node.callee.name);for(let o of n.node.arguments)Go(e,t,o,r)},NewExpression(n){if(n.getFunctionParent()===null)for(let r of n.node.arguments)Go(e,t,r)}})}function ni(e){for(let t of e.helpers.values())t.node.async&&rn(e,t.node)}function ri(e){e.traverse({CallExpression(t){if(De.isIdentifier(t.node.callee,{name:"cleanup"})&&t.scope.getBinding("cleanup")===void 0)throw t.buildCodeFrameError("memo-dom: cleanup(disposer) is only valid directly inside a component factory")}})}import*as Ke from"@babel/types";import*as Ne from"@babel/types";function oi(e){return e.reduce((t,n)=>Ne.logicalExpression("||",t,n))}function ii(e,t){let n=()=>Ne.identifier(e),r=oi(t.map(i=>Ne.binaryExpression("===",n(),Ne.numericLiteral(i)))),o=oi(t.map(i=>Ne.callExpression(Ne.memberExpression(n(),Ne.identifier("has")),[Ne.numericLiteral(i)])));return Ne.logicalExpression("||",Ne.binaryExpression("===",n(),Ne.nullLiteral()),Ne.conditionalExpression(Ne.binaryExpression("===",Ne.unaryExpression("typeof",n()),Ne.stringLiteral("number")),r,o))}function si(e,t,n,r,o,i){let s=new Map(r.map((u,g)=>[u,g])),a=0,l=[...o.map(u=>({order:s.get(u.declaration)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:u.sources,statement:kr(u)})),...i.map(u=>({order:s.get(u.statement)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:u.sources,statement:Ke.blockStatement([...u.resets.map(g=>Ke.expressionStatement(Ke.assignmentExpression("=",Ke.identifier(g.binding),Ke.cloneNode(g.source,!0)))),Ke.cloneNode(u.statement,!0)])}))].sort((u,g)=>u.order-g.order||u.sequence-g.sequence),d=e.instanceReasonIds.get(t),p=[];for(let u of l){let g=n===null||d===void 0?null:u.sources.map(C=>d.get(C)).filter(C=>C!==void 0).sort((C,b)=>C-b),S=g===null||g.length===u.sources.length?g:null,x=S?.join(" ")??"*",f=p.at(-1),m=f?.reasons?.join(" ")??"*";f!==void 0&&m===x?f.statements.push(u.statement):p.push({reasons:S,statements:[u.statement]})}return Ke.blockStatement(p.map(u=>u.reasons===null||n===null?Ke.blockStatement(u.statements):Ke.ifStatement(ii(n,u.reasons),Ke.blockStatement(u.statements))))}import*as V from"@babel/types";function on(e){return!V.isReturnStatement(e)||!V.isJSXElement(e.argument)&&!V.isJSXFragment(e.argument)?null:{jsx:e.argument,statement:e}}function yr(e){return V.isBlockStatement(e)?e.body.length===1?on(e.body[0]):null:on(e)}function ga(e){let t=[];return e.get("body").traverse({ReturnStatement(n){t.push(n.node)},Function(n){n.skip()}}),t}function ba(e){if(V.isFunctionDeclaration(e))return!0;if(V.isVariableDeclaration(e))return e.declarations.every(t=>t.init==null||V.isFunction(t.init)||ha(t.init));if(V.isSwitchStatement(e)||V.isIfStatement(e)){let t=!0;return V.traverseFast(e,n=>{(V.isCallExpression(n)||V.isOptionalCallExpression(n)||V.isNewExpression(n)||V.isAwaitExpression(n)||V.isYieldExpression(n)||V.isThrowStatement(n)||V.isTaggedTemplateExpression(n)||V.isUpdateExpression(n))&&(t=!1)}),t}return V.isTypeScript(e)}function ha(e){let t=!0;return V.traverseFast(e,n=>{(V.isCallExpression(n)||V.isOptionalCallExpression(n)||V.isNewExpression(n)||V.isAwaitExpression(n)||V.isYieldExpression(n)||V.isTaggedTemplateExpression(n)||V.isAssignmentExpression(n)||V.isUpdateExpression(n))&&(t=!1)}),t}function Ea(e){if(!e.cases.some(r=>r.test==null))return null;let t=[],n=[];for(let r of e.cases){if(r.consequent.length!==1)return null;let o=on(r.consequent[0]);if(o===null)return null;let i=t.length;t.push(o.jsx),n.push(V.switchCase(r.test===null?null:V.cloneNode(r.test),[V.returnStatement(V.numericLiteral(i))]))}return{pick:V.arrowFunctionExpression([],V.blockStatement([V.switchStatement(V.cloneNode(e.discriminant),n)])),branches:t,statements:new Set([e])}}function ai(e,t){let n=e.node.body.body,r=ga(e),o=n.at(-1);if(r.length===1&&o!==void 0){let s=on(o);if(s!==null)return s}if(o&&V.isIfStatement(o)&&o.alternate!=null){let s=o.alternate,a=yr(o.consequent),l=yr(s);if(a!==null&&l!==null&&r.length===2)return{pick:V.arrowFunctionExpression([],V.conditionalExpression(V.cloneNode(o.test),V.numericLiteral(0),V.numericLiteral(1))),branches:[a.jsx,l.jsx],statements:new Set([o])}}if(o&&V.isSwitchStatement(o)){let s=Ea(o);if(s!==null&&s.branches.length===r.length)return s}let i=o===void 0?null:on(o);if(i!==null){let s=[],a=[],l=new Set([o]),d=-1,p=!0;for(let u=0;u<n.length-1;u++){let g=n[u];if(V.isIfStatement(g)&&g.alternate==null){let S=yr(g.consequent);if(S!==null){d===-1&&(d=u),s.push(V.cloneNode(g.test)),a.push(S.jsx),l.add(g);continue}}if(d!==-1&&!ba(g)){p=!1;break}}if(a.push(i.jsx),p&&a.length===r.length&&a.length>1){let u=V.numericLiteral(a.length-1);for(let g=s.length-1;g>=0;g--)u=V.conditionalExpression(s[g],V.numericLiteral(g),u);return{pick:V.arrowFunctionExpression([],u),branches:a,statements:l}}}throw e.buildCodeFrameError(`memo-dom: component '${t}' has unsupported JSX return control flow; use a tail chain of JSX early returns, a terminal JSX if/else, or an exhaustive JSX switch`)}function li(e,t,n){let r=t.node,o=ai(t,n),i=e.componentProps.get(n),s=i.params.length,a=e.listedSites.get(n)??[],l=e.linkedComponentRows.get(n)??[],d=a.some(q=>q.sourceLocal===!0)||l.some(q=>q.sourceLocal),p=Ct(e,n),u=p&&l.length===0?pn(i):null,g=u?.length??s,S=rt(e,p),x=e.instanceDerivations.get(n),f=e.instanceControlFlow.get(n),m=e.effects.get(n),C=m?.some(q=>q.localReads.size>0||q.localDerivationReads.size>0||q.conditionLocalReads.size>0||q.conditionLocalDerivationReads.size>0)===!0;(e.selectiveDerivationComponents.has(n)||e.targetedListComponents.has(n)||C)&&(S.reasonVar=A(e,"reasons").name);let b=A(e,"id").name,v=p?null:A(e,"parent").name,F=p&&d?A(e,"owner").name:null,R=new Map;if(p)for(let q of e.componentHostEvents.get(n)??[]){let Ee=A(e,`${q}Binding`).name;R.set(q,Ee),S.delegatedEventBindings.set(q,Ee)}let k=s>0&&!p?A(e,"props").name:null;Nt(e).registerComponentId(n,b);let W;if((a.length>0||l.length>0)&&i.bindings.length>0){let q=[...a.map(G=>nt(G.keyExpr??null,G.itemParam??"")),...l.map(G=>G.keyPath)],Ee=JSON.stringify(q[0]),ne=q.every(G=>JSON.stringify(G)===Ee)?q[0]:null,ue=mn(i,"item"),Pe=Ue(i);W={itemParam:ue??Pe??i.bindings[0],itemPath:ue===null&&Pe!==null?["item"]:[],rowIdVar:b,...p?{refreshVar:S.updateVar}:{},keyPath:ne,sourceKey:a[0]?.sourceKey??l[0]?.sourceKey??"",sourceLocal:d,...d?{ownerIdVar:F??v}:{}}}ei(e,t,n,b,W);let B="jsx"in o?pt(e,S,o.jsx,n,t,null,W):ya(e,S,o,n,t,b),_=p&&"jsx"in o&&M.isJSXElement(o.jsx);if(p&&Kt(e,S,B),x!==void 0)for(let q of x)q.declaration.kind="let";(x!==void 0||f!==void 0)&&S.updaters.unshift(()=>si(e,n,S.reasonVar,r.body.body,x??[],f??[])),m!==void 0&&C&&S.updaters.push(()=>zr(e,n,b,S.reasonVar,m,S));let Q=new Set(m?.map(q=>q.statement)??[]),be=r.body.body.filter(q=>!("jsx"in o?q===o.statement:o.statements.has(q))&&!Q.has(q));s>0&&!p&&S.updaters.unshift(()=>M.blockStatement(Bn(i,i.params.map((q,Ee)=>M.memberExpression(M.identifier(k),M.numericLiteral(Ee),!0)))));let te=[ot(S)];if(s>0&&!p){let q=vr(i,i.params.map((Ee,ne)=>M.memberExpression(M.identifier(k),M.numericLiteral(ne),!0)));q!==null&&te.push(q)}if(te.push(...be,it(S),...p?[]:[St(e,M.identifier(b),M.identifier(v),M.identifier(S.updateVar))]),s>0&&!p&&te.push(M.expressionStatement(M.callExpression(Y(e,"registerProps"),[M.identifier(b),M.identifier(k)]))),te.push(...S.creation,...S.mounts),m!==void 0&&te.push(...Kr(e,b,m)),p){let q=Array.from({length:g},(ne,ue)=>A(e,`nextProp${ue}`)),Ee=u===null?Bn(i,q):u.map(({local:ne},ue)=>M.expressionStatement(M.assignmentExpression("=",M.identifier(ne),M.cloneNode(q[ue]))));te.push(M.returnStatement(M.objectExpression([M.objectProperty(M.identifier("nodes"),_?M.identifier(B):M.callExpression(Y(e,"rootNodes"),[M.identifier(B)])),M.objectProperty(M.identifier("entities"),M.arrayExpression([])),M.objectProperty(M.identifier("update"),M.identifier(S.updateVar)),...g>0?[M.objectProperty(M.identifier("updateProps"),M.arrowFunctionExpression(q,M.blockStatement(Ee)))]:[],...S.disposableCallbacks.length>0?[M.objectProperty(M.identifier("dispose"),M.arrowFunctionExpression([],M.blockStatement([...S.disposableCallbacks].reverse().map(ne=>M.ifStatement(M.binaryExpression("!==",M.cloneNode(ne),M.nullLiteral()),M.expressionStatement(M.callExpression(M.cloneNode(ne),[])))))))]:[]])))}else te.push(M.returnStatement(M.identifier(B)));r.params=p?[...u===null?i.params.map(Nr):u.map(({local:q})=>M.identifier(q)),M.identifier(b),...F===null?[]:[M.identifier(F)],...[...R.values()].map(q=>M.identifier(q))]:s>0?[M.identifier(b),M.identifier(v),M.identifier(k)]:[M.identifier(b),M.identifier(v)],r.body=M.blockStatement(te)}function ya(e,t,n,r,o,i){let s=A(e,"returnRoot").name,a=A(e,"returnRegion").name,l=M.identifier(i),d=M.binaryExpression("+",M.cloneNode(l),M.stringLiteral("/$return"));return t.creation.push(M.variableDeclaration("const",[M.variableDeclarator(M.identifier(s),M.callExpression(M.memberExpression(M.identifier("document"),M.identifier("createDocumentFragment")),[]))])),t.creation.push(M.variableDeclaration("const",[M.variableDeclarator(M.identifier(a),M.callExpression(Y(e,"createCondRegion"),[M.identifier(s),M.cloneNode(d),M.cloneNode(n.pick),M.arrayExpression(n.branches.map(p=>_o(e,p,r,o,d,!1,l,!0,t.usedConds)))]))])),t.updaters.push(()=>M.expressionStatement(M.callExpression(M.memberExpression(M.identifier(a),M.identifier("update")),[]))),s}import*as le from"@babel/types";function Sa(e){return!le.isIdentifier(e.id)||!/^[A-Z]/.test(e.id.name)||!le.isArrowFunctionExpression(e.init)&&!le.isFunctionExpression(e.init)||!de(e.init.body)?null:e.init}function xa(e,t,n){if(t.async||t.generator)throw n.buildCodeFrameError(`memo-dom: component '${e}' must be synchronous`);if(le.isFunctionExpression(t)&&t.id!=null&&t.id.name!==e)throw n.buildCodeFrameError(`memo-dom: named component function expression '${t.id.name}' must match binding '${e}'`);let r=le.functionDeclaration(le.identifier(e),t.params.map(o=>le.cloneNode(o,!0)),le.isBlockStatement(t.body)?le.cloneNode(t.body,!0):le.blockStatement([le.returnStatement(le.cloneNode(t.body,!0))]));return r.returnType=t.returnType==null?null:le.cloneNode(t.returnType,!0),r.typeParameters=t.typeParameters==null?null:le.cloneNode(t.typeParameters,!0),r.loc=t.loc,r}function di(e,t,n){if(e.kind!=="const")return[t?le.exportNamedDeclaration(le.cloneNode(e,!0)):le.cloneNode(e,!0)];let r=[];for(let o of e.declarations){let i=Sa(o),s;i===null?s=le.variableDeclaration("const",[le.cloneNode(o,!0)]):s=xa(o.id.name,i,n),r.push(t?le.exportNamedDeclaration(s):s)}return r.length>0&&le.inheritsComments(r[0],e),r}function sn(e){let t=[],n=!1;for(let r of e.get("body")){let o=r.node;if(le.isVariableDeclaration(o)){let i=di(o,!1,r);n||=i.some(s=>le.isFunctionDeclaration(s)),t.push(...i);continue}if(le.isExportNamedDeclaration(o)&&le.isVariableDeclaration(o.declaration)){let i=di(o.declaration,!0,r);n||=i.some(s=>le.isExportNamedDeclaration(s)&&le.isFunctionDeclaration(s.declaration)),t.push(...i);continue}t.push(o)}n&&(e.set("body",t),e.scope.crawl())}function Ca(e,t){let n=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#`;for(let r of t.get("body")){let o=r.node;if($.isExportNamedDeclaration(o)&&(o=o.declaration),!(!$.isVariableDeclaration(o)||o.kind!=="const"))for(let i of o.declarations){if(!$.isIdentifier(i.id)||i.init==null)continue;let s=i.id.name;if(!e.computeds.has(s))continue;o.kind="let";let a=$.cloneNode(i.init),l=A(e,`${s}Next`),d=$.expressionStatement($.callExpression(Y(e,"register"),[$.objectExpression([$.objectProperty($.identifier("id"),$.stringLiteral(`${n}${s}`)),$.objectProperty($.identifier("parent"),$.nullLiteral()),$.objectProperty($.identifier("depth"),$.unaryExpression("-",$.numericLiteral(1))),$.objectProperty($.identifier("render"),$.arrowFunctionExpression([],$.blockStatement([$.variableDeclaration("const",[$.variableDeclarator(l,a)]),$.ifStatement($.callExpression(Y(e,"computedChanged"),[$.identifier(s),$.cloneNode(l)]),$.blockStatement([$.expressionStatement($.assignmentExpression("=",$.identifier(s),$.cloneNode(l))),$.expressionStatement($.callExpression(Y(e,"commitWrites"),[Ht(e,[s])]))]))])))])]));r.insertAfter(d)}}}function Pa(e,t){let n=new Map(t.get("body").map(r=>[r.node,r]));for(let r of e.moduleControlFlow){let o=n.get(r.statement);if(o===void 0)continue;let i=new Map(r.bindings.map(a=>[a,A(e,`${a}Previous`)])),s=[$.variableDeclaration("const",r.bindings.map(a=>$.variableDeclarator($.cloneNode(i.get(a)),$.identifier(a)))),$.cloneNode(r.statement,!0),...r.bindings.map(a=>$.ifStatement($.callExpression(Y(e,"computedChanged"),[$.cloneNode(i.get(a)),$.identifier(a)]),$.blockStatement([$.expressionStatement($.callExpression(Y(e,"commitWrites"),[Ht(e,[a])]))])))];o.insertAfter($.expressionStatement($.callExpression(Y(e,"register"),[$.objectExpression([$.objectProperty($.identifier("id"),$.stringLiteral(r.entityId)),$.objectProperty($.identifier("parent"),$.nullLiteral()),$.objectProperty($.identifier("depth"),$.unaryExpression("-",$.numericLiteral(1))),$.objectProperty($.identifier("render"),$.arrowFunctionExpression([],$.blockStatement(s)))])])))}}function Sr(e,t={}){let n=ln(t),r=new WeakSet;return{name:"memo-dom",visitor:{Program:{enter(i){sn(i),Rn(n,i),dn(n,i),Ln(n,i),ti(n,i),ni(n)},exit(i){Ur(n,i),ri(i),Hr(i),i.traverse({JSXElement(a){throw a.buildCodeFrameError("memo-dom: JSX outside a component function \u2014 components must be top-level function declarations (L1)")},JSXFragment(a){throw a.buildCodeFrameError("memo-dom: JSX outside a component function - components must be top-level function declarations")}});let s=tr(n);n.computeds.size>0&&Ca(n,i),n.moduleControlFlow.length>0&&Pa(n,i),s&&n.header.push(s);for(let a=n.header.length-1;a>=0;a--)i.unshiftContainer("body",n.header[a]);i.unshiftContainer("body",$.importDeclaration([$.importNamespaceSpecifier($.identifier(Nt(n).runtimeId))],$.stringLiteral(n.runtimePath)))}},FunctionDeclaration(i){let s=i.node.id?.name;!s||!n.comps.has(s)||r.has(i.node)||(r.add(i.node),li(n,i,s),i.skip())}}}}function xr(e,t={}){let n=wa(e,{filename:t.moduleId??"./component.tsx",plugins:[[va,{}],[Sr,t],[ka,{isTSX:!0}]],configFile:!1,babelrc:!1});if(!n||n.code==null)throw new Error("memo-dom: compilation produced no output");return n.code}import{posix as Ut}from"node:path";import{transformSync as Ci}from"@babel/core";import Pi from"@babel/plugin-syntax-jsx";import wi from"@babel/plugin-transform-typescript";import*as z from"@babel/types";function Na(e,t,n){let r=e.get(t);r===void 0&&(r=new Map,e.set(t,r));let o=r.get(n);return o===void 0&&(o={keys:new Set,rootFallback:!1},r.set(n,o)),o}function Ia(e,t,n,r){if(n.type==="state"){r.keys.add(n.key);return}if(n.type==="root"){r.rootFallback=!0;return}if(n.type==="local")return;let o=e.get(t)?.get(n.name);if(o===void 0){r.rootFallback=!0;return}r.rootFallback||=o.rootFallback;let i=n.path.length===0?"":`.${n.path.join(".")}`;for(let s of o.keys)r.keys.add(`${s}${i}`)}function ci(e,t){let n=new Map;for(let s of e.values())for(let a of s.edges)n.set(a.target,(n.get(a.target)??0)+1);let r=new Map,o=new Map(n),i=[...t];for(;i.length>0;){let s=i.shift();for(let a of e.get(s)?.edges??[]){for(let[d,p]of Object.entries(a.propSources??{})){let u=Na(r,a.target,d);for(let g of p)Ia(r,s,g,u)}let l=(o.get(a.target)??1)-1;o.set(a.target,l),l===0&&i.push(a.target)}}return new Map([...r].map(([s,a])=>[s,new Map([...a].map(([l,d])=>[l,{keys:[...d.keys].sort(),rootFallback:d.rootFallback}]))]))}function Ra(e){let t=new Set,n=new Set,r=o=>{if(n.has(o))throw new Error(`memo-dom: recursive cross-module component graph at '${o}'`);if(!t.has(o)){n.add(o);for(let i of e.get(o)?.edges??[])r(i.target);n.delete(o),t.add(o)}};for(let o of e.keys())r(o)}function ui(e,t){let n=new Map(e.map(p=>[p.key,p]));Ra(n);let r=new Map,o=new Map;for(let p of n.values())for(let u of p.edges){if(!n.has(u.target))throw new Error(`memo-dom: component '${p.key}' references unknown factory '${u.target}'`);let g=r.get(u.target)??new Set;if(g.add(u.mode),r.set(u.target,g),u.mode==="row"){let S=o.get(u.target)??[];S.push({keyPath:u.keyPath===void 0||u.keyPath===null?null:[...u.keyPath],sourceKey:u.sourceKey??"",sourceLocal:u.sourceLocal??!1}),o.set(u.target,S)}}for(let[p,u]of r)if(u.size>1)throw new Error(`memo-dom: component '${p}' is used both as a keyed row and a static child`);let i=new Map,s=[...n.keys()].filter(p=>!r.has(p));for(let p of s)i.set(p,new Set([t]));let a=[...s];for(;a.length>0;){let p=a.shift(),u=i.get(p);if(u!==void 0)for(let g of n.get(p)?.edges??[]){let S=i.get(g.target)??new Set,x=S.size;for(let f of u)S.add(`${f}${g.suffix}`);i.set(g.target,S),S.size!==x&&a.push(g.target)}}let l=new Map;for(let p of n.keys())l.set(p,[...i.get(p)??[]].sort());let d=ci(n,s);return{paths:l,rows:o,propSources:d}}import"@babel/types";import*as he from"@babel/types";function pi(e){let t=e;for(;he.isTSAsExpression(t)||he.isTSTypeAssertion(t)||he.isTSNonNullExpression(t)||he.isTSSatisfiesExpression(t);)t=t.expression;return t}function Fa(e,t,n){let r=pi(n);if(he.isIdentifier(r))return!e.state.has(r.name)||t.getBinding(r.name)?.scope.path.isProgram()!==!0?null:Ye(e,r.name);if(!he.isMemberExpression(r))return null;let o=ke(r);return o===null||!e.state.has(o)||t.getBinding(o)?.scope.path.isProgram()!==!0?null:Ye(e,xe(r)??o)}function Ma(e,t){let n=pi(t);if(he.isIdentifier(n)){let a=Ze(e,n.name);return a===null?null:{type:"prop",name:a,path:[]}}if(!he.isMemberExpression(n))return null;let r=ke(n),o=xe(n);if(r===null||o===null)return null;if(Ue(e)===r){let[a,...l]=o.split(".").slice(1);return a===void 0?null:{type:"prop",name:a,path:l}}let s=Ze(e,r);return s===null?null:{type:"prop",name:s,path:o.split(".").slice(1)}}function Da(e,t){let n=!1,r=Ue(e);return Ae(t,o=>{he.isIdentifier(o)&&(o.name===r||Ze(e,o.name)!==null)&&(n=!0)}),n}function La(e){return he.isStringLiteral(e)||he.isNumericLiteral(e)||he.isBooleanLiteral(e)||he.isNullLiteral(e)||he.isBigIntLiteral(e)||he.isTemplateLiteral(e)}function Aa(e,t,n,r){let o=Fa(e,n,r);if(o!==null)return{type:"state",key:o};let i=e.componentProps.get(t),s=Ma(i,r);if(s!==null)return s;let a=he.isIdentifier(r)?r.name:he.isMemberExpression(r)?ke(r):null;return a!==null&&(e.instanceState.get(t)?.has(a)===!0||e.instanceDerivedBindings.get(t)?.has(a)===!0)||cn(e,r).size>0||Da(i,r)?{type:"root"}:La(r)?{type:"local"}:{type:"root"}}function Cr(e,t,n,r){let o=e.get(t)??{},i=o[n]??[],s=JSON.stringify(r);i.some(a=>JSON.stringify(a)===s)||(i.push(r),i.sort((a,l)=>JSON.stringify(a).localeCompare(JSON.stringify(l)))),o[n]=i,e.set(t,o)}function ja(e){return he.isJSXIdentifier(e.name)?e.name.name:null}function fi(e,t){let n=new Map;return e.compPaths.get(t).traverse({JSXOpeningElement(r){let o=r.node.name;if(!he.isJSXIdentifier(o)||!/^[A-Z]/.test(o.name))return;let i=e.componentProps.get(o.name);for(let s of r.get("attributes")){if(s.isJSXSpreadAttribute()){for(let d of i?.names??[])d==="ref"||i?.refProps.includes(d)||Cr(n,o.name,d,{type:"root"});continue}if(!s.isJSXAttribute())continue;let a=ja(s.node);if(a===null||a==="key"||a==="ref"||i?.refProps.includes(a)===!0)continue;let l=s.node.value;if(!he.isJSXExpressionContainer(l)||!he.isExpression(l.expression)){Cr(n,o.name,a,{type:"local"});continue}Cr(n,o.name,a,Aa(e,t,s.scope,l.expression))}}}),n}function mi(e,t){let n=new Map;return e.traverse({FunctionDeclaration(r){let o=r.node.id?.name;if(o!==void 0&&/^[A-Z]/.test(o)&&r.scope.parent?.path.isProgram()===!0&&je(r)){let i=fn(r.node.params);n.set(o,{key:`${t}#${o}`,props:[...i.names],objectProps:i.mode==="object",acceptsUnknownProps:i.acceptsUnknown,hasWholeDefault:i.hasWholeDefault,listLightweight:!1,delegatedEvents:Xt(r.node.body),renderProps:[],renderCallbacks:[],refProps:[],subtreeReads:[]})}r.skip()}}),n}function gi(e,t,n){let r=e.componentProps.get(n);return{key:`${t}#${n}`,props:[...r.names],objectProps:r.mode==="object",acceptsUnknownProps:r.acceptsUnknown,hasWholeDefault:r.hasWholeDefault,listLightweight:kn(e,n),delegatedEvents:[...e.componentHostEvents.get(n)??[]],renderProps:[...r.renderProps],renderCallbacks:[...r.renderCallbacks],refProps:[...r.refProps],subtreeReads:[...Mn(e,n)].map(o=>Ye(e,o)).sort()}}function On(e,t){return e.importedComponents.get(t)?.key??`${e.moduleId}#${t}`}function bi(e,t){let n=[];for(let r of t.comps.keys()){let o=[],i=fi(t,r);for(let[s,a]of t.childRefCounts.get(r)??[]){let l=On(t,s),d=i.get(s);o.push({target:l,suffix:`/${s}`,mode:"static",...d===void 0?{}:{propSources:d}}),a>1&&o.push({target:l,suffix:`/${s}[*]`,mode:"static",...d===void 0?{}:{propSources:d}})}for(let[s,a]of t.conditionalComponentSites)for(let l of a){if(l.owner!==r)continue;let d=i.get(s);o.push({target:On(t,s),suffix:`/${l.suffix}`,mode:"static",...d===void 0?{}:{propSources:d}})}for(let[s,a]of t.rowComponentSites)for(let l of a){if(l.owner!==r)continue;let d=i.get(s);o.push({target:On(t,s),suffix:`/${l.suffix}`,mode:"static",...d===void 0?{}:{propSources:d}})}for(let[s,a]of t.listedSites)for(let l of a)l.owner===r&&o.push({target:On(t,s),suffix:`/${l.suffix}/Row[*]`,mode:"row",keyPath:nt(l.keyExpr??null,l.itemParam??""),sourceKey:l.sourceLocal===!0?l.sourceKey??"":Ye(t,l.sourceKey??""),sourceLocal:l.sourceLocal??!1,...i.get(s)===void 0?{}:{propSources:i.get(s)}});n.push({key:`${e}#${r}`,moduleId:e,local:r,edges:o})}return n}function vi(e){let t=e.replace(/\\/g,"/"),n=Ut.normalize(t);return t.startsWith("./")&&!n.startsWith("../")?`./${n}`:n}function ki(e){return{...e.runtimePath===void 0?{}:{runtimePath:e.runtimePath},...e.rootId===void 0?{}:{rootId:e.rootId}}}function Ja(e){let t=new Map,n=(r,o,i)=>{t.set(`${r}\0${o}\0${i}`,{target:r,prop:o,kind:i})};for(let[r,o]of e.compPaths)o.traverse({JSXElement(i){let s=i.node.openingElement,a=s.name;if(!z.isJSXIdentifier(a)||!/^[A-Z]/.test(a.name))return;let l=e.importedComponents.get(a.name)?.key??(e.comps.has(a.name)?`${e.moduleId}#${a.name}`:null);if(l!==null){for(let d of s.attributes){if(!z.isJSXAttribute(d))continue;let p=z.isJSXIdentifier(d.name)?d.name.name:d.name.name.name,u=d.value;z.isJSXElement(u)||z.isJSXFragment(u)||z.isJSXExpressionContainer(u)&&z.isExpression(u.expression)&&(de(u.expression)||st(e,r,u.expression))?n(l,p,"jsx"):n(l,p,"scalar")}i.node.children.some(d=>!z.isJSXText(d)||d.value.trim()!=="")&&n(l,"children","jsx")}}});return[...t.values()].sort((r,o)=>r.target.localeCompare(o.target)||r.prop.localeCompare(o.prop)||r.kind.localeCompare(o.kind))}function hi(e,t){return[...new Set(t.flatMap(n=>{let r=e.importedComponents.get(n);return r!==void 0?[r.key]:e.comps.has(n)?[`${e.moduleId}#${n}`]:[]}))].sort()}function kt(e,t,n){for(;z.isTSAsExpression(e)||z.isTSTypeAssertion(e)||z.isTSNonNullExpression(e);)e=e.expression;if(z.isIdentifier(e)){t.has(e.name)&&n.add(e.name);return}if(z.isConditionalExpression(e)){kt(e.consequent,t,n),kt(e.alternate,t,n);return}if(z.isLogicalExpression(e)){kt(e.right,t,n);return}if(z.isObjectExpression(e)){for(let r of e.properties)z.isObjectProperty(r)&&z.isExpression(r.value)&&kt(r.value,t,n);return}if(z.isArrayExpression(e))for(let r of e.elements)r!=null&&!z.isSpreadElement(r)&&kt(r,t,n)}function Ei(e,t){let n=new Set;if(z.isExpression(e.body))return kt(e.body,t,n),[...n];let r=o=>{if(!z.isFunction(o)){if(z.isReturnStatement(o)){z.isExpression(o.argument)&&kt(o.argument,t,n);return}for(let i of z.VISITOR_KEYS[o.type]??[]){let s=o[i];if(Array.isArray(s))for(let a of s)a!=null&&typeof a=="object"&&"type"in a&&r(a);else s!=null&&typeof s=="object"&&"type"in s&&r(s)}}};for(let o of e.body.body)r(o);return[...n]}function Ni(e){let t=[];for(let n of e.body)if(!(!z.isImportDeclaration(n)||n.importKind==="type"))for(let r of n.specifiers)if(z.isImportSpecifier(r)){if(r.importKind==="type")continue;let o=z.isIdentifier(r.imported)?r.imported.name:r.imported.value;t.push({local:r.local.name,imported:o,source:n.source.value})}else z.isImportDefaultSpecifier(r)?t.push({local:r.local.name,imported:"default",source:n.source.value}):t.push({local:r.local.name,imported:"*",source:n.source.value});return t}function Ii(e){let t=new Map;for(let n of e.body){if(z.isExportDefaultDeclaration(n)){(z.isFunctionDeclaration(n.declaration)||z.isClassDeclaration(n.declaration))&&n.declaration.id!=null?t.set("default",n.declaration.id.name):z.isIdentifier(n.declaration)&&t.set("default",n.declaration.name);continue}if(!z.isExportNamedDeclaration(n))continue;if(n.source!==null)throw new Error("memo-dom: re-export-from declarations are not supported by compileModules(); import then export the binding explicitly");let r=n.declaration;if(z.isVariableDeclaration(r))for(let o of r.declarations)z.isIdentifier(o.id)&&t.set(o.id.name,o.id.name);else z.isFunctionDeclaration(r)&&r.id!=null&&t.set(r.id.name,r.id.name);for(let o of n.specifiers){if(!z.isExportSpecifier(o))continue;let i=o.local.name,s=z.isIdentifier(o.exported)?o.exported.name:o.exported.value;t.set(s,i)}}return t}function $a(e,t,n){let r,o=()=>({visitor:{Program(i){sn(i);let s=Ni(i.node),a=ln({...ki(n),moduleId:e.id,linkedImports:t});Rn(a,i),dn(a,i),Ln(a,i);let l={},d=er(i.node);for(let[p,u]of Ii(i.node)){if(a.comps.has(u)){l[p]={type:"component",...gi(a,e.id,u)};continue}let g=a.state.get(u);if(g!==void 0){l[p]={type:"state",kind:g,key:a.stateKeys.get(u)??`${e.id}#${u}`,tagCandidates:[...a.stateTagCandidates.get(u)??[]],componentCandidates:hi(a,a.stateComponentCandidates.get(u)??[])};continue}let S=a.importedFunctions.get(u)??(a.helpers.has(u)?He(a,u):void 0);S!==void 0&&(l[p]={type:"function",tagCandidates:[...d.get(u)??a.functionTagCandidates.get(u)??[]],componentCandidates:hi(a,a.functionComponentCandidates.get(u)??[]),reads:[...S.reads].map(x=>Ye(a,x)).sort(),writes:[...S.writes].map(x=>Ye(a,x)).sort(),boundedWrites:[...S.boundedWrites].map(x=>Ye(a,x)).sort(),parameterWrites:S.parameterWrites.map(x=>({index:x.index,path:[...x.path]})).sort((x,f)=>x.index-f.index||x.path.join(".").localeCompare(f.path.join("."))),unbounded:S.unbounded})}r={exports:l,imports:s,components:bi(e.id,a),componentUsages:Ja(a)}}}});if(Ci(e.source,{filename:e.id,plugins:[[Pi,{}],o,[wi,{isTSX:!0}]],configFile:!1,babelrc:!1}),r===void 0)throw new Error(`memo-dom: failed to analyze module '${e.id}'`);return r}function Oa(e){let t,n=()=>({visitor:{Program(r){sn(r);let o=new Map,i=Fn(r.node),s=er(r.node),a=mi(r,e.id),l=new Set(a.keys());for(let[p,u]of a)o.set(p,{type:"component",...u});for(let p of r.node.body){let u=z.isExportNamedDeclaration(p)?p.declaration:p;if(z.isVariableDeclaration(u))for(let g of u.declarations){if(!z.isIdentifier(g.id))continue;if(z.isArrowFunctionExpression(g.init)||z.isFunctionExpression(g.init)){let x=Ei(g.init,l).map(f=>`${e.id}#${f}`);o.set(g.id.name,{type:"function",tagCandidates:[...s.get(g.id.name)??[]],componentCandidates:x,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0});continue}let S;if(u.kind==="let"||u.kind==="var"?S="let":It(g.init)?S="store":Rt(g.init)&&(S="const"),S!==void 0){let x=new Set;z.isExpression(g.init)&&kt(g.init,l,x),o.set(g.id.name,{type:"state",kind:S,key:`${e.id}#${g.id.name}`,tagCandidates:[...i.get(g.id.name)??[]],componentCandidates:[...x].map(f=>`${e.id}#${f}`)})}}else if(z.isFunctionDeclaration(u)&&u.id!=null&&!a.has(u.id.name)){let g=Ei(u,l).map(S=>`${e.id}#${S}`);o.set(u.id.name,{type:"function",tagCandidates:[...s.get(u.id.name)??[]],componentCandidates:g,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0})}}let d={};for(let[p,u]of Ii(r.node)){let g=o.get(u);g!==void 0&&(d[p]=g)}t={exports:d,imports:Ni(r.node),components:[],componentUsages:[]}}}});if(Ci(e.source,{filename:e.id,plugins:[[Pi,{}],n,[wi,{isTSX:!0}]],configFile:!1,babelrc:!1}),t===void 0)throw new Error(`memo-dom: failed to discover module '${e.id}'`);return t}function Ri(e,t,n,r){let i=r.resolveImport?.(t,e);if(i===void 0){let l=Object.entries(r.aliases??{}).sort(([d],[p])=>p.length-d.length);for(let[d,p]of l)if(d.endsWith("/")?t.startsWith(d):t===d||t.startsWith(`${d}/`)){i=`${p}${t.slice(d.length)}`;break}}if(i===void 0)if(t.startsWith(".")){let l=Ut.normalize(Ut.join(Ut.dirname(e),t));i=e.startsWith("./")&&!l.startsWith("../")?`./${l}`:l}else i=t;let s=vi(i??t),a=[s,`${s}.ts`,`${s}.tsx`,`${s}.js`,`${s}.jsx`,`${s}/index.ts`,`${s}/index.tsx`,`${s}/index.js`,`${s}/index.jsx`];for(let l of a){let d=n.get(l);if(d!==void 0)return d}}function Xa(e,t){if(!t.startsWith("."))return t;let n=Ut.relative(Ut.dirname(e),t);return n.startsWith(".")?n:`./${n}`}function yi(e,t,n){return t.map(r=>{for(let[o,i]of n)for(let[s,a]of Object.entries(i.exports))if(!(a.type!=="component"||a.key!==r))return{key:a.key,source:Xa(e.id,o),imported:s,props:[...a.props],objectProps:a.objectProps,acceptsUnknownProps:a.acceptsUnknownProps,hasWholeDefault:a.hasWholeDefault,listLightweight:a.listLightweight,delegatedEvents:a.delegatedEvents,renderProps:[...a.renderProps],renderCallbacks:[...a.renderCallbacks],refProps:[...a.refProps],subtreeReads:[...a.subtreeReads]};throw new Error(`memo-dom: dynamic component candidate '${r}' is not exported; export the component so consuming modules can link it`)})}function Si(e,t,n,r,o,i){let s={};for(let a of t.imports){let l=Ri(e.id,a.source,r,o);if(l===void 0){s[a.local]={type:"function",tagCandidates:[],componentCandidates:[],reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}if(a.imported==="*")throw new Error(`memo-dom: namespace import '${a.local}' from '${a.source}' cannot identify a reactive export; use named imports`);let d=n.get(l.id)?.exports[a.imported];if(d===void 0){s[a.local]={type:"function",tagCandidates:[],componentCandidates:[],reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}if(d.type==="state")s[a.local]={type:"state",kind:d.kind,key:d.key,tagCandidates:[...d.tagCandidates],componentCandidates:yi(e,d.componentCandidates,n)};else if(d.type==="component"){let p=i?.get(d.key),u=d.renderProps.filter(g=>p?.scalar.has(g)!==!0||p.jsx.has(g));s[a.local]={type:"component",key:d.key,props:[...d.props],objectProps:d.objectProps,acceptsUnknownProps:d.acceptsUnknownProps,hasWholeDefault:d.hasWholeDefault,listLightweight:d.listLightweight,delegatedEvents:d.delegatedEvents,renderProps:u,renderCallbacks:[...d.renderCallbacks],refProps:[...d.refProps],subtreeReads:[...d.subtreeReads]}}else s[a.local]={type:"function",tagCandidates:[...d.tagCandidates],componentCandidates:yi(e,d.componentCandidates,n),reads:[...d.reads],writes:[...d.writes],boundedWrites:[...d.boundedWrites],parameterWrites:[...d.parameterWrites],unbounded:d.unbounded}}return s}function xi(e){return JSON.stringify(e)}function Ta(e,t={}){let n=new Map;for(let[a,l]of Object.entries(e)){let d=vi(a);if(n.has(d))throw new Error(`memo-dom: duplicate module id after normalization: '${d}'`);n.set(d,{originalId:a,id:d,source:l})}let r=new Map;for(let a of n.values())r.set(a.id,Oa(a));for(let a=0;a<=n.size;a++){let l=!1,d=new Map;for(let p of n.values()){let u=r.get(p.id),g=Si(p,u,r,n,t),S=$a(p,g,t);d.set(p.id,S),xi(S)!==xi(u)&&(l=!0)}if(r=d,!l)break;if(a===n.size)throw new Error("memo-dom: cross-module export summaries did not converge")}let o=new Map;for(let a of r.values())for(let l of a.componentUsages){let d=o.get(l.target);d===void 0&&(d={jsx:new Set,scalar:new Set},o.set(l.target,d)),d[l.kind].add(l.prop)}for(let[a,l]of o)for(let d of l.jsx)if(l.scalar.has(d))throw new Error(`memo-dom: component '${a}' prop '${d}' is used as both scalar data and JSX content; split the prop or component contract`);let i=ui([...r.values()].flatMap(a=>a.components),t.rootId??"App"),s={};for(let a of n.values()){let l=r.get(a.id),d=Si(a,l,r,n,t,o);for(let x of l.imports){let f=Ri(a.id,x.source,n,t);if(f!==void 0&&r.get(f.id)?.exports[x.imported]===void 0)throw new Error(`memo-dom: '${x.imported}' is not a linkable state, function, or component export of '${x.source}'`)}let p={},u={},g={},S={};for(let x of l.components){p[x.local]=[...i.paths.get(x.key)??[]];let f=i.rows.get(x.key);f!==void 0&&(u[x.local]=f.map(b=>({keyPath:b.keyPath===null?null:[...b.keyPath],sourceKey:b.sourceKey,sourceLocal:b.sourceLocal})));let m=i.propSources.get(x.key);m!==void 0&&(g[x.local]=Object.fromEntries([...m].map(([b,v])=>[b,{keys:[...v.keys],rootFallback:v.rootFallback}])));let C=Object.values(l.exports).find(b=>b.type==="component"&&b.key===x.key);if(C?.type==="component"){let b=o.get(x.key);S[x.local]=C.renderProps.filter(v=>b?.scalar.has(v)!==!0||b.jsx.has(v))}}s[a.originalId]=xr(a.source,{...ki(t),moduleId:a.id,linkedImports:d,linkedComponentPaths:p,linkedComponentRows:u,linkedComponentPropSources:g,linkedComponentRenderProps:S})}return s}export{xr as compile,Ta as compileModules};