@memoized-dom/compiler 0.0.3 → 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 Ca}from"@babel/core";import Pa from"@babel/plugin-syntax-jsx";import wa from"@babel/plugin-transform-typescript";import*as $ from"@babel/types";import"@babel/types";function an(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[E,f]of Object.entries(e.linkedImports??{}))f.type==="state"?(n.set(E,f.kind),r.set(E,f.key),f.tagCandidates!==void 0&&o.set(E,[...f.tagCandidates]),f.componentCandidates!==void 0&&l.set(E,f.componentCandidates.map(m=>({...m}))),d.add(E)):f.type==="function"?(f.tagCandidates!==void 0&&i.set(E,[...f.tagCandidates]),f.componentCandidates!==void 0&&l.set(E,f.componentCandidates.map(m=>({...m}))),u.set(E,{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(E,{...f,props:[...f.props]});let g=new Map;for(let[E,f]of c)g.set(E,{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(([E,f])=>[E,[...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(([E,f])=>[E,[...f]])),linkedComponentRows:new Map(Object.entries(e.linkedComponentRows??{}).map(([E,f])=>[E,f.map(m=>({keyPath:m.keyPath===null?null:[...m.keyPath],sourceKey:m.sourceKey,sourceLocal:m.sourceLocal}))])),linkedComponentPropSources:new Map(Object.entries(e.linkedComponentPropSources??{}).map(([E,f])=>[E,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,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,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 G from"@babel/types";import*as lt from"@babel/types";var On=class{constructor(t,n){this.scope=t;Mi(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 ln(e,t){let n=new On(t.scope,t);return e.identifiers=n,n}function A(e,t){return vt(e).generate(t)}function Je(e,t){return vt(e).componentId(t)}function Q(e,t){return vt(e).runtimeMember(t)}function vt(e){if(e.identifiers===null)throw new Error("memo-dom: generated identifier allocator was not initialized");return e.identifiers}function Mi(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 bt(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 Ut(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 G.identifier(o);let i=A(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 Cr(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=A(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 nt(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 At(e,t){return t===null?!0:t.length===0||e.length>t.length?!1:e.every((n,r)=>t[r]===n)}function ve(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 kt(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 Nt(e){return e?G.isArrayExpression(e)||G.isNewExpression(e):!1}function Be(e){return e==null?null:G.isStringLiteral(e)?e:G.isJSXExpressionContainer(e)?G.isJSXEmptyExpression(e.expression)?null:e.expression:null}function Xn(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 Pr(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 Le(t,i=>G.isIdentifier(i)&&r.has(i.name)?(o=!0,!1):o?!1:void 0),o}function Le(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 de(e){let t=!1;return Le(e,n=>{(G.isJSXElement(n)||G.isJSXFragment(n))&&(t=!0)}),t}function dn(e,t){let n=new Set;return Le(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 P from"@babel/types";import*as ce from"@babel/types";import*as Ge from"@babel/types";function cn(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 Ce from"@babel/types";import*as q from"@babel/types";function un(e){if(e.some(i=>q.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=ht(t[0]);if(t.length===1&&(q.isObjectPattern(n)||q.isIdentifier(n)&&n.name==="props"))return{mode:"object",names:q.isObjectPattern(n)?Di(n):[],acceptsUnknown:q.isIdentifier(n)||n.properties.some(s=>q.isRestElement(s)),bindings:Ht(n),params:t.map(s=>q.cloneNode(s)),hasWholeDefault:q.isAssignmentPattern(t[0]),renderProps:[],renderCallbacks:[],refProps:[]};let o=[];for(let i of t){let s=ht(i);if(!q.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=>Ht(ht(i))),params:t.map(i=>q.cloneNode(i)),hasWholeDefault:!1,renderProps:[],renderCallbacks:[],refProps:[]}}function wr(e,t){return e.params.length===0?null:q.variableDeclaration("let",e.params.map((n,r)=>q.variableDeclarator(Li(ht(n)),Nr(n,t[r]??q.identifier("undefined")))))}function Tn(e,t){return e.params.map((n,r)=>q.expressionStatement(q.assignmentExpression("=",Ir(ht(n)),Nr(n,t[r]??q.identifier("undefined")))))}function vr(e){return q.expressionStatement(q.assignmentExpression("=",Ir(e.target),q.cloneNode(e.source)))}function Ht(e){return Object.keys(q.getBindingIdentifiers(e))}function Ke(e){if(e.mode!=="object"||e.params.length!==1)return null;let t=ht(e.params[0]);return q.isIdentifier(t)?t.name:null}function pn(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=ht(e.params[0]);if(!q.isObjectPattern(n))return null;for(let r of n.properties){if(!q.isObjectProperty(r)||r.computed||(q.isIdentifier(r.key)?r.key.name:q.isStringLiteral(r.key)?r.key.value:null)!==t)continue;let i=q.isAssignmentPattern(r.value)?r.value.left:r.value;return q.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=ht(e.params[0]);if(!q.isObjectPattern(n))return null;for(let r of n.properties)if(!(!q.isObjectProperty(r)||r.computed)&&Object.keys(q.getBindingIdentifiers(r.value)).includes(t)){if(q.isIdentifier(r.key))return r.key.name;if(q.isStringLiteral(r.key))return r.key.value}return null}function ht(e){if(q.isRestElement(e))throw new Error("rest component parameters are not supported");let t=q.isAssignmentPattern(e)?e.left:e;if(!q.isIdentifier(t)&&!q.isObjectPattern(t)&&!q.isArrayPattern(t))throw new Error("unsupported component parameter target");return t}function kr(e){let t=q.cloneNode(e);return _t(t),t}function Nr(e,t){return q.isAssignmentPattern(e)?q.conditionalExpression(q.binaryExpression("===",q.cloneNode(t),q.identifier("undefined")),q.cloneNode(e.right),q.cloneNode(t)):q.cloneNode(t)}function Di(e){let t=[];for(let n of e.properties)if(!q.isRestElement(n)){if(n.computed)throw new Error("computed keys are not supported in component prop patterns");if(q.isIdentifier(n.key))t.push(n.key.name);else if(q.isStringLiteral(n.key))t.push(n.key.value);else throw new Error("component prop pattern keys must be identifiers or strings")}return t}function Li(e){let t=q.cloneNode(e);return _t(t),t}function Ir(e){let t=q.cloneNode(e);return _t(t),t}function _t(e){let t=e;"typeAnnotation"in t&&(t.typeAnnotation=null),"optional"in t&&(t.optional=null);for(let n of q.VISITOR_KEYS[e.type]??[]){let r=e[n];if(Array.isArray(r))for(let o of r)o&&typeof o=="object"&&"type"in o&&_t(o);else r&&typeof r=="object"&&"type"in r&&_t(r)}}function Rr(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&&Ce.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()||!Ce.isJSXIdentifier(a.node.name))return!1;let l=Ce.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 Ai(e){return Ce.isMemberExpression(e.callee)&&!e.callee.computed&&Ce.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=Ke(r);return o!==null&&Ce.isMemberExpression(n)&&!n.computed&&Ce.isIdentifier(n.object,{name:o})&&Ce.isIdentifier(n.property)?n.property.name:Ce.isIdentifier(n)?Ze(r,n.name)??(pn(r,n.name)!==null?n.name:null):null}function Ji(e){return Ce.isExpression(e.body)?e.body:e.body.body.length===1&&Ce.isReturnStatement(e.body.body[0])&&Ce.isExpression(e.body.body[0].argument)?e.body.body[0].argument:null}function jt(e,t,n){if(!Ai(n)||n.arguments.length!==1)return null;let r=n.arguments[0];if(!Ce.isArrowFunctionExpression(r))return null;let o=Ji(r);if(o===null||!Ce.isCallExpression(o)||!Ce.isExpression(o.callee)||o.arguments.some(s=>!Ce.isExpression(s)))return null;let i=ji(e,t,o.callee);return i===null?null:{propName:i,target:Ce.cloneNode(o.callee,!0),arguments:o.arguments.map(s=>Ce.cloneNode(s,!0))}}function Fr(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 Re from"@babel/types";function It(e){for(;Re.isTSAsExpression(e)||Re.isTSTypeAssertion(e)||Re.isTSNonNullExpression(e)||Re.isTSInstantiationExpression(e);)e=e.expression;return e}function fn(e){let t=It(e);return Re.isArrayExpression(t)&&t.elements.every(n=>n!==null&&!Re.isSpreadElement(n)&&(Re.isStringLiteral(n)||Re.isNumericLiteral(n)||Re.isBooleanLiteral(n)||Re.isNullLiteral(n)||Re.isBigIntLiteral(n)))}function Ve(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 Ae(e){let t=!1;return e.traverse({JSXElement(){t=!0},JSXFragment(){t=!0}}),t}function Rt(e,t,n,r,o,i){let s=g=>{throw n.buildCodeFrameError(g)},a=t.callee,l=$i(e,a.object,r,i,s),d=Ti(e,t,r,s),u=Bi(e,d,s),c=zi(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:Wi(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 $i(e,t,n,r,o){return ce.isIdentifier(t)?Oi(e,t,n,o):ce.isMemberExpression(t)?Xi(e,t,n,r,o):ce.isExpression(t)&&fn(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 Oi(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 Xi(e,t,n,r,o){let i=ve(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 Ti(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=cn(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],u=ce.isIdentifier(s)?s.name:null,c=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(c)?c:null,x=jt(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 Bi(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?(Vi(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 Vi(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 Wi(e,t){let n=null;for(let r of e?.attributes??[])if(ce.isJSXAttribute(r)&&ce.isJSXIdentifier(r.name,{name:"key"})&&(n=Be(r.value),n===null))return t("memo-dom: key={...} needs an expression");return n}function zi(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 mn(e){return re.isConditionalExpression(e)||re.isLogicalExpression(e)&&(e.operator==="&&"||e.operator==="||")?e:null}function Ki(e){return re.isNullLiteral(e)||re.isBooleanLiteral(e,{value:!1})||re.isIdentifier(e,{name:"undefined"})}function Ui(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(Ve(o)!==null&&de(o))continue}}}function gn(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||Ki(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&&Ui(l,r);return{pickExpr:o,branches:a,suffix:`when${n.count++}`}}import*as De from"@babel/types";import*as me from"@babel/types";var Jt=class{constructor(t){this.fallback=t}fallback;origins=new WeakMap;trackDeclarator(t,n){if(!me.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(me.isIdentifier(i)||me.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 me.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=Mr(n);if(me.isIdentifier(r))return this.resolveName(t,r.name);if(!me.isMemberExpression(r))return null;let o=Hi(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 bn(e,t){return{locality:"module",root:e,key:e,stateKind:t}}function Et(e,t){return e.key===null?e:{...e,key:[e.key,...t].join(".")}}function hn(e,t){if(e.key===null)return null;let n=[];for(let r of t){if(!me.isObjectExpression(r))return null;for(let o of r.properties){if(!me.isObjectProperty(o)||o.computed||!me.isIdentifier(o.key)&&!me.isStringLiteral(o.key))return null;let i=me.isIdentifier(o.key)?o.key.name:o.key.value;n.push(`${e.key}.${i}`)}}return n}function En(e){let t=[];for(let n of e)me.isExpression(n)?t.push(n):me.isSpreadElement(n)&&t.push(n.argument);return t}function yn(e){return!e.computed&&me.isIdentifier(e.property)?e.property.name:e.computed&&me.isStringLiteral(e.property)?e.property.value:null}function Hi(e){let t=e;for(;me.isMemberExpression(t);){if(me.isSuper(t.object))return null;t=Mr(t.object)}return me.isIdentifier(t)?t.name:null}function Mr(e){let t=e;for(;me.isTSAsExpression(t)||me.isTSTypeAssertion(t)||me.isTSNonNullExpression(t)||me.isTypeCastExpression(t)||me.isTSSatisfiesExpression(t);)t=t.expression;return t}function Ue(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)=>De.isIdentifier(f)?[[f.name,m]]:[])),a={reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!1},l=new Jt((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:bn(f,C)}),d=f=>f.stateKind==="computed"||e.state.get(f.root)==="computed";n.add(t),o.traverse({VariableDeclarator(f){De.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)De.isIdentifier(m)&&i.add(m.name)}});let u=(f,m)=>{a.parameterWrites.some(C=>C.index===f&&C.path.length===m.length&&C.path.every((y,v)=>y===m[v]))||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 C=f.key===null?[]:f.key.split(".").slice(1);u(m,C);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 C=l.resolveExpression(f.scope,m);C!==null&&g(C)},E=(f,m)=>{for(let C of En(m)){if(!De.isIdentifier(C))continue;let y=l.resolveExpression(f.scope,C);y!==null&&!d(y)&&c(y)}};return o.traverse({VariableDeclarator(f){if(!De.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(De.isIdentifier(m))if(i.has(m.name)){if(De.isIdentifier(f.node.right)){let C=l.resolveExpression(f.scope,f.node.right);C!==null&&c(C)}}else e.state.has(m.name)&&a.writes.add(m.name);else if(De.isMemberExpression(m))x(f,m);else for(let C of l.referencedOrigins(f.scope,f.node.right))c(C)},UpdateExpression(f){let m=f.node.argument;De.isIdentifier(m)?!i.has(m.name)&&e.state.has(m.name)&&a.writes.add(m.name):De.isMemberExpression(m)&&x(f,m)},UnaryExpression(f){f.node.operator==="delete"&&De.isMemberExpression(f.node.argument)&&x(f,f.node.argument)},CallExpression(f){let m=f.node.callee;if(De.isMemberExpression(m)){if(yn(m)==="assign"&&De.isIdentifier(m.object,{name:"Object"})){let v=f.node.arguments[0],M=v!==void 0&&De.isExpression(v)?l.resolveExpression(f.scope,v):null;if(M!==null){let R=hn(M,f.node.arguments.slice(1));if(R===null)c(M);else for(let I of R)g({...M,key:I})}return}let y=De.isExpression(m.object)?l.resolveExpression(f.scope,m.object):null;y!==null?c(y):E(f,f.node.arguments);return}if(De.isIdentifier(m)&&(e.helpers.has(m.name)||e.importedFunctions.has(m.name))){let C=e.importedFunctions.get(m.name)??Ue(e,m.name,n);for(let y of C.reads)a.reads.add(y);for(let y of C.writes)a.writes.add(y);for(let y of C.boundedWrites)a.boundedWrites.add(y);for(let y of C.parameterWrites){let v=f.node.arguments[y.index];if(v===void 0||!De.isExpression(v))continue;let M=l.resolveExpression(f.scope,v);M!==null&&c(Et(M,y.path))}C.unbounded&&(a.unbounded=!0);return}E(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=_i(e,f);m!==null&&a.reads.add(m)}}),n.delete(t),e.helperSummaries.set(t,a),a}function _i(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||qi(t)?null:n}function qi(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}import*as b from"@babel/types";import*as se from"@babel/types";function rt(e,t=!1){return{slots:[],tempVar:A(e,"value").name,updateVar:A(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 ot(e){return se.variableDeclaration("let",[...e.slots.map(t=>se.variableDeclarator(se.identifier(t))),se.variableDeclarator(se.identifier(e.tempVar))])}function Bn(e,t){let n=A(e,`slot${t.slots.length}`).name;return t.slots.push(n),n}function Vn(e,t,n){let r=t.tagCounters.get(n)??0;return t.tagCounters.set(n,r+1),A(e,`${n}${r}`).name}function Ft(e,t,n,r){let o=()=>se.identifier(e.tempVar),i=()=>se.identifier(t);return se.ifStatement(se.binaryExpression("!==",i(),se.assignmentExpression("=",o(),n)),se.blockStatement([se.expressionStatement(se.assignmentExpression("=",i(),o())),r(o())]))}function it(e){return se.variableDeclaration("const",[se.variableDeclarator(se.identifier(e.updateVar),se.arrowFunctionExpression(e.reasonVar===null?[]:[se.assignmentPattern(se.identifier(e.reasonVar),se.nullLiteral())],se.blockStatement(e.updaters.map(t=>t()))))])}function yt(e,t,n,r){return se.expressionStatement(se.callExpression(Q(e,"register"),[se.objectExpression([se.objectProperty(se.identifier("id"),t),se.objectProperty(se.identifier("parent"),n),se.objectProperty(se.identifier("render"),r)])]))}function Wn(e){let t=e.replace(/\s+/g," ");return/^\s*\n/.test(e)&&(t=t.replace(/^ /,"")),/\n\s*$/.test(e)&&(t=t.replace(/ $/,"")),t}function qt(e){return e.some(t=>!b.isJSXText(t)||t.value.trim()!=="")}function pt(e,t,n){let r=e.componentProps.get(t);if(r===void 0)return null;let o=Ke(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=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=pt(e,t,n);return r!==null&&e.componentProps.get(t)?.renderProps.includes(r)===!0}function Dr(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"),u=A(e,"childrenOwner"),c=A(e,"childrenKey"),g=A(e,"childrenSlot"),x=A(e,"childrenNextUpdate"),E=A(e,"childrenActive"),f=A(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(E),b.booleanLiteral(!0))]),ot(o),it(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(E)),b.returnStatement()),b.expressionStatement(b.assignmentExpression("=",b.cloneNode(E),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(Q(e,"unregisterSubtree"),[b.cloneNode(m,!0)])))])))]),b.expressionStatement(b.callExpression(Q(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 zn(e,t,n,r,o){let i=A(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 Lr(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=Wn(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=Ve(s);if(a!==null){r.emitList(a,n);continue}let l=mn(s);if(l!==null&&de(l)){r.emitCondition(l,n);continue}o(r.emitText(b.cloneNode(s)))}}import*as j from"@babel/types";function Cn(e){return j.isIdentifier(e.node.callee,{name:"effect"})&&e.scope.getBinding("effect")===void 0}function xn(e,t){return j.binaryExpression("+",j.identifier(e),j.stringLiteral(`/$effects/${t}`))}function Gi(e,t){return j.binaryExpression("+",xn(e,t),j.stringLiteral("/$active"))}function Zi(e){if(e.isFunctionDeclaration())return e;if(!e.isVariableDeclarator())return null;let t=e.get("init");return t.isArrowFunctionExpression()||t.isFunctionExpression()?t:null}function Or(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:Zi(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 Ar(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),y=C===void 0?void 0:s.get(C);if(y===void 0)return;let v=m.parentPath;!y.local&&e.state.get(y.source)==="store"&&v?.isMemberExpression()&&v.node.object===m.node||(y.local?i.add(y.source):o.add(y.source))},u=m=>{let C=ye(m.node),y=ve(m.node);C===null||y===null||e.state.get(y)!=="store"||m.scope.getBinding(y)?.scope.path.isProgram()!==!0||o.add(C)},c=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 y=e.importedFunctions.get(C.name)??Ue(e,C.name);for(let v of y.reads)o.add(v)};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,E=new Set;for(let m of i)a.has(m)&&E.add(m);let f=(m,C)=>{if(C.has(m))return;let y=l.get(m);if(y===void 0){a.has(m)?g.add(m):e.state.has(m)&&o.add(m);return}C.add(m),y.some(M=>E.has(M))||x.add(m);for(let M of y)f(M,C);C.delete(m)};for(let m of i)f(m,new Set);return{moduleReads:o,localReads:g,localDerivationReads:x}}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=ye(s.node),l=ve(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)??Ue(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 Kn(e){if(!e.isExpressionStatement())return null;let t=e.get("expression");return t.isCallExpression()&&Cn(t)?t:null}function Xr(e){if(Kn(e)!==null)return!0;let t=!1;return e.traverse({Function(n){n.skip()},CallExpression(n){Cn(n)&&(t=!0,n.stop())}}),t}function Sn(e,t,n,r){let o=Kn(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(!Xr(i))throw i.buildCodeFrameError("memo-dom: a conditional effect branch may contain only effect() calls, nested if statements, or empty statements");Sn(i,t,n,r)}return}if(e.isIfStatement()){let i=e.get("test");Sn(e.get("consequent"),t,[...n,{path:i,negated:!1}],r);let s=e.get("alternate");s.node!==null&&Sn(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 Tr(e){let t=[];for(let n of e){let r=Kn(n);if(r!==null){t.push({callPath:r,rootStatement:n.node,conditions:[]});continue}!n.isIfStatement()||!Xr(n)||Sn(n,n.node,[],t)}return t}function Br(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 Yi(e,t){let n=[],r=Tr(t.get("body"));for(let o of r){let i=Or(e,o.callPath),s=i.path===null?i.importedReads:jr(e,i.path),a=new Set;for(let d of o.conditions)for(let u of jr(e,d.path))a.add(u);let l=n.length;n.push({index:l,statement:o.rootStatement,callback:i.expression,moduleReads:s,condition:Br(o.conditions),conditionModuleReads:a,entityId:`${e.rootId}/$module-effects/${encodeURIComponent(e.moduleId)}/${l}`})}e.moduleEffects.push(...n)}function Vr(e,t){Yi(e,t);for(let[n,r]of e.compPaths){let o=[],i=new Set,s=Tr(r.get("body").get("body"));for(let l of s){let d=Or(e,l.callPath),u=d.path===null?{moduleReads:d.importedReads,localReads:new Set,localDerivationReads:new Set}:Ar(e,n,r,d.path),c=new Set,g=new Set,x=new Set;for(let E of l.conditions){let f=Ar(e,n,r,E.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:Br(l.conditions),conditionModuleReads:c,conditionLocalReads:g,conditionLocalDerivationReads:x}),i.add(l.callPath.node)}if(r.traverse({CallExpression(l){if(!(!Cn(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 Jr(e){return e.reduce((t,n)=>j.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=()=>j.identifier(n),a=Jr(i.map(d=>j.binaryExpression("===",s(),j.numericLiteral(d)))),l=Jr(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 Wr(e,t,n,r,o,i){let s=(l,d,u,c,g)=>{if(u.size===0&&c.size===0)return null;let x=j.expressionStatement(j.callExpression(Q(e,"markDirty"),[d]));if(c.size>0&&i!==void 0){let f=[],m=[];for(let y of c){let v=A(e,`eff${l.index}_${g}_${y}`).name;i.creation.push(j.variableDeclaration("let",[j.variableDeclarator(j.identifier(v),j.identifier(y))])),f.push(j.binaryExpression("!==",j.identifier(v),j.identifier(y))),m.push(j.expressionStatement(j.assignmentExpression("=",j.identifier(v),j.identifier(y))))}let C=f.length===1?f[0]:f.reduce((y,v)=>j.logicalExpression("||",y,v));x=j.ifStatement(C,j.blockStatement([...m,x]))}if(r===null)return x;let E=Qi(e,t,r,u);return E===null?x:j.ifStatement(E,x)},a=o.flatMap(l=>{let d=l.condition===null?null:s(l,xn(n,l.index),l.conditionLocalReads,l.conditionLocalDerivationReads,"condition"),u=s(l,l.condition===null?xn(n,l.index):Gi(n,l.index),l.localReads,l.localDerivationReads,"callback");return[d,u].filter(c=>c!==null)});return j.blockStatement(a)}function zr(e,t,n){return n.map(r=>j.expressionStatement(j.callExpression(Q(e,r.condition===null?"registerEffect":"registerConditionalEffect"),[xn(t,r.index),j.identifier(t),...r.condition===null?[]:[j.arrowFunctionExpression([],j.cloneNode(r.condition,!0))],j.cloneNode(r.callback,!0)])))}function $r(){return j.memberExpression(j.metaProperty(j.identifier("import"),j.identifier("meta")),j.identifier("hot"))}function Kr(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(Q(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($r(),j.expressionStatement(j.callExpression(j.memberExpression($r(),j.identifier("dispose")),[j.arrowFunctionExpression([],j.callExpression(Q(e,"unregisterSubtree"),[j.stringLiteral(l.entityId)]))]))));s.replaceWithMultiple(a)}}function Ur(e){e.traverse({CallExpression(t){if(Cn(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 Hr(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function _r(e){let t=new Set,n=[];for(let r of e){let o=Pn(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 Pn(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 _r(e.body);if(Qe.isIfStatement(e)){let t=e.alternate;if(t==null)return null;let n=Pn(e.consequent),r=Pn(t);return n===null||r===null||!Hr(n.bindings,r.bindings)?null:{bindings:n.bindings,expressions:[e.test,...n.expressions,...r.expressions]}}return null}function es(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=_r(i);if(s===null)return null;if(n=!1,t===null)t=s.bindings;else if(!Hr(t,s.bindings))return null;r.push(...s.expressions)}return t===null||n?null:{bindings:t,expressions:r}}function ts(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function ns(e,t){let n=e;for(;n?.parentPath!==t;)n=n?.parentPath??null;return n}function qr(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()?Pn(s):es(s);if(a===null)continue;let l=!0,d=[];for(let E of a.bindings){let f=t.scope.getBinding(E),m=f?.path,C=m?.parentPath,y=m===void 0?null:ns(m,t);if(f===void 0||!m?.isVariableDeclarator()||!C?.isVariableDeclaration()||C.node.kind!=="let"&&C.node.kind!=="var"||y===null||(o.get(y.node)??Number.MAX_SAFE_INTEGER)>=(o.get(s)??-1)){l=!1;break}d.push(...f.constantViolations.filter(v=>!ts(v,s)))}if(!l)continue;let u=new Set,c=null;for(let E of a.expressions){let f=n(e,E);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 E of a.bindings)if(u.has(E))throw i.buildCodeFrameError(`memo-dom: module control-flow derivation '${E}' 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 E of x)bt(e,E,"computed");e.moduleControlFlow.push({statement:s,bindings:x,sources:[...u].sort(),entityId:`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#$flow${g}`})}}import*as ue from"@babel/types";function Un(e,t){let n=new Set,r=!1,o,i=new Set,s=l=>{r||(r=!0,o=l)},a=l=>{ue.isIdentifier(l)?i.add(l.name):Le(l,d=>{ue.isIdentifier(d)&&i.add(d.name)})};return Le(t,(l,d)=>{if(ue.isFunction(l)){if(!(d!==null&&(ue.isCallExpression(d)||ue.isNewExpression(d))))return!1;for(let c of l.params)ue.isLVal(c)&&a(c);return}if(ue.isVariableDeclarator(l)&&ue.isLVal(l.id)){a(l.id);return}if(ue.isAssignmentExpression(l)){let u=ue.isIdentifier(l.left)?l.left.name:ue.isMemberExpression(l.left)?ve(l.left):null;(u===null||!i.has(u))&&s("contains an assignment \u2014 writes belong in handlers, not derivations");return}if(ue.isUpdateExpression(l)){let u=l.argument,c=ue.isIdentifier(u)?u.name:ue.isMemberExpression(u)?ve(u):null;(c===null||!i.has(c))&&s("contains an update (++/--) \u2014 writes belong in handlers, not derivations");return}if(ue.isAwaitExpression(l)||ue.isYieldExpression(l)){s("uses await/yield \u2014 derivations must be synchronous");return}if(ue.isCallExpression(l)){let u=l.callee;if(ue.isIdentifier(u)&&(e.helpers.has(u.name)||e.importedFunctions.has(u.name))){let c=e.importedFunctions.get(u.name)??Ue(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(ue.isIdentifier(l)){!i.has(l.name)&&e.state.has(l.name)&&n.add(l.name);return}if(ue.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 Gr(e,t){for(let n of t.node.body){let r=ue.isExportNamedDeclaration(n)?n.declaration:n;if(!(!ue.isVariableDeclaration(r)||r.kind!=="const"))for(let o of r.declarations){if(!ue.isIdentifier(o.id)||o.init==null)continue;let i=o.id.name;if(e.state.get(i)==="let"||e.state.get(i)==="computed"||ue.isFunction(o.init)||ue.isJSX(o.init))continue;let s=Un(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&&(bt(e,i,"computed"),e.computeds.set(i,{reads:s.reads}))}}}import*as je from"@babel/types";function Zr(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"||kt(i.init)||Nt(i.init))&&r.add(i.id.name);r.size>0&&e.instanceState.set(t,r)}}function Yr(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(!je.isIdentifier(x.id)&&!je.isObjectPattern(x.id)&&!je.isArrayPattern(x.id)||x.init==null||je.isFunction(x.init)||je.isIdentifier(x.id)&&e.instanceState.get(t)?.has(x.id.name)===!0&&(kt(x.init)||Nt(x.init)))continue;let E=g.get("init");if(!E.isExpression())continue;let f=new Set,m=null,C=(I,H)=>{let O=H.scope.getBinding(I);return O!==void 0&&r.has(O)},y=I=>{if(!je.isIdentifier(I.node))return;let H=I.scope.getBinding(I.node.name),O=H===void 0?void 0:r.get(H);O!==void 0&&f.add(O)},v=I=>je.isIdentifier(I)?I.name:je.isMemberExpression(I)?ve(I):null;if(E.isReferencedIdentifier()&&y(E),E.isAssignmentExpression()){let I=v(E.node.left);I!==null&&C(I,E)&&(m="contains an assignment to reactive state")}else if(E.isUpdateExpression()){let I=v(E.node.argument);I!==null&&C(I,E)&&(m="contains an update (++/--) to reactive state")}else E.isAwaitExpression()?m="uses await; per-instance derivations must be synchronous":E.isYieldExpression()&&(m="uses yield; per-instance derivations must be synchronous");if(E.traverse({Function(I){I.skip()},ReferencedIdentifier(I){y(I)},AssignmentExpression(I){let H=v(I.node.left);H!==null&&C(H,I)&&(m="contains an assignment to reactive state")},UpdateExpression(I){let H=v(I.node.argument);H!==null&&C(H,I)&&(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(E.traverse({ReferencedIdentifier(I){y(I)},AssignmentExpression(I){let H=v(I.node.left);H!==null&&C(H,I)&&(m="contains an assignment to reactive state")},UpdateExpression(I){let H=v(I.node.argument);H!==null&&C(H,I)&&(m="contains an update (++/--) to reactive state")}}),m!==null){let I=Ht(x.id);throw g.buildCodeFrameError(`memo-dom: local const '${I.join(", ")||"<pattern>"}' is a per-instance derivation but ${m}`)}let M=Ht(x.id),R=new Set;for(let I of f){let H=s.get(I);if(H===void 0)R.add(I);else for(let O of H)R.add(O)}o.push({declaration:c.node,target:je.cloneNode(x.id),source:je.cloneNode(x.init),bindings:M,sources:[...R].sort()});for(let I of M){i.add(I),s.set(I,new Set(R));let H=n.scope.getBinding(I);H&&r.set(H,I),e.instanceState.get(t)?.delete(I)}}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 pe from"@babel/types";function Zt(e){let t=!0;return pe.traverseFast(e,n=>{if(pe.isAssignmentExpression(n)||pe.isUpdateExpression(n)||pe.isAwaitExpression(n)||pe.isYieldExpression(n)||pe.isNewExpression(n)||pe.isTaggedTemplateExpression(n)||pe.isFunction(n)){t=!1;return}if(pe.isCallExpression(n)||pe.isOptionalCallExpression(n)){let r=n.callee;t=t&&pe.isMemberExpression(r)&&!r.computed&&pe.isIdentifier(r.object,{name:"Math"})&&pe.isIdentifier(r.property)}}),t}function rs(e){return!pe.isExpressionStatement(e)||!pe.isAssignmentExpression(e.expression,{operator:"="})||!pe.isIdentifier(e.expression.left)||!Zt(e.expression.right)?null:e.expression.left.name}function Qr(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function Gt(e){if(pe.isExpressionStatement(e)){let t=rs(e);return t===null?null:{bindings:new Set([t]),partial:new Set}}if(pe.isBlockStatement(e)){let t=new Set,n=new Set;for(let r of e.body){let o=Gt(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(pe.isIfStatement(e)){if(!Zt(e.test))return null;let t=Gt(e.consequent);if(t===null)return null;if(e.alternate==null)return{bindings:t.bindings,partial:new Set([...t.bindings,...t.partial])};let n=Gt(e.alternate);return n===null||!Qr(t.bindings,n.bindings)?null:{bindings:t.bindings,partial:new Set([...t.partial,...n.partial])}}return null}function os(e){if(!Zt(e.discriminant))return null;let t=null;for(let n of e.cases){if(n.test!=null&&!Zt(n.test))return null;let r=[...n.consequent];if(r.at(-1)&&pe.isBreakStatement(r.at(-1))&&r.pop(),r.some(i=>pe.isBreakStatement(i)))return null;let o=Gt(pe.blockStatement(r));if(o===null)return null;if(t===null)t=o;else{if(!Qr(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 is(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function eo(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()?Gt(a.node):os(a.node);if(l===null)continue;let d=!0,u=[],c=[];for(let f of l.bindings){let m=n.scope.getBinding(f),C=m?.path,y=C?.parentPath;if(m===void 0||!C?.isVariableDeclarator()||!y?.isVariableDeclaration()||y.node.kind!=="let"&&y.node.kind!=="var"||m.constantViolations.some(v=>!is(v,a.node))){d=!1;break}if(l.partial.has(f)){let v=C.get("init");if(!v.isExpression()||!Zt(v.node)){d=!1;break}u.push({binding:f,source:v.node}),c.push(v)}}if(!d)continue;let g=new Set,x=f=>{let m=f.scope.getBinding(f.node.name),C=m===void 0?void 0:r.get(m);C!==void 0&&g.add(C)},E={Function(f){f.skip()},ReferencedIdentifier(f){f.isIdentifier()&&x(f)}};a.traverse(E);for(let f of c)f.isReferencedIdentifier()&&x(f),f.traverse(E);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 to(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),E=new Set;for(let f of g)for(let m of i(f,x))E.add(m);return E};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 Yt from"@babel/types";function ss(e){let t=e.indexOf("[");return t<0?e:e.slice(0,t)}function St(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(ss(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(u=>et(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 et(e,d.owner,n))l.push(`${u}/${d.suffix}`);for(let d of a)for(let u of et(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 et(e,d,n))u>1?l.push(`${c}/${t}`,`${c}/${t}[*]`):l.push(`${c}/${t}`)}return n.delete(t),l}function Hn(e,t){let n=e.linkedComponentPaths.get(t);if(n!==void 0)return St(e,n.flatMap(i=>[i,`${i}/*`]));let r=e.listedSites.get(t),o=[];if(r&&r.length>0){if($t(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 St(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 St(e,o)}for(let i of et(e,t))o.push(i,`${i}/*`);return St(e,o)}function $t(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&&wn(e,t)&&(o=!0),e.lightweightCache.set(t,o),o}function wn(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;Yt.isJSXIdentifier(i)&&/^[A-Z]/.test(i.name)&&(n=!1)},CallExpression(o){(Yt.isIdentifier(o.node.callee,{name:"cleanup"})&&o.scope.getBinding("cleanup")===void 0||Yt.isIdentifier(o.node.callee,{name:"effect"})&&o.scope.getBinding("effect")===void 0)&&(n=!1),Ve(o.node)&&Ae(o)&&(n=!1)},ConditionalExpression(o){Ae(o)&&(n=!1)},LogicalExpression(o){Ae(o)&&(n=!1)}}),n}import*as K from"@babel/types";function no(e,t){let n=e.findParent(r=>r.isFunctionDeclaration()||r.isFunctionExpression()||r.isArrowFunctionExpression());return n===t?!0:n?.findParent(r=>r===t)!==null}function _n(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(!K.isJSXIdentifier(s)||!/^[A-Z]/.test(s.name))return!1;let a=K.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 as(e,t){if(K.isArrayExpression(e))return e;if(!K.isIdentifier(e))return null;let n=t.scope.getBinding(e.name);return n?.path.isVariableDeclarator()&&K.isArrayExpression(n.path.node.init)?n.path.node.init:null}function qn(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||K.isNullLiteral(o)||K.isBooleanLiteral(o))){if(K.isSpreadElement(o)){if(!K.isExpression(o.argument))throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");let i=as(o.argument,t);if(i===null)throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");r.push(...qn(i,t,n));continue}if(K.isArrayExpression(o)){r.push(...qn(o,t,n));continue}if(K.isJSXElement(o)||K.isJSXFragment(o)){r.push(K.cloneNode(o,!0));continue}if(!K.isExpression(o))throw t.buildCodeFrameError("memo-dom: JSX arrays require renderable expression entries");r.push(K.jsxExpressionContainer(K.cloneNode(o,!0)))}}finally{n.delete(e)}return r}function ro(e,t){return K.jsxFragment(K.jsxOpeningFragment(),K.jsxClosingFragment(),qn(e,t))}function ls(e,t){return K.isArrayExpression(e)?e.elements.map((n,r)=>{if(n==null||K.isSpreadElement(n))throw t.buildCodeFrameError("memo-dom: JSX arrays cannot contain holes or spread elements");return{key:K.numericLiteral(r),value:n}}):e.properties.map(n=>{if(!K.isObjectProperty(n)||n.computed||!K.isExpression(n.value))throw t.buildCodeFrameError("memo-dom: JSX objects require static data properties without spreads");let r=K.isIdentifier(n.key)?K.stringLiteral(n.key.name):K.isStringLiteral(n.key)||K.isNumericLiteral(n.key)?K.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 ds(e,t){let n=e.node,r=null;if(!n.computed&&K.isIdentifier(n.property)?r=n.property.name:n.computed&&(K.isStringLiteral(n.property)||K.isNumericLiteral(n.property))&&(r=n.property.value),r!==null){let i=t.find(s=>(K.isStringLiteral(s.key)||K.isNumericLiteral(s.key))&&s.key.value===r);if(i===void 0)throw e.buildCodeFrameError(`memo-dom: JSX collection has no entry for '${r}'`);return K.cloneNode(i.value,!0)}if(!n.computed||!K.isExpression(n.property))throw e.buildCodeFrameError("memo-dom: JSX collection selection requires a static or expression key");let o=K.nullLiteral();for(let i=t.length-1;i>=0;i--){let s=t[i];o=K.conditionalExpression(K.binaryExpression("===",K.cloneNode(n.property,!0),K.cloneNode(s.key,!0)),K.cloneNode(s.value,!0),o)}return o}function oo(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(ro(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(!K.isIdentifier(a.id)||l==null||!de(l))continue;let d=s.scope.getBinding(a.id.name);if(d?.path!==s)continue;let u=[...d.referencePaths];if(K.isObjectExpression(l)||K.isArrayExpression(l))for(let c of u){if(!c.isIdentifier()||!no(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(!_n(g,e))throw g.buildCodeFrameError(`memo-dom: JSX collection '${a.id.name}' is used outside a render position`);g.replaceWith(ds(g,ls(l,s)));continue}if(K.isArrayExpression(l)&&c.parentPath?.isSpreadElement()&&c.parentPath.parentPath?.isArrayExpression()){c.replaceWith(K.cloneNode(l,!0));continue}if(K.isArrayExpression(l)&&_n(c,e)){c.replaceWith(ro(l,c));continue}throw c.buildCodeFrameError(K.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()||!no(c,t))){if(!_n(c,e))throw c.buildCodeFrameError(`memo-dom: JSX value '${a.id.name}' is used outside a render position`);c.replaceWith(K.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)&&(K.isJSXElement(i)||K.isJSXFragment(i))&&o.replaceWith(i)}}),t.scope.crawl())}}import*as F from"@babel/types";function Gn(e){return F.isReturnStatement(e)&&F.isExpression(e.argument)?e.argument:F.isBlockStatement(e)&&e.body.length===1?Gn(e.body[0]):null}function Ot(e){let t=Gn(e);if(t!==null)return t;if(F.isIfStatement(e)&&e.alternate!=null){let n=Ot(e.consequent),r=Ot(e.alternate);return n===null||r===null?null:F.conditionalExpression(F.cloneNode(e.test,!0),F.cloneNode(n,!0),F.cloneNode(r,!0))}if(F.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=F.conditionalExpression(F.binaryExpression("===",F.cloneNode(e.discriminant,!0),F.cloneNode(i.test,!0)),F.cloneNode(s,!0),r)}return r}return null}function cs(e,t){if(F.isExpression(e.body))return{expression:F.cloneNode(e.body,!0),locals:new Map};let n=new Map,r=[];for(let s of e.body.body){if(F.isVariableDeclaration(s,{kind:"const"})){for(let a of s.declarations)(!F.isIdentifier(a.id)||a.init==null||!F.isExpression(a.init))&&t("memo-dom: JSX render functions require identifier const declarations with expression initializers"),n.set(a.id.name,F.cloneNode(a.init,!0));continue}F.isTypeScript(s)||F.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:Gn(o);if(i!==null){let s=F.cloneNode(i,!0);for(let a=r.length-2;a>=0;a--){let l=r[a];if(F.isIfStatement(l)&&l.alternate==null){let d=Ot(l.consequent);if(d!==null){s=F.conditionalExpression(F.cloneNode(l.test,!0),F.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 us(e,t){return(F.isMemberExpression(e)||F.isOptionalMemberExpression(e))&&t==="property"&&!e.computed||(F.isObjectProperty(e)||F.isObjectMethod(e)||F.isClassMethod(e))&&t==="key"&&!e.computed||F.isVariableDeclarator(e)&&t==="id"||(F.isFunction(e)||F.isCatchClause(e))&&(t==="params"||t==="param"||t==="id")||F.isLabeledStatement(e)&&t==="label"}function io(e,t,n=new Set){let r=F.cloneNode(e,!0),o=(i,s,a,l)=>{if(F.isIdentifier(i)&&!l.has(i.name)&&t.has(i.name)&&(s===null||!us(s,a)))return F.cloneNode(t.get(i.name),!0);let d=l;if(F.isFunction(i)&&i!==r){let u=i.params.flatMap(c=>Object.keys(F.getBindingIdentifiers(c)));d=new Set([...l,...u])}for(let u of F.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 F.isObjectProperty(i)&&i.shorthand&&!F.isIdentifier(i.value,{name:F.isIdentifier(i.key)?i.key.name:""})&&(i.shorthand=!1),i};return o(r,null,"",n)}function ps(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=>F.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&&F.isExpression(d)?d:F.identifier("undefined");if(F.isIdentifier(l)){o.set(l.name,F.cloneNode(u,!0));continue}if(F.isAssignmentPattern(l)&&F.isIdentifier(l.left)){o.set(l.left.name,F.conditionalExpression(F.binaryExpression("===",F.cloneNode(u,!0),F.identifier("undefined")),F.cloneNode(l.right,!0),F.cloneNode(u,!0)));continue}n("memo-dom: JSX render functions currently require identifier parameters with optional defaults")}let i=cs(r,n);for(let[a,l]of i.locals)o.set(a,io(l,o));let s=io(i.expression,o);return de(s)||n("memo-dom: JSX render function expansion did not produce JSX"),s}function fs(e,t){let n=t.get("callee");return Array.isArray(n)||!n.isIdentifier()?null:so(e,n)}function so(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((F.isFunctionExpression(i)||F.isArrowFunctionExpression(i))&&de(i.body))return{node:i,bindingPath:o.path}}return null}function ao(e){return F.isMemberExpression(e.callee)&&!e.callee.computed&&F.isIdentifier(e.callee.property,{name:"map"})}function ms(e){let t=e.parentPath;return t?.isCallExpression()===!0&&(t.node.callee===e.node||ao(t.node)&&t.node.arguments[0]===e.node)}function gs(e,t){let n=e.node;if(n.async||n.generator)throw t.buildCodeFrameError("memo-dom: JSX render callbacks must be synchronous");return F.arrowFunctionExpression(n.params.map(r=>F.cloneNode(r,!0)),F.cloneNode(n.body,!0))}function vn(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()&&vn(t)}}}function bs(e,t){let n=t.findParent(r=>r.isProgram());if(n===null||!n.isProgram()){vn(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()&&F.isIdentifier(a.node.id,{name:e}));if(s!==void 0){i.length===1?r.remove():s.remove();return}}vn(t)}function hs(e,t){let n=e.parentPath,r=n?.parentPath;if((F.isJSXElement(t)||F.isJSXFragment(t))&&n?.isJSXExpressionContainer()&&(r?.isJSXElement()||r?.isJSXFragment())&&r.node.children.includes(n.node)){n.replaceWith(t);return}e.replaceWith(t)}function lo(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()&&!ms(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(!ao(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=so(e,i);s!==null&&(i.replaceWith(gs(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=fs(e,i);s!==null&&(hs(i,ps(s,i)),t.add(s.bindingPath),r=!0)}}}for(let[n,r]of e.jsxHelpers)bs(n,r);for(let n of t)vn(n)}import*as He from"@babel/types";function Es(e){let t=It(e);return He.isIdentifier(t)||He.isMemberExpression(t)||fn(t)}function ys(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 Ss(e,t){return e.findParent(n=>n.isFunctionDeclaration()||n.isFunctionExpression()||n.isArrowFunctionExpression())===t}function co(e){for(let[,t]of e.compPaths){let n=[];if(t.traverse({CallExpression(s){if(Ve(s.node)===null||!He.isMemberExpression(s.node.callee)||!He.isExpression(s.node.callee.object)||Es(s.node.callee.object)||!Ss(s,t))return;let a=ys(s,t);a!==null&&n.push({path:s,source:He.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(He.variableDeclarator(He.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(He.cloneNode(a))}n[0].statement.insertBefore(He.variableDeclaration("const",i)),t.scope.crawl()}}import*as We from"@babel/types";var xs=new Set(["==","==="]);function kn(e,t,n){if(n(e,t),!We.isFunction(e))for(let r of We.VISITOR_KEYS[e.type]??[]){let o=e[r];if(Array.isArray(o))for(let i of o)i&&kn(i,e,n);else o&&kn(o,e,n)}}function uo(e,t,n){if(!We.isBinaryExpression(t)||!xs.has(t.operator))return!1;let r=t.left===e?t.right:t.left;return We.isExpression(r)&&We.isNodesEquivalent(r,n)}function po(e,t){if(e.jsx===null||e.keyExpr===null||!e.sourceLocal||!We.isIdentifier(e.sourceExpr)||!t.has(e.sourceExpr.name))return[];let n=e.sourceExpr.name,r=new Set;if(kn(e.jsx,null,(i,s)=>{We.isIdentifier(i)&&t.has(i.name)&&i.name!==n&&uo(i,s,e.keyExpr)&&r.add(i.name)}),r.size===0)return[];let o=new Set;return kn(e.jsx,null,(i,s)=>{We.isIdentifier(i)&&r.has(i.name)&&We.isReferenced(i,s)&&!uo(i,s,e.keyExpr)&&o.add(i.name)}),[...r].filter(i=>!o.has(i)).sort()}import*as k from"@babel/types";function Cs(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 Nn(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,Cs(x)),o.push(k.importDeclaration(d.imported==="default"?[k.importDefaultSpecifier(k.identifier(u))]:[k.importSpecifier(k.identifier(u),k.isValidIdentifier(d.imported)?k.identifier(d.imported):k.stringLiteral(d.imported))],k.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 Zn(e){let t=e;for(;k.isTSAsExpression(t)||k.isTSTypeAssertion(t)||k.isTSNonNullExpression(t);)t=t.expression;return t}function fo(e){return k.isJSXIdentifier(e)?k.identifier(e.name):k.memberExpression(fo(e.object),k.identifier(e.property.name))}function mo(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=Zn(s),!k.isObjectExpression(s))return null;let l=s.properties.find(d=>!k.isObjectProperty(d)||d.computed?!1:(k.isIdentifier(d.key)?d.key.name:k.isStringLiteral(d.key)?d.key.value:null)===a);if(l===void 0||!k.isObjectProperty(l)||!k.isExpression(l.value))return null;s=l.value}return s}function Ps(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()&&(k.isFunctionExpression(n.path.node.init)||k.isArrowFunctionExpression(n.path.node.init))&&(r=n.path.node.init),r===null?[]:go(r)}function go(e){if(k.isExpression(e.body))return[e.body];let t=[],n=r=>{if(!k.isFunction(r)){if(k.isReturnStatement(r)){k.isExpression(r.argument)&&t.push(r.argument);return}for(let o of k.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 xt(e,t,n,r=new Set){let o=Zn(t);if(!r.has(o)){if(r.add(o),k.isIdentifier(o)&&(e.comps.has(o.name)||e.importedComponents.has(o.name))){n.add(o.name);return}if(k.isIdentifier(o)){for(let i of e.stateComponentCandidates.get(o.name)??e.functionComponentCandidates.get(o.name)??[])n.add(i);return}if(k.isConditionalExpression(o)){xt(e,o.consequent,n,r),xt(e,o.alternate,n,r);return}if(k.isLogicalExpression(o)){xt(e,o.right,n,r);return}if(k.isObjectExpression(o)){for(let i of o.properties)k.isObjectProperty(i)&&k.isExpression(i.value)&&xt(e,i.value,n,r);return}if(k.isArrayExpression(o)){for(let i of o.elements)i!=null&&!k.isSpreadElement(i)&&xt(e,i,n,r);return}if(k.isCallExpression(o)&&k.isIdentifier(o.callee)){for(let i of e.functionComponentCandidates.get(o.callee.name)??[])n.add(i);return}if(k.isMemberExpression(o)){let i=ve(o);if(i!==null)for(let s of e.stateComponentCandidates.get(i)??[])n.add(s)}}}function bo(e,t){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)||i.init==null)continue;let s=new Set;xt(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;(k.isFunctionDeclaration(a)||k.isFunctionExpression(a)||k.isArrowFunctionExpression(a))&&(s=go(a));for(let l of s)xt(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=Zn(n);if(!o.has(i)){if(o.add(i),k.isConditionalExpression(i)){tt(e,t,i.consequent,r,o),tt(e,t,i.alternate,r,o);return}if(k.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:k.cloneNode(i),tag:k.jsxIdentifier(i.value)});return}if(k.isIdentifier(i)){if(e.comps.has(i.name)||e.importedComponents.has(i.name)){r.push({compare:k.cloneNode(i),tag:k.jsxIdentifier(i.name)});return}let s=e.stateTagCandidates.get(i.name);if(s!==void 0)for(let l of s)tt(e,t,k.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(k.isCallExpression(i)&&k.isIdentifier(i.callee)){for(let s of e.functionTagCandidates.get(i.callee.name)??[])tt(e,t,k.stringLiteral(s),r,o);for(let s of Ps(t,i.callee.name))tt(e,t,s,r,o);for(let s of e.functionComponentCandidates.get(i.callee.name)??[])tt(e,t,k.identifier(s),r,o);return}if(k.isMemberExpression(i)){let s=mo(t,i);if(s!==null){tt(e,t,s,r,o);return}let a=ve(i);if(a===null)return;let l=t.scope.getBinding(a);if(l?.path.isVariableDeclarator()&&l.path.node.init!=null){let d=new Set;xt(e,l.path.node.init,d);for(let u of d)tt(e,t,k.identifier(u),r,o)}for(let d of e.stateTagCandidates.get(a)??[])tt(e,t,k.stringLiteral(d),r,o);for(let d of e.stateComponentCandidates.get(a)??[])tt(e,t,k.identifier(d),r,o)}}}function ws(e){return k.isStringLiteral(e.compare)?`string:${e.compare.value}`:k.isIdentifier(e.compare)?`component:${e.compare.name}`:JSON.stringify(e.compare)}function vs(e,t){if(k.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==="="&&k.isExpression(r.node.right)?[r.node.right]:[])]:[]}if(k.isMemberExpression(t)){let n=mo(e,t),r=ye(t),o=[];return r!==null&&(e.getFunctionParent()??e.findParent(a=>a.isProgram()))?.traverse({AssignmentExpression(a){a.node.operator==="="&&k.isMemberExpression(a.node.left)&&ye(a.node.left)===r&&k.isExpression(a.node.right)&&o.push(a.node.right)}}),[...n===null?[]:[n],...o]}return[]}function ho(e,t){let n=k.cloneNode(e,!0);n.openingElement.name=k.cloneNode(t);let r=n.closingElement;return r!=null&&(r.name=k.cloneNode(t)),n}function ks(e,t,n){let r=k.nullLiteral();for(let o=n.length-1;o>=0;o--){let i=n[o];r=k.conditionalExpression(k.binaryExpression("===",k.cloneNode(e,!0),k.cloneNode(i.compare,!0)),ho(t,i.tag),r)}return r}function Ns(e){return k.isIdentifier(e)?e.name:k.isMemberExpression(e)?ye(e)??"<member expression>":"<expression>"}function Eo(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(k.isJSXNamespacedName(i))throw o.buildCodeFrameError("memo-dom: namespaced JSX tags are not supported");if(k.isJSXIdentifier(i)&&(!/^[A-Z]/.test(i.name)||e.comps.has(i.name)||e.importedComponents.has(i.name)))continue;let s=fo(i),a=vs(o,s),l=[];for(let u of a)tt(e,o,u,l);let d=[...new Map(l.map(u=>[ws(u),u])).values()];if(d.length===0)throw o.buildCodeFrameError(`memo-dom: dynamic JSX tag '${Ns(s)}' has no finite string or linked-component candidates`);for(let u of d){if(!k.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(k.isJSXSpreadAttribute(x)||!k.isJSXIdentifier(x.name)||!c.renderProps.includes(x.name.name))continue;let E=Be(x.value),f=g.get(x.name.name)??{scalar:!1,jsx:!1,at:o};E!==null&&de(E)?f.jsx=!0:f.scalar=!0,g.set(x.name.name,f)}}if(d.length===1){o.replaceWith(ho(o.node,d[0].tag));continue}o.replaceWith(k.jsxFragment(k.jsxOpeningFragment(),k.jsxClosingFragment(),[k.jsxExpressionContainer(ks(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 te from"@babel/types";function Yn(e){return te.isExportNamedDeclaration(e)?e.declaration??null:te.isDeclaration(e)?e:null}function yo(e){let t=new Map;for(let n of e.body){let r=Yn(n);te.isTSTypeAliasDeclaration(r)&&t.set(r.id.name,r.typeAnnotation)}return t}function ft(e,t,n=new Set){if(te.isTSLiteralType(e)&&te.isStringLiteral(e.literal))return[e.literal.value];if(te.isTSUnionType(e))return e.types.flatMap(r=>ft(r,t,n));if(te.isTSIntersectionType(e))return e.types.flatMap(r=>ft(r,t,n));if(te.isTSParenthesizedType(e))return ft(e.typeAnnotation,t,n);if(te.isTSTypeLiteral(e))return e.members.flatMap(r=>(te.isTSPropertySignature(r)||te.isTSIndexSignature(r))&&te.isTSTypeAnnotation(r.typeAnnotation)&&te.isTSType(r.typeAnnotation.typeAnnotation)?ft(r.typeAnnotation.typeAnnotation,t,n):[]);if(te.isTSMappedType(e)&&e.typeAnnotation!=null&&te.isTSType(e.typeAnnotation))return ft(e.typeAnnotation,t,n);if(te.isTSTypeReference(e)&&te.isIdentifier(e.typeName)){let r=e.typeName.name;if((r==="Record"||r==="Readonly"||r==="Partial")&&te.isTSTypeParameterInstantiation(e.typeArguments)){let s=r==="Record"?e.typeArguments.params[1]:e.typeArguments.params[0];if(s!==void 0&&te.isTSType(s))return ft(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),ft(o,t,i)}return[]}function In(e){let t=yo(e),n=new Map;for(let r of e.body){let o=Yn(r);if(te.isVariableDeclaration(o))for(let i of o.declarations){if(!te.isIdentifier(i.id)||!te.isTSTypeAnnotation(i.id.typeAnnotation))continue;let s=[...new Set(ft(i.id.typeAnnotation.typeAnnotation,t))];s.length>0&&n.set(i.id.name,s)}}return n}function Qn(e){let t=yo(e),n=new Map,r=(o,i)=>{if(!te.isTSTypeAnnotation(i)||!te.isTSType(i.typeAnnotation))return;let s=[...new Set(ft(i.typeAnnotation,t))];s.length>0&&n.set(o,s)};for(let o of e.body){let i=Yn(o);if(te.isFunctionDeclaration(i)&&i.id!=null){r(i.id.name,i.returnType);continue}if(te.isVariableDeclaration(i))for(let s of i.declarations)te.isIdentifier(s.id)&&(te.isArrowFunctionExpression(s.init)||te.isFunctionExpression(s.init))&&r(s.id.name,s.init.returnType)}return n}import*as dt from"@babel/types";import*as Ee from"@babel/types";function Qt(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=$e(a.name);if(l==="key"&&t.skipKey)continue;let d=Is(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 $e(e){return Ee.isJSXIdentifier(e)?e.name:`${e.namespace.name}:${e.name.name}`}function Is(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 '${$e(e.name)}' must contain a JavaScript expression`)}function Rn(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 Rn(e,a.name,n))o.add(l)}}),n.delete(t),o}function So(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=$e(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)||Le(l.expression,d=>{if(dt.isJSXOpeningElement(d)&&dt.isJSXIdentifier(d.name)&&/^[A-Z]/.test(d.name.name))for(let u of Rn(e,d.name.name))r.add(u)})}})}}import*as Ct from"@babel/types";function xo(e){for(let[t,n]of e.compPaths){let r=e.componentProps.get(t);n.traverse({JSXAttribute(o){if($e(o.node.name)!=="ref")return;let i=o.node.value;if(!(!Ct.isJSXExpressionContainer(i)||!Ct.isExpression(i.expression)))for(let s of Co(e,t,i.expression))r.refProps.includes(s)||r.refProps.push(s)}})}}function Co(e,t,n){let r=pt(e,t,n);if(r!==null)return[r];if(!Ct.isArrayExpression(n))return[];let o=[];for(let i of n.elements)i===null||Ct.isSpreadElement(i)||o.push(...Co(e,t,i));return o}import*as Mt from"@babel/types";function Fn(e){let t=!1;return Le(e,n=>{if(t||!Mt.isJSXOpeningElement(n))return;let r=n.name;!Mt.isJSXIdentifier(r)||!/^[a-z]/.test(r.name)||(t=n.attributes.some(o=>Mt.isJSXAttribute(o)&&Mt.isJSXIdentifier(o.name)&&/^on[A-Z]/.test(o.name.name)))}),t}import*as Oe from"@babel/types";function er(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=Hn(e,r);for(let s of o)t(s,i)}for(let{owner:r,suffix:o,vars:i}of e.rowReads.values()){let s=St(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=St(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=Hn(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])=>Oe.objectProperty(Oe.stringLiteral(r),Oe.arrayExpression([...o].sort().map(i=>Oe.stringLiteral(i)))));return Oe.expressionStatement(Oe.callExpression(Q(e,"installAccessTable"),[Oe.objectExpression([Oe.objectProperty(Oe.identifier("readers"),Oe.objectExpression(n))]),Oe.stringLiteral(e.rootId)]))}function wo(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(!P.isJSXIdentifier(o)||!/^[A-Z]/.test(o.name))return!1;let i=n.node.name,s=P.isJSXIdentifier(i)?i.name:i.name.name;return e.componentProps.get(o.name)?.renderProps.includes(s)===!0}function Po(e,t){let n=t.parentPath,r=n?.parentPath;if(!n?.isJSXExpressionContainer()||!r?.isJSXElement()&&!r?.isJSXFragment()&&!wo(e,n))throw t.buildCodeFrameError("memo-dom: conditional rendering must be a direct JSX child: <div>{cond ? <A/> : <B/>}</div>");t.skip()}function Rs(e,t){for(let n of t.get("body"))if(!(!n.isImportDeclaration()||n.node.importKind==="type"))for(let r of n.node.specifiers){if(P.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 Fs(e,t){let n=In(t.node);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)&&(o.kind==="let"||o.kind==="var"?bt(e,i.id.name,"let"):o.kind==="const"&&(kt(i.init)?bt(e,i.id.name,"store"):Nt(i.init)&&bt(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 Ms(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(Ae(n))if(/^[A-Z]/.test(r)){e.comps.set(r,{parents:new Set,jsxCount:0}),e.compPaths.set(r,n),Fn(n.node.body)&&e.componentsWithHostEvents.add(r);try{e.componentProps.set(r,un(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()||!P.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");!P.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 Mn(e,t,n=new Set){if(P.isTSStringKeyword(e)||P.isTSNumberKeyword(e)||P.isTSBooleanKeyword(e)||P.isTSBigIntKeyword(e)||P.isTSSymbolKeyword(e)||P.isTSNullKeyword(e)||P.isTSUndefinedKeyword(e)||P.isTSLiteralType(e))return!0;if(P.isTSParenthesizedType(e))return Mn(e.typeAnnotation,t,n);if(P.isTSUnionType(e))return e.types.every(r=>Mn(r,t,n));if(P.isTSTypeReference(e)&&P.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=P.isExportNamedDeclaration(i)?i.declaration:i;if(P.isTSTypeAliasDeclaration(s)&&s.id.name===r)return Mn(s.typeAnnotation,t,o)}}return!1}function Ds(e,t){let n=l=>P.isStringLiteral(l)||P.isNumericLiteral(l)||P.isBooleanLiteral(l)||P.isBigIntLiteral(l)||P.isUnaryExpression(l)&&(l.operator==="+"||l.operator==="-")&&P.isNumericLiteral(l.argument);for(let l of e.node.params){if(P.isTSParameterProperty(l))continue;if(P.isAssignmentPattern(l)&&P.isIdentifier(l.left,{name:t})&&n(l.right))return!0;if(P.isAssignmentPattern(l)&&P.isObjectPattern(l.left)&&P.isObjectExpression(l.right)){let u=l.right.properties.find(c=>!P.isObjectProperty(c)||c.computed?!1:(P.isIdentifier(c.key)?c.key.name:P.isStringLiteral(c.key)?c.key.value:null)===t);if(P.isObjectProperty(u)&&P.isExpression(u.value)&&n(u.value))return!0}let d=P.isAssignmentPattern(l)?l.left:l;if(P.isObjectPattern(d))for(let u of d.properties){if(!P.isObjectProperty(u)||u.computed)continue;if((P.isIdentifier(u.key)?u.key.name:P.isStringLiteral(u.key)?u.key.value:null)===t&&P.isAssignmentPattern(u.value)&&n(u.value.right))return!0}}let r=e.node.params[0];if(r==null||P.isTSParameterProperty(r))return!1;let o=P.isAssignmentPattern(r)?r.left:r;if(!P.isIdentifier(o)&&!P.isObjectPattern(o)&&!P.isArrayPattern(o))return!1;let i=o.typeAnnotation;if(!P.isTSTypeAnnotation(i))return!1;let s=e.findParent(l=>l.isProgram());if(!s?.isProgram())return!1;let a=i.typeAnnotation;if(P.isTSTypeReference(a)&&P.isIdentifier(a.typeName)){let l=a.typeName.name,d=s.node.body.map(u=>P.isExportNamedDeclaration(u)?u.declaration:u).find(u=>(P.isTSInterfaceDeclaration(u)||P.isTSTypeAliasDeclaration(u))&&u.id.name===l);P.isTSInterfaceDeclaration(d)?a=P.tsTypeLiteral(d.body.body):P.isTSTypeAliasDeclaration(d)&&(a=d.typeAnnotation)}if(!P.isTSTypeLiteral(a))return!1;for(let l of a.members){if(!P.isTSPropertySignature(l)||l.computed)continue;if((P.isIdentifier(l.key)?l.key.name:P.isStringLiteral(l.key)?l.key.value:null)===t&&P.isTSTypeAnnotation(l.typeAnnotation))return Mn(l.typeAnnotation.typeAnnotation,s.node)}return!1}function tr(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?tr(r,t):!1}}if(e.isMemberExpression()){let n=e.get("object");return!Array.isArray(n)&&tr(n,t)}return!1}function Ls(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(!P.isExpression(l))return;let d=pt(e,o,l);d!==null&&(Ds(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(!P.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=>!P.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=P.isJSXIdentifier(g)?g.name:g.name.name;if(!d.has(x))continue;let E=u.get(x)??{scalar:!1,jsx:!1,at:c},f=c.get("value"),m=!1;if(f.isJSXExpressionContainer()&&P.isExpression(f.node.expression)){let C=f.get("expression");!Array.isArray(C)&&(tr(C)||P.isExpression(C.node)&&pt(e,o,C.node)!==null)&&(m=!0)}m?E.jsx=!0:E.scalar=!0,u.set(x,E)}}});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()||!P.isExpression(l.node.expression))return;let d=pt(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(!P.isJSXIdentifier(c)||!/^[A-Z]/.test(c.name))return;let g=e.componentProps.get(c.name),x=a.node.name,E=P.isJSXIdentifier(x)?x.name:x.name.name;g?.renderProps.includes(E)===!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 As(e,t){let n=e.compPaths.get(t),r=e.comps.get(t);n.traverse({JSXElement(o){let i=o.node.openingElement;if(!P.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(!P.isJSXSpreadAttribute(a)&&a.name.name==="key"){if(Rr(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=>!P.isJSXText(d)||d.value.trim()!=="")||i.attributes.some(d=>{if(P.isJSXSpreadAttribute(d)||e.componentProps.get(s)?.renderProps.includes(P.isJSXIdentifier(d.name)?d.name.name:d.name.name.name)!==!0)return!1;let u=Be(d.value);return u!==null&&de(u)}))&&e.renderSlotOwners.add(t);return}r.jsxCount++},ConditionalExpression(o){Ae(o)&&Po(e,o)},LogicalExpression(o){if(Ae(o)){if(o.node.operator!=="&&"&&o.node.operator!=="||")throw o.buildCodeFrameError("memo-dom: only && / || conditionals are supported (R8 L1), not ??");Po(e,o)}},CallExpression(o){let i=Ve(o.node);if(i&&(Ae(o)||jt(e,t,i)!==null)){let s=o.parentPath,a=s?.parentPath;if(!s?.isJSXExpressionContainer()||!a?.isJSXElement()&&!a?.isJSXFragment()&&!wo(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 Js(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||js(t)?null:n}function vo(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 $s(e,t){let n=[],r=e;for(;r=It(r),!!P.isMemberExpression(r);){if(n.unshift(r),P.isSuper(r.object))return null;r=r.object}if(!P.isIdentifier(r,{name:t}))return null;let o=n[0];if(o===void 0||!o.computed||!P.isExpression(o.property)||!(P.isIdentifier(o.property)||P.isNumericLiteral(o.property)||P.isStringLiteral(o.property))||n.length<2)return null;let i=[];for(let s of n.slice(1))if(!s.computed&&P.isIdentifier(s.property))i.push(s.property.name);else if(s.computed&&P.isStringLiteral(s.property))i.push(s.property.value);else return null;return i}function Os(e,t,n){let r=!1;return Le(e.node.body,o=>{if(r)return;let i=P.isAssignmentExpression(o)&&P.isMemberExpression(o.left)?o.left:P.isUpdateExpression(o)&&P.isMemberExpression(o.argument)||P.isUnaryExpression(o,{operator:"delete"})&&P.isMemberExpression(o.argument)?o.argument:null;if(i===null)return;let s=$s(i,t);s!==null&&!At(s,n)&&(r=!0)}),r}function Xs(e,t,n,r){if(!r.sourceLocal||!P.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||!Os(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 u={source:o,keyPath:i,keysVariable:A(e,`${o}ChangedKeys`).name,targetedReason:`${a}\0content`,structuralReason:`${a}\0structure`,call:n};l.set(o,u),e.keyedListMutations.set(n,u),e.targetedListComponents.add(t),vo(e,t,[o,u.targetedReason,u.structuralReason])}function Ts(e){for(let[a]of e.comps){let g=function(y,v,M){let R=Ve(y.node);if(R===null||!Ae(y))return;let I=Rt(e,R,y,a,M),H=`${v}/${I.suffix}`;if(I.form==="component"){let O=e.listedSites.get(I.rowComp)??[];O.some(_=>_.owner===a&&_.suffix===H)||O.push({owner:a,suffix:H,itemParam:I.itemParam,keyExpr:I.keyExpr,sourceKey:I.sourceKey,sourceLocal:I.sourceLocal}),e.listedSites.set(I.rowComp,O)}else m(y,I,H);y.skip()},x=function(y,v,M){let R=y.node.openingElement.name;if(!P.isJSXIdentifier(R)||!/^[A-Z]/.test(R.name))return;if(!e.comps.has(R.name)&&!e.importedComponents.has(R.name))throw y.buildCodeFrameError(`memo-dom: <${R.name} /> is not a linked component factory`);let I=M.get(R.name)??0;M.set(R.name,I+1);let H=I===0?R.name:`${R.name}[${I}]`,O=`${v}/${H}`,_=e.conditionalComponentSites.get(R.name)??[];_.some(Y=>Y.owner===a&&Y.suffix===O)||_.push({owner:a,suffix:O}),e.conditionalComponentSites.set(R.name,_)},E=function(y,v,M){let R=y.node.openingElement.name;if(!P.isJSXIdentifier(R)||!/^[A-Z]/.test(R.name))return;if(!e.comps.has(R.name)&&!e.importedComponents.has(R.name))throw y.buildCodeFrameError(`memo-dom: <${R.name} /> is not a linked component factory`);let I=M.get(R.name)??0;M.set(R.name,I+1);let H=I===0?R.name:`${R.name}[${I}]`,O=`${v}/Row[*]/${H}`,_=e.rowComponentSites.get(R.name)??[];_.some(Y=>Y.owner===a&&Y.suffix===O)||_.push({owner:a,suffix:O}),e.rowComponentSites.set(R.name,_)},f=function(y,v){let M=e.listedSites.get(y.rowComp)??[];M.some(R=>R.owner===a&&R.suffix===v)||M.push({owner:a,suffix:v,itemParam:y.itemParam,keyExpr:y.keyExpr,sourceKey:y.sourceKey,sourceLocal:y.sourceLocal}),e.listedSites.set(y.rowComp,M)},m=function(y,v,M){let R=y.get("arguments")[0];if(R===void 0)return;let I=new Set,H=new Map,O=new Map;R.traverse({Identifier(_){_.node.name!==v.itemParam&&e.state.has(_.node.name)&&_.scope.getBinding(_.node.name)?.scope.path.isProgram()===!0&&I.add(_.node.name)},JSXElement(_){E(_,M,H)},CallExpression(_){let Y=Ve(_.node);if(Y!==null&&Ae(_)){let ne=Rt(e,Y,_,a,O,v),xe=`${M}/Row[*]/${ne.suffix}`;ne.form==="component"?f(ne,xe):m(_,ne,xe),_.skip();return}let Z=_.node.callee;if(P.isIdentifier(Z)&&(e.helpers.has(Z.name)||e.importedFunctions.has(Z.name))){let ne=e.importedFunctions.get(Z.name)??Ue(e,Z.name);for(let xe of ne.reads)I.add(xe)}}}),I.size>0&&e.rowReads.set(`${a}/${M}`,{owner:a,suffix:M,vars:I})},C=function(y,v=null){let M=y.node;if(!Ae(y))return;let R=gn(M,y,c),I=v===null?R.suffix:`${v}/${R.suffix}`,H=[];if(y.isConditionalExpression()){let _=y;for(;_.isConditionalExpression();)H.push(_.get("consequent")),_=_.get("alternate");H.push(_)}else H.push(y.get("right"));for(let _ of H){let Y=new Map,Z=new Map;if((_.isConditionalExpression()||_.isLogicalExpression())&&Ae(_)){C(_,I);continue}_.isJSXElement()&&x(_,I,Z),_.traverse({ConditionalExpression(ne){Ae(ne)&&(C(ne,I),ne.skip())},LogicalExpression(ne){Ae(ne)&&(C(ne,I),ne.skip())},JSXElement(ne){x(ne,I,Z)},CallExpression(ne){g(ne,I,Y)}})}let O=dn(e,M);O.size>0&&v===null&&e.condReads.set(`${a}/${I}`,{owner:a,suffix:I,vars:O}),y.skip()};var t=g,n=x,r=E,o=f,i=m,s=C;let l=e.compPaths.get(a),d=new Set,u=new Map,c={count:0};l.traverse({JSXAttribute(y){let v=y.node.name;(P.isJSXIdentifier(v,{name:"ref"})||P.isJSXNamespacedName(v)&&v.namespace.name==="ref")&&y.skip()},ConditionalExpression(y){C(y)},LogicalExpression(y){C(y)},CallExpression(y){if(P.isIdentifier(y.node.callee,{name:"effect"})&&y.scope.getBinding("effect")===void 0){y.skip();return}let v=Ve(y.node);if(v&&(Ae(y)||jt(e,a,v)!==null)){let R=Rt(e,v,y,a,u);Xs(e,a,v,R);let I=po(R,e.instanceState.get(a)??new Set);if(I.length>0&&P.isIdentifier(R.sourceExpr)){let H=R.sourceExpr.name;e.targetedListDependencies.set(v,I.map(O=>({source:H,value:O}))),e.targetedListComponents.add(a),vo(e,a,[H,...I])}if(R.sourceLocal||d.add(R.sourceKey),R.form==="component"){for(let O of R.jsx.openingElement.attributes){if(P.isJSXSpreadAttribute(O))continue;let _=O,Y=P.isJSXIdentifier(_.name)?_.name.name:`${_.name.namespace.name}:${_.name.name.name}`;if(Y==="key"||Y==="ref"||e.componentProps.get(R.rowComp)?.refProps.includes(Y)===!0)continue;let Z=Be(_.value);Z&&Le(Z,ne=>{if(P.isIdentifier(ne)&&e.state.has(ne.name)&&y.scope.getBinding(ne.name)?.scope.path.isProgram()===!0&&d.add(ne.name),P.isMemberExpression(ne)){let xe=ye(ne);if(xe!==null&&xe.includes(".")){let be=xe.split(".")[0];e.state.get(be)==="store"&&y.scope.getBinding(be)?.scope.path.isProgram()===!0&&d.add(xe)}}})}let H=e.listedSites.get(R.rowComp)??[];H.some(O=>O.owner===a&&O.suffix===R.suffix)||H.push({owner:a,suffix:R.suffix,itemParam:R.itemParam,keyExpr:R.keyExpr,sourceKey:R.sourceKey,sourceLocal:R.sourceLocal}),e.listedSites.set(R.rowComp,H)}else m(y,R,R.suffix);y.skip();return}let M=y.node.callee;if(P.isIdentifier(M)&&(e.helpers.has(M.name)||e.importedFunctions.has(M.name))&&y.scope.getBinding(M.name)?.scope.path.isProgram()===!0){let R=e.importedFunctions.get(M.name)??Ue(e,M.name);for(let I of R.reads)d.add(I)}},Identifier(y){if(!e.state.has(y.node.name)||y.scope.getBinding(y.node.name)?.scope.path.isProgram()!==!0)return;let v=y.parentPath;v.isAssignmentExpression({operator:"="})&&v.node.left===y.node||d.add(y.node.name)},MemberExpression(y){let v=Js(e,y);v!==null&&d.add(v)}}),e.compReads.set(a,d)}}function Dn(e,t){Rs(e,t),Fs(e,t),Ms(e,t),xo(e),Fr(e),lo(e),bo(e,t),Ls(e),oo(e),Eo(e),co(e),Zr(e),Gr(e,t),qr(e,t,Un),Yr(e),eo(e),to(e),Vr(e,t);for(let[r]of e.comps)As(e,r);Ts(e),So(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 D from"@babel/types";import*as h from"@babel/types";import*as Pe from"@babel/types";import*as oe from"@babel/types";function Dt(){return{writes:new Set,rootFallback:!1,rowLocal:!1,rowOwnerLocal:!1,instanceLocal:!1,instanceWrites:new Set,eventOrigin:null}}function Xt(e,t){e.instanceLocal=!0,e.instanceWrites.add(t)}function Tt(e,t,n,r){let o=t.rowLocal&&r!==void 0?oe.expressionStatement(r.refreshVar!==void 0?oe.callExpression(oe.identifier(r.refreshVar),[]):oe.callExpression(Q(e,"markDirty"),[oe.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=oe.expressionStatement(oe.callExpression(Q(e,"markDirty"),[Je(e,n),...c?[u.length===1?oe.numericLiteral(u[0]):Cr(e,u)]:[]]))}let s=t.rowOwnerLocal&&r?.ownerIdVar!==void 0?oe.expressionStatement(oe.callExpression(Q(e,"markDirty"),[oe.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]:oe.blockStatement(u)};if(t.rootFallback)return a(oe.expressionStatement(oe.callExpression(Q(e,"markDirtySubtree"),[oe.stringLiteral(e.rootId)])));if(t.writes.size===0)return a(null);let l=[...t.writes].sort();return a(oe.expressionStatement(oe.callExpression(Q(e,"commitWrites"),[Ut(e,l)])))}function ko(e,t,n){if(oe.isBlockStatement(t.body)){nr(t.body,n),t.body.body.push(n);return}let r=A(e,"returnValue");t.body=oe.blockStatement([oe.variableDeclaration("const",[oe.variableDeclarator(r,t.body)]),n,oe.returnStatement(oe.cloneNode(r))])}function nr(e,t){if(!oe.isFunction(e))for(let n of oe.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)||oe.isFunction(i)||(oe.isReturnStatement(i)?(r.splice(o,0,oe.cloneNode(t)),o++):nr(i,t))}else if(r&&typeof r=="object"&&"type"in r){if(oe.isFunction(r))continue;oe.isReturnStatement(r)?e[n]=oe.blockStatement([oe.cloneNode(t),r]):nr(r,t)}}}import*as Se from"@babel/types";function Pt(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?Je(e,t):Se.stringLiteral(e.rootId));return Se.expressionStatement(Se.callExpression(Q(e,"markDirty"),[Se.cloneNode(o)]))}function Bt(e,t,n){let r=A(e,"event"),o=A(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 Ro from"@babel/traverse";import*as T from"@babel/types";function Bs(e,t,n){if(n.key===null)return null;let r=e.componentProps.get(t);if(r===void 0)return null;let o=Ke(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 rr(e,t,n,r,o){let i=Bs(e,t,r);if(i===null)return!1;n===void 0?Xt(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 Ln(e){return he.isIdentifier(e)||he.isObjectPattern(e)||he.isArrayPattern(e)||he.isAssignmentPattern(e)||he.isRestElement(e)}function Vs(e){let t=e;for(;he.isTSAsExpression(t)||he.isTSTypeAssertion(t)||he.isTSNonNullExpression(t)||he.isTSSatisfiesExpression(t);)t=t.expression;return t}function en(e,t,n){if(he.isIdentifier(t)){e.set(t.name,n);return}if(he.isAssignmentPattern(t)){Ln(t.left)&&en(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];Ln(o)&&en(e,o,Et(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)){Ln(r.value)&&en(e,r.value,{...n,key:null});continue}let o=he.isIdentifier(r.key)?r.key.name:String(r.key.value);Ln(r.value)&&en(e,r.value,Et(n,[o]))}}}function No(e,t,n,r){let o=Vs(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:Ke(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(!he.isMemberExpression(o))return null;let s=ve(o),a=ye(o);if(s===null)return null;let l=No(e,t,n,he.identifier(s));return l===null?null:a===null?{...l,key:null}:Et(l,a.split(".").slice(1))}function Io(e,t){let n=new Map;for(let r of e.instanceDerivations.get(t)??[]){let o=No(e,t,n,r.source);o!==null&&en(n,r.target,o)}return n}var Fo=Ro.default??Ro;function Ws(e,t){let n=[],r=e;for(;r=It(r),!!T.isMemberExpression(r);){if(n.unshift(r),T.isSuper(r.object))return null;r=r.object}if(!T.isIdentifier(r,{name:t.source}))return null;let o=n[0];if(o===void 0||!o.computed||!T.isExpression(o.property)||!(T.isIdentifier(o.property)||T.isNumericLiteral(o.property)||T.isStringLiteral(o.property))||n.length<2)return null;let i=[];for(let a of n.slice(1))if(!a.computed&&T.isIdentifier(a.property))i.push(a.property.name);else if(a.computed&&T.isStringLiteral(a.property))i.push(a.property.value);else return null;if(At(i,t.keyPath))return null;let s=T.cloneNode(o,!0);for(let a of t.keyPath)s=T.memberExpression(s,T.identifier(a));return s}function zs(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 Mo(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 zs(e,r))if(i==="__rows__"||i==="__regions__"||!o.has(i))return!0;return!1}function tn(e,t,n,r,o=!1,i,s=!1){let a=T.cloneNode(t),l=a,d=T.file(T.program([T.isFunctionDeclaration(a)?a:T.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:Io(e,n),x=n!==null?new Set(e.componentProps.get(n)?.bindings??[]):new Set,E=new Set([...x,...u??[],...c??[]]);if(n!==null)for(let S of e.compPaths.get(n)?.node.body.body??[])if(T.isVariableDeclaration(S))for(let w of S.declarations)for(let L of Object.keys(T.getBindingIdentifiers(w.id)))E.add(L);else T.isFunctionDeclaration(S)&&S.id&&E.add(S.id.name);let f=new Jt((S,w)=>{if(w!==void 0)return null;let L=g.get(S);if(L!==void 0)return L;if(r!==void 0&&S===r.itemParam)return{locality:"row",root:S,key:S};if(u?.has(S)===!0)return{locality:"instance",root:S,key:S};if(x.has(S))return{locality:"prop",root:S,key:S};if(E.has(S))return null;let ee=e.state.get(S);return ee===void 0?null:bn(S,ee)}),m=S=>S.stateKind==="computed"||e.state.get(S.root)==="computed",C=n===null?void 0:e.keyedListMutationSources.get(n),y=(S,w,L="structural")=>{Xt(S,w);let ee=C?.get(w);ee!==void 0&&Xt(S,L==="targeted"?ee.targetedReason:ee.structuralReason)},v=(S,w,L)=>{S.isExpression()&&(S.replaceWith(T.sequenceExpression([T.callExpression(T.memberExpression(T.identifier(w.keysVariable),T.identifier("add")),[L]),S.node])),S.skip())},M=new Set;for(let S of a.params)T.isIdentifier(S)&&M.add(S.name);Fo(d,{VariableDeclarator(S){T.isIdentifier(S.node.id)&&(M.add(S.node.id.name),S.parentPath.isVariableDeclaration()&&f.trackDeclarator(S.scope,S.node))},Function(S){for(let w of S.node.params)T.isIdentifier(w)&&M.add(w.name)}});let R=new Map,I=new Map,H=S=>{let w=S.getFunctionParent()?.node??l,L=R.get(w);return L||R.set(w,L=Dt()),L},O=(S,w)=>{if(w(H(S)),!s||S.getFunctionParent()?.node!==l)return;let L=I.get(S.node);L===void 0&&(L={path:S,writes:Dt()},I.set(S.node,L)),w(L.writes)},_=S=>{O(S,w=>{r?.sourceLocal?w.rowOwnerLocal=!0:r!==void 0&&w.writes.add(r.sourceKey)})},Y=S=>{if(r===void 0)return null;let w=S.split(".").slice(1);return r.itemPath.some((L,ee)=>w[ee]!==L)?null:w.slice(r.itemPath.length)},Z=(S,w)=>{O(S,L=>{w!==void 0&&n!==null&&rr(e,n,r,w,L)||(L.rowLocal=!0,L.rootFallback=!0)})},ne=(S,w)=>{O(S,L=>{(n===null||!rr(e,n,r,w,L))&&(r===void 0?(n!==null&&Xt(L,w.root),L.rootFallback=!0):(L.rowLocal=!0,L.rootFallback=!0))})},xe=(S,w)=>{if(r===void 0||ve(w)!==r.itemParam)return!1;let L=ye(w);if(L===null)return r.itemPath.length===0?_(S):Z(S),!0;let ee=L.split(".").slice(1);return r.itemPath.some((Xe,Ie)=>ee[Ie]!==Xe)?!1:(ee.splice(0,r.itemPath.length),At(ee,r.keyPath)?_(S):(O(S,Xe=>{Xe.rowLocal=!0}),Mo(e,n,r)&&_(S)),!0)},be=(S,w)=>{if(w.locality==="instance"){O(S,L=>{y(L,w.root)});return}if(w.locality==="row"){if(r===void 0){O(S,ee=>{ee.rootFallback=!0});return}if(w.key===null){r.itemPath.length===0?_(S):Z(S);return}let L=Y(w.key);if(L===null){Z(S,w);return}At(L,r.keyPath)?_(S):(O(S,ee=>{ee.rowLocal=!0}),Mo(e,n,r)&&_(S));return}if(w.locality==="prop"){ne(S,w);return}if(w.stateKind==="computed")throw S.buildCodeFrameError(`memo-dom: cannot mutate computed '${w.root}' (R13) - it is derived; write its SOURCE state instead`);if(w.stateKind!=="store"){O(S,L=>{L.writes.add(w.root)});return}w.key!==null&&w.key.includes(".")?O(S,L=>{L.writes.add(w.key)}):O(S,L=>{L.writes.add(w.root)})},ie=(S,w)=>{if(w.locality==="instance"){O(S,L=>{y(L,w.root)});return}if(w.locality==="row"){if(r===void 0){O(S,Xe=>{Xe.rootFallback=!0});return}if(w.key===null){r.itemPath.length===0?_(S):Z(S);return}let L=Y(w.key);if(L===null){Z(S,w);return}L.length===0&&(r.keyPath===null||r.keyPath.length>0)?_(S):be(S,w);return}if(w.locality==="prop"){ne(S,w);return}if(w.stateKind==="computed")throw S.buildCodeFrameError(`memo-dom: cannot mutate computed '${w.root}' (R13) - write its SOURCE state instead`);O(S,L=>{L.writes.add(w.key??w.root)})},V=(S,w)=>{if(!(s&&S.getFunctionParent()?.node===l))for(let L of En(w)){if(!T.isIdentifier(L))continue;let ee=f.resolveExpression(S.scope,L);ee!==null&&(m(ee)||ie(S,ee))}},le=(S,w)=>{let L=ve(w);if(L!==void 0&&u?.has(L??"")===!0){let Ie=C?.get(L),qe=Ie===void 0?null:Ws(w,Ie);O(S,sn=>{y(sn,L,qe===null?"structural":"targeted")}),Ie!==void 0&&qe!==null&&v(S,Ie,qe);return}if(L!==null&&c?.has(L)&&!g.has(L))throw S.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${L}' (R14) \u2014 write its source instead`);if(xe(S,w))return;let ee=f.resolveExpression(S.scope,w);if(ee!==null){be(S,ee);return}if(L!==null&&x.has(L)){ne(S,{locality:"prop",root:L,key:ye(w)});return}if(L!==null&&E.has(L)||!L||!e.state.has(L))return;let Xe=e.state.get(L);if(Xe==="computed")throw S.buildCodeFrameError(`memo-dom: cannot mutate computed '${L}' (R13) \u2014 it is derived; write its SOURCE state instead`);O(S,Ie=>{if(Xe!=="store"){Ie.writes.add(L);return}let qe=ye(w);qe!==null&&qe.includes(".")?Ie.writes.add(qe):Ie.writes.add(L)})};Fo(d,{VariableDeclarator(S){if(!T.isIdentifier(S.node.id)&&S.node.init!==null)for(let w of f.referencedOrigins(S.scope,S.node.init))ie(S,w)},AssignmentExpression(S){let w=S.node.left;if(T.isIdentifier(w)){if(M.has(w.name)){if(T.isIdentifier(S.node.right)){let ee=f.resolveExpression(S.scope,S.node.right);ee!==null&&ie(S,ee)}return}if(c?.has(w.name))throw S.buildCodeFrameError(`memo-dom: cannot assign per-instance derivation '${w.name}' (R14) \u2014 write its source instead`);if(u?.has(w.name)===!0){O(S,ee=>{y(ee,w.name)});return}if(x.has(w.name))throw S.buildCodeFrameError(`memo-dom: cannot assign prop '${w.name}' \u2014 copy it to component-local let state first`);if(E.has(w.name))throw S.buildCodeFrameError(`memo-dom: cannot assign component-local const '${w.name}'`);let L=e.state.get(w.name);if(!L)throw S.buildCodeFrameError(`memo-dom: handler assigns '${w.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(w.name))throw S.buildCodeFrameError(`memo-dom: cannot reassign imported state '${w.name}' - ES module imports are read-only; export a mutator or mutate an imported store property`);if(L==="store")throw S.buildCodeFrameError(`memo-dom: cannot reassign store '${w.name}' \u2014 assign a property (${w.name}.field = \u2026) instead`);if(L==="const")throw S.buildCodeFrameError(`memo-dom: cannot reassign mutable const root '${w.name}' - mutate the object instead`);if(L==="computed")throw S.buildCodeFrameError(`memo-dom: cannot assign computed '${w.name}' (R13) \u2014 it is derived; write its SOURCE state instead and the derivation recomputes`);O(S,ee=>{ee.writes.add(w.name)})}else if(T.isMemberExpression(w))le(S,w);else for(let L of f.referencedOrigins(S.scope,S.node.right))ie(S,L)},UpdateExpression(S){let w=S.node.argument;if(T.isIdentifier(w)){if(M.has(w.name))return;if(c?.has(w.name))throw S.buildCodeFrameError(`memo-dom: cannot update per-instance derivation '${w.name}' (R14) \u2014 write its source instead`);if(u?.has(w.name)===!0){O(S,ee=>{y(ee,w.name)});return}if(x.has(w.name))throw S.buildCodeFrameError(`memo-dom: cannot update prop '${w.name}' \u2014 copy it to component-local let state first`);if(E.has(w.name))throw S.buildCodeFrameError(`memo-dom: cannot update component-local const '${w.name}'`);let L=e.state.get(w.name);if(!L)throw S.buildCodeFrameError(`memo-dom: handler updates '${w.name}', which is neither module state nor a handler local`);if(e.importedState.has(w.name))throw S.buildCodeFrameError(`memo-dom: cannot update imported state '${w.name}' - ES module imports are read-only; call an exported mutator instead`);if(L!=="let")throw S.buildCodeFrameError(L==="computed"?`memo-dom: cannot update computed '${w.name}' (R13) \u2014 it is derived; write its SOURCE state instead`:`memo-dom: cannot update '${w.name}' \u2014 it is a const binding; mutate its contents instead`);O(S,ee=>{ee.writes.add(w.name)})}else T.isMemberExpression(w)&&le(S,w)},UnaryExpression(S){S.node.operator==="delete"&&T.isMemberExpression(S.node.argument)&&le(S,S.node.argument)},CallExpression(S){let w=S.node.callee;if(T.isMemberExpression(w)){if(yn(w)==="assign"&&T.isIdentifier(w.object,{name:"Object"})){let Ie=S.node.arguments[0],qe=Ie!==void 0&&T.isExpression(Ie)?f.resolveExpression(S.scope,Ie):null;if(qe!==null)if(qe.locality==="module"&&qe.stateKind==="store"){let sn=hn(qe,S.node.arguments.slice(1));sn===null?ie(S,qe):O(S,Ri=>{for(let Fi of sn)Ri.writes.add(Fi)})}else be(S,qe);return}let ee=T.isIdentifier(w.object)?w.object.name:T.isMemberExpression(w.object)?ve(w.object):null;if(ee!==null&&c?.has(ee)&&!g.has(ee))throw S.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${ee}' (R14) - write its source instead`);let Xe=T.isExpression(w.object)?f.resolveExpression(S.scope,w.object):null;Xe!==null?ie(S,Xe):V(S,S.node.arguments);return}if(T.isIdentifier(w)&&!E.has(w.name)&&(e.helpers.has(w.name)||e.importedFunctions.has(w.name))){let L=e.importedFunctions.get(w.name)??Ue(e,w.name);O(S,ee=>{for(let Ie of L.writes)ee.writes.add(Ie);for(let Ie of L.boundedWrites)ee.writes.add(Ie);let Xe=s&&S.getFunctionParent()?.node===l;L.unbounded&&!Xe&&(ee.rootFallback=!0)});for(let ee of L.parameterWrites){let Xe=S.node.arguments[ee.index];if(Xe===void 0||!T.isExpression(Xe))continue;let Ie=f.resolveExpression(S.scope,Xe);if(Ie!==null){if(m(Ie))continue;ie(S,Et(Ie,ee.path))}}return}V(S,S.node.arguments)}});let Te=R.has(l);if(e.handlerHasRootCommit.set(t,Te),o&&!R.has(l)){let S=Dt();S.eventOrigin=Pt(e,n,r,i),R.set(l,S)}let we=[];if(s)for(let S of I.values()){let w=Tt(e,S.writes,n,r);w!==null&&we.push({...S,commit:w})}for(let S of we)S.flag=A(e,"didWrite");we.sort((S,w)=>Do(w.path)-Do(S.path)).forEach(S=>Ks(S.path,S.flag));for(let[S,w]of R){let L=s&&S===l?we.length===0?null:T.blockStatement(we.map(ee=>T.ifStatement(T.cloneNode(ee.flag),T.cloneNode(ee.commit)))):Tt(e,w,n,r);L&&ko(e,S,L)}if(we.length>0){if(!T.isBlockStatement(a.body))throw new Error("memo-dom: execution-aware callback commit did not produce a block body");a.body.body.unshift(T.variableDeclaration("let",we.map(S=>T.variableDeclarator(T.cloneNode(S.flag),T.booleanLiteral(!1)))))}t.body=a.body}function Do(e){let t=0,n=e;for(;n.parentPath!==null;)t++,n=n.parentPath;return t}function Ks(e,t){let n=T.assignmentExpression("=",T.cloneNode(t),T.booleanLiteral(!0));if(e.isVariableDeclarator()){let r=e.node.init;if(r===null||!T.isExpression(r))throw new Error("memo-dom: execution-aware variable site has no expression initializer");e.node.init=T.sequenceExpression([n,r]);return}if(!e.isExpression())throw new Error(`memo-dom: unsupported execution-aware write site '${e.node.type}'`);e.replaceWith(T.sequenceExpression([n,e.node]))}import*as ct from"@babel/types";function Lo(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 mt(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&&(Pe.isArrowFunctionExpression(o)||Pe.isFunctionExpression(o))?o:null}function at(e,t,n,r,o,i=!1){e.analyzedFunctions.has(n)||(or(e,t,n,r,o),e.analyzedFunctions.add(n),tn(e,n,r,o,!1,void 0,i))}function nn(e,t,n=!1){e.analyzedFunctions.has(t)||(e.analyzedFunctions.add(t),tn(e,t,null,void 0,!1,void 0,n))}function or(e,t,n,r,o){let i=new Set;Le(n.body,s=>{Pe.isCallExpression(s)&&Pe.isIdentifier(s.callee)&&i.add(s.callee.name)});for(let s of i){let a=mt(t,s);a===null||e.analyzedFunctions.has(a)||(e.analyzedFunctions.add(a),or(e,t,a,r,o),tn(e,a,r,o,!1))}}function ir(e,t,n,r,o,i,s){let a=null,l=!1,d=e.componentProps.get(o),u=d===void 0?null:Ke(d);if(d!==void 0&&(Pe.isIdentifier(n)&&Ze(d,n.name)!==null||Pe.isMemberExpression(n)&&u!==null&&ve(n)===u))return Bt(e,n,Pt(e,o,i,s));if(Pe.isArrowFunctionExpression(n)||Pe.isFunctionExpression(n))a=n;else if(Pe.isIdentifier(n)){let g=e.importedFunctions.get(n.name);if(g!==void 0){let f=Dt();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,Bt(e,n,Tt(e,f,null)??Pt(e,o,i,s))}let x=t.scope.getBinding(n.name),E=x?.path;if(E&&E.isVariableDeclarator()){let f=E.node.init;f&&(Pe.isArrowFunctionExpression(f)||Pe.isFunctionExpression(f))&&(a=f,l=x?.scope.path.isProgram()===!0&&e.helpers.has(n.name))}else E&&E.isFunctionDeclaration()&&(e.helpers.has(n.name)?(a=E.node,l=!0):a=mt(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(Pe.isBlockStatement(a.body)||(a.body=Pe.blockStatement([Pe.expressionStatement(a.body)])),!e.analyzedFunctions.has(a)){l||or(e,t,a,o,i);let g=!l&&!Pe.isIdentifier(n)&&Lo(a,x=>{let E=mt(t,x);return E!==null&&e.handlerHasRootCommit.get(E)===!0});e.analyzedFunctions.add(a),tn(e,a,l?null:o,l?void 0:i,!l&&!Pe.isIdentifier(n)&&!g,s)}if(l){let g=Ue(e,n.name);if(a.async){let x=Dt();for(let E of g.writes)x.writes.add(E);for(let E of g.boundedWrites)x.writes.add(E);return x.rootFallback=g.unbounded,Bt(e,n,Tt(e,x,null)??Pt(e,o,i,s))}if(g.writes.size===0&&g.boundedWrites.size===0&&!g.unbounded)return Bt(e,n,Pt(e,o,i,s))}return Pe.isIdentifier(n)&&!l&&(e.handlerHasRootCommit.get(a)===!1||a.async)?Bt(e,n,Pt(e,o,i,s)):Pe.isIdentifier(n)?n:a}import*as Ne from"@babel/types";function sr(e,t){let n=[];for(let r of e){if(Ne.isJSXText(r)){let a=Wn(r.value);a!==""&&n.push({type:"node",variable:t.emitText(Ne.stringLiteral(a))});continue}if(Ne.isJSXElement(r)||Ne.isJSXFragment(r)){n.push({type:"node",variable:t.emitNode(r)});continue}if(Ne.isJSXExpressionContainer(r)||t.fail("memo-dom: spread children are not supported"),Ne.isJSXEmptyExpression(r.expression))continue;Ne.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:Ne.cloneNode(o)});continue}if(Ne.isNullLiteral(o)||Ne.isBooleanLiteral(o)||Ne.isIdentifier(o,{name:"undefined"}))continue;let i=Ve(o);if(i!==null){n.push({type:"list",expression:i});continue}let s=mn(o);if(s!==null&&de(s)){n.push({type:"condition",expression:s});continue}n.push({type:"node",variable:t.emitText(Ne.cloneNode(o))})}return n}import*as B from"@babel/types";var Us=new Set(["innerHTML","checked","value","selected","disabled","hidden","multiple","required","readOnly","muted","open","controls","loop","autoFocus","autoPlay","tabIndex"]),Ao={htmlFor:"for",crossOrigin:"crossorigin"};function ar(e,t){return!t&&Us.has(e)?e:null}function lr(e,t){return!t&&e in Ao}function dr(e,t,n){let r=B.identifier(e);if(t==="tabIndex")return B.isStringLiteral(n)?B.expressionStatement(B.assignmentExpression("=",B.memberExpression(r,B.identifier(t)),B.cloneNode(n))):B.expressionStatement(B.conditionalExpression(B.binaryExpression("==",B.cloneNode(n),B.nullLiteral()),B.callExpression(B.memberExpression(B.cloneNode(r),B.identifier("removeAttribute")),[B.stringLiteral("tabindex")]),B.assignmentExpression("=",B.memberExpression(B.cloneNode(r),B.identifier(t)),B.cloneNode(n))));let o=t==="value"||t==="innerHTML"?B.stringLiteral(""):B.booleanLiteral(!1),i=B.isStringLiteral(n)?B.cloneNode(n):B.conditionalExpression(B.binaryExpression("==",B.cloneNode(n),B.nullLiteral()),o,B.cloneNode(n));return B.expressionStatement(B.assignmentExpression("=",B.memberExpression(r,B.identifier(t)),i))}function An(e,t,n){let r=B.identifier(e),o=Ao[t]??t;return B.isStringLiteral(n)?B.expressionStatement(B.callExpression(B.memberExpression(r,B.identifier("setAttribute")),[B.stringLiteral(o),B.cloneNode(n)])):B.expressionStatement(B.conditionalExpression(B.logicalExpression("||",B.binaryExpression("==",B.cloneNode(n),B.nullLiteral()),B.binaryExpression("===",B.cloneNode(n),B.booleanLiteral(!1))),B.callExpression(B.memberExpression(B.cloneNode(r),B.identifier("removeAttribute")),[B.stringLiteral(o)]),B.callExpression(B.memberExpression(r,B.identifier("setAttribute")),[B.stringLiteral(o),B.conditionalExpression(B.binaryExpression("===",B.cloneNode(n),B.booleanLiteral(!0)),B.stringLiteral(""),B.callExpression(B.identifier("String"),[B.cloneNode(n)]))])))}import*as _e from"@babel/types";var Hs="http://www.w3.org/2000/svg",_s=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"||_s.has(e)}function Jo(e,t){return t?_e.callExpression(_e.memberExpression(_e.identifier("document"),_e.identifier("createElementNS")),[_e.stringLiteral(Hs),_e.stringLiteral(e)]):_e.callExpression(_e.memberExpression(_e.identifier("document"),_e.identifier("createElement")),[_e.stringLiteral(e)])}import*as fe 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?[fe.identifier("undefined")]:[fe.objectExpression(n.map(s=>fe.objectProperty(fe.identifier(s.name),s.value,!1,fe.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)??fe.identifier("undefined"))}function Vt(e,t,n){let r=e.componentProps.get(t);return r?.mode==="object"?[fe.cloneNode(n)]:(r?.names??[]).map(o=>fe.memberExpression(fe.cloneNode(n),fe.isValidIdentifier(o)?fe.identifier(o):fe.stringLiteral(o),!fe.isValidIdentifier(o)))}function $o(e,t,n,r,o){let i=A(e,`${t}Props`);return fe.blockStatement([fe.variableDeclaration("const",[fe.variableDeclarator(fe.cloneNode(i),fe.cloneNode(o))]),fe.expressionStatement(fe.callExpression(Q(e,"setProps"),[fe.binaryExpression("+",fe.cloneNode(n),fe.stringLiteral(r)),fe.arrayExpression(Vt(e,t,i))]))])}import*as Fe from"@babel/types";function Wt(e){return(Fe.isArrowFunctionExpression(e)||Fe.isFunctionExpression(e))&&!qs(e.body)}function cr(e,t,n,r="callback"){let o=A(e,r);return t.creation.push(Fe.variableDeclaration("const",[Fe.variableDeclarator(Fe.cloneNode(o),Fe.cloneNode(n,!0))])),o}function ur(e,t,n,r="callback"){let o=A(e,r);return t.push(Fe.variableDeclaration("const",[Fe.variableDeclarator(Fe.cloneNode(o),Fe.cloneNode(n,!0))])),o}function qs(e){let t=!1;return Fe.traverseFast(e,n=>{if(Fe.isJSXElement(n)||Fe.isJSXFragment(n))return t=!0,Fe.traverseFast.stop}),t}import*as U from"@babel/types";function Oo(e,t,n,r,o,i,s,a=!1,l=Je(e,o),d=!1){let u=gn(n,i,t.usedConds),c=A(e,u.suffix).name,g=U.binaryExpression("+",U.cloneNode(l),U.stringLiteral(`/${u.suffix}`)),x=U.arrowFunctionExpression([],U.cloneNode(u.pickExpr)),E=u.branches.map(f=>f!==null?pr(e,f,o,i,g,s,a,g,!1,t.usedConds):U.nullLiteral());t.creation.push(yt(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(Q(e,"createCondRegion"),[U.identifier(r),U.cloneNode(g),x,U.arrayExpression(E)]))])),(d||Pr(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 pr(e,t,n,r,o,i,s=!1,a=o,l=!1,d){let u=rt(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(Q(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(E=>U.ifStatement(U.binaryExpression("!==",U.cloneNode(E),U.nullLiteral()),U.expressionStatement(U.callExpression(U.cloneNode(E),[])))),...u.disposableRegions.map(E=>U.expressionStatement(U.callExpression(U.memberExpression(U.identifier(E),U.identifier("dispose")),[]))),...u.disposableEntities.map(E=>U.expressionStatement(U.callExpression(Q(e,"unregisterSubtree"),[U.cloneNode(E)])))];g.push(U.objectProperty(U.identifier("dispose"),U.arrowFunctionExpression([],U.blockStatement(x))))}return U.arrowFunctionExpression([],U.blockStatement([ot(u),it(u),...u.creation,...u.mounts,U.returnStatement(U.objectExpression(g))]))}import*as p from"@babel/types";import*as X from"@babel/types";function gt(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 gt(e,t,n,o)})):Gs(e,n,r)?X.cloneNode(r,!0):Zs(t,r)||X.isMemberExpression(r)?Xo(e,r):X.cloneNode(r,!0)}function fr(e,t,n,r,o){let i=A(e,"refDispose");t.mounts.push(X.variableDeclaration("const",[X.variableDeclarator(X.cloneNode(i),X.callExpression(Q(e,"mountRef"),[X.cloneNode(n,!0),X.cloneNode(o,!0)]))])),t.manualDisposal?t.disposableCallbacks.push(i):t.mounts.push(X.expressionStatement(X.callExpression(Q(e,"cleanup"),[X.cloneNode(r,!0),X.cloneNode(i)])))}function Gs(e,t,n){let r=pt(e,t,n);return r!==null&&e.componentProps.get(t)?.refProps.includes(r)===!0}function Zs(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 Xo(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 Ys=new Set(["setClassValue","setStyleValue","setDomValue"]);function zt(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 y=ea(C);if(y===null)return!1;r.push(y),o.add(y.name)}if(!o.has(n)||r.length<2)return!1;let i=new Map,s=new Map;for(let C of t.creation){let y=To(C);if(y===null)continue;if(!o.has(y.parent)||!o.has(y.child))return!1;let v=s.get(y.parent)??0;s.set(y.parent,v+1),i.set(y.child,{parent:y.parent,index:v})}let a=new Map;for(let C of o){let y=ta(C,n,i);if(y===null)return!1;a.set(C,y)}let l=[],d=[];for(let C of t.creation)J.isVariableDeclaration(C)||ra(C,o)?l.push(J.cloneNode(C,!0)):d.push(C);let u=A(e,`${n}Template`);e.header.push(J.variableDeclaration("let",[J.variableDeclarator(J.cloneNode(u))]));let c=J.callExpression(J.arrowFunctionExpression([],J.blockStatement([...l,J.returnStatement(J.identifier(n))])),[]),g=J.conditionalExpression(J.binaryExpression("===",J.cloneNode(u),J.unaryExpression("void",J.numericLiteral(0))),J.assignmentExpression("=",J.cloneNode(u),c),J.cloneNode(u)),x=J.callExpression(J.memberExpression(g,J.identifier("cloneNode")),[J.booleanLiteral(!0)]),E=new Set([n]);for(let C of d)Le(C,y=>{J.isIdentifier(y)&&o.has(y.name)&&E.add(y.name)});let f=[],m=r.filter(({name:C})=>E.has(C)).sort((C,y)=>a.get(C.name).length-a.get(y.name).length).map(({name:C})=>{let y=a.get(C),v;if(C===n)v=J.cloneNode(x,!0);else{let M=f[0];for(let R of f)R.path.length>M.path.length&&Qs(R.path,y)&&(M=R);v=na(M.name,y.slice(M.path.length))}return f.push({name:C,path:y}),J.variableDeclaration("const",[J.variableDeclarator(J.identifier(C),v)])});return t.creation=[...m,...d],!0}function Qs(e,t){return e.length<=t.length&&e.every((n,r)=>t[r]===n)}function ea(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 To(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 ta(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 na(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 ra(e,t){let n=To(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)&&Jn(o))||J.isIdentifier(r.callee.object)&&J.isIdentifier(r.callee.property)&&Ys.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)&&Jn(o))))}function Jn(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)&&Jn(t)):J.isObjectExpression(e)?e.properties.every(t=>J.isObjectProperty(t)&&!t.computed&&J.isExpression(t.value)&&Jn(t.value)):!1}function Bo(e,t,n,r,o,i,s,a,l=!1,d=Je(e,o),u){let c=Rt(e,n,i,o,t.usedPrefixes,u===void 0?void 0:{itemParam:u.itemParam,sourceKey:u.sourceKey,sourceLocal:u.sourceLocal??!1}),g=A(e,`region${t.regionCounter++}`).name,x=c.form==="callback"?ia(e,c,r):c.form==="component"?sa(e,c,r,o,i,a,l,d):aa(e,c,r,o,i,s,l,d),E=[p.identifier(r),p.binaryExpression("+",p.cloneNode(d),p.stringLiteral(`/${c.suffix}`)),x];if(c.form==="callback"){let v=p.memberExpression(p.cloneNode(c.renderCallback,!0),p.identifier("key"));E.push(p.arrowFunctionExpression([p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]],p.conditionalExpression(p.binaryExpression("==",p.cloneNode(v),p.nullLiteral()),p.cloneNode(c.itemPattern,!0),p.callExpression(p.cloneNode(v),[p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]]))))}else c.keyExpr!==null&&E.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(Q(e,"createListRegion"),E))])),t.disposableRegions.push(g);let f=e.targetedListDependencies.get(n)??[],m=e.keyedListMutations.get(n);m!==void 0&&t.creation.push(p.variableDeclaration("const",[p.variableDeclarator(p.identifier(m.keysVariable),p.newExpression(p.identifier("Set"),[]))]));let C=f.map(v=>({dependency:v,cache:A(e,`${v.value}ListKey`).name}));C.length>0&&t.creation.push(p.variableDeclaration("let",C.map(({dependency:v,cache:M})=>p.variableDeclarator(p.identifier(M),p.identifier(v.value)))));let y=()=>p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(g),p.identifier("reconcile")),[p.cloneNode(c.sourceExpr)]));t.creation.push(y()),C.length===0&&m===void 0||t.reasonVar===null?t.updaters.push(y):t.updaters.push(()=>oa(e,o,t.reasonVar,g,c.sourceExpr,C,m))}function Lt(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 mr(e,t){return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(e),p.identifier("refreshKey")),[t]))}function oa(e,t,n,r,o,i,s){let a=e.instanceReasonIds.get(t);if(a===void 0)return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(r),p.identifier("reconcile")),[p.cloneNode(o)]));let l=s?.source??i[0]?.dependency.source,d=l===void 0?void 0:a.get(l);if(d===void 0)return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(r),p.identifier("reconcile")),[p.cloneNode(o)]));let u=[p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(r),p.identifier("reconcile")),[p.cloneNode(o)])),...i.map(({dependency:x,cache:E})=>p.expressionStatement(p.assignmentExpression("=",p.identifier(E),p.identifier(x.value)))),...s===void 0?[]:[p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(s.keysVariable),p.identifier("clear")),[]))]],c=[];if(s!==void 0){let x=a.get(s.targetedReason);if(x!==void 0){let E=A(e,"changedListKey");c.push(p.ifStatement(Lt(n,x),p.blockStatement([p.forOfStatement(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(E))]),p.identifier(s.keysVariable),p.blockStatement([mr(r,p.cloneNode(E))])),p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(s.keysVariable),p.identifier("clear")),[]))])))}}for(let{dependency:x,cache:E}of i){let f=a.get(x.value);if(f===void 0)continue;let m=A(e,"previousListKey");c.push(p.ifStatement(Lt(n,f),p.blockStatement([p.variableDeclaration("const",[p.variableDeclarator(m,p.identifier(E))]),p.expressionStatement(p.assignmentExpression("=",p.identifier(E),p.identifier(x.value))),mr(r,p.cloneNode(m)),p.ifStatement(p.unaryExpression("!",p.callExpression(p.memberExpression(p.identifier("Object"),p.identifier("is")),[p.cloneNode(m),p.identifier(E)])),mr(r,p.identifier(E)))])))}let g=p.binaryExpression("===",p.identifier(n),p.nullLiteral());if(s!==void 0){let x=a.get(s.structuralReason),E=a.get(s.targetedReason);x!==void 0&&(g=p.logicalExpression("||",g,Lt(n,x))),g=p.logicalExpression("||",g,E===void 0?Lt(n,d):p.logicalExpression("&&",Lt(n,d),p.unaryExpression("!",Lt(n,E))))}else g=p.logicalExpression("||",g,Lt(n,d));return p.ifStatement(g,p.blockStatement(u),c.length===0?void 0:p.blockStatement(c))}function ia(e,t,n){let r=A(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 sa(e,t,n,r,o,i,s=!1,a=Je(e,r)){let l=t.rowComp,d=A(e,"rowId"),u=A(e,"nextItem"),c=t.indexParam===null?null:A(e,"nextIndex"),g=A(e,"refreshRow"),x=rt(e),E=$t(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:nt(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal&&p.isIdentifier(a)?{ownerIdVar:a.name}:{}},C=t.jsx.openingElement.attributes.filter(V=>p.isJSXSpreadAttribute(V)||$e(V.name)!=="key"),y=C.some(V=>p.isJSXSpreadAttribute(V)),v=[],M=[],R=null,I=e.componentProps.get(l),H=V=>{let le=p.isJSXElement(V)||p.isJSXFragment(V)?[V]:[p.jsxExpressionContainer(V)];return i(e,x,le,r,o,"row",m,d,s,d)};if(y){R=Qt(C,{attributeValue:(V,le)=>V==="ref"||I?.refProps.includes(V)===!0?gt(e,o,r,le):le,fail:V=>{throw o.buildCodeFrameError(V)}}).expression;for(let V of R.properties){if(!p.isObjectProperty(V)||V.computed||!p.isExpression(V.value))continue;let le=p.isIdentifier(V.key)?V.key.name:p.isStringLiteral(V.key)?V.key.value:null;if(le!==null)if(I?.renderProps.includes(le)===!0){if(st(e,r,V.value))continue;if(!de(V.value))throw o.buildCodeFrameError(`memo-dom: render prop '${le}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);V.value=H(V.value)}else{if(de(V.value))throw o.buildCodeFrameError(`memo-dom: JSX prop '${le}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);le!=="ref"&&I?.refProps.includes(le)!==!0&&Wt(V.value)&&(at(e,o,V.value,r,m,!0),V.value=ur(e,M,V.value,`${le}Callback`))}}}else for(let V of C){let le=V,Te=$e(le.name),we=le.value==null?p.booleanLiteral(!0):Be(le.value);if(we===null)throw o.buildCodeFrameError(`memo-dom: prop '${$e(le.name)}' on <${l}> must be an expression`);if(I?.renderProps.includes(Te)===!0){if(st(e,r,we)){v.push({name:Te,value:p.cloneNode(we)});continue}if(!de(we))throw o.buildCodeFrameError(`memo-dom: render prop '${Te}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);v.push({name:Te,value:H(we)});continue}if(Te==="ref"||I?.refProps.includes(Te)===!0){v.push({name:Te,value:gt(e,o,r,we)});continue}if(de(we))throw o.buildCodeFrameError(`memo-dom: JSX prop '${Te}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);let S=Wt(we);if(S)at(e,o,we,r,m,!0);else if(p.isIdentifier(we)){let w=mt(o,we.name);w!==null&&!de(w.body)&&at(e,o,w,r,m,!0)}v.push({name:Te,value:S?ur(e,M,we,`${Te}Callback`):p.cloneNode(we)})}if(qt(t.jsx.children)){if(C.some(le=>p.isJSXAttribute(le)&&$e(le.name)==="children"))throw o.buildCodeFrameError(`memo-dom: <${l}> cannot use both a children prop and nested JSX children`);let V=i(e,x,t.jsx.children,r,o,"row",m,d,s,d);R!==null?R.properties.push(p.objectProperty(p.identifier("children"),p.cloneNode(V))):v.push({name:"children",value:p.cloneNode(V)})}let O;if(R!==null){let V=A(e,`${l}Props`);M.push(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(V),p.cloneNode(R))])),O=Vt(e,l,V)}else O=jn(e,l,v);let _=[p.expressionStatement(p.assignmentExpression("=",p.cloneNode(t.itemPattern,!0),p.cloneNode(u)))];c!==null&&t.indexParam!==null&&_.push(p.expressionStatement(p.assignmentExpression("=",p.identifier(t.indexParam),p.cloneNode(c))));let Y=O.map(V=>p.cloneNode(V));if(R!==null){let V=A(e,`next${l}Props`);_.push(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(V),p.cloneNode(R))])),Y=Vt(e,l,V)}let Z=A(e,E?"entry":"rowElement"),ne=O.length>0||x.updaters.length>0,xe=E&&ne,be=xe?A(e,"pushRowProps"):null;E?_.push(p.expressionStatement(p.callExpression(be===null?p.memberExpression(p.cloneNode(Z),p.identifier("updateProps")):p.cloneNode(be),Y))):_.push(p.expressionStatement(p.callExpression(Q(e,"setProps"),[p.cloneNode(d),p.arrayExpression(Y)])),p.expressionStatement(p.callExpression(Q(e,"markDirty"),[p.cloneNode(d)]))),x.updaters.length>0&&_.push(p.expressionStatement(p.callExpression(p.identifier(x.updateVar),[])));let ie=E?[p.objectProperty(p.identifier("nodes"),p.memberExpression(p.cloneNode(Z),p.identifier("nodes"))),p.objectProperty(p.identifier("entities"),p.arrayExpression([])),p.objectProperty(p.identifier("update"),p.memberExpression(p.cloneNode(Z),p.identifier("update"))),p.objectProperty(p.identifier("dispose"),p.memberExpression(p.cloneNode(Z),p.identifier("dispose")))]:[p.objectProperty(p.identifier("nodes"),p.callExpression(Q(e,"rootNodes"),[p.cloneNode(Z)])),p.objectProperty(p.identifier("entities"),p.arrayExpression([p.cloneNode(d)]))];return ne&&!xe&&ie.push(p.objectProperty(p.identifier("updateProps"),p.arrowFunctionExpression([p.cloneNode(u),...c===null?[]:[p.cloneNode(c)]],p.blockStatement(_)))),p.arrowFunctionExpression([p.cloneNode(t.itemPattern,!0),p.cloneNode(d),...t.indexParam===null?[]:[p.identifier(t.indexParam)]],p.blockStatement([...x.updaters.length>0?[ot(x),it(x)]:[],...x.creation,...x.mounts,...M,p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(Z),E?p.callExpression(p.identifier(l),[...O.map(V=>p.cloneNode(V)),p.cloneNode(d),...t.sourceLocal?[p.cloneNode(a)]:[],...f?[p.identifier(n)]:[]]):p.callExpression(p.identifier(l),[p.cloneNode(d),p.cloneNode(a),...O.length>0?[p.arrayExpression(O)]:[]]))]),...x.updaters.length>0?[p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(g),p.arrowFunctionExpression([],p.blockStatement([p.expressionStatement(E?p.callExpression(p.memberExpression(p.cloneNode(Z),p.identifier("update")),[]):p.callExpression(Q(e,"markDirty"),[p.cloneNode(d)])),p.expressionStatement(p.callExpression(p.identifier(x.updateVar),[]))])))])]:[],...be===null?[]:[p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(be),p.memberExpression(p.cloneNode(Z),p.identifier("updateProps")))]),p.expressionStatement(p.assignmentExpression("=",p.memberExpression(p.cloneNode(Z),p.identifier("updateProps")),p.arrowFunctionExpression([p.cloneNode(u),...c===null?[]:[p.cloneNode(c)]],p.blockStatement(_))))],p.returnStatement(xe?p.cloneNode(Z):p.objectExpression(ie))]))}function aa(e,t,n,r,o,i,s=!1,a=Je(e,r)){t.jsx.openingElement.attributes=t.jsx.openingElement.attributes.filter(f=>p.isJSXSpreadAttribute(f)||f.name.name!=="key");let l=rt(e);l.delegatedEventRootVar=n;let d=A(e,"rowId").name,u=A(e,"nextItem"),c=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:p.isIdentifier(a)?a.name:Je(e,r).name}:{}},x=i(e,l,t.jsx,r,o,"row",g,p.identifier(d),s,p.identifier(d));zt(e,l,x);let E=[p.expressionStatement(p.assignmentExpression("=",p.cloneNode(t.itemPattern,!0),p.cloneNode(u)))];return c!==null&&t.indexParam!==null&&E.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([ot(l),it(l),yt(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(E))),p.objectProperty(p.identifier("update"),p.identifier(l.updateVar))]))]))}import*as N from"@babel/types";function la(e){return N.isJSXElement(e.body)?e.body:N.isBlockStatement(e.body)&&e.body.body.length===1&&N.isReturnStatement(e.body.body[0])&&N.isJSXElement(e.body.body[0].argument)?e.body.body[0].argument:null}function gr(e,t,n,r,o,i,s,a){if(!N.isArrowFunctionExpression(n)&&!N.isFunctionExpression(n)||n.async||n.generator)throw o.buildCodeFrameError("memo-dom: render callbacks must be synchronous inline arrows or function expressions");let l=la(n),d=n.params[0],u=n.params[1];if(l===null||n.params.length<1||n.params.length>2||!N.isIdentifier(d)&&!N.isObjectPattern(d)&&!N.isArrayPattern(d)||u!==void 0&&!N.isIdentifier(u))throw o.buildCodeFrameError("memo-dom: render callbacks take an item binding pattern and optional index, then return one JSX element");let c=cn(d),g=Object.keys(N.getBindingIdentifiers(c));if(g.length===0)throw o.buildCodeFrameError("memo-dom: render callback item patterns must bind at least one name");let x=N.isIdentifier(c)?c.name:g[0],E=u===void 0?null:u.name,f=null;l.openingElement.attributes=l.openingElement.attributes.filter(be=>{if(N.isJSXSpreadAttribute(be)||!N.isJSXIdentifier(be.name)||be.name.name!=="key")return!0;if(f=Be(be.value),f===null)throw o.buildCodeFrameError("memo-dom: key={...} needs an expression");return!1});let m=A(e,"renderCallback"),C=A(e,"renderRows"),y=A(e,"renderNextUpdate"),v=A(e,"renderRowId"),M=A(e,"renderEventRoot"),R=A(e,"refreshRenderRow"),I=A(e,"renderNextItem"),H=E===null?null:A(e,"renderNextIndex"),O=rt(e);O.delegatedEventRootVar=M.name;let _={itemParam:x,itemPath:[],rowIdVar:v.name,keyPath:nt(f,x),sourceKey:"$render-callback",sourceLocal:!0,...N.isIdentifier(a)?{ownerIdVar:a.name}:{}},Y=i(e,O,l,r,o,"row",_,v,s,v);zt(e,O,Y),t.creation.push(N.variableDeclaration("const",[N.variableDeclarator(N.cloneNode(C),N.newExpression(N.identifier("Set"),[]))])),t.updaters.push(()=>N.forOfStatement(N.variableDeclaration("const",[N.variableDeclarator(N.cloneNode(y))]),N.cloneNode(C),N.expressionStatement(N.callExpression(N.cloneNode(y),[]))));let Z=[N.expressionStatement(N.assignmentExpression("=",N.cloneNode(c,!0),N.cloneNode(I)))];H!==null&&E!==null&&Z.push(N.expressionStatement(N.assignmentExpression("=",N.identifier(E),N.cloneNode(H))));let ne=N.arrowFunctionExpression([N.cloneNode(c,!0),N.cloneNode(v),...E===null?[]:[N.identifier(E)],N.cloneNode(M)],N.blockStatement([ot(O),it(O),N.variableDeclaration("const",[N.variableDeclarator(N.cloneNode(R),N.arrowFunctionExpression([],N.blockStatement([N.expressionStatement(N.callExpression(N.identifier(O.updateVar),[])),N.expressionStatement(N.callExpression(Q(e,"renderDescendants"),[N.cloneNode(v)]))])))]),yt(e,N.cloneNode(v),N.cloneNode(a,!0),N.cloneNode(R)),...O.creation,...O.mounts,N.expressionStatement(N.callExpression(N.memberExpression(N.cloneNode(C),N.identifier("add")),[N.cloneNode(R)])),N.returnStatement(N.objectExpression([N.objectProperty(N.identifier("nodes"),N.callExpression(Q(e,"rootNodes"),[N.identifier(Y)])),N.objectProperty(N.identifier("entities"),N.arrayExpression([N.cloneNode(v)])),N.objectProperty(N.identifier("updateProps"),N.arrowFunctionExpression([N.cloneNode(I),...H===null?[]:[N.cloneNode(H)]],N.blockStatement(Z))),N.objectProperty(N.identifier("update"),N.cloneNode(R)),N.objectProperty(N.identifier("dispose"),N.arrowFunctionExpression([],N.callExpression(N.memberExpression(N.cloneNode(C),N.identifier("delete")),[N.cloneNode(R)])))]))])),xe=f===null?N.nullLiteral():N.arrowFunctionExpression([N.cloneNode(c,!0),...E===null?[]:[N.identifier(E)]],N.cloneNode(f));return t.creation.push(N.variableDeclaration("const",[N.variableDeclarator(N.cloneNode(m),N.objectExpression([N.objectProperty(N.identifier("create"),ne),N.objectProperty(N.identifier("key"),xe)]))])),m}function da(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 ca(e,t,n,r){return()=>Ft(e,t,h.cloneNode(r),o=>h.expressionStatement(h.assignmentExpression("=",h.memberExpression(h.identifier(n),h.identifier("data")),da(o))))}function br(e,t,n){let r=A(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=Bn(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=ca(t,o,r,n);return t.creation.push(i()),t.updaters.push(i),r}function Vo(e,t){let n=!1;return h.traverseFast(e,r=>{h.isIdentifier(r,{name:t})&&(n=!0)}),n}function ut(e,t,n,r,o,i=null,s,a,l=!1,d=Je(e,r)){return h.isJSXFragment(n)?ua(e,t,n,r,o,i,s,a,l,d):pa(e,t,n,r,o,i,s,a,l,d)}function ua(e,t,n,r,o,i,s,a,l=!1,d=Je(e,r)){let u=sr(n.children,{emitText:g=>br(e,t,g),emitNode:g=>ut(e,t,g,r,o,i,s,a,l,d),isForwarded:g=>st(e,r,g),fail:g=>{throw o.buildCodeFrameError(g)}}),c=Vn(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")),[]))])),zo(e,t,u,c,r,o,i,s,l,d),c}function zo(e,t,n,r,o,i,s=null,a,l=!1,d=Je(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"?zn(e,t,u.expression,r,d):u.type==="list"?Ko(e,t,u.expression,r,o,i,l,d,a):Uo(e,t,u.expression,r,o,i,l,d,s!==null)}function hr(e,t,n,r,o,i,s,a,l,d){return Dr(e,t,d,(u,c,g)=>{Lr(u,n,c.name,{emitText:x=>br(e,u,x),emitNode:x=>ut(e,u,x,r,o,i,s,a,l,g),emitList:(x,E)=>Ko(e,u,x,E,r,o,l,g,s),emitCondition:(x,E)=>Uo(e,u,x,E,r,o,l,g,i!==null),isForwarded:x=>st(e,r,x),emitForwarded:(x,E)=>zn(e,u,x,E,g),fail:x=>{throw o.buildCodeFrameError(x)}})})}function Wo(e,t,n,r,o,i,s,a,l,d){let u=h.isJSXElement(n)||h.isJSXFragment(n)?[n]:[h.jsxExpressionContainer(n)];return hr(e,t,u,r,o,i,s,a,l,d)}function pa(e,t,n,r,o,i=null,s,a,l=!1,d=Je(e,r)){let u=n.openingElement,c=u.name.name;if(/^[A-Z]/.test(c)){let y=t.childCounts.get(c)??0;t.childCounts.set(c,y+1);let v=c.charAt(0).toLowerCase()+c.slice(1),M=y===0?v:`${v}${y}`,R=A(e,M).name,I=y===0?`/${c}`:`/${c}[${y}]`,H=[],O=e.componentProps.get(c);if(qt(n.children)&&u.attributes.some(be=>h.isJSXAttribute(be)&&$e(be.name)==="children"))throw o.buildCodeFrameError(`memo-dom: <${c}> cannot use both a children prop and nested JSX children`);let _=u.attributes.some(be=>h.isJSXSpreadAttribute(be)),Y=null,Z=!1;if(_){Y=Qt(u.attributes,{attributeValue:(ie,V)=>ie==="ref"||O?.refProps.includes(ie)===!0?gt(e,o,r,V):V,fail:ie=>{throw o.buildCodeFrameError(ie)}}).expression;for(let ie of Y.properties){if(!h.isObjectProperty(ie)||ie.computed||!h.isExpression(ie.value))continue;let V=h.isIdentifier(ie.key)?ie.key.name:h.isStringLiteral(ie.key)?ie.key.value:null;if(V!==null)if(O?.renderCallbacks.includes(V)===!0)ie.value=gr(e,t,ie.value,r,o,ut,l,d);else if(O?.renderProps.includes(V)===!0){if(st(e,r,ie.value))continue;if(!de(ie.value))throw o.buildCodeFrameError(`memo-dom: render prop '${V}' on <${c}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);ie.value=Wo(e,t,ie.value,r,o,i,s,a,l,d)}else{if(de(ie.value))throw o.buildCodeFrameError(`memo-dom: JSX prop '${V}' on <${c}> is not rendered by the callee; interpolate that prop in <${c}> to declare a render slot`);V!=="ref"&&O?.refProps.includes(V)!==!0&&Wt(ie.value)&&(at(e,o,ie.value,r,s,!0),ie.value=cr(e,t,ie.value,`${V}Callback`))}}Z=Xn(e,Y,r)||s!==void 0&&Vo(Y,s.itemParam)}else for(let be of u.attributes){let ie=be,V=$e(ie.name),le=ie.value==null?h.booleanLiteral(!0):Be(ie.value);if(le==null)throw o.buildCodeFrameError(`memo-dom: prop '${$e(ie.name)}' on <${c}> must be an expression`);if(O?.renderCallbacks.includes(V)===!0){H.push({name:V,value:gr(e,t,le,r,o,ut,l,d)});continue}if(V==="ref"||O?.refProps.includes(V)===!0){H.push({name:V,value:gt(e,o,r,le)});continue}if(O?.renderProps.includes(V)===!0){if(st(e,r,le)){H.push({name:V,value:h.cloneNode(le)});continue}if(!de(le))throw o.buildCodeFrameError(`memo-dom: render prop '${V}' on <${c}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);H.push({name:V,value:Wo(e,t,le,r,o,i,s,a,l,d)});continue}if(de(le))throw o.buildCodeFrameError(`memo-dom: JSX prop '${V}' on <${c}> is not rendered by the callee; interpolate that prop in <${c}> to declare a render slot`);let Te=Wt(le);if(!Te&&(Xn(e,le,r)||s!==void 0&&Vo(le,s.itemParam))&&(Z=!0),Te)at(e,o,le,r,s,!0);else if(h.isIdentifier(le)){let we=mt(o,le.name);we!==null&&!de(we.body)&&at(e,o,we,r,s,!0)}H.push({name:V,value:Te?cr(e,t,le,`${V}Callback`):h.cloneNode(le)})}if(qt(n.children)){if(u.attributes.some(ie=>h.isJSXAttribute(ie)&&$e(ie.name)==="children"))throw o.buildCodeFrameError(`memo-dom: <${c}> cannot use both a children prop and nested JSX children`);let be=hr(e,t,n.children,r,o,i,s,a,l,d);Y!==null?Y.properties.push(h.objectProperty(h.identifier("children"),h.cloneNode(be))):H.push({name:"children",value:h.cloneNode(be)})}let ne;if(Y!==null){let be=A(e,`${v}Props`);t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(be),h.cloneNode(Y))])),ne=Vt(e,c,be)}else ne=jn(e,c,H);let xe=h.binaryExpression("+",h.cloneNode(d),h.stringLiteral(I));return t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(R),h.callExpression(h.identifier(c),[xe,h.cloneNode(d),...ne.length>0?[h.arrayExpression(ne)]:[]]))])),t.disposableEntities.push(h.cloneNode(xe)),Z&&t.updaters.push(()=>Y===null?h.expressionStatement(h.callExpression(Q(e,"setProps"),[h.binaryExpression("+",h.cloneNode(d),h.stringLiteral(I)),h.arrayExpression(ne.map(be=>h.cloneNode(be)))])):$o(e,c,d,I,Y)),R}let g=jo(c,l),x=g&&c!=="foreignObject";if(u.attributes.find(y=>h.isJSXAttribute(y)&&$e(y.name)==="innerHTML")!==void 0){if(g)throw o.buildCodeFrameError("memo-dom: innerHTML is only supported on HTML elements");if(n.children.some(v=>!h.isJSXText(v)||v.value.trim()!==""))throw o.buildCodeFrameError("memo-dom: an element using innerHTML cannot also have JSX children")}let f=sr(n.children,{emitText:y=>br(e,t,y),emitNode:y=>ut(e,t,y,r,o,i,s,a,x,d),isForwarded:y=>st(e,r,y),fail:y=>{throw o.buildCodeFrameError(y)}}),m=Vn(e,t,c);if(t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(m),Jo(c,g))])),u.attributes.some(y=>h.isJSXSpreadAttribute(y))){let y=Qt(u.attributes,{attributeValue:(R,I)=>R==="ref"?gt(e,o,r,I):I,eventValue:(R,I)=>{let H=ir(e,o,I,R,r,s,a),O=A(e,`${R}Handler`);return t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(O),H)])),O},fail:R=>{throw o.buildCodeFrameError(R)}}),v=A(e,`${c}Props`);t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(v),h.cloneNode(y.expression))]));let M=R=>h.expressionStatement(h.callExpression(Q(e,"patchDomProps"),[h.identifier(m),h.cloneNode(R),h.stringLiteral(e.rootId),h.arrayExpression(y.safeEventKeys.map(I=>h.stringLiteral(I)))]));t.creation.push(M(v)),fr(e,t,h.identifier(m),d,h.memberExpression(h.cloneNode(v),h.identifier("ref"))),t.updaters.push(()=>M(y.expression))}else for(let y of u.attributes){let v=y,M=$e(v.name);if(M==="ref"){let Y=Be(v.value);if(Y===null)throw o.buildCodeFrameError("memo-dom: ref needs an expression");fr(e,t,h.identifier(m),d,gt(e,o,r,Y));continue}if(M==="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(M)){let Y=Be(v.value);if(Y==null)throw o.buildCodeFrameError(`memo-dom: ${M} needs a handler expression (L1)`);let Z=ir(e,o,Y,M,r,s,a);t.creation.push(t.delegatedEventRootVar===null?h.expressionStatement(h.assignmentExpression("=",h.memberExpression(h.identifier(m),h.identifier(M.toLowerCase())),Z)):h.expressionStatement(h.callExpression(Q(e,"setDelegatedEvent"),[h.identifier(t.delegatedEventRootVar),h.identifier(m),h.stringLiteral(M),Z])));continue}if(h.isStringLiteral(v.value)){M==="class"||M==="className"?t.creation.push(h.expressionStatement(h.callExpression(Q(e,"setClassValue"),[h.identifier(m),h.stringLiteral(v.value.value)]))):M==="style"?t.creation.push(h.expressionStatement(h.callExpression(Q(e,"setStyleValue"),[h.identifier(m),h.stringLiteral(v.value.value)]))):ar(M,g)!==null?t.creation.push(dr(m,M,h.stringLiteral(v.value.value))):lr(M,g)?t.creation.push(An(m,M,h.stringLiteral(v.value.value))):g?t.creation.push(h.expressionStatement(h.callExpression(Q(e,"setDomValue"),[h.identifier(m),h.stringLiteral(M),h.stringLiteral(v.value.value)]))):t.creation.push(h.expressionStatement(h.callExpression(h.memberExpression(h.identifier(m),h.identifier("setAttribute")),[h.stringLiteral(M),h.stringLiteral(v.value.value)])));continue}let R=v.value==null?h.booleanLiteral(!0):Be(v.value);if(R==null||h.isStringLiteral(R))throw o.buildCodeFrameError(`memo-dom: attribute '${M}' needs a string or an expression (L1)`);let I=h.cloneNode(R);if(M==="style"){let Y=()=>h.expressionStatement(h.callExpression(Q(e,"setStyleValue"),[h.identifier(m),h.cloneNode(I)]));t.creation.push(Y()),t.updaters.push(Y);continue}let H=Bn(e,t),O=ar(M,g),_=()=>M==="class"||M==="className"?Ft(t,H,h.callExpression(Q(e,"classValue"),[h.cloneNode(I)]),Y=>h.expressionStatement(h.callExpression(Q(e,"setClassValue"),[h.identifier(m),Y]))):O!==null?Ft(t,H,h.cloneNode(I),Y=>dr(m,O,Y)):lr(M,g)?Ft(t,H,h.cloneNode(I),Y=>An(m,M,Y)):g?Ft(t,H,h.cloneNode(I),Y=>h.expressionStatement(h.callExpression(Q(e,"setDomValue"),[h.identifier(m),h.stringLiteral(M),Y]))):Ft(t,H,h.cloneNode(I),Y=>An(m,M,Y));t.creation.push(_()),t.updaters.push(_)}return zo(e,t,f,m,r,o,i,s,x,d),m}function Ko(e,t,n,r,o,i,s=!1,a=Je(e,o),l){Bo(e,t,n,r,o,i,ut,hr,s,a,l)}function Uo(e,t,n,r,o,i,s=!1,a=Je(e,o),l=!1){Oo(e,t,n,r,o,i,ut,s,a,l)}function Ho(e,t,n,r,o,i=!1,s=o,a=!1,l){return pr(e,t,n,r,o,ut,i,s,a,l)}import*as Me from"@babel/types";function Go(e){if(e.isFunctionDeclaration())return e.node;if(!e.isVariableDeclarator())return null;let t=e.node.init;return t&&(Me.isArrowFunctionExpression(t)||Me.isFunctionExpression(t))?t:null}function Zo(e,t,n,r,o,i=!1){let s=mt(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=Go(a.path);l!==null&&nn(e,l,i)}function _o(e,t,n,r,o,i=!1){if(Me.isArrowFunctionExpression(n)||Me.isFunctionExpression(n)){if(de(n.body))return;at(e,t,n,r,o,i)}else Me.isIdentifier(n)&&Zo(e,t,n.name,r,o,i)}function Yo(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=Go(o.path);i!==null&&nn(e,i,r)}function qo(e,t,n,r=!1){if(Me.isArrowFunctionExpression(n)||Me.isFunctionExpression(n)){if(de(n.body))return;nn(e,n,r)}else Me.isIdentifier(n)&&Yo(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=Me.isIdentifier(a,{name:"effect"})&&i.scope.getBinding("effect")===void 0;if(Me.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||!Me.isExpression(d))throw i.buildCodeFrameError("memo-dom: cleanup(disposer) requires exactly one disposer expression");i.node.callee=Q(e,"cleanup"),i.node.arguments.unshift(Me.identifier(r))}if(s){Me.isIdentifier(a)&&Zo(e,t,a.name,n,o);for(let d of i.node.arguments)_o(e,t,d,n,o,l)}},NewExpression(i){if(i.getFunctionParent()===t)for(let s of i.node.arguments)_o(e,t,s,n,o)}})}function ei(e,t){t.traverse({CallExpression(n){if(n.getFunctionParent()!==null)return;let r=Me.isIdentifier(n.node.callee,{name:"effect"})&&n.scope.getBinding("effect")===void 0;Me.isIdentifier(n.node.callee)&&Yo(e,t,n.node.callee.name);for(let o of n.node.arguments)qo(e,t,o,r)},NewExpression(n){if(n.getFunctionParent()===null)for(let r of n.node.arguments)qo(e,t,r)}})}function ti(e){for(let t of e.helpers.values())t.node.async&&nn(e,t.node)}function ni(e){e.traverse({CallExpression(t){if(Me.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 ze from"@babel/types";import*as ke from"@babel/types";function ri(e){return e.reduce((t,n)=>ke.logicalExpression("||",t,n))}function oi(e,t){let n=()=>ke.identifier(e),r=ri(t.map(i=>ke.binaryExpression("===",n(),ke.numericLiteral(i)))),o=ri(t.map(i=>ke.callExpression(ke.memberExpression(n(),ke.identifier("has")),[ke.numericLiteral(i)])));return ke.logicalExpression("||",ke.binaryExpression("===",n(),ke.nullLiteral()),ke.conditionalExpression(ke.binaryExpression("===",ke.unaryExpression("typeof",n()),ke.stringLiteral("number")),r,o))}function ii(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:vr(c)})),...i.map(c=>({order:s.get(c.statement)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:c.sources,statement:ze.blockStatement([...c.resets.map(g=>ze.expressionStatement(ze.assignmentExpression("=",ze.identifier(g.binding),ze.cloneNode(g.source,!0)))),ze.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(C=>d.get(C)).filter(C=>C!==void 0).sort((C,y)=>C-y),x=g===null||g.length===c.sources.length?g:null,E=x?.join(" ")??"*",f=u.at(-1),m=f?.reasons?.join(" ")??"*";f!==void 0&&m===E?f.statements.push(c.statement):u.push({reasons:x,statements:[c.statement]})}return ze.blockStatement(u.map(c=>c.reasons===null||n===null?ze.blockStatement(c.statements):ze.ifStatement(oi(n,c.reasons),ze.blockStatement(c.statements))))}import*as W from"@babel/types";function rn(e){return!W.isReturnStatement(e)||!W.isJSXElement(e.argument)&&!W.isJSXFragment(e.argument)?null:{jsx:e.argument,statement:e}}function Er(e){return W.isBlockStatement(e)?e.body.length===1?rn(e.body[0]):null:rn(e)}function fa(e){let t=[];return e.get("body").traverse({ReturnStatement(n){t.push(n.node)},Function(n){n.skip()}}),t}function ma(e){if(W.isFunctionDeclaration(e))return!0;if(W.isVariableDeclaration(e))return e.declarations.every(t=>t.init==null||W.isFunction(t.init)||ga(t.init));if(W.isSwitchStatement(e)||W.isIfStatement(e)){let t=!0;return W.traverseFast(e,n=>{(W.isCallExpression(n)||W.isOptionalCallExpression(n)||W.isNewExpression(n)||W.isAwaitExpression(n)||W.isYieldExpression(n)||W.isThrowStatement(n)||W.isTaggedTemplateExpression(n)||W.isUpdateExpression(n))&&(t=!1)}),t}return W.isTypeScript(e)}function ga(e){let t=!0;return W.traverseFast(e,n=>{(W.isCallExpression(n)||W.isOptionalCallExpression(n)||W.isNewExpression(n)||W.isAwaitExpression(n)||W.isYieldExpression(n)||W.isTaggedTemplateExpression(n)||W.isAssignmentExpression(n)||W.isUpdateExpression(n))&&(t=!1)}),t}function ba(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=rn(r.consequent[0]);if(o===null)return null;let i=t.length;t.push(o.jsx),n.push(W.switchCase(r.test===null?null:W.cloneNode(r.test),[W.returnStatement(W.numericLiteral(i))]))}return{pick:W.arrowFunctionExpression([],W.blockStatement([W.switchStatement(W.cloneNode(e.discriminant),n)])),branches:t,statements:new Set([e])}}function si(e,t){let n=e.node.body.body,r=fa(e),o=n.at(-1);if(r.length===1&&o!==void 0){let s=rn(o);if(s!==null)return s}if(o&&W.isIfStatement(o)&&o.alternate!=null){let s=o.alternate,a=Er(o.consequent),l=Er(s);if(a!==null&&l!==null&&r.length===2)return{pick:W.arrowFunctionExpression([],W.conditionalExpression(W.cloneNode(o.test),W.numericLiteral(0),W.numericLiteral(1))),branches:[a.jsx,l.jsx],statements:new Set([o])}}if(o&&W.isSwitchStatement(o)){let s=ba(o);if(s!==null&&s.branches.length===r.length)return s}let i=o===void 0?null:rn(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(W.isIfStatement(g)&&g.alternate==null){let x=Er(g.consequent);if(x!==null){d===-1&&(d=c),s.push(W.cloneNode(g.test)),a.push(x.jsx),l.add(g);continue}}if(d!==-1&&!ma(g)){u=!1;break}}if(a.push(i.jsx),u&&a.length===r.length&&a.length>1){let c=W.numericLiteral(a.length-1);for(let g=s.length-1;g>=0;g--)c=W.conditionalExpression(s[g],W.numericLiteral(g),c);return{pick:W.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 ai(e,t,n){let r=t.node,o=si(t,n),i=e.componentProps.get(n),s=i.params.length,a=e.listedSites.get(n)??[],l=e.linkedComponentRows.get(n)??[],d=a.some(Z=>Z.sourceLocal===!0)||l.some(Z=>Z.sourceLocal),u=$t(e,n),c=rt(e,u),g=e.instanceDerivations.get(n),x=e.instanceControlFlow.get(n),E=e.effects.get(n),f=E?.some(Z=>Z.localReads.size>0||Z.localDerivationReads.size>0||Z.conditionLocalReads.size>0||Z.conditionLocalDerivationReads.size>0)===!0;(e.selectiveDerivationComponents.has(n)||e.targetedListComponents.has(n)||f)&&(c.reasonVar=A(e,"reasons").name);let m=A(e,"id").name,C=u?null:A(e,"parent").name,y=u&&d?A(e,"owner").name:null,v=u&&e.componentsWithHostEvents.has(n)?A(e,"eventRoot").name:null;c.delegatedEventRootVar=v;let M=s>0&&!u?A(e,"props").name:null;vt(e).registerComponentId(n,m);let R;if((a.length>0||l.length>0)&&i.bindings.length>0){let Z=[...a.map(V=>nt(V.keyExpr??null,V.itemParam??"")),...l.map(V=>V.keyPath)],ne=JSON.stringify(Z[0]),xe=Z.every(V=>JSON.stringify(V)===ne)?Z[0]:null,be=pn(i,"item"),ie=Ke(i);R={itemParam:be??ie??i.bindings[0],itemPath:be===null&&ie!==null?["item"]:[],rowIdVar:m,...u?{refreshVar:c.updateVar}:{},keyPath:xe,sourceKey:a[0]?.sourceKey??l[0]?.sourceKey??"",sourceLocal:d,...d?{ownerIdVar:y??C}:{}}}Qo(e,t,n,m,R);let I="jsx"in o?ut(e,c,o.jsx,n,t,null,R):ha(e,c,o,n,t,m),H=u&&"jsx"in o&&D.isJSXElement(o.jsx);if(u&&zt(e,c,I),g!==void 0)for(let Z of g)Z.declaration.kind="let";(g!==void 0||x!==void 0)&&c.updaters.unshift(()=>ii(e,n,c.reasonVar,r.body.body,g??[],x??[])),E!==void 0&&f&&c.updaters.push(()=>Wr(e,n,m,c.reasonVar,E,c));let O=new Set(E?.map(Z=>Z.statement)??[]),_=r.body.body.filter(Z=>!("jsx"in o?Z===o.statement:o.statements.has(Z))&&!O.has(Z));s>0&&!u&&c.updaters.unshift(()=>D.blockStatement(Tn(i,i.params.map((Z,ne)=>D.memberExpression(D.identifier(M),D.numericLiteral(ne),!0)))));let Y=[ot(c)];if(s>0&&!u){let Z=wr(i,i.params.map((ne,xe)=>D.memberExpression(D.identifier(M),D.numericLiteral(xe),!0)));Z!==null&&Y.push(Z)}if(Y.push(..._,it(c),...u?[]:[yt(e,D.identifier(m),D.identifier(C),D.identifier(c.updateVar))]),s>0&&!u&&Y.push(D.expressionStatement(D.callExpression(Q(e,"registerProps"),[D.identifier(m),D.identifier(M)]))),Y.push(...c.creation,...c.mounts),E!==void 0&&Y.push(...zr(e,m,E)),u){let Z=i.params.map((ne,xe)=>A(e,`nextProp${xe}`));Y.push(D.returnStatement(D.objectExpression([D.objectProperty(D.identifier("nodes"),H?D.identifier(I):D.callExpression(Q(e,"rootNodes"),[D.identifier(I)])),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(Z,D.blockStatement(Tn(i,Z))))]:[],...c.disposableCallbacks.length>0?[D.objectProperty(D.identifier("dispose"),D.arrowFunctionExpression([],D.blockStatement([...c.disposableCallbacks].reverse().map(ne=>D.ifStatement(D.binaryExpression("!==",D.cloneNode(ne),D.nullLiteral()),D.expressionStatement(D.callExpression(D.cloneNode(ne),[])))))))]:[]])))}else Y.push(D.returnStatement(D.identifier(I)));r.params=u?[...i.params.map(kr),D.identifier(m),...y===null?[]:[D.identifier(y)],...v===null?[]:[D.identifier(v)]]:s>0?[D.identifier(m),D.identifier(C),D.identifier(M)]:[D.identifier(m),D.identifier(C)],r.body=D.blockStatement(Y)}function ha(e,t,n,r,o,i){let s=A(e,"returnRoot").name,a=A(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(Q(e,"createCondRegion"),[D.identifier(s),D.cloneNode(d),D.cloneNode(n.pick),D.arrayExpression(n.branches.map(u=>Ho(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 ae from"@babel/types";function Ea(e){return!ae.isIdentifier(e.id)||!/^[A-Z]/.test(e.id.name)||!ae.isArrowFunctionExpression(e.init)&&!ae.isFunctionExpression(e.init)||!de(e.init.body)?null:e.init}function ya(e,t,n){if(t.async||t.generator)throw n.buildCodeFrameError(`memo-dom: component '${e}' must be synchronous`);if(ae.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=ae.functionDeclaration(ae.identifier(e),t.params.map(o=>ae.cloneNode(o,!0)),ae.isBlockStatement(t.body)?ae.cloneNode(t.body,!0):ae.blockStatement([ae.returnStatement(ae.cloneNode(t.body,!0))]));return r.returnType=t.returnType==null?null:ae.cloneNode(t.returnType,!0),r.typeParameters=t.typeParameters==null?null:ae.cloneNode(t.typeParameters,!0),r.loc=t.loc,r}function li(e,t,n){if(e.kind!=="const")return[t?ae.exportNamedDeclaration(ae.cloneNode(e,!0)):ae.cloneNode(e,!0)];let r=[];for(let o of e.declarations){let i=Ea(o),s;i===null?s=ae.variableDeclaration("const",[ae.cloneNode(o,!0)]):s=ya(o.id.name,i,n),r.push(t?ae.exportNamedDeclaration(s):s)}return r.length>0&&ae.inheritsComments(r[0],e),r}function on(e){let t=[],n=!1;for(let r of e.get("body")){let o=r.node;if(ae.isVariableDeclaration(o)){let i=li(o,!1,r);n||=i.some(s=>ae.isFunctionDeclaration(s)),t.push(...i);continue}if(ae.isExportNamedDeclaration(o)&&ae.isVariableDeclaration(o.declaration)){let i=li(o.declaration,!0,r);n||=i.some(s=>ae.isExportNamedDeclaration(s)&&ae.isFunctionDeclaration(s.declaration)),t.push(...i);continue}t.push(o)}n&&(e.set("body",t),e.scope.crawl())}function Sa(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(Q(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(Q(e,"computedChanged"),[$.identifier(s),$.cloneNode(l)]),$.blockStatement([$.expressionStatement($.assignmentExpression("=",$.identifier(s),$.cloneNode(l))),$.expressionStatement($.callExpression(Q(e,"commitWrites"),[Ut(e,[s])]))]))])))])]));r.insertAfter(d)}}}function xa(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(Q(e,"computedChanged"),[$.cloneNode(i.get(a)),$.identifier(a)]),$.blockStatement([$.expressionStatement($.callExpression(Q(e,"commitWrites"),[Ut(e,[a])]))])))];o.insertAfter($.expressionStatement($.callExpression(Q(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 yr(e,t={}){let n=an(t),r=new WeakSet;return{name:"memo-dom",visitor:{Program:{enter(i){on(i),Nn(n,i),ln(n,i),Dn(n,i),ei(n,i),ti(n)},exit(i){Kr(n,i),ni(i),Ur(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=er(n);n.computeds.size>0&&Sa(n,i),n.moduleControlFlow.length>0&&xa(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(vt(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),ai(n,i,s),i.skip())}}}}function Sr(e,t={}){let n=Ca(e,{filename:t.moduleId??"./component.tsx",plugins:[[Pa,{}],[yr,t],[wa,{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 Kt}from"node:path";import{transformSync as xi}from"@babel/core";import Ci from"@babel/plugin-syntax-jsx";import Pi from"@babel/plugin-transform-typescript";import*as z from"@babel/types";function va(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 ka(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 di(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=va(r,a.target,d);for(let g of u)ka(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 Na(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 ci(e,t){let n=new Map(e.map(u=>[u.key,u]));Na(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,E=x.size;for(let f of c)x.add(`${f}${g.suffix}`);i.set(g.target,x),x.size!==E&&a.push(g.target)}}let l=new Map;for(let u of n.keys())l.set(u,[...i.get(u)??[]].sort());let d=di(n,s);return{paths:l,rows:o,propSources:d}}import"@babel/types";import*as ge from"@babel/types";function ui(e){let t=e;for(;ge.isTSAsExpression(t)||ge.isTSTypeAssertion(t)||ge.isTSNonNullExpression(t)||ge.isTSSatisfiesExpression(t);)t=t.expression;return t}function Ia(e,t,n){let r=ui(n);if(ge.isIdentifier(r))return!e.state.has(r.name)||t.getBinding(r.name)?.scope.path.isProgram()!==!0?null:Ye(e,r.name);if(!ge.isMemberExpression(r))return null;let o=ve(r);return o===null||!e.state.has(o)||t.getBinding(o)?.scope.path.isProgram()!==!0?null:Ye(e,ye(r)??o)}function Ra(e,t){let n=ui(t);if(ge.isIdentifier(n)){let a=Ze(e,n.name);return a===null?null:{type:"prop",name:a,path:[]}}if(!ge.isMemberExpression(n))return null;let r=ve(n),o=ye(n);if(r===null||o===null)return null;if(Ke(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 Fa(e,t){let n=!1,r=Ke(e);return Le(t,o=>{ge.isIdentifier(o)&&(o.name===r||Ze(e,o.name)!==null)&&(n=!0)}),n}function Ma(e){return ge.isStringLiteral(e)||ge.isNumericLiteral(e)||ge.isBooleanLiteral(e)||ge.isNullLiteral(e)||ge.isBigIntLiteral(e)||ge.isTemplateLiteral(e)}function Da(e,t,n,r){let o=Ia(e,n,r);if(o!==null)return{type:"state",key:o};let i=e.componentProps.get(t),s=Ra(i,r);if(s!==null)return s;let a=ge.isIdentifier(r)?r.name:ge.isMemberExpression(r)?ve(r):null;return a!==null&&(e.instanceState.get(t)?.has(a)===!0||e.instanceDerivedBindings.get(t)?.has(a)===!0)||dn(e,r).size>0||Fa(i,r)?{type:"root"}:Ma(r)?{type:"local"}:{type:"root"}}function xr(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 La(e){return ge.isJSXIdentifier(e.name)?e.name.name:null}function pi(e,t){let n=new Map;return e.compPaths.get(t).traverse({JSXOpeningElement(r){let o=r.node.name;if(!ge.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)||xr(n,o.name,d,{type:"root"});continue}if(!s.isJSXAttribute())continue;let a=La(s.node);if(a===null||a==="key"||a==="ref"||i?.refProps.includes(a)===!0)continue;let l=s.node.value;if(!ge.isJSXExpressionContainer(l)||!ge.isExpression(l.expression)){xr(n,o.name,a,{type:"local"});continue}xr(n,o.name,a,Da(e,t,s.scope,l.expression))}}}),n}function fi(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&&Ae(r)){let i=un(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:Fn(r.node.body),renderProps:[],renderCallbacks:[],refProps:[],subtreeReads:[]})}r.skip()}}),n}function mi(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:wn(e,n),delegatedEvents:e.componentsWithHostEvents.has(n),renderProps:[...r.renderProps],renderCallbacks:[...r.renderCallbacks],refProps:[...r.refProps],subtreeReads:[...Rn(e,n)].map(o=>Ye(e,o)).sort()}}function $n(e,t){return e.importedComponents.get(t)?.key??`${e.moduleId}#${t}`}function gi(e,t){let n=[];for(let r of t.comps.keys()){let o=[],i=pi(t,r);for(let[s,a]of t.childRefCounts.get(r)??[]){let l=$n(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:$n(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:$n(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:$n(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 wi(e){let t=e.replace(/\\/g,"/"),n=Kt.normalize(t);return t.startsWith("./")&&!n.startsWith("../")?`./${n}`:n}function vi(e){return{...e.runtimePath===void 0?{}:{runtimePath:e.runtimePath},...e.rootId===void 0?{}:{rootId:e.rootId}}}function Aa(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 u=z.isJSXIdentifier(d.name)?d.name.name:d.name.name.name,c=d.value;z.isJSXElement(c)||z.isJSXFragment(c)||z.isJSXExpressionContainer(c)&&z.isExpression(c.expression)&&(de(c.expression)||st(e,r,c.expression))?n(l,u,"jsx"):n(l,u,"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 bi(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 wt(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)){wt(e.consequent,t,n),wt(e.alternate,t,n);return}if(z.isLogicalExpression(e)){wt(e.right,t,n);return}if(z.isObjectExpression(e)){for(let r of e.properties)z.isObjectProperty(r)&&z.isExpression(r.value)&&wt(r.value,t,n);return}if(z.isArrayExpression(e))for(let r of e.elements)r!=null&&!z.isSpreadElement(r)&&wt(r,t,n)}function hi(e,t){let n=new Set;if(z.isExpression(e.body))return wt(e.body,t,n),[...n];let r=o=>{if(!z.isFunction(o)){if(z.isReturnStatement(o)){z.isExpression(o.argument)&&wt(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 ki(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 Ni(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 ja(e,t,n){let r,o=()=>({visitor:{Program(i){on(i);let s=ki(i.node),a=an({...vi(n),moduleId:e.id,linkedImports:t});Nn(a,i),ln(a,i),Dn(a,i);let l={},d=Qn(i.node);for(let[u,c]of Ni(i.node)){if(a.comps.has(c)){l[u]={type:"component",...mi(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:bi(a,a.stateComponentCandidates.get(c)??[])};continue}let x=a.importedFunctions.get(c)??(a.helpers.has(c)?Ue(a,c):void 0);x!==void 0&&(l[u]={type:"function",tagCandidates:[...d.get(c)??a.functionTagCandidates.get(c)??[]],componentCandidates:bi(a,a.functionComponentCandidates.get(c)??[]),reads:[...x.reads].map(E=>Ye(a,E)).sort(),writes:[...x.writes].map(E=>Ye(a,E)).sort(),boundedWrites:[...x.boundedWrites].map(E=>Ye(a,E)).sort(),parameterWrites:x.parameterWrites.map(E=>({index:E.index,path:[...E.path]})).sort((E,f)=>E.index-f.index||E.path.join(".").localeCompare(f.path.join("."))),unbounded:x.unbounded})}r={exports:l,imports:s,components:gi(e.id,a),componentUsages:Aa(a)}}}});if(xi(e.source,{filename:e.id,plugins:[[Ci,{}],o,[Pi,{isTSX:!0}]],configFile:!1,babelrc:!1}),r===void 0)throw new Error(`memo-dom: failed to analyze module '${e.id}'`);return r}function Ja(e){let t,n=()=>({visitor:{Program(r){on(r);let o=new Map,i=In(r.node),s=Qn(r.node),a=fi(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=z.isExportNamedDeclaration(u)?u.declaration:u;if(z.isVariableDeclaration(c))for(let g of c.declarations){if(!z.isIdentifier(g.id))continue;if(z.isArrowFunctionExpression(g.init)||z.isFunctionExpression(g.init)){let E=hi(g.init,l).map(f=>`${e.id}#${f}`);o.set(g.id.name,{type:"function",tagCandidates:[...s.get(g.id.name)??[]],componentCandidates:E,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0});continue}let x;if(c.kind==="let"||c.kind==="var"?x="let":kt(g.init)?x="store":Nt(g.init)&&(x="const"),x!==void 0){let E=new Set;z.isExpression(g.init)&&wt(g.init,l,E),o.set(g.id.name,{type:"state",kind:x,key:`${e.id}#${g.id.name}`,tagCandidates:[...i.get(g.id.name)??[]],componentCandidates:[...E].map(f=>`${e.id}#${f}`)})}}else if(z.isFunctionDeclaration(c)&&c.id!=null&&!a.has(c.id.name)){let g=hi(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 Ni(r.node)){let g=o.get(c);g!==void 0&&(d[u]=g)}t={exports:d,imports:ki(r.node),components:[],componentUsages:[]}}}});if(xi(e.source,{filename:e.id,plugins:[[Ci,{}],n,[Pi,{isTSX:!0}]],configFile:!1,babelrc:!1}),t===void 0)throw new Error(`memo-dom: failed to discover module '${e.id}'`);return t}function Ii(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=Kt.normalize(Kt.join(Kt.dirname(e),t));i=e.startsWith("./")&&!l.startsWith("../")?`./${l}`:l}else i=t;let s=wi(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 $a(e,t){if(!t.startsWith("."))return t;let n=Kt.relative(Kt.dirname(e),t);return n.startsWith(".")?n:`./${n}`}function Ei(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:$a(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 yi(e,t,n,r,o,i){let s={};for(let a of t.imports){let l=Ii(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:Ei(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:Ei(e,d.componentCandidates,n),reads:[...d.reads],writes:[...d.writes],boundedWrites:[...d.boundedWrites],parameterWrites:[...d.parameterWrites],unbounded:d.unbounded}}return s}function Si(e){return JSON.stringify(e)}function Oa(e,t={}){let n=new Map;for(let[a,l]of Object.entries(e)){let d=wi(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,Ja(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=yi(u,c,r,n,t),x=ja(u,g,t);d.set(u.id,x),Si(x)!==Si(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=ci([...r.values()].flatMap(a=>a.components),t.rootId??"App"),s={};for(let a of n.values()){let l=r.get(a.id),d=yi(a,l,r,n,t,o);for(let E of l.imports){let f=Ii(a.id,E.source,n,t);if(f!==void 0&&r.get(f.id)?.exports[E.imported]===void 0)throw new Error(`memo-dom: '${E.imported}' is not a linkable state, function, or component export of '${E.source}'`)}let u={},c={},g={},x={};for(let E of l.components){u[E.local]=[...i.paths.get(E.key)??[]];let f=i.rows.get(E.key);f!==void 0&&(c[E.local]=f.map(y=>({keyPath:y.keyPath===null?null:[...y.keyPath],sourceKey:y.sourceKey,sourceLocal:y.sourceLocal})));let m=i.propSources.get(E.key);m!==void 0&&(g[E.local]=Object.fromEntries([...m].map(([y,v])=>[y,{keys:[...v.keys],rootFallback:v.rootFallback}])));let C=Object.values(l.exports).find(y=>y.type==="component"&&y.key===E.key);if(C?.type==="component"){let y=o.get(E.key);x[E.local]=C.renderProps.filter(v=>y?.scalar.has(v)!==!0||y.jsx.has(v))}}s[a.originalId]=Sr(a.source,{...vi(t),moduleId:a.id,linkedImports:d,linkedComponentPaths:u,linkedComponentRows:c,linkedComponentPropSources:g,linkedComponentRenderProps:x})}return s}export{Sr as compile,Oa 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};