@memoized-dom/compiler 0.0.3 → 0.0.5
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/README.md +51 -1
- package/dist/analysis/access-table.d.ts.map +1 -1
- package/dist/analysis/component-graph.d.ts.map +1 -1
- package/dist/analysis/instance.d.ts.map +1 -1
- package/dist/analysis/opaque-volatility.d.ts +7 -0
- package/dist/analysis/opaque-volatility.d.ts.map +1 -0
- package/dist/analysis.d.ts.map +1 -1
- package/dist/compile.d.ts +22 -0
- package/dist/compile.d.ts.map +1 -1
- package/dist/component-linker.d.ts +5 -1
- package/dist/component-linker.d.ts.map +1 -1
- package/dist/components/children.d.ts +2 -1
- package/dist/components/children.d.ts.map +1 -1
- package/dist/components/local-derived.d.ts.map +1 -1
- package/dist/components/manifest.d.ts +1 -1
- package/dist/components/manifest.d.ts.map +1 -1
- package/dist/components/props.d.ts +11 -0
- package/dist/components/props.d.ts.map +1 -1
- package/dist/components/render-callbacks.d.ts +2 -2
- package/dist/components/render-callbacks.d.ts.map +1 -1
- package/dist/context/ast.d.ts +8 -4
- package/dist/context/ast.d.ts.map +1 -1
- package/dist/context/model.d.ts +40 -8
- package/dist/context/model.d.ts.map +1 -1
- package/dist/diagnostics.d.ts +18 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/effects.d.ts.map +1 -1
- package/dist/emission/component.d.ts.map +1 -1
- package/dist/emission/conditional-region.d.ts.map +1 -1
- package/dist/emission/list-region.d.ts +2 -1
- package/dist/emission/list-region.d.ts.map +1 -1
- package/dist/emission/render-callback.d.ts.map +1 -1
- package/dist/emission/route-region.d.ts +9 -0
- package/dist/emission/route-region.d.ts.map +1 -0
- package/dist/emission/scope.d.ts +3 -3
- package/dist/emission/scope.d.ts.map +1 -1
- package/dist/emit.d.ts.map +1 -1
- package/dist/handler-commits.d.ts.map +1 -1
- package/dist/handlers/analyze.d.ts.map +1 -1
- package/dist/identifiers.d.ts +2 -0
- package/dist/identifiers.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/jsx/children.d.ts +2 -1
- package/dist/jsx/children.d.ts.map +1 -1
- package/dist/jsx/conditional-directives.d.ts +12 -0
- package/dist/jsx/conditional-directives.d.ts.map +1 -0
- package/dist/jsx/events.d.ts +1 -1
- package/dist/jsx/events.d.ts.map +1 -1
- package/dist/jsx-types.d.ts +39 -0
- package/dist/jsx-types.d.ts.map +1 -0
- package/dist/linker.d.ts +50 -5
- package/dist/linker.d.ts.map +1 -1
- package/dist/lists/calculated-sources.d.ts.map +1 -1
- package/dist/lists/map-site.d.ts +6 -4
- package/dist/lists/map-site.d.ts.map +1 -1
- package/dist/lists/source-shapes.d.ts.map +1 -1
- package/dist/lists.d.ts +1 -0
- package/dist/lists.d.ts.map +1 -1
- package/dist/plugin.d.ts +6 -9
- package/dist/plugin.d.ts.map +1 -1
- package/dist/router.d.ts +28 -0
- package/dist/router.d.ts.map +1 -0
- package/package.json +8 -2
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{transformFromAstSync as Ll,transformSync as Al}from"@babel/core";import jl from"@babel/plugin-syntax-jsx";import Jl from"@babel/plugin-transform-typescript";import*as Ui from"@babel/types";import*as O from"@babel/types";import"@babel/types";function En(e={}){let t=e.moduleId??"./component.tsx",n=new Map,o=new Map,r=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[b,f]of Object.entries(e.linkedImports??{}))f.type==="state"?(n.set(b,f.kind),o.set(b,f.key),f.tagCandidates!==void 0&&r.set(b,[...f.tagCandidates]),f.componentCandidates!==void 0&&l.set(b,f.componentCandidates.map(g=>({...g}))),d.add(b)):f.type==="function"?(f.tagCandidates!==void 0&&i.set(b,[...f.tagCandidates]),f.componentCandidates!==void 0&&l.set(b,f.componentCandidates.map(g=>({...g}))),u.set(b,{reads:new Set(f.reads),writes:new Set(f.writes),boundedWrites:new Set(f.boundedWrites),parameterWrites:f.parameterWrites.map(g=>({index:g.index,path:[...g.path]})),unbounded:f.unbounded})):c.set(b,{...f,props:[...f.props]});let m=new Map;for(let[b,f]of c)m.set(b,{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 E=new Map(Object.entries(e.linkedComponentRenderProps??{}).map(([b,f])=>[b,[...f]]));return{runtimePath:e.runtimePath??"@memoized-dom/runtime",routerPath:e.routerPath??"@memoized-dom/router/internal",rootId:e.rootId??"App",rootComponent:e.rootComponent??null,hot:e.hot??!1,moduleId:t,linkedRoutes:e.linkedRoutes??null,emitRouteManifest:e.emitRouteManifest??e.linkedRoutes===void 0,routeElements:new WeakMap,localRoutes:[],usesRouter:!1,state:n,stateKeys:o,stateTagCandidates:r,functionTagCandidates:i,stateComponentCandidates:s,functionComponentCandidates:a,linkedDynamicComponentCandidates:l,importedState:d,importedFunctions:u,importedComponents:c,linkedComponentPaths:new Map(Object.entries(e.linkedComponentPaths??{}).map(([b,f])=>[b,[...f]])),linkedComponentRows:new Map(Object.entries(e.linkedComponentRows??{}).map(([b,f])=>[b,f.map(g=>({keyPath:g.keyPath===null?null:[...g.keyPath],sourceKey:g.sourceKey,sourceLocal:g.sourceLocal}))])),linkedComponentPropSources:new Map(Object.entries(e.linkedComponentPropSources??{}).map(([b,f])=>[b,new Map(Object.entries(f).map(([g,h])=>[g,{keys:[...h.keys],rootFallback:h.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:m,linkedComponentRenderProps:E,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,volatileComponents:new Set,opaqueBindings:new Map,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 U from"@babel/types";import*as et from"@babel/types";var Qn=class{constructor(t,n){this.scope=t;Ss(n.node,o=>this.reserved.add(o)),this.runtimeId=this.generate("MD").name,this.routerId=this.generate("MR").name}scope;runtimeId;routerId;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 et.identifier(n)}runtimeMember(t){return et.memberExpression(et.identifier(this.runtimeId),et.identifier(t))}};function hn(e,t){let n=new Qn(t.scope,t);return e.identifiers=n,n}function J(e,t){return Et(e).generate(t)}function Te(e,t){return Et(e).componentId(t)}function ne(e,t){return Et(e).runtimeMember(t)}function bt(e,t){let n=Et(e);return et.memberExpression(et.identifier(n.routerId),et.identifier(t))}function Et(e){if(e.identifiers===null)throw new Error("memo-dom: generated identifier allocator was not initialized");return e.identifiers}function Ss(e,t){let n=o=>{et.isIdentifier(o)&&t(o.name);for(let r of et.VISITOR_KEYS[o.type]??[]){let i=o[r];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 $t(e){for(;U.isTSAsExpression(e)||U.isTSTypeAssertion(e)||U.isTSNonNullExpression(e)||U.isTSSatisfiesExpression(e)||U.isTSInstantiationExpression(e);)e=e.expression;return e}function wt(e,t,n){e.state.set(t,n),e.stateKeys.has(t)||e.stateKeys.set(t,`${e.moduleId}#${t}`)}function tt(e,t){if(t.includes("#"))return t;let n=t.indexOf("."),o=n===-1?t:t.slice(0,n),r=n===-1?"":t.slice(n);return`${e.stateKeys.get(o)??o}${r}`}function Qt(e,t){let n=[...new Set(t.map(s=>tt(e,s)))].sort(),o=n.join(" "),r=e.writeConsts.get(o);if(r!==void 0)return U.identifier(r);let i=J(e,`WRITES_${e.writeConstCounter++}`);return e.writeConsts.set(o,i.name),e.header.push(U.variableDeclaration("const",[U.variableDeclarator(i,U.arrayExpression(n.map(s=>U.stringLiteral(s))))])),i}function Ho(e,t){let n=[...new Set(t)].sort((s,a)=>s-a),o=n.join(" "),r=e.reasonConsts.get(o);if(r!==void 0)return U.identifier(r);let i=J(e,`REASONS_${e.reasonConstCounter++}`);return e.reasonConsts.set(o,i.name),e.header.push(U.variableDeclaration("const",[U.variableDeclarator(i,U.arrayExpression(n.map(s=>U.numericLiteral(s))))])),i}function Uo(e){return U.isMemberExpression(e)||U.isOptionalMemberExpression(e)}function Pe(e){let t=[],n=e;for(;Uo(n);){if(n.computed){if(!U.isStringLiteral(n.property))return null;t.unshift(n.property.value)}else{if(!U.isIdentifier(n.property))return null;t.unshift(n.property.name)}if(U.isSuper(n.object))return null;n=n.object}for(;U.isTSNonNullExpression(n)||U.isTSAsExpression(n)||U.isTSTypeAssertion(n)||U.isTSSatisfiesExpression(n)||U.isTSInstantiationExpression(n);)n=n.expression;return U.isIdentifier(n)?(t.unshift(n.name),t.join(".")):null}function it(e,t){if(e===null)return[];let n=[],o=e;for(;U.isMemberExpression(o)&&!o.computed;){if(!U.isIdentifier(o.property)||(n.unshift(o.property.name),U.isSuper(o.object)))return null;o=o.object}return!U.isIdentifier(o,{name:t})||n.length===0?null:n}function Xt(e,t){return t===null?!0:t.length===0||e.length>t.length?!1:e.every((n,o)=>t[o]===n)}function Re(e){let t=e;for(;;){if(Uo(t)){if(U.isSuper(t.object))return null;t=t.object;continue}if(U.isTSNonNullExpression(t)||U.isTSAsExpression(t)||U.isTSTypeAssertion(t)||U.isTSSatisfiesExpression(t)||U.isTSInstantiationExpression(t)){t=t.expression;continue}break}return U.isIdentifier(t)?t.name:null}function Dt(e){if(!e)return!1;let t=$t(e);return U.isObjectExpression(t)?t.properties.every(n=>U.isObjectProperty(n)&&!n.computed&&(U.isIdentifier(n.key)||U.isStringLiteral(n.key))):!1}function Lt(e){if(!e)return!1;let t=$t(e);return U.isArrayExpression(t)||U.isNewExpression(t)}function ze(e){return e==null?null:U.isStringLiteral(e)?e:U.isJSXExpressionContainer(e)?U.isJSXEmptyExpression(e.expression)?null:e.expression:null}function eo(e,t,n){let o=n!==void 0?e.instanceState.get(n):void 0,r=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(U.isIdentifier(l)&&(e.state.has(l.name)||o?.has(l.name)===!0||r?.has(l.name)===!0||i?.includes(l.name)===!0)){s=!0;return}for(let d of U.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 qo(e,t,n){let o=new Set([...e.instanceState.get(n)??[],...e.instanceDerivedBindings.get(n)??[],...e.componentProps.get(n)?.bindings??[]]);if(o.size===0)return!1;let r=!1;return Oe(t,i=>U.isIdentifier(i)&&o.has(i.name)?(r=!0,!1):r?!1:void 0),r}function Oe(e,t){let n=(o,r)=>{if(t(o,r)!==!1)for(let i of U.VISITOR_KEYS[o.type]??[]){let s=o[i];if(Array.isArray(s))for(let a of s)a&&typeof a=="object"&&"type"in a&&n(a,o);else s&&typeof s=="object"&&"type"in s&&n(s,o)}};n(e,null)}function fe(e){let t=!1;return Oe(e,n=>{(U.isJSXElement(n)||U.isJSXFragment(n))&&(t=!0)}),t}function yn(e,t){let n=new Set;return Oe(t,o=>{if(U.isJSXAttribute(o)&&U.isJSXIdentifier(o.name,{name:"ref"}))return!1;U.isIdentifier(o)&&e.state.has(o.name)&&n.add(o.name)}),n}import*as P from"@babel/types";import*as re from"@babel/types";import*as Ze from"@babel/types";function xn(e){let t=Ze.cloneNode(e,!0);return Ze.traverseFast(t,n=>{(Ze.isIdentifier(n)||Ze.isObjectPattern(n)||Ze.isArrayPattern(n)||Ze.isRestElement(n)||Ze.isAssignmentPattern(n))&&(n.typeAnnotation=null)}),t}import*as ve from"@babel/types";import*as Y from"@babel/types";function Sn(e){if(e.mode!=="object"||e.params.length!==1||e.hasWholeDefault)return null;let t=e.params[0];if(!Y.isObjectPattern(t))return null;let n=[];for(let o of t.properties){if(!Y.isObjectProperty(o)||o.computed||!Y.isIdentifier(o.value))return null;let r=Y.isIdentifier(o.key)?o.key.name:Y.isStringLiteral(o.key)?o.key.value:null;if(r===null)return null;n.push({name:r,local:o.value.name})}return n}function Cn(e){if(e.some(i=>Y.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=Pt(t[0]);if(t.length===1&&(Y.isObjectPattern(n)||Y.isIdentifier(n)&&n.name==="props"))return{mode:"object",names:Y.isObjectPattern(n)?Cs(n):[],acceptsUnknown:Y.isIdentifier(n)||n.properties.some(s=>Y.isRestElement(s)),bindings:en(n),params:t.map(s=>Y.cloneNode(s)),hasWholeDefault:Y.isAssignmentPattern(t[0]),renderProps:[],renderCallbacks:[],refProps:[]};let r=[];for(let i of t){let s=Pt(i);if(!Y.isIdentifier(s))throw new Error("object-destructured props must be the component's only parameter");r.push(s.name)}return{mode:"positional",names:r,acceptsUnknown:!1,bindings:t.flatMap(i=>en(Pt(i))),params:t.map(i=>Y.cloneNode(i)),hasWholeDefault:!1,renderProps:[],renderCallbacks:[],refProps:[]}}function _o(e,t){return e.params.length===0?null:Y.variableDeclaration("let",e.params.map((n,o)=>Y.variableDeclarator(ws(Pt(n)),Yo(n,t[o]??Y.identifier("undefined")))))}function to(e,t){return e.params.map((n,o)=>Y.expressionStatement(Y.assignmentExpression("=",Qo(Pt(n)),Yo(n,t[o]??Y.identifier("undefined")))))}function Go(e){return Y.expressionStatement(Y.assignmentExpression("=",Qo(e.target),Y.cloneNode(e.source)))}function en(e){return Object.keys(Y.getBindingIdentifiers(e))}function qe(e){if(e.mode!=="object"||e.params.length!==1)return null;let t=Pt(e.params[0]);return Y.isIdentifier(t)?t.name:null}function wn(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=Pt(e.params[0]);if(!Y.isObjectPattern(n))return null;for(let o of n.properties){if(!Y.isObjectProperty(o)||o.computed||(Y.isIdentifier(o.key)?o.key.name:Y.isStringLiteral(o.key)?o.key.value:null)!==t)continue;let i=Y.isAssignmentPattern(o.value)?o.value.left:o.value;return Y.isIdentifier(i)?i.name:null}return null}function Ye(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=Pt(e.params[0]);if(!Y.isObjectPattern(n))return null;for(let o of n.properties)if(!(!Y.isObjectProperty(o)||o.computed)&&Object.keys(Y.getBindingIdentifiers(o.value)).includes(t)){if(Y.isIdentifier(o.key))return o.key.name;if(Y.isStringLiteral(o.key))return o.key.value}return null}function Pt(e){if(Y.isRestElement(e))throw new Error("rest component parameters are not supported");let t=Y.isAssignmentPattern(e)?e.left:e;if(!Y.isIdentifier(t)&&!Y.isObjectPattern(t)&&!Y.isArrayPattern(t))throw new Error("unsupported component parameter target");return t}function Zo(e){let t=Y.cloneNode(e);return tn(t),t}function Yo(e,t){return Y.isAssignmentPattern(e)?Y.conditionalExpression(Y.binaryExpression("===",Y.cloneNode(t),Y.identifier("undefined")),Y.cloneNode(e.right),Y.cloneNode(t)):Y.cloneNode(t)}function Cs(e){let t=[];for(let n of e.properties)if(!Y.isRestElement(n)){if(n.computed)throw new Error("computed keys are not supported in component prop patterns");if(Y.isIdentifier(n.key))t.push(n.key.name);else if(Y.isStringLiteral(n.key))t.push(n.key.value);else throw new Error("component prop pattern keys must be identifiers or strings")}return t}function ws(e){let t=Y.cloneNode(e);return tn(t),t}function Qo(e){let t=Y.cloneNode(e);return tn(t),t}function tn(e){let t=e;"typeAnnotation"in t&&(t.typeAnnotation=null),"optional"in t&&(t.optional=null);for(let n of Y.VISITOR_KEYS[e.type]??[]){let o=e[n];if(Array.isArray(o))for(let r of o)r&&typeof r=="object"&&"type"in r&&tn(r);else o&&typeof o=="object"&&"type"in o&&tn(o)}}function er(e,t){let n=t.findParent(d=>d.isArrowFunctionExpression()||d.isFunctionExpression());if(n===null||!n.isArrowFunctionExpression()&&!n.isFunctionExpression())return!1;let o=n.get("body");if(!(o.isJSXElement()&&o.node===t.node||o.isBlockStatement()&&o.node.body.length===1&&ve.isReturnStatement(o.node.body[0])&&o.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()||!ve.isJSXIdentifier(a.node.name))return!1;let l=ve.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 Ps(e){return(ve.isMemberExpression(e.callee)||ve.isOptionalMemberExpression(e.callee))&&!e.callee.computed&&ve.isIdentifier(e.callee.property,{name:"map"})}function vs(e,t,n){let o=e.componentProps.get(t);if(o===void 0)return null;let r=qe(o);return r!==null&&ve.isMemberExpression(n)&&!n.computed&&ve.isIdentifier(n.object,{name:r})&&ve.isIdentifier(n.property)?n.property.name:ve.isIdentifier(n)?Ye(o,n.name)??(wn(o,n.name)!==null?n.name:null):null}function ks(e){return ve.isExpression(e.body)?e.body:e.body.body.length===1&&ve.isReturnStatement(e.body.body[0])&&ve.isExpression(e.body.body[0].argument)?e.body.body[0].argument:null}function Tt(e,t,n){if(!Ps(n)||n.arguments.length!==1)return null;let o=n.arguments[0];if(!ve.isArrowFunctionExpression(o))return null;let r=ks(o);if(r===null||!ve.isCallExpression(r)||!ve.isExpression(r.callee)||r.arguments.some(s=>!ve.isExpression(s)))return null;let i=vs(e,t,r.callee);return i===null?null:{propName:i,target:ve.cloneNode(r.callee,!0),arguments:r.arguments.map(s=>ve.cloneNode(s,!0))}}function tr(e){for(let[t,n]of e.compPaths){let o=e.componentProps.get(t),r=i=>{let s=Tt(e,t,i.node);s!==null&&!o.renderCallbacks.includes(s.propName)&&o.renderCallbacks.push(s.propName)};n.traverse({CallExpression:r,OptionalCallExpression:r})}}import*as Qe from"@babel/types";function ht(e){return $t(e)}function Pn(e){let t=ht(e);return Qe.isArrayExpression(t)&&t.elements.every(n=>n!==null&&!Qe.isSpreadElement(n)&&(Qe.isStringLiteral(n)||Qe.isNumericLiteral(n)||Qe.isBooleanLiteral(n)||Qe.isNullLiteral(n)||Qe.isBigIntLiteral(n)))}function Ke(e){if(!re.isCallExpression(e)&&!re.isOptionalCallExpression(e))return null;let t=e.callee;return(re.isMemberExpression(t)||re.isOptionalMemberExpression(t))&&!t.computed&&re.isIdentifier(t.property,{name:"map"})?e:null}function $e(e){let t=!1;return e.traverse({JSXElement(){t=!0},JSXFragment(){t=!0}}),t}function At(e,t,n,o,r,i){let s=m=>{throw n.buildCodeFrameError(m)},a=t.callee,l=Ns(e,a.object,o,i,s),d=Ms(e,t,o,s),u=Ds(e,d,s),c=js(l.suffixBase,r);return{sourceKey:l.key,sourceExpr:re.cloneNode(l.expression),optional:re.isOptionalCallExpression(t)||Fs(a.object),sourceLocal:l.local,itemPattern:d.itemPattern,itemParam:d.itemParam,indexParam:d.indexParam,keyExpr:As(d.jsx?.openingElement??null,s),jsx:d.jsx,form:u.form,rowComp:u.rowComp,renderCallback:u.renderCallback,owner:o,suffix:c,prefix:`${o}/${c}`}}function Ns(e,t,n,o,r){let i=re.isExpression(t)?ht(t):t;return re.isIdentifier(i)?Rs(e,i,n,r):re.isMemberExpression(i)||re.isOptionalMemberExpression(i)?Is(e,i,n,o,r):re.isExpression(i)&&Pn(i)?{expression:i,key:"$static-list",local:!0,suffixBase:"$static-list"}:r("memo-dom: assign an ordered collection view to reactive state or a local derivation before mapping it")}function Rs(e,t,n,o){let r=e.componentProps.get(n)?.bindings??[],i=e.opaqueBindings.get(n),s=e.instanceState.get(n)?.has(t.name)===!0||e.instanceDerivedBindings.get(n)?.has(t.name)===!0||r.includes(t.name)||i?.has(t.name)===!0,a=e.state.get(t.name);return!s&&a!=="let"&&a!=="const"&&a!=="computed"?o("memo-dom: list views must come from reactive module state, component props, component state, or a local derivation"):{expression:t,key:t.name,local:s,suffixBase:t.name}}function Is(e,t,n,o,r){let i=Re(t),s=Pe(t),a=e.componentProps.get(n)?.bindings??[],l=e.opaqueBindings.get(n),d=i!==null&&(e.instanceState.get(n)?.has(i)===!0||e.instanceDerivedBindings.get(n)?.has(i)===!0||a.includes(i)||l?.has(i)===!0),u=i!==null&&s!==null&&o!==void 0&&i===o.itemParam;return i===null||s===null||!s.includes(".")||!u&&!d&&e.state.get(i)!=="store"?r("memo-dom: list member views must be a static path on reactive module state, component props, component state, or a local derivation"):{expression:t,key:u?o.sourceKey:s,local:u?o.sourceLocal:d,suffixBase:s.slice(s.lastIndexOf(".")+1)}}function Fs(e){let t=e;for(;!re.isSuper(t);){if(re.isOptionalMemberExpression(t))return!0;if(!re.isMemberExpression(t))return!1;t=t.object}return!1}function Ms(e,t,n,o){if(t.arguments.length!==1||!re.isArrowFunctionExpression(t.arguments[0]))return o("memo-dom: list rendering expects items.map(item => <JSX />) \u2014 R7 L1");let r=t.arguments[0],i=r.params[0],s=r.params[1];if(r.params.length<1||r.params.length>2||!re.isIdentifier(i)&&!re.isObjectPattern(i)&&!re.isArrayPattern(i)||s!==void 0&&!re.isIdentifier(s))return o("memo-dom: list callback must take an item binding pattern and optional index identifier \u2014 R7 L1");let a=xn(i),l=Object.keys(re.getBindingIdentifiers(a));if(l.length===0)return o("memo-dom: list callback item pattern must bind at least one name \u2014 R7 L1");let d=re.isIdentifier(a)?a.name:l[0],u=re.isIdentifier(s)?s.name:null,c=re.isBlockStatement(r.body)&&r.body.body.length===1&&re.isReturnStatement(r.body.body[0])?r.body.body[0].argument:null,m=re.isJSXElement(r.body)?r.body:re.isJSXElement(c)?c:null,E=Tt(e,n,t);return m===null&&E===null?o("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:m,renderInvocation:E}}function Ds(e,t,n){let o=t.jsx?.openingElement??null;if(o!==null&&!re.isJSXIdentifier(o.name))return n("memo-dom: namespaced JSX tags are not supported (L1)");let r=o!==null&&re.isJSXIdentifier(o.name)?o.name.name:null;return t.renderInvocation!==null?(Ls(t,n),{form:"callback",rowComp:null,renderCallback:re.cloneNode(t.renderInvocation.target,!0)}):r!==null&&/^[A-Z]/.test(r)?!e.comps.has(r)&&!e.importedComponents.has(r)?n(`memo-dom: <${r} /> is not a linked component factory`):{form:"component",rowComp:r,renderCallback:null}:{form:"inline",rowComp:null,renderCallback:null}}function Ls(e,t){let n=e.renderInvocation;(!re.isIdentifier(e.itemPattern)||n.arguments.length<1||n.arguments.length>2||!re.isIdentifier(n.arguments[0],{name:e.itemPattern.name})||n.arguments.length===2&&(e.indexParam===null||!re.isIdentifier(n.arguments[1],{name:e.indexParam})))&&t("memo-dom: render callback maps must pass their item and optional index bindings directly")}function As(e,t){let n=null;for(let o of e?.attributes??[])if(re.isJSXAttribute(o)&&re.isJSXIdentifier(o.name,{name:"key"})&&(n=ze(o.value),n===null))return t("memo-dom: key={...} needs an expression");return n}function js(e,t){let n=t.get(e)??0;return t.set(e,n+1),n===0?e:`${e}${n}`}import*as ae from"@babel/types";function vn(e){return ae.isConditionalExpression(e)||ae.isLogicalExpression(e)&&(e.operator==="&&"||e.operator==="||")?e:null}function Js(e){return ae.isNullLiteral(e)||ae.isBooleanLiteral(e,{value:!1})||ae.isIdentifier(e,{name:"undefined"})}function Os(e,t){let n=[e];for(;n.length>0;){let o=n.pop();if(ae.isJSXElement(o)){for(let r of o.openingElement.attributes)!ae.isJSXSpreadAttribute(r)&&r.name.name==="key"&&t("memo-dom: key={...} is only meaningful on list rows");n.push(...o.children)}else if(ae.isJSXFragment(o))n.push(...o.children);else if(ae.isJSXExpressionContainer(o)&&ae.isExpression(o.expression)){let r=o.expression;if(Ke(r)!==null&&fe(r))continue}}}function kn(e,t,n){let o=l=>{throw t.buildCodeFrameError(l)},r,i;if(ae.isConditionalExpression(e)){let l=[];i=[];let d=e;for(;ae.isConditionalExpression(d);)l.push(ae.cloneNode(d.test)),i.push(d.consequent),d=d.alternate;i.push(d),r=ae.numericLiteral(i.length-1);for(let u=l.length-1;u>=0;u--)r=ae.conditionalExpression(l[u],ae.numericLiteral(u),r)}else e.operator==="&&"?(r=ae.conditionalExpression(ae.cloneNode(e.left),ae.numericLiteral(0),ae.numericLiteral(1)),i=[e.right,null]):(r=ae.conditionalExpression(ae.cloneNode(e.left),ae.numericLiteral(1),ae.numericLiteral(0)),i=[e.right,null]);let s=l=>l===null||Js(l)?null:ae.isJSXElement(l)||ae.isJSXFragment(l)?l:ae.isExpression(l)?ae.jsxFragment(ae.jsxOpeningFragment(),ae.jsxClosingFragment(),[ae.jsxExpressionContainer(ae.cloneNode(l,!0))]):o("memo-dom: conditional branches must be JSX, renderable text expressions, or null/false"),a=i.map(s);for(let l of a)l!==null&&Os(l,o);return{pickExpr:r,branches:a,suffix:`when${n.count++}`}}import*as Je from"@babel/types";import*as ye from"@babel/types";var Bt=class{constructor(t){this.fallback=t}fallback;origins=new WeakMap;trackDeclarator(t,n){if(!ye.isIdentifier(n.id)||n.init===null)return;let o=this.resolveExpression(t,n.init);if(o===null)return;let r=t.getBinding(n.id.name);r!==void 0&&this.origins.set(r.identifier,o)}referencedOrigins(t,n){let o=new Map,r=i=>{if(ye.isIdentifier(i)||ye.isMemberExpression(i)){let s=this.resolveExpression(t,i);if(s!==null){let a=[s.locality,s.root,s.key??"*"].join(":");o.set(a,s);return}}for(let s of ye.VISITOR_KEYS[i.type]??[]){let a=i[s];if(Array.isArray(a))for(let l of a)l&&typeof l=="object"&&"type"in l&&r(l);else a&&typeof a=="object"&&"type"in a&&r(a)}};return r(n),[...o.values()]}resolveName(t,n){let o=t.getBinding(n);if(o!==void 0){let r=this.origins.get(o.identifier);if(r!==void 0)return r}return this.fallback(n,o)}resolveExpression(t,n){let o=nr(n);if(ye.isIdentifier(o))return this.resolveName(t,o.name);if(!ye.isMemberExpression(o))return null;let r=$s(o);if(r===null)return null;let i=this.resolveName(t,r);if(i===null)return null;let s=Pe(o);if(i.key===null||s===null)return{...i,key:null};let a=s.split(".").slice(1);return{...i,key:[i.key,...a].join(".")}}};function Nn(e,t){return{locality:"module",root:e,key:e,stateKind:t}}function vt(e,t){return e.key===null?e:{...e,key:[e.key,...t].join(".")}}function Rn(e,t){if(e.key===null)return null;let n=[];for(let o of t){if(!ye.isObjectExpression(o))return null;for(let r of o.properties){if(!ye.isObjectProperty(r)||r.computed||!ye.isIdentifier(r.key)&&!ye.isStringLiteral(r.key))return null;let i=ye.isIdentifier(r.key)?r.key.name:r.key.value;n.push(`${e.key}.${i}`)}}return n}function In(e){let t=[];for(let n of e)ye.isExpression(n)?t.push(n):ye.isSpreadElement(n)&&t.push(n.argument);return t}function Fn(e){return!e.computed&&ye.isIdentifier(e.property)?e.property.name:e.computed&&ye.isStringLiteral(e.property)?e.property.value:null}function $s(e){let t=e;for(;ye.isMemberExpression(t);){if(ye.isSuper(t.object))return null;t=nr(t.object)}return ye.isIdentifier(t)?t.name:null}function nr(e){let t=e;for(;ye.isTSAsExpression(t)||ye.isTSTypeAssertion(t)||ye.isTSNonNullExpression(t)||ye.isTypeCastExpression(t)||ye.isTSSatisfiesExpression(t);)t=t.expression;return t}function Be(e,t,n=new Set){let o=e.helperSummaries.get(t);if(o)return o;if(n.has(t))return{reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!0};let r=e.helpers.get(t),i=new Set,s=new Map(r.node.params.flatMap((f,g)=>Je.isIdentifier(f)?[[f.name,g]]:[])),a={reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!1},l=new Bt((f,g)=>{if(s.has(f)&&g?.scope.block===r.node)return{locality:"prop",root:f,key:f};let h=e.state.get(f);return h===void 0||g!==void 0&&!g.scope.path.isProgram()?null:Nn(f,h)}),d=f=>f.stateKind==="computed"||e.state.get(f.root)==="computed";n.add(t),r.traverse({VariableDeclarator(f){Je.isIdentifier(f.node.id)&&(i.add(f.node.id.name),f.parentPath.isVariableDeclaration()&&l.trackDeclarator(f.scope,f.node))},Function(f){for(let g of f.node.params)Je.isIdentifier(g)&&i.add(g.name)}});let u=(f,g)=>{a.parameterWrites.some(h=>h.index===f&&h.path.length===g.length&&h.path.every((C,N)=>C===g[N]))||a.parameterWrites.push({index:f,path:g})},c=f=>{if(!d(f)){if(f.locality==="module"){a.boundedWrites.add(f.key??f.root);return}if(f.locality==="prop"){let g=s.get(f.root);if(g!==void 0){let h=f.key===null?[]:f.key.split(".").slice(1);u(g,h);return}}a.unbounded=!0}},m=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)},E=(f,g)=>{let h=l.resolveExpression(f.scope,g);h!==null&&m(h)},b=(f,g)=>{for(let h of In(g)){if(!Je.isIdentifier(h))continue;let C=l.resolveExpression(f.scope,h);C!==null&&!d(C)&&c(C)}};return r.traverse({VariableDeclarator(f){if(!Je.isIdentifier(f.node.id)&&f.node.init!==null)for(let g of l.referencedOrigins(f.scope,f.node.init))c(g)},AssignmentExpression(f){let g=f.node.left;if(Je.isIdentifier(g))if(i.has(g.name)){if(Je.isIdentifier(f.node.right)){let h=l.resolveExpression(f.scope,f.node.right);h!==null&&c(h)}}else e.state.has(g.name)&&a.writes.add(g.name);else if(Je.isMemberExpression(g))E(f,g);else for(let h of l.referencedOrigins(f.scope,f.node.right))c(h)},UpdateExpression(f){let g=f.node.argument;Je.isIdentifier(g)?!i.has(g.name)&&e.state.has(g.name)&&a.writes.add(g.name):Je.isMemberExpression(g)&&E(f,g)},UnaryExpression(f){f.node.operator==="delete"&&Je.isMemberExpression(f.node.argument)&&E(f,f.node.argument)},CallExpression(f){let g=f.node.callee;if(Je.isMemberExpression(g)){if(Fn(g)==="assign"&&Je.isIdentifier(g.object,{name:"Object"})){let N=f.node.arguments[0],v=N!==void 0&&Je.isExpression(N)?l.resolveExpression(f.scope,N):null;if(v!==null){let $=Rn(v,f.node.arguments.slice(1));if($===null)c(v);else for(let _ of $)m({...v,key:_})}return}let C=Je.isExpression(g.object)?l.resolveExpression(f.scope,g.object):null;C!==null?c(C):b(f,f.node.arguments);return}if(Je.isIdentifier(g)&&(e.helpers.has(g.name)||e.importedFunctions.has(g.name))){let h=e.importedFunctions.get(g.name)??Be(e,g.name,n);for(let C of h.reads)a.reads.add(C);for(let C of h.writes)a.writes.add(C);for(let C of h.boundedWrites)a.boundedWrites.add(C);for(let C of h.parameterWrites){let N=f.node.arguments[C.index];if(N===void 0||!Je.isExpression(N))continue;let v=l.resolveExpression(f.scope,N);v!==null&&c(vt(v,C.path))}h.unbounded&&(a.unbounded=!0);return}b(f,f.node.arguments)},Identifier(f){let g=f.node.name;if(!e.state.has(g)||i.has(g))return;let h=f.parentPath;h.isAssignmentExpression({operator:"="})&&h.node.left===f.node||a.reads.add(g)},MemberExpression(f){let g=Xs(e,f);g!==null&&a.reads.add(g)}}),n.delete(t),e.helperSummaries.set(t,a),a}function Xs(e,t){let n=Pe(t.node);if(!n||!n.includes("."))return null;let o=n.split(".")[0];if(e.state.get(o)!=="store"||t.scope.getBinding(o)?.scope.path.isProgram()!==!0)return null;let r=t.parentPath;return r.isAssignmentExpression({operator:"="})&&r.node.left===t.node||Ts(t)?null:n}function Ts(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}import*as x from"@babel/types";import*as le from"@babel/types";function st(e,t=!1){return{slots:[],tempVar:J(e,"value").name,updateVar:J(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 at(e){return le.variableDeclaration("let",[...e.slots.map(t=>le.variableDeclarator(le.identifier(t))),le.variableDeclarator(le.identifier(e.tempVar))])}function no(e,t){let n=J(e,`slot${t.slots.length}`).name;return t.slots.push(n),n}function oo(e,t,n){let o=t.tagCounters.get(n)??0;return t.tagCounters.set(n,o+1),J(e,`${n}${o}`).name}function jt(e,t,n,o){let r=()=>le.identifier(e.tempVar),i=()=>le.identifier(t);return le.ifStatement(le.binaryExpression("!==",i(),le.assignmentExpression("=",r(),n)),le.blockStatement([le.expressionStatement(le.assignmentExpression("=",i(),r())),o(r())]))}function lt(e){return le.variableDeclaration("const",[le.variableDeclarator(le.identifier(e.updateVar),le.arrowFunctionExpression(e.reasonVar===null?[]:[le.assignmentPattern(le.identifier(e.reasonVar),le.nullLiteral())],le.blockStatement(e.updaters.map(t=>t()))))])}function ft(e,t,n,o,r=!1){return le.expressionStatement(le.callExpression(ne(e,"register"),[le.objectExpression([le.objectProperty(le.identifier("id"),t),le.objectProperty(le.identifier("parent"),n),le.objectProperty(le.identifier("render"),o),...r?[le.objectProperty(le.identifier("volatile"),le.booleanLiteral(!0))]:[]])]))}function ro(e){let t=e.replace(/\s+/g," ");return/^\s*\n/.test(e)&&(t=t.replace(/^ /,"")),/\n\s*$/.test(e)&&(t=t.replace(/ $/,"")),t}function nn(e){return e.some(t=>!x.isJSXText(t)||t.value.trim()!=="")}function yt(e,t,n){let o=e.componentProps.get(t);if(o===void 0)return null;let r=qe(o);if(r!==null&&x.isMemberExpression(n)&&!n.computed&&x.isIdentifier(n.object,{name:r})&&x.isIdentifier(n.property))return n.property.name;if(x.isIdentifier(n)){let i=Ye(o,n.name);if(i!==null)return i;if(n.name==="children"&&e.instanceDerivedBindings.get(t)?.has("children")===!0)return"children"}return null}function dt(e,t,n){let o=yt(e,t,n);return o!==null&&e.componentProps.get(t)?.renderProps.includes(o)===!0}function or(e,t,n,o){let r=st(e,!0);r.childCounts=t.childCounts,r.usedPrefixes=t.usedPrefixes,r.usedConds=t.usedConds;let i=J(e,"childrenUpdate"),s=J(e,"childrenUpdates"),a=J(e,"childrenMountSequence"),l=J(e,"children"),d=J(e,"childrenParent"),u=J(e,"childrenOwner"),c=J(e,"childrenKey"),m=J(e,"childrenSlot"),E=J(e,"childrenNextUpdate"),b=J(e,"childrenActive"),f=J(e,"childrenDispose");return o(r,d,m),t.creation.push(x.variableDeclaration("let",[x.variableDeclarator(x.cloneNode(i),x.nullLiteral()),x.variableDeclarator(x.cloneNode(s),x.nullLiteral()),x.variableDeclarator(x.cloneNode(a),x.numericLiteral(0))]),x.variableDeclaration("const",[x.variableDeclarator(x.cloneNode(l),x.arrowFunctionExpression([x.cloneNode(d),x.cloneNode(u),x.cloneNode(c)],x.blockStatement([x.variableDeclaration("const",[x.variableDeclarator(x.cloneNode(m),x.conditionalExpression(x.binaryExpression("===",x.cloneNode(a),x.numericLiteral(0)),x.cloneNode(n,!0),x.binaryExpression("+",x.binaryExpression("+",x.cloneNode(n,!0),x.stringLiteral("/$slot[")),x.binaryExpression("+",x.cloneNode(a),x.stringLiteral("]")))))]),x.expressionStatement(x.updateExpression("++",x.cloneNode(a))),x.variableDeclaration("let",[x.variableDeclarator(x.cloneNode(b),x.booleanLiteral(!0))]),at(r),lt(r),...r.creation,...r.mounts,x.ifStatement(x.binaryExpression("===",x.cloneNode(i),x.nullLiteral()),x.expressionStatement(x.assignmentExpression("=",x.cloneNode(i),x.identifier(r.updateVar))),x.blockStatement([x.ifStatement(x.binaryExpression("===",x.cloneNode(s),x.nullLiteral()),x.expressionStatement(x.assignmentExpression("=",x.cloneNode(s),x.newExpression(x.identifier("Set"),[])))),x.expressionStatement(x.callExpression(x.memberExpression(x.cloneNode(s),x.identifier("add")),[x.identifier(r.updateVar)]))])),x.variableDeclaration("const",[x.variableDeclarator(x.cloneNode(f),x.arrowFunctionExpression([],x.blockStatement([x.ifStatement(x.unaryExpression("!",x.cloneNode(b)),x.returnStatement()),x.expressionStatement(x.assignmentExpression("=",x.cloneNode(b),x.booleanLiteral(!1))),x.ifStatement(x.binaryExpression("===",x.cloneNode(i),x.identifier(r.updateVar)),x.expressionStatement(x.assignmentExpression("=",x.cloneNode(i),x.nullLiteral())),x.ifStatement(x.binaryExpression("!==",x.cloneNode(s),x.nullLiteral()),x.expressionStatement(x.callExpression(x.memberExpression(x.cloneNode(s),x.identifier("delete")),[x.identifier(r.updateVar)])))),...r.disposableRegions.map(g=>x.expressionStatement(x.callExpression(x.memberExpression(x.identifier(g),x.identifier("dispose")),[]))),...[...r.disposableCallbacks].reverse().map(g=>x.ifStatement(x.binaryExpression("!==",x.cloneNode(g),x.nullLiteral()),x.expressionStatement(x.callExpression(x.cloneNode(g),[])))),...r.disposableEntities.map(g=>x.expressionStatement(x.callExpression(ne(e,"unregisterSubtree"),[x.cloneNode(g,!0)])))])))]),x.expressionStatement(x.callExpression(ne(e,"cleanup"),[x.cloneNode(u),x.cloneNode(f)])),x.returnStatement(x.cloneNode(f))])))])),t.updaters.push(()=>x.blockStatement([x.ifStatement(x.binaryExpression("!==",x.cloneNode(i),x.nullLiteral()),x.expressionStatement(x.callExpression(x.cloneNode(i),[]))),x.ifStatement(x.binaryExpression("!==",x.cloneNode(s),x.nullLiteral()),x.forOfStatement(x.variableDeclaration("const",[x.variableDeclarator(x.cloneNode(E))]),x.cloneNode(s),x.expressionStatement(x.callExpression(x.cloneNode(E),[]))))])),l}function io(e,t,n,o,r){let i=J(e,"slotDispose"),s=t.forwardedSlotCounter++;t.creation.push(x.variableDeclaration("const",[x.variableDeclarator(x.cloneNode(i),x.conditionalExpression(x.binaryExpression("==",x.cloneNode(n,!0),x.nullLiteral()),x.nullLiteral(),x.callExpression(x.cloneNode(n,!0),[x.identifier(o),x.cloneNode(r,!0),x.stringLiteral(String(s))])))])),t.disposableCallbacks.push(i)}function rr(e,t,n,o){let r=i=>{e.creation.push(x.expressionStatement(x.callExpression(x.memberExpression(x.identifier(n),x.identifier("appendChild")),[x.identifier(i)])))};for(let i of t){if(x.isJSXText(i)){let d=ro(i.value);d!==""&&r(o.emitText(x.stringLiteral(d)));continue}if(x.isJSXElement(i)||x.isJSXFragment(i)){r(o.emitNode(i));continue}if(x.isJSXExpressionContainer(i)||o.fail("memo-dom: spread children are not supported (L1)"),x.isJSXEmptyExpression(i.expression))continue;x.isExpression(i.expression)||o.fail("memo-dom: unsupported expression in component children");let s=i.expression;if(x.isNullLiteral(s)||x.isBooleanLiteral(s)||x.isIdentifier(s,{name:"undefined"}))continue;if(o.isForwarded(s)){o.emitForwarded(s,n);continue}let a=Ke(s);if(a!==null){o.emitList(a,n);continue}let l=vn(s);if(l!==null&&fe(l)){o.emitCondition(l,n);continue}r(o.emitText(x.cloneNode(s)))}}import*as D from"@babel/types";function Ln(e){return D.isIdentifier(e.node.callee,{name:"effect"})&&e.scope.getBinding("effect")===void 0}function Dn(e,t){return D.binaryExpression("+",D.identifier(e),D.stringLiteral(`/$effects/${t}`))}function Bs(e,t){return D.binaryExpression("+",Dn(e,t),D.stringLiteral("/$active"))}function Vs(e){if(e.isFunctionDeclaration())return e;if(!e.isVariableDeclarator())return null;let t=e.get("init");return t.isArrowFunctionExpression()||t.isFunctionExpression()?t:null}function dr(e,t){let n=t.get("arguments"),o=n[0];if(n.length!==1||o===void 0)throw t.buildCodeFrameError("memo-dom: effect() requires exactly one callback");if(o.isArrowFunctionExpression()||o.isFunctionExpression()){if(o.node.async||o.node.generator)throw o.buildCodeFrameError("memo-dom: effect callback must be synchronous; start async work inside it and return a synchronous teardown");return{expression:o.node,path:o,importedReads:new Set}}if(!o.isIdentifier())throw o.buildCodeFrameError("memo-dom: effect callback must be an inline function or a resolvable function identifier");if(e.importedFunctions.get(o.node.name)!==void 0)throw o.buildCodeFrameError(`memo-dom: imported named effect callback '${o.node.name}' is not supported yet; define a local synchronous wrapper so its cleanup and writes can be instrumented`);let i=o.scope.getBinding(o.node.name),s=i===void 0?null:Vs(i.path);if(s===null)throw o.buildCodeFrameError(`memo-dom: cannot resolve effect callback '${o.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(fe(s.node.body))throw s.buildCodeFrameError("memo-dom: a JSX component cannot be used as an effect callback");return{expression:D.cloneNode(o.node),path:s,importedReads:new Set}}function ir(e,t,n,o){let r=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 g of e.instanceDerivations.get(t)??[])for(let h of g.bindings)l.set(h,g.sources);for(let g of e.instanceControlFlow.get(t)??[])for(let h of g.bindings)l.set(h,g.sources);for(let g of a){let h=n.scope.getBinding(g);h!==void 0&&s.set(h,{source:g,local:!0})}for(let g of l.keys()){let h=n.scope.getBinding(g);h!==void 0&&s.set(h,{source:g,local:!0})}for(let g of e.state.keys()){let h=n.scope.getBinding(g);h?.scope.path.isProgram()===!0&&s.set(h,{source:g,local:!1})}let d=g=>{let h=g.scope.getBinding(g.node.name),C=h===void 0?void 0:s.get(h);if(C===void 0)return;let N=g.parentPath;!C.local&&e.state.get(C.source)==="store"&&N?.isMemberExpression()&&N.node.object===g.node||(C.local?i.add(C.source):r.add(C.source))},u=g=>{let h=Pe(g.node),C=Re(g.node);h===null||C===null||e.state.get(C)!=="store"||g.scope.getBinding(C)?.scope.path.isProgram()!==!0||r.add(h)},c=g=>{let h=g.node.callee;if(!D.isIdentifier(h)||g.scope.getBinding(h.name)?.scope.path.isProgram()!==!0||!e.helpers.has(h.name)&&!e.importedFunctions.has(h.name))return;let C=e.importedFunctions.get(h.name)??Be(e,h.name);for(let N of C.reads)r.add(N)};o.isIdentifier()&&o.isReferencedIdentifier()&&d(o),o.isMemberExpression()&&u(o),o.isCallExpression()&&c(o),o.traverse({Function(g){g.skip()},ReferencedIdentifier(g){g.isIdentifier()&&d(g)},MemberExpression(g){u(g)},CallExpression(g){c(g)}});let m=new Set,E=new Set,b=new Set;for(let g of i)a.has(g)&&b.add(g);let f=(g,h)=>{if(h.has(g))return;let C=l.get(g);if(C===void 0){a.has(g)?m.add(g):e.state.has(g)&&r.add(g);return}h.add(g),C.some(v=>b.has(v))||E.add(g);for(let v of C)f(v,h);h.delete(g)};for(let g of i)f(g,new Set);return{moduleReads:r,localReads:m,localDerivationReads:E}}function sr(e,t){let n=new Set,o=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)},r=s=>{let a=Pe(s.node),l=Re(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(!D.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)??Be(e,a.name);for(let d of l.reads)n.add(d)};return t.isIdentifier()&&t.isReferencedIdentifier()&&o(t),t.isMemberExpression()&&r(t),t.isCallExpression()&&i(t),t.traverse({Function(s){s.skip()},ReferencedIdentifier(s){s.isIdentifier()&&o(s)},MemberExpression(s){r(s)},CallExpression(s){i(s)}}),n}function so(e){if(!e.isExpressionStatement())return null;let t=e.get("expression");return t.isCallExpression()&&Ln(t)?t:null}function cr(e){if(so(e)!==null)return!0;let t=!1;return e.traverse({Function(n){n.skip()},CallExpression(n){Ln(n)&&(t=!0,n.stop())}}),t}function Mn(e,t,n,o){let r=so(e);if(r!==null){o.push({callPath:r,rootStatement:t,conditions:[...n]});return}if(!e.isEmptyStatement()){if(e.isBlockStatement()){for(let i of e.get("body"))if(!i.isEmptyStatement()){if(!cr(i))throw i.buildCodeFrameError("memo-dom: a conditional effect branch may contain only effect() calls, nested if statements, or empty statements");Mn(i,t,n,o)}return}if(e.isIfStatement()){let i=e.get("test");Mn(e.get("consequent"),t,[...n,{path:i,negated:!1}],o);let s=e.get("alternate");s.node!==null&&Mn(s,t,[...n,{path:i,negated:!0}],o);return}throw e.buildCodeFrameError("memo-dom: conditional effect() calls must be controlled by top-level if statements")}}function ur(e){let t=[];for(let n of e){let o=so(n);if(o!==null){t.push({callPath:o,rootStatement:n.node,conditions:[]});continue}!n.isIfStatement()||!cr(n)||Mn(n,n.node,[],t)}return t}function pr(e){return e.length===0?null:e.map(({path:n,negated:o})=>o?D.unaryExpression("!",D.cloneNode(n.node,!0)):D.cloneNode(n.node,!0)).reduce((n,o)=>D.logicalExpression("&&",n,o))}function Ws(e,t){let n=[],o=ur(t.get("body"));for(let r of o){let i=dr(e,r.callPath),s=i.path===null?i.importedReads:sr(e,i.path),a=new Set;for(let d of r.conditions)for(let u of sr(e,d.path))a.add(u);let l=n.length;n.push({index:l,statement:r.rootStatement,callback:i.expression,moduleReads:s,condition:pr(r.conditions),conditionModuleReads:a,entityId:`${e.rootId}/$module-effects/${encodeURIComponent(e.moduleId)}/${l}`})}e.moduleEffects.push(...n)}function fr(e,t){Ws(e,t);for(let[n,o]of e.compPaths){let r=[],i=new Set,s=ur(o.get("body").get("body"));for(let l of s){let d=dr(e,l.callPath),u=d.path===null?{moduleReads:d.importedReads,localReads:new Set,localDerivationReads:new Set}:ir(e,n,o,d.path),c=new Set,m=new Set,E=new Set;for(let b of l.conditions){let f=ir(e,n,o,b.path);for(let g of f.moduleReads)c.add(g);for(let g of f.localReads)m.add(g);for(let g of f.localDerivationReads)E.add(g)}r.push({index:r.length,statement:l.rootStatement,callback:d.expression,...u,condition:pr(l.conditions),conditionModuleReads:c,conditionLocalReads:m,conditionLocalDerivationReads:E}),i.add(l.callPath.node)}if(o.traverse({CallExpression(l){if(!(!Ln(l)||i.has(l.node)))throw l.buildCodeFrameError("memo-dom: effect() must be a direct top-level statement in a component body")}}),r.length===0)continue;e.effects.set(n,r);let a=new Set([...e.instanceReasonIds.get(n)?.keys()??[],...e.instanceState.get(n)??[],...e.componentProps.get(n)?.bindings??[],...r.flatMap(l=>[...l.localReads]),...r.flatMap(l=>[...l.conditionLocalReads])]);a.size>0&&e.instanceReasonIds.set(n,new Map([...a].sort().map((l,d)=>[l,d])))}}function ar(e){return e.reduce((t,n)=>D.logicalExpression("||",t,n))}function zs(e,t,n,o){let r=e.instanceReasonIds.get(t);if(r===void 0)return null;let i=[...o].map(d=>r.get(d)).filter(d=>d!==void 0).sort((d,u)=>d-u);if(i.length===0||i.length!==o.size)return null;let s=()=>D.identifier(n),a=ar(i.map(d=>D.binaryExpression("===",s(),D.numericLiteral(d)))),l=ar(i.map(d=>D.callExpression(D.memberExpression(s(),D.identifier("has")),[D.numericLiteral(d)])));return D.logicalExpression("||",D.binaryExpression("===",s(),D.nullLiteral()),D.conditionalExpression(D.binaryExpression("===",D.unaryExpression("typeof",s()),D.stringLiteral("number")),a,l))}function Ks(e){let t=()=>D.identifier(e);return D.logicalExpression("||",D.binaryExpression("===",t(),D.unaryExpression("-",D.numericLiteral(1))),D.logicalExpression("&&",D.logicalExpression("&&",D.binaryExpression("!==",t(),D.nullLiteral()),D.binaryExpression("!==",D.unaryExpression("typeof",t()),D.stringLiteral("number"))),D.logicalExpression("&&",D.binaryExpression("===",D.memberExpression(t(),D.identifier("size")),D.numericLiteral(1)),D.callExpression(D.memberExpression(t(),D.identifier("has")),[D.unaryExpression("-",D.numericLiteral(1))]))))}function mr(e,t,n,o,r,i){let s=(l,d,u,c,m)=>{if(u.size===0&&c.size===0)return null;let E=D.expressionStatement(D.callExpression(ne(e,"markDirty"),[d]));if(c.size>0&&i!==void 0){let g=[],h=[];for(let N of c){let v=J(e,`eff${l.index}_${m}_${N}`).name;i.creation.push(D.variableDeclaration("let",[D.variableDeclarator(D.identifier(v),D.identifier(N))])),g.push(D.binaryExpression("!==",D.identifier(v),D.identifier(N))),h.push(D.expressionStatement(D.assignmentExpression("=",D.identifier(v),D.identifier(N))))}let C=g.length===1?g[0]:g.reduce((N,v)=>D.logicalExpression("||",N,v));E=D.ifStatement(C,D.blockStatement([...h,E]))}if(o===null)return E;let b=zs(e,t,o,u),f=b===null?E:D.ifStatement(b,E);return D.ifStatement(D.unaryExpression("!",Ks(o)),f)},a=r.flatMap(l=>{let d=l.condition===null?null:s(l,Dn(n,l.index),l.conditionLocalReads,l.conditionLocalDerivationReads,"condition"),u=s(l,l.condition===null?Dn(n,l.index):Bs(n,l.index),l.localReads,l.localDerivationReads,"callback");return[d,u].filter(c=>c!==null)});return D.blockStatement(a)}function gr(e,t,n){return n.map(o=>D.expressionStatement(D.callExpression(ne(e,o.condition===null?"registerEffect":"registerConditionalEffect"),[Dn(t,o.index),D.identifier(t),...o.condition===null?[]:[D.arrowFunctionExpression([],D.cloneNode(o.condition,!0))],D.cloneNode(o.callback,!0)])))}function lr(){return D.memberExpression(D.metaProperty(D.identifier("import"),D.identifier("meta")),D.identifier("hot"))}function br(e,t){if(e.moduleEffects.length===0)return;let n=new Map(t.get("body").map(r=>[r.node,r])),o=new Map;for(let r of e.moduleEffects){let i=o.get(r.statement)??[];i.push(r),o.set(r.statement,i)}for(let[r,i]of o){let s=n.get(r);if(s===void 0)continue;let a=[];for(let l of i)a.push(D.expressionStatement(D.callExpression(ne(e,l.condition===null?"registerEffect":"registerConditionalEffect"),[D.stringLiteral(l.entityId),D.nullLiteral(),...l.condition===null?[]:[D.arrowFunctionExpression([],D.cloneNode(l.condition,!0))],D.cloneNode(l.callback,!0)])),D.ifStatement(lr(),D.expressionStatement(D.callExpression(D.memberExpression(lr(),D.identifier("dispose")),[D.arrowFunctionExpression([],D.callExpression(ne(e,"unregisterSubtree"),[D.stringLiteral(l.entityId)]))]))));s.replaceWithMultiple(a)}}function Er(e){e.traverse({CallExpression(t){if(Ln(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 nt from"@babel/types";function hr(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function yr(e){let t=new Set,n=[];for(let o of e){let r=An(o);if(r===null)return null;for(let i of r.bindings){if(t.has(i))return null;t.add(i)}n.push(...r.expressions)}return t.size===0?null:{bindings:t,expressions:n}}function An(e){if(nt.isExpressionStatement(e)&&nt.isAssignmentExpression(e.expression,{operator:"="})&&nt.isIdentifier(e.expression.left))return{bindings:new Set([e.expression.left.name]),expressions:[e.expression.right]};if(nt.isBlockStatement(e))return yr(e.body);if(nt.isIfStatement(e)){let t=e.alternate;if(t==null)return null;let n=An(e.consequent),o=An(t);return n===null||o===null||!hr(n.bindings,o.bindings)?null:{bindings:n.bindings,expressions:[e.test,...n.expressions,...o.expressions]}}return null}function Hs(e){if(!e.cases.some(r=>r.test==null))return null;let t=null,n=!1,o=[e.discriminant];for(let r of e.cases){r.test!=null&&o.push(r.test);let i=[...r.consequent];if(i.length===0){n=!0;continue}if(i.at(-1)&&nt.isBreakStatement(i.at(-1))&&i.pop(),i.some(a=>nt.isBreakStatement(a)))return null;let s=yr(i);if(s===null)return null;if(n=!1,t===null)t=s.bindings;else if(!hr(t,s.bindings))return null;o.push(...s.expressions)}return t===null||n?null:{bindings:t,expressions:o}}function Us(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function qs(e,t){let n=e;for(;n?.parentPath!==t;)n=n?.parentPath??null;return n}function xr(e,t,n){let o=t.get("body"),r=new Map(o.map((i,s)=>[i.node,s]));for(let i of o){if(!i.isIfStatement()&&!i.isSwitchStatement())continue;let s=i.node,a=i.isIfStatement()?An(s):Hs(s);if(a===null)continue;let l=!0,d=[];for(let b of a.bindings){let f=t.scope.getBinding(b),g=f?.path,h=g?.parentPath,C=g===void 0?null:qs(g,t);if(f===void 0||!g?.isVariableDeclarator()||!h?.isVariableDeclaration()||h.node.kind!=="let"&&h.node.kind!=="var"||C===null||(r.get(C.node)??Number.MAX_SAFE_INTEGER)>=(r.get(s)??-1)){l=!1;break}d.push(...f.constantViolations.filter(N=>!Us(N,s)))}if(!l)continue;let u=new Set,c=null;for(let b of a.expressions){let f=n(e,b);for(let g of f.reads)u.add(g);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 b of a.bindings)if(u.has(b))throw i.buildCodeFrameError(`memo-dom: module control-flow derivation '${b}' 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 m=e.moduleControlFlow.length,E=[...a.bindings].sort();for(let b of E)wt(e,b,"computed");e.moduleControlFlow.push({statement:s,bindings:E,sources:[...u].sort(),entityId:`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#$flow${m}`})}}import*as ge from"@babel/types";function ao(e,t){let n=new Set,o=!1,r,i=new Set,s=l=>{o||(o=!0,r=l)},a=l=>{ge.isIdentifier(l)?i.add(l.name):Oe(l,d=>{ge.isIdentifier(d)&&i.add(d.name)})};return Oe(t,(l,d)=>{if(ge.isFunction(l)){if(!(d!==null&&(ge.isCallExpression(d)||ge.isNewExpression(d))))return!1;for(let c of l.params)ge.isLVal(c)&&a(c);return}if(ge.isVariableDeclarator(l)&&ge.isLVal(l.id)){a(l.id);return}if(ge.isAssignmentExpression(l)){let u=ge.isIdentifier(l.left)?l.left.name:ge.isMemberExpression(l.left)?Re(l.left):null;(u===null||!i.has(u))&&s("contains an assignment \u2014 writes belong in handlers, not derivations");return}if(ge.isUpdateExpression(l)){let u=l.argument,c=ge.isIdentifier(u)?u.name:ge.isMemberExpression(u)?Re(u):null;(c===null||!i.has(c))&&s("contains an update (++/--) \u2014 writes belong in handlers, not derivations");return}if(ge.isAwaitExpression(l)||ge.isYieldExpression(l)){s("uses await/yield \u2014 derivations must be synchronous");return}if(ge.isCallExpression(l)){let u=l.callee;if(ge.isIdentifier(u)&&(e.helpers.has(u.name)||e.importedFunctions.has(u.name))){let c=e.importedFunctions.get(u.name)??Be(e,u.name);for(let m of c.reads)n.add(m);if(c.writes.size>0){for(let m of c.writes)n.add(m);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(ge.isIdentifier(l)){!i.has(l.name)&&e.state.has(l.name)&&n.add(l.name);return}if(ge.isMemberExpression(l)&&!l.computed){let u=Pe(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:o,reason:r}}function Sr(e,t){for(let n of t.node.body){let o=ge.isExportNamedDeclaration(n)?n.declaration:n;if(!(!ge.isVariableDeclaration(o)||o.kind!=="const"))for(let r of o.declarations){if(!ge.isIdentifier(r.id)||r.init==null)continue;let i=r.id.name;if(e.state.get(i)==="let"||e.state.get(i)==="computed"||ge.isFunction(r.init)||ge.isJSX(r.init))continue;let s=ao(e,r.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&&(wt(e,i,"computed"),e.computeds.set(i,{reads:s.reads}))}}}import*as Fe from"@babel/types";function _s(e,t,n){let o=t.scope.getBinding(n);if(o===void 0)return null;let r=null;if(o.path.isFunctionDeclaration())r=o.path;else if(o.path.isVariableDeclarator()){let i=o.path.get("init");!Array.isArray(i)&&(i.isFunctionExpression()||i.isArrowFunctionExpression())&&(r=i)}return r===null||r.findParent(i=>i.node===e.node)===null?null:r}function Cr(e,t,n,o,r,i,s){let a=_s(t,n,o);if(a===null)return null;let l=i.get(a.node);if(l!==void 0)return l;if(s.has(a.node))return{reads:new Set,reason:`calls recursive local helper '${o}'`};let d={reads:new Set,reason:null},u=b=>{d.reason??=b},c=b=>{if(!b.isIdentifier())return;let f=b.scope.getBinding(b.node.name),g=f===void 0?void 0:r.get(f);g!==void 0&&d.reads.add(g)},m=(b,f)=>{let g=Fe.isIdentifier(f)?f.name:Fe.isMemberExpression(f)?Re(f):null;if(g===null)return;let h=b.scope.getBinding(g),C=h===void 0?void 0:r.get(h);C!==void 0&&u(`calls local helper '${o}' which writes reactive state '${C}'`)},E=b=>{let f=b.node.callee;if(!Fe.isIdentifier(f))return;let g=Cr(e,t,b,f.name,r,i,s);if(g!==null){for(let C of g.reads)d.reads.add(C);g.reason!==null&&u(g.reason);return}if(!e.helpers.has(f.name)&&!e.importedFunctions.has(f.name))return;let h=e.importedFunctions.get(f.name)??Be(e,f.name);for(let C of h.reads)d.reads.add(C);h.writes.size!==0||h.boundedWrites.size!==0?u(`calls helper '${f.name}' which writes reactive state`):h.unbounded&&e.helpers.has(f.name)&&u(`calls recursive helper '${f.name}' which cannot be analyzed`)};return s.add(a.node),a.traverse({Function(b){let f=b.parentPath;(f.isCallExpression()||f.isNewExpression())&&f.node.callee===b.node||b.skip()},ReferencedIdentifier(b){c(b)},AssignmentExpression(b){m(b,b.node.left)},UpdateExpression(b){m(b,b.node.argument)},AwaitExpression(){u(`calls async local helper '${o}'`)},YieldExpression(){u(`calls yielding local helper '${o}'`)},CallExpression(b){E(b)}}),d.reads.size!==0&&a.traverse({Function(b){let f=b.parentPath;(f.isCallExpression()||f.isNewExpression())&&(f.node.callee===b.node||f.node.arguments.some(h=>h===b.node))||b.skip()},ReferencedIdentifier(b){c(b)},AssignmentExpression(b){m(b,b.node.left)},UpdateExpression(b){m(b,b.node.argument)},AwaitExpression(){u(`calls async local helper '${o}'`)},YieldExpression(){u(`calls yielding local helper '${o}'`)},CallExpression(b){E(b)}}),s.delete(a.node),i.set(a.node,d),d}function wr(e){for(let[t,n]of e.compPaths){let o=new Set;for(let r of n.node.body.body)if(Fe.isVariableDeclaration(r)&&!(r.kind!=="let"&&r.kind!=="var"&&r.kind!=="const"))for(let i of r.declarations)Fe.isIdentifier(i.id)&&(r.kind==="let"||r.kind==="var"||Dt(i.init)||Lt(i.init))&&o.add(i.id.name);o.size>0&&e.instanceState.set(t,o)}}function Pr(e){for(let[t,n]of e.compPaths){let o=new Map;for(let c of e.componentProps.get(t)?.bindings??[]){let m=n.scope.getBinding(c);m&&o.set(m,c)}for(let c of e.instanceState.get(t)??[]){let m=n.scope.getBinding(c);m&&o.set(m,c)}for(let c of e.state.keys()){let m=n.scope.getBinding(c);m?.scope.path.isProgram()&&o.set(m,c)}let r=[],i=new Set,s=new Map,a=n.get("body").get("body");for(let c of a)if(c.isVariableDeclaration({kind:"const"}))for(let m of c.get("declarations")){let E=m.node;if(!Fe.isIdentifier(E.id)&&!Fe.isObjectPattern(E.id)&&!Fe.isArrayPattern(E.id)||E.init==null||Fe.isFunction(E.init)||Fe.isIdentifier(E.id)&&e.instanceState.get(t)?.has(E.id.name)===!0&&(Dt(E.init)||Lt(E.init)))continue;let b=m.get("init");if(!b.isExpression())continue;let f=new Set,g=null,h=(k,W)=>{let T=W.scope.getBinding(k);return T!==void 0&&o.has(T)},C=k=>{if(!Fe.isIdentifier(k.node))return;let W=k.scope.getBinding(k.node.name),T=W===void 0?void 0:o.get(W);T!==void 0&&f.add(T)},N=k=>Fe.isIdentifier(k)?k.name:Fe.isMemberExpression(k)?Re(k):null,v=new Map,$=new Set,_=k=>{let W=k.node.callee;if(!Fe.isIdentifier(W))return;let T=Cr(e,n,k,W.name,o,v,$);if(T!==null){for(let oe of T.reads)f.add(oe);g??=T.reason;return}if(!e.helpers.has(W.name)&&!e.importedFunctions.has(W.name))return;let ee=e.importedFunctions.get(W.name)??Be(e,W.name);for(let oe of ee.reads)f.add(oe);ee.writes.size!==0||ee.boundedWrites.size!==0?g??=`calls helper '${W.name}' which writes reactive state`:ee.unbounded&&e.helpers.has(W.name)&&(g??=`calls recursive helper '${W.name}' which cannot be analyzed`)};if(b.isReferencedIdentifier()&&C(b),b.isAssignmentExpression()){let k=N(b.node.left);k!==null&&h(k,b)&&(g="contains an assignment to reactive state")}else if(b.isUpdateExpression()){let k=N(b.node.argument);k!==null&&h(k,b)&&(g="contains an update (++/--) to reactive state")}else b.isAwaitExpression()?g="uses await; per-instance derivations must be synchronous":b.isYieldExpression()&&(g="uses yield; per-instance derivations must be synchronous");if(b.isCallExpression()&&_(b),b.traverse({Function(k){let W=k.parentPath;(W.isCallExpression()||W.isNewExpression())&&W.node.callee===k.node||k.skip()},ReferencedIdentifier(k){C(k)},AssignmentExpression(k){let W=N(k.node.left);W!==null&&h(W,k)&&(g="contains an assignment to reactive state")},UpdateExpression(k){let W=N(k.node.argument);W!==null&&h(W,k)&&(g="contains an update (++/--) to reactive state")},AwaitExpression(){g="uses await; per-instance derivations must be synchronous"},YieldExpression(){g="uses yield; per-instance derivations must be synchronous"},CallExpression(k){_(k)}}),f.size===0)continue;if(b.traverse({Function(k){let W=k.parentPath;(W.isCallExpression()||W.isNewExpression())&&(W.node.callee===k.node||W.node.arguments.some(ee=>ee===k.node))||k.skip()},ReferencedIdentifier(k){C(k)},AssignmentExpression(k){let W=N(k.node.left);W!==null&&h(W,k)&&(g="contains an assignment to reactive state")},UpdateExpression(k){let W=N(k.node.argument);W!==null&&h(W,k)&&(g="contains an update (++/--) to reactive state")},AwaitExpression(){g="uses await; per-instance derivations must be synchronous"},YieldExpression(){g="uses yield; per-instance derivations must be synchronous"},CallExpression(k){_(k)}}),g!==null){let k=en(E.id);throw m.buildCodeFrameError(`memo-dom: local const '${k.join(", ")||"<pattern>"}' is a per-instance derivation but ${g}`)}let B=en(E.id),R=new Set;for(let k of f){let W=s.get(k);if(W===void 0)R.add(k);else for(let T of W)R.add(T)}r.push({declaration:c.node,target:Fe.cloneNode(E.id),source:Fe.cloneNode(E.init),bindings:B,sources:[...R].sort()});for(let k of B){i.add(k),s.set(k,new Set(R));let W=n.scope.getBinding(k);W&&o.set(W,k),e.instanceState.get(t)?.delete(k)}}if(r.length===0)continue;e.instanceDerivations.set(t,r),e.instanceDerivedBindings.set(t,i);let l=new Set([...e.instanceState.get(t)??[],...e.componentProps.get(t)?.bindings??[]]);if(![...l].some(c=>r.some(m=>!m.sources.includes(c))))continue;let u=new Set([...l,...r.flatMap(c=>c.sources)]);e.instanceReasonIds.set(t,new Map([...u].sort().map((c,m)=>[c,m]))),e.selectiveDerivationComponents.add(t)}}import*as _e from"@babel/types";function vr(e){return e?.path.isImportSpecifier()===!0||e?.path.isImportDefaultSpecifier()===!0||e?.path.isImportNamespaceSpecifier()===!0}function Gs(e){if(_e.isIdentifier(e))return e.name;if(!_e.isMemberExpression(e))return null;let t=e.object;for(;_e.isMemberExpression(t);)t=t.object;return _e.isIdentifier(t)?t.name:null}function jn(e,t,n,o,r=new Set){let i=Gs(t.node.callee);if(i===null)return!1;if(n.has(i))return!0;let s=e.importedFunctions.get(i);if(s!==void 0)return s.unbounded;if(vr(t.scope.getBinding(i)))return!0;if(o===void 0||!t.isCallExpression())return!1;let a=t.scope.getBinding(i),l=null;if(a?.path.isFunctionDeclaration()===!0)l=a.path;else if(a?.path.isVariableDeclarator()===!0){let E=a.path.get("init");!Array.isArray(E)&&(E.isFunctionExpression()||E.isArrowFunctionExpression())&&(l=E)}if(l===null||r.has(l.node))return!1;r.add(l.node);let d=!1,u=new Set,c=E=>{if(d||!E.isExpression())return;if(Vt(E,o,n).size>0){d=!0;return}if(E.isIdentifier()){let f=E.scope.getBinding(E.node.name);if(f?.path.isVariableDeclarator()===!0&&!u.has(f)){let g=f.path.get("init");!Array.isArray(g)&&g.node!==null&&(u.add(f),c(g),u.delete(f))}if(d)return}let b=f=>{jn(e,f,n,o,r)&&(d=!0)};(E.isCallExpression()||E.isNewExpression())&&b(E),E.traverse({Function(f){f.skip()},CallExpression:b,NewExpression:b})},m=l.get("body");return!Array.isArray(m)&&m.isExpression()?c(m):!Array.isArray(m)&&m.isBlockStatement()&&m.traverse({Function(E){E.skip()},ReturnStatement(E){let b=E.get("argument");!Array.isArray(b)&&b.node!==null&&c(b)}}),r.delete(l.node),d}function Zs(e){let t=e;for(;_e.isMemberExpression(t)||_e.isOptionalMemberExpression(t);)t=t.object;return _e.isIdentifier(t)?t.name:null}function Vt(e,t,n){let o=new Set,r=i=>{let s=i.node.name;if(!n.has(s))return;let a=i.scope.getBinding(s);a!==void 0&&a===t.scope.getBinding(s)&&o.add(s)};return e.traverse({ReferencedIdentifier(i){i.isIdentifier()&&r(i)}}),e.isReferencedIdentifier()&&r(e),o}function Ys(e,t,n){let o=t.findParent(a=>a.isProgram());if(o===null||!o.isProgram())return new Set(n);let r=new Set(Object.keys(o.scope.bindings)),i=new Set(n),s=!0;for(;s;){s=!1;for(let[a,l]of Object.entries(o.scope.bindings)){if(i.has(a))continue;let d=l.path.isVariableDeclarator()?l.path:l.path.findParent(E=>E.isVariableDeclarator());if(d===null||!d.isVariableDeclarator()||d.node.init===null)continue;let u=d.get("init"),m=[...Vt(u,o,r)].some(E=>i.has(E));m||u.traverse({CallExpression(E){jn(e,E,i,o)&&(m=!0)},NewExpression(E){jn(e,E,i,o)&&(m=!0)}}),m&&(i.add(a),s=!0)}}return i}function Qs(e,t){let n=new Set;return e.traverse({JSXExpressionContainer(o){let r=o.parentPath;if(r.isJSXAttribute()){let i=r.node.name,s=_e.isJSXIdentifier(i)?i.name:`${i.namespace.name}:${i.name.name}`;if(s==="ref"||/^on[A-Z]/.test(s))return}for(let i of Vt(o.get("expression"),e,t))n.add(i)},JSXSpreadAttribute(o){for(let r of Vt(o.get("argument"),e,t))n.add(r)}}),n}function kr(e){for(let[t,n]of e.compPaths){let o=Object.entries(n.scope.getProgramParent().bindings).filter(([d,u])=>{if(!vr(u)||e.importedState.has(d)||e.importedComponents.has(d))return!1;let c=e.importedFunctions.get(d);return c===void 0||c.unbounded}).map(([d])=>d),r=Ys(e,n,o),i=new Set([...Object.keys(n.scope.bindings),...e.state.keys(),...r,...e.instanceState.get(t)??[],...e.instanceDerivedBindings.get(t)??[],...e.componentProps.get(t)?.bindings??[]]);if(i.size===0)continue;let s=new Set(r),a=!0;for(;a;){a=!1;let d=c=>{!i.has(c)||s.has(c)||(s.add(c),a=!0)},u=c=>{if(!jn(e,c,s,n))return;for(let b of c.get("arguments"))if(!b.isSpreadElement())for(let f of Vt(b,n,i))d(f);let m=c.findParent(b=>b.isVariableDeclarator());if(m?.isVariableDeclarator()===!0)for(let b of Object.keys(_e.getBindingIdentifiers(m.node.id)))d(b);let E=c.findParent(b=>b.isAssignmentExpression({operator:"="}));if(E?.isAssignmentExpression({operator:"="})===!0){let b=Zs(E.node.left);b!==null&&d(b)}};n.traverse({CallExpression(c){u(c)},NewExpression(c){u(c)},VariableDeclarator(c){if(!(c.node.init===null||![...Vt(c.get("init"),n,i)].some(E=>s.has(E))))for(let E of Object.keys(_e.getBindingIdentifiers(c.node.id)))d(E)}})}let l=Qs(n,i);e.opaqueBindings.set(t,s),[...s].some(d=>l.has(d))&&e.volatileComponents.add(t)}}import*as be from"@babel/types";function rn(e){let t=!0;return be.traverseFast(e,n=>{if(be.isAssignmentExpression(n)||be.isUpdateExpression(n)||be.isAwaitExpression(n)||be.isYieldExpression(n)||be.isNewExpression(n)||be.isTaggedTemplateExpression(n)||be.isFunction(n)){t=!1;return}if(be.isCallExpression(n)||be.isOptionalCallExpression(n)){let o=n.callee;t=t&&be.isMemberExpression(o)&&!o.computed&&be.isIdentifier(o.object,{name:"Math"})&&be.isIdentifier(o.property)}}),t}function ea(e){return!be.isExpressionStatement(e)||!be.isAssignmentExpression(e.expression,{operator:"="})||!be.isIdentifier(e.expression.left)||!rn(e.expression.right)?null:e.expression.left.name}function Nr(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function on(e){if(be.isExpressionStatement(e)){let t=ea(e);return t===null?null:{bindings:new Set([t]),partial:new Set}}if(be.isBlockStatement(e)){let t=new Set,n=new Set;for(let o of e.body){let r=on(o);if(r===null)return null;for(let i of r.bindings){if(t.has(i))return null;t.add(i)}for(let i of r.partial)n.add(i)}return t.size===0?null:{bindings:t,partial:n}}if(be.isIfStatement(e)){if(!rn(e.test))return null;let t=on(e.consequent);if(t===null)return null;if(e.alternate==null)return{bindings:t.bindings,partial:new Set([...t.bindings,...t.partial])};let n=on(e.alternate);return n===null||!Nr(t.bindings,n.bindings)?null:{bindings:t.bindings,partial:new Set([...t.partial,...n.partial])}}return null}function ta(e){if(!rn(e.discriminant))return null;let t=null;for(let n of e.cases){if(n.test!=null&&!rn(n.test))return null;let o=[...n.consequent];if(o.at(-1)&&be.isBreakStatement(o.at(-1))&&o.pop(),o.some(i=>be.isBreakStatement(i)))return null;let r=on(be.blockStatement(o));if(r===null)return null;if(t===null)t=r;else{if(!Nr(t.bindings,r.bindings))return null;for(let i of r.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 na(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function Rr(e){for(let[t,n]of e.compPaths){let o=new Map;for(let s of e.componentProps.get(t)?.bindings??[]){let a=n.scope.getBinding(s);a&&o.set(a,s)}for(let s of e.instanceState.get(t)??[]){let a=n.scope.getBinding(s);a&&o.set(a,s)}for(let s of e.instanceDerivedBindings.get(t)??[]){let a=n.scope.getBinding(s);a&&o.set(a,s)}for(let s of e.state.keys()){let a=n.scope.getBinding(s);a?.scope.path.isProgram()&&o.set(a,s)}let r=[],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()?on(a.node):ta(a.node);if(l===null)continue;let d=!0,u=[],c=[];for(let f of l.bindings){let g=n.scope.getBinding(f),h=g?.path,C=h?.parentPath;if(g===void 0||!h?.isVariableDeclarator()||!C?.isVariableDeclaration()||C.node.kind!=="let"&&C.node.kind!=="var"||g.constantViolations.some(N=>!na(N,a.node))){d=!1;break}if(l.partial.has(f)){let N=h.get("init");if(!N.isExpression()||!rn(N.node)){d=!1;break}u.push({binding:f,source:N.node}),c.push(N)}}if(!d)continue;let m=new Set,E=f=>{let g=f.scope.getBinding(f.node.name),h=g===void 0?void 0:o.get(g);h!==void 0&&m.add(h)},b={Function(f){f.skip()},ReferencedIdentifier(f){f.isIdentifier()&&E(f)}};a.traverse(b);for(let f of c)f.isReferencedIdentifier()&&E(f),f.traverse(b);if(m.size!==0){for(let f of l.bindings)if(m.has(f))throw a.buildCodeFrameError(`memo-dom: reactive control-flow derivation '${f}' reads its own previous value`);r.push({statement:a.node,bindings:[...l.bindings].sort(),resets:u,sources:[...m].sort()});for(let f of l.bindings){i.add(f);let g=n.scope.getBinding(f);g&&o.set(g,f),e.instanceState.get(t)?.delete(f)}}}r.length>0&&(e.instanceControlFlow.set(t,r),e.instanceDerivedBindings.set(t,i))}}function Ir(e){for(let[t]of e.compPaths){let n=e.instanceDerivations.get(t)??[],o=e.instanceControlFlow.get(t)??[];if(n.length===0&&o.length===0)continue;let r=new Map;for(let u of n)for(let c of u.bindings)r.set(c,new Set(u.sources));for(let u of o)for(let c of u.bindings)r.set(c,new Set(u.sources));let i=(u,c=new Set)=>{let m=r.get(u);if(m===void 0)return new Set([u]);if(c.has(u))return new Set([u]);let E=new Set(c).add(u),b=new Set;for(let f of m)for(let g of i(f,E))b.add(g);return b};for(let u of n)u.sources=[...new Set(u.sources.flatMap(c=>[...i(c)]))].sort();for(let u of o)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,...o],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 sn from"@babel/types";function oa(e){let t=e.indexOf("[");return t<0?e:e.slice(0,t)}function kt(e,t){let n=new Set;for(let o of t){let r=o.split("/"),i=[[]];for(let s=0;s<r.length;s++){let a=r[s],l=i.map(d=>[...d,a]);if(s<r.length-1&&e.renderSlotOwners.has(oa(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 ot(e,t,n=new Set){let o=e.linkedComponentPaths.get(t);if(o!==void 0)return[...o];if(n.has(t))throw e.compPaths.get(t).buildCodeFrameError(`memo-dom: recursive component '${t}' \u2014 components cannot render themselves (L1)`);let r=e.listedSites.get(t);if(r!==void 0&&r.length>0){n.add(t);let d=r.flatMap(u=>ot(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 ot(e,d.owner,n))l.push(`${u}/${d.suffix}`);for(let d of a)for(let u of ot(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 ot(e,d,n))u>1?l.push(`${c}/${t}`,`${c}/${t}[*]`):l.push(`${c}/${t}`)}return n.delete(t),l}function lo(e,t){let n=e.linkedComponentPaths.get(t);if(n!==void 0)return kt(e,n.flatMap(i=>[i,`${i}/*`]));let o=e.listedSites.get(t),r=[];if(o&&o.length>0){if(Nt(e,t)){for(let i of o){let s=i.suffix.lastIndexOf("/"),a=s<0?"":`/${i.suffix.slice(0,s)}`;for(let l of ot(e,i.owner))r.push(`${l}${a}`,`${l}${a}/*`)}return kt(e,r)}for(let i of o)for(let s of ot(e,i.owner))r.push(`${s}/${i.suffix}/Row[*]`,`${s}/${i.suffix}/Row[*]/*`);return kt(e,r)}for(let i of ot(e,t))r.push(i,`${i}/*`);return kt(e,r)}function Nt(e,t){let n=e.importedComponents.get(t);if(n!==void 0)return n.listLightweight;let o=e.lightweightCache.get(t);if(o!==void 0)return o;let r=!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&&Jn(e,t)&&(r=!0),e.lightweightCache.set(t,r),r}function Jn(e,t){if((e.instanceState.get(t)?.size??0)>0)return!1;let n=!0,o=e.compPaths.get(t),r=i=>{(sn.isIdentifier(i.node.callee,{name:"cleanup"})&&i.scope.getBinding("cleanup")===void 0||sn.isIdentifier(i.node.callee,{name:"effect"})&&i.scope.getBinding("effect")===void 0)&&(n=!1),Ke(i.node)&&$e(i)&&(n=!1)};return o.traverse({JSXElement(i){let s=i.node.openingElement.name;sn.isJSXIdentifier(s)&&/^[A-Z]/.test(s.name)&&(n=!1)},CallExpression:r,OptionalCallExpression:r,ConditionalExpression(i){$e(i)&&(n=!1)},LogicalExpression(i){$e(i)&&(n=!1)}}),n}import*as Q from"@babel/types";function Fr(e,t){let n=e.findParent(o=>o.isFunctionDeclaration()||o.isFunctionExpression()||o.isArrowFunctionExpression());return n===t?!0:n?.findParent(o=>o===t)!==null}function co(e,t){let n=e;for(;n!==null;){let o=n.parentPath;if(o===null||o.isJSXAttribute()||o.isJSXSpreadAttribute())return!1;if(o.isJSXExpressionContainer()){if(o.parentPath?.isJSXAttribute()===!0){let r=o.parentPath.node,i=o.parentPath.parentPath;if(!i?.isJSXOpeningElement())return!1;let s=i.node.name;if(!Q.isJSXIdentifier(s)||!/^[A-Z]/.test(s.name))return!1;let a=Q.isJSXIdentifier(r.name)?r.name.name:r.name.name.name;return t.componentProps.get(s.name)?.renderProps.includes(a)===!0}return o.parentPath?.isJSXElement()===!0||o.parentPath?.isJSXFragment()===!0}if(o.isReturnStatement()&&o.node.argument===n.node||o.isArrowFunctionExpression()&&o.node.body===n.node||o.isVariableDeclarator()&&o.node.init===n.node)return!0;n=o}return!1}function ra(e,t){if(Q.isArrayExpression(e))return e;if(!Q.isIdentifier(e))return null;let n=t.scope.getBinding(e.name);return n?.path.isVariableDeclarator()&&Q.isArrayExpression(n.path.node.init)?n.path.node.init:null}function uo(e,t,n=new Set){if(n.has(e))throw t.buildCodeFrameError("memo-dom: cyclic JSX array spread");n.add(e);let o=[];try{for(let r of e.elements)if(!(r==null||Q.isNullLiteral(r)||Q.isBooleanLiteral(r))){if(Q.isSpreadElement(r)){if(!Q.isExpression(r.argument))throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");let i=ra(r.argument,t);if(i===null)throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");o.push(...uo(i,t,n));continue}if(Q.isArrayExpression(r)){o.push(...uo(r,t,n));continue}if(Q.isJSXElement(r)||Q.isJSXFragment(r)){o.push(Q.cloneNode(r,!0));continue}if(!Q.isExpression(r))throw t.buildCodeFrameError("memo-dom: JSX arrays require renderable expression entries");o.push(Q.jsxExpressionContainer(Q.cloneNode(r,!0)))}}finally{n.delete(e)}return o}function Mr(e,t){return Q.jsxFragment(Q.jsxOpeningFragment(),Q.jsxClosingFragment(),uo(e,t))}function ia(e,t){return Q.isArrayExpression(e)?e.elements.map((n,o)=>{if(n==null||Q.isSpreadElement(n))throw t.buildCodeFrameError("memo-dom: JSX arrays cannot contain holes or spread elements");return{key:Q.numericLiteral(o),value:n}}):e.properties.map(n=>{if(!Q.isObjectProperty(n)||n.computed||!Q.isExpression(n.value))throw t.buildCodeFrameError("memo-dom: JSX objects require static data properties without spreads");let o=Q.isIdentifier(n.key)?Q.stringLiteral(n.key.name):Q.isStringLiteral(n.key)||Q.isNumericLiteral(n.key)?Q.cloneNode(n.key):null;if(o===null)throw t.buildCodeFrameError("memo-dom: JSX objects require identifier, string, or numeric keys");return{key:o,value:n.value}})}function sa(e,t){let n=e.node,o=null;if(!n.computed&&Q.isIdentifier(n.property)?o=n.property.name:n.computed&&(Q.isStringLiteral(n.property)||Q.isNumericLiteral(n.property))&&(o=n.property.value),o!==null){let i=t.find(s=>(Q.isStringLiteral(s.key)||Q.isNumericLiteral(s.key))&&s.key.value===o);if(i===void 0)throw e.buildCodeFrameError(`memo-dom: JSX collection has no entry for '${o}'`);return Q.cloneNode(i.value,!0)}if(!n.computed||!Q.isExpression(n.property))throw e.buildCodeFrameError("memo-dom: JSX collection selection requires a static or expression key");let r=Q.nullLiteral();for(let i=t.length-1;i>=0;i--){let s=t[i];r=Q.conditionalExpression(Q.binaryExpression("===",Q.cloneNode(n.property,!0),Q.cloneNode(s.key,!0)),Q.cloneNode(s.value,!0),r)}return r}function Dr(e){for(let[,t]of e.compPaths){let n=!1;t.traverse({JSXExpressionContainer(r){if(!r.parentPath?.isJSXElement()&&!r.parentPath?.isJSXFragment())return;let i=r.get("expression");Array.isArray(i)||!i.isArrayExpression()||!fe(i.node)||(r.replaceWith(Mr(i.node,i)),n=!0)}});let o=!0;for(;o;){o=!1,t.scope.crawl();let r=t.get("body").get("body");for(let i of r)if(i.isVariableDeclaration({kind:"const"})){for(let s of i.get("declarations")){let a=s.node,l=a.init;if(!Q.isIdentifier(a.id)||l==null||!fe(l))continue;let d=s.scope.getBinding(a.id.name);if(d?.path!==s)continue;let u=[...d.referencePaths];if(Q.isObjectExpression(l)||Q.isArrayExpression(l))for(let c of u){if(!c.isIdentifier()||!Fr(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 m=c.parentPath;if(!co(m,e))throw m.buildCodeFrameError(`memo-dom: JSX collection '${a.id.name}' is used outside a render position`);m.replaceWith(sa(m,ia(l,s)));continue}if(Q.isArrayExpression(l)&&c.parentPath?.isSpreadElement()&&c.parentPath.parentPath?.isArrayExpression()){c.replaceWith(Q.cloneNode(l,!0));continue}if(Q.isArrayExpression(l)&&co(c,e)){c.replaceWith(Mr(l,c));continue}throw c.buildCodeFrameError(Q.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()||!Fr(c,t))){if(!co(c,e))throw c.buildCodeFrameError(`memo-dom: JSX value '${a.id.name}' is used outside a render position`);c.replaceWith(Q.cloneNode(l,!0))}i.node.declarations.length===1?i.remove():s.remove(),n=!0,o=!0;break}if(o)break}}n&&(t.traverse({JSXExpressionContainer(r){let i=r.node.expression;(r.parentPath?.isJSXElement()===!0||r.parentPath?.isJSXFragment()===!0)&&(Q.isJSXElement(i)||Q.isJSXFragment(i))&&r.replaceWith(i)}}),t.scope.crawl())}}import*as X from"@babel/types";function po(e){return X.isReturnStatement(e)&&X.isExpression(e.argument)?e.argument:X.isBlockStatement(e)&&e.body.length===1?po(e.body[0]):null}function Wt(e){let t=po(e);if(t!==null)return t;if(X.isIfStatement(e)&&e.alternate!=null){let n=Wt(e.consequent),o=Wt(e.alternate);return n===null||o===null?null:X.conditionalExpression(X.cloneNode(e.test,!0),X.cloneNode(n,!0),X.cloneNode(o,!0))}if(X.isSwitchStatement(e)){let n=e.cases.find(r=>r.test==null);if(n===void 0||n.consequent.length!==1)return null;let o=Wt(n.consequent[0]);if(o===null)return null;for(let r=e.cases.length-1;r>=0;r--){let i=e.cases[r];if(i.test==null)continue;if(i.consequent.length!==1)return null;let s=Wt(i.consequent[0]);if(s===null)return null;o=X.conditionalExpression(X.binaryExpression("===",X.cloneNode(e.discriminant,!0),X.cloneNode(i.test,!0)),X.cloneNode(s,!0),o)}return o}return null}function aa(e,t){if(X.isExpression(e.body))return{expression:X.cloneNode(e.body,!0),locals:new Map};let n=new Map,o=[];for(let s of e.body.body){if(X.isVariableDeclaration(s,{kind:"const"})){for(let a of s.declarations)(!X.isIdentifier(a.id)||a.init==null||!X.isExpression(a.init))&&t("memo-dom: JSX render functions require identifier const declarations with expression initializers"),n.set(a.id.name,X.cloneNode(a.init,!0));continue}X.isTypeScript(s)||X.isEmptyStatement(s)||o.push(s)}if(o.length===1){let s=Wt(o[0]);if(s!==null)return{expression:s,locals:n}}let r=o.at(-1),i=r===void 0?null:po(r);if(i!==null){let s=X.cloneNode(i,!0);for(let a=o.length-2;a>=0;a--){let l=o[a];if(X.isIfStatement(l)&&l.alternate==null){let d=Wt(l.consequent);if(d!==null){s=X.conditionalExpression(X.cloneNode(l.test,!0),X.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 la(e,t){return(X.isMemberExpression(e)||X.isOptionalMemberExpression(e))&&t==="property"&&!e.computed||(X.isObjectProperty(e)||X.isObjectMethod(e)||X.isClassMethod(e))&&t==="key"&&!e.computed||X.isVariableDeclarator(e)&&t==="id"||(X.isFunction(e)||X.isCatchClause(e))&&(t==="params"||t==="param"||t==="id")||X.isLabeledStatement(e)&&t==="label"}function Lr(e,t,n=new Set){let o=X.cloneNode(e,!0),r=(i,s,a,l)=>{if(X.isIdentifier(i)&&!l.has(i.name)&&t.has(i.name)&&(s===null||!la(s,a)))return X.cloneNode(t.get(i.name),!0);let d=l;if(X.isFunction(i)&&i!==o){let u=i.params.flatMap(c=>Object.keys(X.getBindingIdentifiers(c)));d=new Set([...l,...u])}for(let u of X.VISITOR_KEYS[i.type]??[]){let c=i[u];Array.isArray(c)?i[u]=c.map(m=>m!=null&&typeof m=="object"&&"type"in m?r(m,i,u,d):m):c!=null&&typeof c=="object"&&"type"in c&&(i[u]=r(c,i,u,d))}return X.isObjectProperty(i)&&i.shorthand&&!X.isIdentifier(i.value,{name:X.isIdentifier(i.key)?i.key.name:""})&&(i.shorthand=!1),i};return r(o,null,"",n)}function da(e,t){let n=a=>{throw t.buildCodeFrameError(a)},o=e.node;(o.async||o.generator)&&n("memo-dom: JSX render functions must be synchronous"),t.node.arguments.some(a=>X.isSpreadElement(a))&&n("memo-dom: JSX render function calls do not support spread arguments"),t.node.arguments.length>o.params.length&&n("memo-dom: JSX render function received more arguments than parameters");let r=new Map;for(let a=0;a<o.params.length;a++){let l=o.params[a],d=t.node.arguments[a],u=d!==void 0&&X.isExpression(d)?d:X.identifier("undefined");if(X.isIdentifier(l)){r.set(l.name,X.cloneNode(u,!0));continue}if(X.isAssignmentPattern(l)&&X.isIdentifier(l.left)){r.set(l.left.name,X.conditionalExpression(X.binaryExpression("===",X.cloneNode(u,!0),X.identifier("undefined")),X.cloneNode(l.right,!0),X.cloneNode(u,!0)));continue}n("memo-dom: JSX render functions currently require identifier parameters with optional defaults")}let i=aa(o,n);for(let[a,l]of i.locals)r.set(a,Lr(l,r));let s=Lr(i.expression,r);return fe(s)||n("memo-dom: JSX render function expansion did not produce JSX"),s}function ca(e,t){let n=t.get("callee");return Array.isArray(n)||!n.isIdentifier()?null:Ar(e,n)}function Ar(e,t){let n=t.node.name,o=e.jsxHelpers.get(n);if(o!==void 0)return{node:o.node,bindingPath:o};let r=t.scope.getBinding(n);if(r?.path.isFunctionDeclaration()&&fe(r.path.node))return{node:r.path.node,bindingPath:r.path};if(r?.path.isVariableDeclarator()){let i=r.path.node.init;if((X.isFunctionExpression(i)||X.isArrowFunctionExpression(i))&&fe(i.body))return{node:i,bindingPath:r.path}}return null}function jr(e){return X.isMemberExpression(e.callee)&&!e.callee.computed&&X.isIdentifier(e.callee.property,{name:"map"})}function ua(e){let t=e.parentPath;return t?.isCallExpression()===!0&&(t.node.callee===e.node||jr(t.node)&&t.node.arguments[0]===e.node)}function pa(e,t){let n=e.node;if(n.async||n.generator)throw t.buildCodeFrameError("memo-dom: JSX render callbacks must be synchronous");return X.arrowFunctionExpression(n.params.map(o=>X.cloneNode(o,!0)),X.cloneNode(n.body,!0))}function On(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()&&On(t)}}}function fa(e,t){let n=t.findParent(o=>o.isProgram());if(n===null||!n.isProgram()){On(t);return}for(let o of n.get("body")){let r=o.isExportNamedDeclaration()?o.get("declaration"):o;if(Array.isArray(r)||r==null)continue;if(r.isFunctionDeclaration()&&r.node.id?.name===e){o.remove();return}if(!r.isVariableDeclaration())continue;let i=r.get("declarations"),s=i.find(a=>a.isVariableDeclarator()&&X.isIdentifier(a.node.id,{name:e}));if(s!==void 0){i.length===1?o.remove():s.remove();return}}On(t)}function ma(e,t){let n=e.parentPath,o=n?.parentPath;if((X.isJSXElement(t)||X.isJSXFragment(t))&&n?.isJSXExpressionContainer()&&(o?.isJSXElement()||o?.isJSXFragment())&&o.node.children.includes(n.node)){n.replaceWith(t);return}e.replaceWith(t)}function Jr(e){let t=new Set;for(let[n,o]of e.jsxHelpers)if((o.scope.parent?.getBinding(n)??o.parentPath?.scope.getBinding(n))?.referencePaths.some(i=>i.isIdentifier()&&!ua(i)))throw o.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(r){if(!jr(r.node)||r.node.arguments.length!==1)return;let i=r.get("arguments")[0];if(i===void 0||Array.isArray(i)||!i.isIdentifier())return;let s=Ar(e,i);s!==null&&(i.replaceWith(pa(s,i)),t.add(s.bindingPath))}});let o=!0;for(;o;){o=!1,n.scope.crawl();let r=[];n.traverse({CallExpression(i){r.push(i)}});for(let i of r.reverse()){if(i.removed)continue;let s=ca(e,i);s!==null&&(ma(i,da(s,i)),t.add(s.bindingPath),o=!0)}}}for(let[n,o]of e.jsxHelpers)fa(n,o);for(let n of t)On(n)}import*as Ve from"@babel/types";function ga(e){let t=ht(e);return Ve.isIdentifier(t)||Ve.isMemberExpression(t)||Ve.isOptionalMemberExpression(t)||Pn(t)}function ba(e,t){let n=e,o=t.get("body");for(;n!==null&&n.parentPath!==o;)n=n.parentPath;return n?.isStatement()===!0?n:null}function Ea(e,t){return e.findParent(n=>n.isFunctionDeclaration()||n.isFunctionExpression()||n.isArrowFunctionExpression())===t}function Or(e){for(let[,t]of e.compPaths){let n=[],o=a=>{let l=a.node.callee;if(Ke(a.node)===null||!Ve.isMemberExpression(l)&&!Ve.isOptionalMemberExpression(l)||!Ve.isExpression(l.object)||ga(l.object)||!Ea(a,t))return;let d=ba(a,t);d!==null&&n.push({path:a,source:Ve.cloneNode(l.object,!0),statement:d})};if(t.traverse({CallExpression:o,OptionalCallExpression:o}),n.length===0)continue;let r=t.get("body").get("body"),i=new Map(r.map((a,l)=>[a.node,l]));n.sort((a,l)=>(i.get(a.statement.node)??0)-(i.get(l.statement.node)??0));let s=[];for(let a of n){let l=J(e,"listView");s.push(Ve.variableDeclarator(Ve.cloneNode(l),a.source));let d=a.path.get("callee");if(Array.isArray(d)||!d.isMemberExpression()&&!d.isOptionalMemberExpression())continue;let u=d.get("object");Array.isArray(u)||u.replaceWith(Ve.cloneNode(l))}n[0].statement.insertBefore(Ve.variableDeclaration("const",s)),t.scope.crawl()}}import*as He from"@babel/types";var ha=new Set(["==","==="]);function $n(e,t,n){if(n(e,t),!He.isFunction(e))for(let o of He.VISITOR_KEYS[e.type]??[]){let r=e[o];if(Array.isArray(r))for(let i of r)i&&$n(i,e,n);else r&&$n(r,e,n)}}function $r(e,t,n){if(!He.isBinaryExpression(t)||!ha.has(t.operator))return!1;let o=t.left===e?t.right:t.left;return He.isExpression(o)&&He.isNodesEquivalent(o,n)}function Xr(e,t){if(e.jsx===null||e.keyExpr===null||!e.sourceLocal||!He.isIdentifier(e.sourceExpr)||!t.has(e.sourceExpr.name))return[];let n=e.sourceExpr.name,o=new Set;if($n(e.jsx,null,(i,s)=>{He.isIdentifier(i)&&t.has(i.name)&&i.name!==n&&$r(i,s,e.keyExpr)&&o.add(i.name)}),o.size===0)return[];let r=new Set;return $n(e.jsx,null,(i,s)=>{He.isIdentifier(i)&&o.has(i.name)&&He.isReferenced(i,s)&&!$r(i,s,e.keyExpr)&&r.add(i.name)}),[...o].filter(i=>!r.has(i)).sort()}import*as I from"@babel/types";function ya(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 Xn(e,t){if(e.linkedDynamicComponentCandidates.size===0)return;t.scope.crawl();let n=new Set(Object.keys(t.scope.bindings)),o=new Map([...e.importedComponents].map(([i,s])=>[s.key,i])),r=[];for(let[i,s]of e.linkedDynamicComponentCandidates){let a=[];for(let d of s){let u=o.get(d.key);if(u===void 0){let c=`MDDynamic_${d.imported.replace(/[^A-Za-z0-9_$]/g,"_")}`;u=c;let m=1;for(;n.has(u);)u=`${c}${m++}`;n.add(u),o.set(d.key,u);let E={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,E),e.componentProps.set(u,ya(E)),r.push(I.importDeclaration(d.imported==="default"?[I.importDefaultSpecifier(I.identifier(u))]:[I.importSpecifier(I.identifier(u),I.isValidIdentifier(d.imported)?I.identifier(d.imported):I.stringLiteral(d.imported))],I.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 r.reverse())t.unshiftContainer("body",i);t.scope.crawl()}function fo(e){let t=e;for(;I.isTSAsExpression(t)||I.isTSTypeAssertion(t)||I.isTSNonNullExpression(t);)t=t.expression;return t}function Tr(e){return I.isJSXIdentifier(e)?I.identifier(e.name):I.memberExpression(Tr(e.object),I.identifier(e.property.name))}function Br(e,t){let n=Pe(t);if(n===null)return null;let[o,...r]=n.split(".");if(o===void 0||r.length===0)return null;let i=e.scope.getBinding(o);if(!i?.path.isVariableDeclarator())return null;let s=i.path.node.init;if(s==null)return null;for(let a of r){if(s=fo(s),!I.isObjectExpression(s))return null;let l=s.properties.find(d=>!I.isObjectProperty(d)||d.computed?!1:(I.isIdentifier(d.key)?d.key.name:I.isStringLiteral(d.key)?d.key.value:null)===a);if(l===void 0||!I.isObjectProperty(l)||!I.isExpression(l.value))return null;s=l.value}return s}function xa(e,t){let n=e.scope.getBinding(t);if(n===void 0)return[];let o=null;return n.path.isFunctionDeclaration()?o=n.path.node:n.path.isVariableDeclarator()&&(I.isFunctionExpression(n.path.node.init)||I.isArrowFunctionExpression(n.path.node.init))&&(o=n.path.node.init),o===null?[]:Vr(o)}function Vr(e){if(I.isExpression(e.body))return[e.body];let t=[],n=o=>{if(!I.isFunction(o)){if(I.isReturnStatement(o)){I.isExpression(o.argument)&&t.push(o.argument);return}for(let r of I.VISITOR_KEYS[o.type]??[]){let i=o[r];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 o of e.body.body)n(o);return t}function Rt(e,t,n,o=new Set){let r=fo(t);if(!o.has(r)){if(o.add(r),I.isIdentifier(r)&&(e.comps.has(r.name)||e.importedComponents.has(r.name))){n.add(r.name);return}if(I.isIdentifier(r)){for(let i of e.stateComponentCandidates.get(r.name)??e.functionComponentCandidates.get(r.name)??[])n.add(i);return}if(I.isConditionalExpression(r)){Rt(e,r.consequent,n,o),Rt(e,r.alternate,n,o);return}if(I.isLogicalExpression(r)){Rt(e,r.right,n,o);return}if(I.isObjectExpression(r)){for(let i of r.properties)I.isObjectProperty(i)&&I.isExpression(i.value)&&Rt(e,i.value,n,o);return}if(I.isArrayExpression(r)){for(let i of r.elements)i!=null&&!I.isSpreadElement(i)&&Rt(e,i,n,o);return}if(I.isCallExpression(r)&&I.isIdentifier(r.callee)){for(let i of e.functionComponentCandidates.get(r.callee.name)??[])n.add(i);return}if(I.isMemberExpression(r)){let i=Re(r);if(i!==null)for(let s of e.stateComponentCandidates.get(i)??[])n.add(s)}}}function Wr(e,t){for(let o of t.node.body){let r=I.isExportNamedDeclaration(o)?o.declaration:o;if(I.isVariableDeclaration(r))for(let i of r.declarations){if(!I.isIdentifier(i.id)||i.init==null)continue;let s=new Set;Rt(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[o,r]of e.helpers){let i=new Set(e.functionComponentCandidates.get(o)??[]),s=[],a=r.node;(I.isFunctionDeclaration(a)||I.isFunctionExpression(a)||I.isArrowFunctionExpression(a))&&(s=Vr(a));for(let l of s)Rt(e,l,i);i.size>0&&i.size!==(e.functionComponentCandidates.get(o)?.length??0)&&(e.functionComponentCandidates.set(o,[...i]),n=!0)}}}function rt(e,t,n,o,r=new Set){let i=fo(n);if(!r.has(i)){if(r.add(i),I.isConditionalExpression(i)){rt(e,t,i.consequent,o,r),rt(e,t,i.alternate,o,r);return}if(I.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`);o.push({compare:I.cloneNode(i),tag:I.jsxIdentifier(i.value)});return}if(I.isIdentifier(i)){if(e.comps.has(i.name)||e.importedComponents.has(i.name)){o.push({compare:I.cloneNode(i),tag:I.jsxIdentifier(i.name)});return}let s=e.stateTagCandidates.get(i.name);if(s!==void 0)for(let l of s)rt(e,t,I.stringLiteral(l),o,r);let a=t.scope.getBinding(i.name);a?.path.isVariableDeclarator()&&a.path.node.init!=null&&rt(e,t,a.path.node.init,o,r);return}if(I.isCallExpression(i)&&I.isIdentifier(i.callee)){for(let s of e.functionTagCandidates.get(i.callee.name)??[])rt(e,t,I.stringLiteral(s),o,r);for(let s of xa(t,i.callee.name))rt(e,t,s,o,r);for(let s of e.functionComponentCandidates.get(i.callee.name)??[])rt(e,t,I.identifier(s),o,r);return}if(I.isMemberExpression(i)){let s=Br(t,i);if(s!==null){rt(e,t,s,o,r);return}let a=Re(i);if(a===null)return;let l=t.scope.getBinding(a);if(l?.path.isVariableDeclarator()&&l.path.node.init!=null){let d=new Set;Rt(e,l.path.node.init,d);for(let u of d)rt(e,t,I.identifier(u),o,r)}for(let d of e.stateTagCandidates.get(a)??[])rt(e,t,I.stringLiteral(d),o,r);for(let d of e.stateComponentCandidates.get(a)??[])rt(e,t,I.identifier(d),o,r)}}}function Sa(e){return I.isStringLiteral(e.compare)?`string:${e.compare.value}`:I.isIdentifier(e.compare)?`component:${e.compare.name}`:JSON.stringify(e.compare)}function Ca(e,t){if(I.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(o=>o.isAssignmentExpression()&&o.node.operator==="="&&I.isExpression(o.node.right)?[o.node.right]:[])]:[]}if(I.isMemberExpression(t)){let n=Br(e,t),o=Pe(t),r=[];return o!==null&&(e.getFunctionParent()??e.findParent(a=>a.isProgram()))?.traverse({AssignmentExpression(a){a.node.operator==="="&&I.isMemberExpression(a.node.left)&&Pe(a.node.left)===o&&I.isExpression(a.node.right)&&r.push(a.node.right)}}),[...n===null?[]:[n],...r]}return[]}function zr(e,t){let n=I.cloneNode(e,!0);n.openingElement.name=I.cloneNode(t);let o=n.closingElement;return o!=null&&(o.name=I.cloneNode(t)),n}function wa(e,t,n){let o=I.nullLiteral();for(let r=n.length-1;r>=0;r--){let i=n[r];o=I.conditionalExpression(I.binaryExpression("===",I.cloneNode(e,!0),I.cloneNode(i.compare,!0)),zr(t,i.tag),o)}return o}function Pa(e){return I.isIdentifier(e)?e.name:I.isMemberExpression(e)?Pe(e)??"<member expression>":"<expression>"}function Kr(e){let t=new Map;for(let[,n]of e.compPaths){n.scope.crawl();let o=[];n.traverse({JSXElement(r){o.push(r)}});for(let r of o.reverse()){if(r.removed)continue;let i=r.node.openingElement.name;if(I.isJSXNamespacedName(i))throw r.buildCodeFrameError("memo-dom: namespaced JSX tags are not supported");if(I.isJSXIdentifier(i)&&(!/^[A-Z]/.test(i.name)||e.comps.has(i.name)||e.importedComponents.has(i.name)))continue;let s=Tr(i),a=Ca(r,s),l=[];for(let u of a)rt(e,r,u,l);let d=[...new Map(l.map(u=>[Sa(u),u])).values()];if(d.length===0)throw r.buildCodeFrameError(`memo-dom: dynamic JSX tag '${Pa(s)}' has no finite string or linked-component candidates`);for(let u of d){if(!I.isJSXIdentifier(u.tag))continue;let c=e.componentProps.get(u.tag.name);if(c===void 0||c.renderProps.length===0)continue;let m=t.get(u.tag.name);m===void 0&&(m=new Map,t.set(u.tag.name,m));for(let E of r.node.openingElement.attributes){if(I.isJSXSpreadAttribute(E)||!I.isJSXIdentifier(E.name)||!c.renderProps.includes(E.name.name))continue;let b=ze(E.value),f=m.get(E.name.name)??{scalar:!1,jsx:!1,at:r};b!==null&&fe(b)?f.jsx=!0:f.scalar=!0,m.set(E.name.name,f)}}if(d.length===1){r.replaceWith(zr(r.node,d[0].tag));continue}r.replaceWith(I.jsxFragment(I.jsxOpeningFragment(),I.jsxClosingFragment(),[I.jsxExpressionContainer(wa(s,r.node,d))]))}n.scope.crawl()}for(let[n,o]of t){let r=e.componentProps.get(n);for(let[i,s]of o){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&&(r.renderProps=r.renderProps.filter(a=>a!==i))}}}import*as se from"@babel/types";function mo(e){return se.isExportNamedDeclaration(e)?e.declaration??null:se.isDeclaration(e)?e:null}function Hr(e){let t=new Map;for(let n of e.body){let o=mo(n);se.isTSTypeAliasDeclaration(o)&&t.set(o.id.name,o.typeAnnotation)}return t}function xt(e,t,n=new Set){if(se.isTSLiteralType(e)&&se.isStringLiteral(e.literal))return[e.literal.value];if(se.isTSUnionType(e))return e.types.flatMap(o=>xt(o,t,n));if(se.isTSIntersectionType(e))return e.types.flatMap(o=>xt(o,t,n));if(se.isTSParenthesizedType(e))return xt(e.typeAnnotation,t,n);if(se.isTSTypeLiteral(e))return e.members.flatMap(o=>(se.isTSPropertySignature(o)||se.isTSIndexSignature(o))&&se.isTSTypeAnnotation(o.typeAnnotation)&&se.isTSType(o.typeAnnotation.typeAnnotation)?xt(o.typeAnnotation.typeAnnotation,t,n):[]);if(se.isTSMappedType(e)&&e.typeAnnotation!=null&&se.isTSType(e.typeAnnotation))return xt(e.typeAnnotation,t,n);if(se.isTSTypeReference(e)&&se.isIdentifier(e.typeName)){let o=e.typeName.name;if((o==="Record"||o==="Readonly"||o==="Partial")&&se.isTSTypeParameterInstantiation(e.typeArguments)){let s=o==="Record"?e.typeArguments.params[1]:e.typeArguments.params[0];if(s!==void 0&&se.isTSType(s))return xt(s,t,n)}if(n.has(o))return[];let r=t.get(o);if(r===void 0)return[];let i=new Set(n);return i.add(o),xt(r,t,i)}return[]}function Tn(e){let t=Hr(e),n=new Map;for(let o of e.body){let r=mo(o);if(se.isVariableDeclaration(r))for(let i of r.declarations){if(!se.isIdentifier(i.id)||!se.isTSTypeAnnotation(i.id.typeAnnotation))continue;let s=[...new Set(xt(i.id.typeAnnotation.typeAnnotation,t))];s.length>0&&n.set(i.id.name,s)}}return n}function go(e){let t=Hr(e),n=new Map,o=(r,i)=>{if(!se.isTSTypeAnnotation(i)||!se.isTSType(i.typeAnnotation))return;let s=[...new Set(xt(i.typeAnnotation,t))];s.length>0&&n.set(r,s)};for(let r of e.body){let i=mo(r);if(se.isFunctionDeclaration(i)&&i.id!=null){o(i.id.name,i.returnType);continue}if(se.isVariableDeclaration(i))for(let s of i.declarations)se.isIdentifier(s.id)&&(se.isArrowFunctionExpression(s.init)||se.isFunctionExpression(s.init))&&o(s.id.name,s.init.returnType)}return n}import*as mt from"@babel/types";import*as we from"@babel/types";function an(e,t){let n=[],o=[],r=-1;for(let s=0;s<e.length;s++)we.isJSXSpreadAttribute(e[s])&&(r=s);let i=[];for(let s=0;s<e.length;s++){let a=e[s];if(we.isJSXSpreadAttribute(a)){n.push(we.spreadElement(we.cloneNode(a.argument))),o.push(we.cloneNode(a.argument));continue}let l=De(a.name);if(l==="key"&&t.skipKey)continue;let d=va(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(we.objectProperty(we.isValidIdentifier(l)?we.identifier(l):we.stringLiteral(l),c,!1,we.isIdentifier(c)&&c.name===l)),o.push(we.cloneNode(d)),/^on[A-Z]/.test(l)&&s>r&&i.push(l)}return{expression:we.objectExpression(n),sources:o,safeEventKeys:i}}function De(e){return we.isJSXIdentifier(e)?e.name:`${e.namespace.name}:${e.name.name}`}function va(e,t){return e.value==null?we.booleanLiteral(!0):we.isStringLiteral(e.value)?we.cloneNode(e.value):we.isJSXExpressionContainer(e.value)&&we.isExpression(e.value.expression)?we.cloneNode(e.value.expression):t(`memo-dom: attribute '${De(e.name)}' must contain a JavaScript expression`)}function Bn(e,t,n=new Set){let o=e.importedComponents.get(t);if(o!==void 0)return new Set(o.subtreeReads??[]);if(n.has(t))return new Set;n.add(t);let r=new Set(e.compReads.get(t)??[]);for(let s of e.effects.get(t)??[]){for(let a of s.moduleReads)r.add(a);for(let a of s.conditionModuleReads)r.add(a)}let i=e.compPaths.get(t);return i!==void 0&&i.traverse({JSXElement(s){let a=s.node.openingElement.name;if(!(!mt.isJSXIdentifier(a)||!/^[A-Z]/.test(a.name)))for(let l of Bn(e,a.name,n))r.add(l)}}),n.delete(t),r}function Ur(e){for(let[t,n]of e.compPaths){let o=e.compReads.get(t);o!==void 0&&n.traverse({JSXAttribute(r){let i=r.parentPath;if(!i?.isJSXOpeningElement())return;let s=i.node.name;if(!mt.isJSXIdentifier(s))return;let a=De(r.node.name);if(e.componentProps.get(s.name)?.renderCallbacks.includes(a)!==!0)return;let l=r.node.value;!mt.isJSXExpressionContainer(l)||!mt.isExpression(l.expression)||Oe(l.expression,d=>{if(mt.isJSXOpeningElement(d)&&mt.isJSXIdentifier(d.name)&&/^[A-Z]/.test(d.name.name))for(let u of Bn(e,d.name.name))o.add(u)})}})}}import*as It from"@babel/types";function qr(e){for(let[t,n]of e.compPaths){let o=e.componentProps.get(t);n.traverse({JSXAttribute(r){if(De(r.node.name)!=="ref")return;let i=r.node.value;if(!(!It.isJSXExpressionContainer(i)||!It.isExpression(i.expression)))for(let s of _r(e,t,i.expression))o.refProps.includes(s)||o.refProps.push(s)}})}}function _r(e,t,n){let o=yt(e,t,n);if(o!==null)return[o];if(!It.isArrayExpression(n))return[];let r=[];for(let i of n.elements)i===null||It.isSpreadElement(i)||r.push(..._r(e,t,i));return r}import*as Jt from"@babel/types";function zt(e){let t=new Set;return Oe(e,n=>{if(!Jt.isJSXOpeningElement(n))return;let o=n.name;if(!(!Jt.isJSXIdentifier(o)||!/^[a-z]/.test(o.name)))for(let r of n.attributes)Jt.isJSXAttribute(r)&&Jt.isJSXIdentifier(r.name)&&/^on[A-Z]/.test(r.name.name)&&t.add(r.name.name)}),[...t].sort()}import*as Xe from"@babel/types";function ln(e){let t=(o,r)=>{let i=tt(e,o),s=e.readers.get(i);s||e.readers.set(i,s=new Set);for(let a of r)s.add(a)};for(let[o,r]of e.compReads){if(r.size===0)continue;let i=lo(e,o);for(let s of r)t(s,i)}for(let{owner:o,suffix:r,vars:i}of e.rowReads.values()){let s=kt(e,ot(e,o).flatMap(a=>[`${a}/${r}/Row[*]`,`${a}/${r}/Row[*]/*`]));for(let a of i)t(a,s)}for(let{owner:o,suffix:r,vars:i}of e.condReads.values()){let s=kt(e,ot(e,o).flatMap(a=>[`${a}/${r}`,`${a}/${r}/*`]));for(let a of i)t(a,s)}for(let[o,r]of e.effects){let i=lo(e,o).filter(s=>!s.endsWith("/*"));for(let s of r){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 o of e.moduleEffects){let r=o.condition===null?o.entityId:`${o.entityId}/$active`;for(let i of o.moduleReads)t(i,[r]);for(let i of o.conditionModuleReads)t(i,[o.entityId])}for(let[o,r]of e.computeds){let i=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#${o}`;for(let s of r.reads)t(s,[i])}for(let o of e.moduleControlFlow)for(let r of o.sources)t(r,[o.entityId]);if(e.readers.size===0)return null;let n=[...e.readers.entries()].sort(([o],[r])=>o<r?-1:1).map(([o,r])=>Xe.objectProperty(Xe.stringLiteral(o),Xe.arrayExpression([...r].sort().map(i=>Xe.stringLiteral(i)))));return Xe.expressionStatement(Xe.callExpression(ne(e,"installAccessTable"),[Xe.objectExpression([Xe.objectProperty(Xe.identifier("readers"),Xe.objectExpression(n))]),Xe.stringLiteral(e.rootId),Xe.stringLiteral(e.moduleId)]))}function Zr(e,t){let n=t?.parentPath;if(!n?.isJSXAttribute())return!1;let o=n.parentPath;if(!o.isJSXOpeningElement())return!1;let r=o.node.name;if(!P.isJSXIdentifier(r)||!/^[A-Z]/.test(r.name))return!1;let i=n.node.name,s=P.isJSXIdentifier(i)?i.name:i.name.name;return e.componentProps.get(r.name)?.renderProps.includes(s)===!0}function Gr(e,t){let n=t.parentPath,o=n?.parentPath;if(!n?.isJSXExpressionContainer()||!o?.isJSXElement()&&!o?.isJSXFragment()&&!Zr(e,n))throw t.buildCodeFrameError("memo-dom: conditional rendering must be a direct JSX child: <div>{cond ? <A/> : <B/>}</div>");t.skip()}function ka(e,t){for(let n of t.get("body"))if(!(!n.isImportDeclaration()||n.node.importKind==="type"))for(let o of n.node.specifiers){if(P.isImportSpecifier(o)&&o.importKind==="type")continue;let r=o.local.name;if(!(e.importedState.has(r)||e.importedFunctions.has(r)||e.importedComponents.has(r)))throw n.buildCodeFrameError(`memo-dom: value import '${r}' requires compileModules() so its reactive identity can be linked`)}}function Na(e,t){let n=Tn(t.node);for(let o of t.node.body){let r=P.isExportNamedDeclaration(o)?o.declaration:o;if(P.isVariableDeclaration(r)){for(let i of r.declarations)if(P.isIdentifier(i.id)&&(r.kind==="let"||r.kind==="var"?wt(e,i.id.name,"let"):r.kind==="const"&&(Dt(i.init)?wt(e,i.id.name,"store"):Lt(i.init)&&wt(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 Ra(e,t){let n=o=>{if(o===null||Array.isArray(o))return null;let r=o;for(;r.isTSAsExpression()||r.isTSTypeAssertion()||r.isTSNonNullExpression()||r.isTSSatisfiesExpression()||r.isTSInstantiationExpression();){let i=r.get("expression");if(Array.isArray(i))return null;r=i}return r.isArrowFunctionExpression()||r.isFunctionExpression()?r:null};t.traverse({FunctionDeclaration(o){let r=o.node.id?.name;if(r&&!e.comps.has(r)&&!e.helpers.has(r)&&!e.jsxHelpers.has(r))if($e(o))if(/^[A-Z]/.test(r)){e.comps.set(r,{parents:new Set,jsxCount:0}),e.compPaths.set(r,o);let i=zt(o.node.body);e.componentHostEvents.set(r,i),i.length!==0&&e.componentsWithHostEvents.add(r);try{e.componentProps.set(r,Cn(o.node.params))}catch(s){throw o.buildCodeFrameError(`memo-dom: invalid props for component '${r}': ${s instanceof Error?s.message:String(s)}`)}}else e.jsxHelpers.set(r,o);else e.helpers.set(r,o);o.skip()},VariableDeclarator(o){if(!o.scope.path.isProgram()||!P.isIdentifier(o.node.id))return;let r=n(o.get("init"));r!==null&&(fe(r.node.body)?/^[A-Z]/.test(o.node.id.name)||e.jsxHelpers.set(o.node.id.name,r):e.helpers.set(o.node.id.name,r),r.skip())}});for(let o of t.get("body")){let r=o.isExportNamedDeclaration()?o.get("declaration"):o;if(!(Array.isArray(r)||!r.isVariableDeclaration()))for(let i of r.get("declarations")){if(!i.isVariableDeclarator())continue;let s=i.node.id,a=n(i.get("init"));!P.isIdentifier(s)||/^[A-Z]/.test(s.name)||a===null||!fe(a.node.body)||(e.helpers.delete(s.name),e.jsxHelpers.set(s.name,a))}}}function Vn(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 Vn(e.typeAnnotation,t,n);if(P.isTSUnionType(e))return e.types.every(o=>Vn(o,t,n));if(P.isTSTypeReference(e)&&P.isIdentifier(e.typeName)){let o=e.typeName.name;if(n.has(o))return!1;let r=new Set(n);r.add(o);for(let i of t.body){let s=P.isExportNamedDeclaration(i)?i.declaration:i;if(P.isTSTypeAliasDeclaration(s)&&s.id.name===o)return Vn(s.typeAnnotation,t,r)}}return!1}function Ia(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 o=e.node.params[0];if(o==null||P.isTSParameterProperty(o))return!1;let r=P.isAssignmentPattern(o)?o.left:o;if(!P.isIdentifier(r)&&!P.isObjectPattern(r)&&!P.isArrayPattern(r))return!1;let i=r.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 Vn(l.typeAnnotation.typeAnnotation,s.node)}return!1}function bo(e,t=new Set){if(fe(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 o=n.path.get("init");return!Array.isArray(o)&&o.node!=null?bo(o,t):!1}}if(e.isMemberExpression()){let n=e.get("object");return!Array.isArray(n)&&bo(n,t)}return!1}function Fa(e){let t=new Map;for(let[r,i]of e.compPaths){let s=new Set;if(t.set(r,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=yt(e,r,l);d!==null&&(Ia(i,d)||s.add(d))}}),(i.parentPath?.isExportNamedDeclaration()||i.parentPath?.isExportDefaultDeclaration())&&!e.linkedComponentRenderProps.has(r)){let a=e.componentProps.get(r);for(let l of s)a.renderProps.includes(l)||a.renderProps.push(l)}}let n=new Map;for(let[r,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 m=c.node.name,E=P.isJSXIdentifier(m)?m.name:m.name.name;if(!d.has(E))continue;let b=u.get(E)??{scalar:!1,jsx:!1,at:c},f=c.get("value"),g=!1;if(f.isJSXExpressionContainer()&&P.isExpression(f.node.expression)){let h=f.get("expression");!Array.isArray(h)&&(bo(h)||P.isExpression(h.node)&&yt(e,r,h.node)!==null)&&(g=!0)}g?b.jsx=!0:b.scalar=!0,u.set(E,b)}}});for(let[r,i]of n){let s=e.componentProps.get(r);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 <${r}> 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 o=!0;for(;o;){o=!1;for(let[r,i]of e.compPaths){let s=e.componentProps.get(r);i.traverse({JSXAttribute(a){let l=a.get("value");if(!l.isJSXExpressionContainer()||!P.isExpression(l.node.expression))return;let d=yt(e,r,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 m=e.componentProps.get(c.name),E=a.node.name,b=P.isJSXIdentifier(E)?E.name:E.name.name;m?.renderProps.includes(b)===!0&&(s.renderProps.push(d),o=!0)}})}}for(let[r,i]of e.linkedComponentRenderProps){let s=e.componentProps.get(r);s!==void 0&&(s.renderProps=[...i])}}function Ma(e,t){let n=e.compPaths.get(t),o=e.comps.get(t),r=i=>{let s=Ke(i.node);if(s&&($e(i)||Tt(e,t,s)!==null)){let a=i.parentPath,l=a?.parentPath;if(!a?.isJSXExpressionContainer()||!l?.isJSXElement()&&!l?.isJSXFragment()&&!Zr(e,a))throw i.buildCodeFrameError("memo-dom: list rendering must be a direct JSX child: <ul>{items.map(item => <Row />)}</ul>");i.skip()}};n.traverse({JSXElement(i){let s=i.node.openingElement;if(!P.isJSXIdentifier(s.name))throw i.buildCodeFrameError("memo-dom: namespaced or member-expression JSX tags are not supported (L1)");for(let l of s.attributes)if(!P.isJSXSpreadAttribute(l)&&l.name.name==="key"){if(er(e,i))continue;throw i.buildCodeFrameError("memo-dom: key={...} is only meaningful on list rows: items.map(item => <Row key={item.id} />)")}let a=s.name.name;if(/^[A-Z]/.test(a)){let l=e.comps.has(a);if(!l&&!e.importedComponents.has(a))throw i.buildCodeFrameError(`memo-dom: <${a} /> is not a linked component factory`);l&&e.comps.get(a).parents.add(t);let d=e.childRefCounts.get(t);d||e.childRefCounts.set(t,d=new Map),d.set(a,(d.get(a)??0)+1),(i.node.children.some(u=>!P.isJSXText(u)||u.value.trim()!=="")||s.attributes.some(u=>{if(P.isJSXSpreadAttribute(u)||e.componentProps.get(a)?.renderProps.includes(P.isJSXIdentifier(u.name)?u.name.name:u.name.name.name)!==!0)return!1;let c=ze(u.value);return c!==null&&fe(c)}))&&e.renderSlotOwners.add(t);return}o.jsxCount++},ConditionalExpression(i){$e(i)&&Gr(e,i)},LogicalExpression(i){if($e(i)){if(i.node.operator!=="&&"&&i.node.operator!=="||")throw i.buildCodeFrameError("memo-dom: only && / || conditionals are supported (R8 L1), not ??");Gr(e,i)}},CallExpression:r,OptionalCallExpression:r})}function Da(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}function La(e,t){let n=Pe(t.node);if(!n||!n.includes("."))return null;let o=n.split(".")[0];if(e.state.get(o)!=="store"||t.scope.getBinding(o)?.scope.path.isProgram()!==!0)return null;let r=t.parentPath;return r.isAssignmentExpression({operator:"="})&&r.node.left===t.node||Da(t)?null:n}function Yr(e,t,n){let o=new Set([...e.instanceReasonIds.get(t)?.keys()??[],...n]);e.instanceReasonIds.set(t,new Map([...o].sort().map((r,i)=>[r,i])))}function Aa(e,t){let n=[],o=e;for(;o=ht(o),!!P.isMemberExpression(o);){if(n.unshift(o),P.isSuper(o.object))return null;o=o.object}if(!P.isIdentifier(o,{name:t}))return null;let r=n[0];if(r===void 0||!r.computed||!P.isExpression(r.property)||!(P.isIdentifier(r.property)||P.isNumericLiteral(r.property)||P.isStringLiteral(r.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 ja(e,t,n){let o=!1;return Oe(e.node.body,r=>{if(o)return;let i=P.isAssignmentExpression(r)&&P.isMemberExpression(r.left)?r.left:P.isUpdateExpression(r)&&P.isMemberExpression(r.argument)||P.isUnaryExpression(r,{operator:"delete"})&&P.isMemberExpression(r.argument)?r.argument:null;if(i===null)return;let s=Aa(i,t);s!==null&&!Xt(s,n)&&(o=!0)}),o}function Ja(e,t,n,o){if(!o.sourceLocal||!P.isIdentifier(o.sourceExpr))return;let r=o.sourceExpr.name;if(e.instanceState.get(t)?.has(r)!==!0)return;let i=it(o.keyExpr,o.itemParam);if(i===null||i.length===0)return;let s=e.compPaths.get(t);if(s===void 0||!ja(s,r,i))return;let a=`${t}\0${r}`;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(r);if(d!==void 0){e.keyedListMutations.delete(d.call),l.delete(r),e.disabledKeyedListMutationSources.add(a);return}let u={source:r,keyPath:i,keysVariable:J(e,`${r}ChangedKeys`).name,targetedReason:`${a}\0content`,topologyReason:`${a}\0topology`,structuralReason:`${a}\0structure`,call:n};l.set(r,u),e.keyedListMutations.set(n,u),e.targetedListComponents.add(t),Yr(e,t,[r,u.targetedReason,u.topologyReason,u.structuralReason])}function Oa(e){for(let[l]of e.comps){let E=function(v,$,_){let B=Ke(v.node);if(B===null||!$e(v))return;let R=At(e,B,v,l,_),k=`${$}/${R.suffix}`;if(R.form==="component"){let W=e.listedSites.get(R.rowComp)??[];W.some(T=>T.owner===l&&T.suffix===k)||W.push({owner:l,suffix:k,itemParam:R.itemParam,keyExpr:R.keyExpr,sourceKey:R.sourceKey,sourceLocal:R.sourceLocal}),e.listedSites.set(R.rowComp,W)}else h(v,R,k);v.skip()},b=function(v,$,_){let B=v.node.openingElement.name;if(!P.isJSXIdentifier(B)||!/^[A-Z]/.test(B.name))return;if(!e.comps.has(B.name)&&!e.importedComponents.has(B.name))throw v.buildCodeFrameError(`memo-dom: <${B.name} /> is not a linked component factory`);let R=_.get(B.name)??0;_.set(B.name,R+1);let k=R===0?B.name:`${B.name}[${R}]`,W=`${$}/${k}`,T=e.conditionalComponentSites.get(B.name)??[];T.some(ee=>ee.owner===l&&ee.suffix===W)||T.push({owner:l,suffix:W}),e.conditionalComponentSites.set(B.name,T)},f=function(v,$,_){let B=v.node.openingElement.name;if(!P.isJSXIdentifier(B)||!/^[A-Z]/.test(B.name))return;if(!e.comps.has(B.name)&&!e.importedComponents.has(B.name))throw v.buildCodeFrameError(`memo-dom: <${B.name} /> is not a linked component factory`);let R=_.get(B.name)??0;_.set(B.name,R+1);let k=R===0?B.name:`${B.name}[${R}]`,W=`${$}/Row[*]/${k}`,T=e.rowComponentSites.get(B.name)??[];T.some(ee=>ee.owner===l&&ee.suffix===W)||T.push({owner:l,suffix:W}),e.rowComponentSites.set(B.name,T)},g=function(v,$){let _=e.listedSites.get(v.rowComp)??[];_.some(B=>B.owner===l&&B.suffix===$)||_.push({owner:l,suffix:$,itemParam:v.itemParam,keyExpr:v.keyExpr,sourceKey:v.sourceKey,sourceLocal:v.sourceLocal}),e.listedSites.set(v.rowComp,_)},h=function(v,$,_){let B=v.get("arguments")[0];if(B===void 0)return;let R=new Set,k=new Map,W=new Map,T=ee=>{let oe=Ke(ee.node);if(oe!==null&&$e(ee)){let me=At(e,oe,ee,l,W,$),de=`${_}/Row[*]/${me.suffix}`;me.form==="component"?g(me,de):h(ee,me,de),ee.skip();return}let ue=ee.node.callee;if(P.isIdentifier(ue)&&(e.helpers.has(ue.name)||e.importedFunctions.has(ue.name))){let me=e.importedFunctions.get(ue.name)??Be(e,ue.name);for(let de of me.reads)R.add(de)}};B.traverse({Identifier(ee){ee.node.name!==$.itemParam&&e.state.has(ee.node.name)&&ee.scope.getBinding(ee.node.name)?.scope.path.isProgram()===!0&&R.add(ee.node.name)},JSXElement(ee){f(ee,_,k)},CallExpression:T,OptionalCallExpression:T}),R.size>0&&e.rowReads.set(`${l}/${_}`,{owner:l,suffix:_,vars:R})},C=function(v,$=null){let _=v.node;if(!$e(v))return;let B=kn(_,v,m),R=$===null?B.suffix:`${$}/${B.suffix}`,k=[];if(v.isConditionalExpression()){let T=v;for(;T.isConditionalExpression();)k.push(T.get("consequent")),T=T.get("alternate");k.push(T)}else k.push(v.get("right"));for(let T of k){let ee=new Map,oe=new Map;if((T.isConditionalExpression()||T.isLogicalExpression())&&$e(T)){C(T,R);continue}T.isJSXElement()&&b(T,R,oe),T.traverse({ConditionalExpression(ue){$e(ue)&&(C(ue,R),ue.skip())},LogicalExpression(ue){$e(ue)&&(C(ue,R),ue.skip())},JSXElement(ue){b(ue,R,oe)},CallExpression(ue){E(ue,R,ee)},OptionalCallExpression(ue){E(ue,R,ee)}})}let W=yn(e,_);W.size>0&&$===null&&e.condReads.set(`${l}/${R}`,{owner:l,suffix:R,vars:W}),v.skip()},N=function(v){if(P.isIdentifier(v.node.callee,{name:"effect"})&&v.scope.getBinding("effect")===void 0){v.skip();return}let $=Ke(v.node);if($&&($e(v)||Tt(e,l,$)!==null)){let B=At(e,$,v,l,c);Ja(e,l,$,B);let R=Xr(B,e.instanceState.get(l)??new Set);if(R.length>0&&P.isIdentifier(B.sourceExpr)){let k=B.sourceExpr.name;e.targetedListDependencies.set($,R.map(W=>({source:k,value:W}))),e.targetedListComponents.add(l),Yr(e,l,[k,...R])}if(B.sourceLocal||u.add(B.sourceKey),B.form==="component"){for(let W of B.jsx.openingElement.attributes){if(P.isJSXSpreadAttribute(W))continue;let T=W,ee=P.isJSXIdentifier(T.name)?T.name.name:`${T.name.namespace.name}:${T.name.name.name}`;if(ee==="key"||ee==="ref"||e.componentProps.get(B.rowComp)?.refProps.includes(ee)===!0)continue;let oe=ze(T.value);oe&&Oe(oe,ue=>{if(P.isIdentifier(ue)&&e.state.has(ue.name)&&v.scope.getBinding(ue.name)?.scope.path.isProgram()===!0&&u.add(ue.name),P.isMemberExpression(ue)){let me=Pe(ue);if(me!==null&&me.includes(".")){let de=me.split(".")[0];e.state.get(de)==="store"&&v.scope.getBinding(de)?.scope.path.isProgram()===!0&&u.add(me)}}})}let k=e.listedSites.get(B.rowComp)??[];k.some(W=>W.owner===l&&W.suffix===B.suffix)||k.push({owner:l,suffix:B.suffix,itemParam:B.itemParam,keyExpr:B.keyExpr,sourceKey:B.sourceKey,sourceLocal:B.sourceLocal}),e.listedSites.set(B.rowComp,k)}else h(v,B,B.suffix);v.skip();return}let _=v.node.callee;if(P.isIdentifier(_)&&(e.helpers.has(_.name)||e.importedFunctions.has(_.name))&&v.scope.getBinding(_.name)?.scope.path.isProgram()===!0){let B=e.importedFunctions.get(_.name)??Be(e,_.name);for(let R of B.reads)u.add(R)}};var t=E,n=b,o=f,r=g,i=h,s=C,a=N;let d=e.compPaths.get(l),u=new Set,c=new Map,m={count:0};d.traverse({JSXAttribute(v){let $=v.node.name;(P.isJSXIdentifier($,{name:"ref"})||P.isJSXNamespacedName($)&&$.namespace.name==="ref")&&v.skip()},ConditionalExpression(v){C(v)},LogicalExpression(v){C(v)},CallExpression:N,OptionalCallExpression:N,Identifier(v){if(!e.state.has(v.node.name)||v.scope.getBinding(v.node.name)?.scope.path.isProgram()!==!0)return;let $=v.parentPath;$.isAssignmentExpression({operator:"="})&&$.node.left===v.node||u.add(v.node.name)},MemberExpression(v){let $=La(e,v);$!==null&&u.add($)}}),e.compReads.set(l,u)}}function Wn(e,t){ka(e,t),Na(e,t),Ra(e,t),qr(e),tr(e),Jr(e),Wr(e,t),Fa(e),Dr(e),Kr(e),Or(e),wr(e),Sr(e,t),xr(e,t,ao),Pr(e),Rr(e),Ir(e),fr(e,t),kr(e);for(let[o]of e.comps)Ma(e,o);Oa(e),Ur(e);for(let[o]of e.comps)ot(e,o);let n=new Set([...e.listedSites.keys(),...e.linkedComponentRows.keys()]);for(let o of n){if(e.importedComponents.has(o))continue;let r=e.listedSites.get(o)??[],i=e.compPaths.get(o);if((r.length>0||e.linkedComponentRows.has(o))&&(e.comps.get(o).parents.size>0||(e.conditionalComponentSites.get(o)?.length??0)>0))throw i.buildCodeFrameError(`memo-dom: <${o}> is used both as a list row and as a static child \u2014 split it into two components (R7 L1)`)}}import*as A from"@babel/types";import*as S from"@babel/types";import*as Ie from"@babel/types";import*as ce from"@babel/types";function Ot(){return{writes:new Set,rootFallback:!1,rowLocal:!1,rowOwnerLocal:!1,instanceLocal:!1,instanceWrites:new Set,eventOrigin:null}}function Kt(e,t){e.instanceLocal=!0,e.instanceWrites.add(t)}function Ht(e,t,n,o){let r=t.rowLocal&&o!==void 0?ce.expressionStatement(o.refreshVar!==void 0?ce.callExpression(ce.identifier(o.refreshVar),[]):ce.callExpression(ne(e,"markDirty"),[ce.identifier(o.rowIdVar)])):null,i=null;if(t.instanceLocal&&n!==null){let d=e.instanceReasonIds.get(n),u=[...t.instanceWrites].map(m=>d?.get(m)).filter(m=>m!==void 0).sort((m,E)=>m-E),c=t.instanceWrites.size>0&&u.length===t.instanceWrites.size;i=ce.expressionStatement(ce.callExpression(ne(e,"markDirty"),[Te(e,n),...c?[u.length===1?ce.numericLiteral(u[0]):Ho(e,u)]:[]]))}let s=t.rowOwnerLocal&&o?.ownerIdVar!==void 0?ce.expressionStatement(ce.callExpression(ne(e,"markDirty"),[ce.identifier(o.ownerIdVar)])):null,a=d=>{let u=[];return t.eventOrigin!==null&&u.push(t.eventOrigin),r!==null&&u.push(r),s!==null&&u.push(s),i!==null&&u.push(i),d!==null&&u.push(d),u.length===0?null:u.length===1?u[0]:ce.blockStatement(u)};if(t.rootFallback)return ce.expressionStatement(ce.callExpression(ne(e,"markDirtySubtree"),[ce.stringLiteral(e.rootId)]));if(t.writes.size===0)return a(null);let l=[...t.writes].sort();return a(ce.expressionStatement(ce.callExpression(ne(e,"commitWrites"),[Qt(e,l)])))}function Qr(e,t,n){if(ce.isBlockStatement(t.body)){Eo(t.body,n),t.body.body.push(n);return}let o=J(e,"returnValue");t.body=ce.blockStatement([ce.variableDeclaration("const",[ce.variableDeclarator(o,t.body)]),n,ce.returnStatement(ce.cloneNode(o))])}function Eo(e,t){if(!ce.isFunction(e))for(let n of ce.VISITOR_KEYS[e.type]??[]){let o=e[n];if(Array.isArray(o))for(let r=0;r<o.length;r++){let i=o[r];!i||typeof i!="object"||!("type"in i)||ce.isFunction(i)||(ce.isReturnStatement(i)?(o.splice(r,0,ce.cloneNode(t)),r++):Eo(i,t))}else if(o&&typeof o=="object"&&"type"in o){if(ce.isFunction(o))continue;ce.isReturnStatement(o)?e[n]=ce.blockStatement([ce.cloneNode(t),o]):Eo(o,t)}}}import*as ke from"@babel/types";function Ft(e,t,n,o){if(o===void 0&&n?.refreshVar!==void 0)return ke.expressionStatement(ke.callExpression(ke.identifier(n.refreshVar),[]));let r=o??(n!==void 0?ke.identifier(n.rowIdVar):t!==null?Te(e,t):ke.stringLiteral(e.rootId));return ke.expressionStatement(ke.callExpression(ne(e,"markDirty"),[ke.cloneNode(r)]))}function Ut(e,t,n){let o=J(e,"event"),r=J(e,"returnValue");return ke.arrowFunctionExpression([o],ke.blockStatement([ke.variableDeclaration("const",[ke.variableDeclarator(r,ke.callExpression(ke.cloneNode(t),[ke.cloneNode(o)]))]),n,ke.returnStatement(ke.cloneNode(r))]))}import ni from"@babel/traverse";import*as M from"@babel/types";function $a(e,t,n){if(n.key===null)return null;let o=e.componentProps.get(t);if(o===void 0)return null;let r=qe(o);if(n.root===r){let[s,...a]=n.key.split(".").slice(1);return s===void 0?null:{name:s,path:a}}let i=Ye(o,n.root);return i===null?null:{name:i,path:n.key.split(".").slice(1)}}function ho(e,t,n,o,r){let i=$a(e,t,o);if(i===null)return!1;n===void 0?Kt(r,o.root):r.rowLocal=!0;let s=e.linkedComponentPropSources.get(t)?.get(i.name);if(s===void 0)return r.rootFallback=!0,!0;r.rootFallback||=s.rootFallback;let a=i.path.length===0?"":`.${i.path.join(".")}`;for(let l of s.keys)r.writes.add(`${l}${a}`);return!0}import*as Se from"@babel/types";function zn(e){return Se.isIdentifier(e)||Se.isObjectPattern(e)||Se.isArrayPattern(e)||Se.isAssignmentPattern(e)||Se.isRestElement(e)}function Xa(e){let t=e;for(;Se.isTSAsExpression(t)||Se.isTSTypeAssertion(t)||Se.isTSNonNullExpression(t)||Se.isTSSatisfiesExpression(t);)t=t.expression;return t}function dn(e,t,n){if(Se.isIdentifier(t)){e.set(t.name,n);return}if(Se.isAssignmentPattern(t)){zn(t.left)&&dn(e,t.left,n);return}if(!Se.isRestElement(t)){if(Se.isArrayPattern(t)){for(let o=0;o<t.elements.length;o++){let r=t.elements[o];zn(r)&&dn(e,r,vt(n,[String(o)]))}return}if(Se.isObjectPattern(t))for(let o of t.properties){if(Se.isRestElement(o))continue;if(o.computed||!Se.isIdentifier(o.key)&&!Se.isStringLiteral(o.key)&&!Se.isNumericLiteral(o.key)){zn(o.value)&&dn(e,o.value,{...n,key:null});continue}let r=Se.isIdentifier(o.key)?o.key.name:String(o.key.value);zn(o.value)&&dn(e,o.value,vt(n,[r]))}}}function ei(e,t,n,o){let r=Xa(o),i=e.componentProps.get(t);if(i===void 0)return null;if(Se.isIdentifier(r)){let d=n.get(r.name);return d!==void 0?d:qe(i)===r.name?{locality:"prop",root:r.name,key:r.name}:Ye(i,r.name)===null?null:{locality:"prop",root:r.name,key:r.name}}if(!Se.isMemberExpression(r))return null;let s=Re(r),a=Pe(r);if(s===null)return null;let l=ei(e,t,n,Se.identifier(s));return l===null?null:a===null?{...l,key:null}:vt(l,a.split(".").slice(1))}function ti(e,t){let n=new Map;for(let o of e.instanceDerivations.get(t)??[]){let r=ei(e,t,n,o.source);r!==null&&dn(n,o.target,r)}return n}var oi=ni.default??ni,Ta=new Set(["copyWithin","fill","pop","push","reverse","shift","sort","splice","unshift"]);function Ba(e,t){let n=[],o=e;for(;o=ht(o),!!M.isMemberExpression(o);){if(n.unshift(o),M.isSuper(o.object))return null;o=o.object}if(!M.isIdentifier(o,{name:t.source}))return null;let r=n[0];if(r===void 0||!r.computed||!M.isExpression(r.property)||!(M.isIdentifier(r.property)||M.isNumericLiteral(r.property)||M.isStringLiteral(r.property))||n.length<2)return null;let i=[];for(let a of n.slice(1))if(!a.computed&&M.isIdentifier(a.property))i.push(a.property.name);else if(a.computed&&M.isStringLiteral(a.property))i.push(a.property.value);else return null;if(Xt(i,t.keyPath))return null;let s=M.cloneNode(r,!0);for(let a of t.keyPath)s=M.memberExpression(s,M.identifier(a));return s}function Va(e,t){let n=new Set;for(let[o,r]of e.compReads)r.has(t)&&n.add(o);for(let o of e.rowReads.values())o.vars.has(t)&&n.add("__rows__");for(let o of e.condReads.values())o.vars.has(t)&&n.add("__regions__");return n}function ri(e,t,n){if(n.sourceLocal)return!0;let o=n.sourceKey;if(o==="")return!0;for(let i of e.computeds.values())if(i.reads.has(o))return!0;let r=new Set((e.listedSites.get(t??"")??[]).map(i=>i.owner));r.size===0&&t!==null&&r.add(t);for(let i of Va(e,o))if(i==="__rows__"||i==="__regions__"||!r.has(i))return!0;return!1}function Wa(e,t,n,o,r,i,s,a,l,d,u){if(e.handlerHasRootCommit.set(t,r.has(o)),l&&!r.has(o)){let m=Ot();m.eventOrigin=Ft(e,s,a,d),r.set(o,m)}let c=[];if(u)for(let m of i.values()){let E=Ht(e,m.writes,s,a);E!==null&&c.push({...m,commit:E})}for(let m of c)m.flag=J(e,"didWrite");c.sort((m,E)=>ii(E.path)-ii(m.path)).forEach(m=>{m.temporaries=za(e,m.path,m.flag)});for(let[m,E]of r){let b=u&&m===o?c.length===0?null:M.blockStatement(c.map(f=>M.ifStatement(M.cloneNode(f.flag),M.cloneNode(f.commit)))):Ht(e,E,s,a);b!==null&&Qr(e,m,b)}if(c.length>0){if(!M.isBlockStatement(n.body))throw new Error("memo-dom: execution-aware callback commit did not produce a block body");n.body.body.unshift(M.variableDeclaration("let",c.flatMap(m=>[M.variableDeclarator(M.cloneNode(m.flag),M.booleanLiteral(!1)),...(m.temporaries??[]).map(E=>M.variableDeclarator(M.cloneNode(E)))])))}t.body=n.body}function cn(e,t,n,o,r=!1,i,s=!1){let a=M.cloneNode(t),l=a,d=M.file(M.program([M.isFunctionDeclaration(a)?a:M.expressionStatement(a)])),u=n!==null?e.instanceState.get(n):void 0,c=n!==null?e.instanceDerivedBindings.get(n):void 0,m=n===null?new Map:ti(e,n),E=n!==null?new Set(e.componentProps.get(n)?.bindings??[]):new Set,b=new Set([...E,...u??[],...c??[]]);if(n!==null)for(let y of e.compPaths.get(n)?.node.body.body??[])if(M.isVariableDeclaration(y))for(let w of y.declarations)for(let L of Object.keys(M.getBindingIdentifiers(w.id)))b.add(L);else M.isFunctionDeclaration(y)&&y.id&&b.add(y.id.name);let f=new Bt((y,w)=>{if(w!==void 0)return null;let L=m.get(y);if(L!==void 0)return L;if(o!==void 0&&y===o.itemParam)return{locality:"row",root:y,key:y};if(u?.has(y)===!0)return{locality:"instance",root:y,key:y};if(E.has(y))return{locality:"prop",root:y,key:y};if(b.has(y))return null;let ie=e.state.get(y);return ie===void 0?null:Nn(y,ie)}),g=y=>y.stateKind==="computed"||e.state.get(y.root)==="computed",h=n===null?void 0:e.keyedListMutationSources.get(n),C=(y,w,L="structural")=>{Kt(y,w);let ie=h?.get(w);ie!==void 0&&Kt(y,L==="targeted"?ie.targetedReason:L==="topology"?ie.topologyReason:ie.structuralReason)},N=(y,w,L)=>{y.isExpression()&&(y.replaceWith(M.sequenceExpression([M.callExpression(M.memberExpression(M.identifier(w.keysVariable),M.identifier("add")),[L]),y.node])),y.skip())},v=new Set;for(let y of a.params)M.isIdentifier(y)&&v.add(y.name);oi(d,{VariableDeclarator(y){M.isIdentifier(y.node.id)&&(v.add(y.node.id.name),y.parentPath.isVariableDeclaration()&&f.trackDeclarator(y.scope,y.node))},Function(y){for(let w of y.node.params)M.isIdentifier(w)&&v.add(w.name)}});let $=new Map,_=new Map,B=y=>{let w=y.getFunctionParent()?.node??l,L=$.get(w);return L||$.set(w,L=Ot()),L},R=(y,w)=>{if(w(B(y)),!s||y.getFunctionParent()?.node!==l)return;let L=_.get(y.node);L===void 0&&(L={path:y,writes:Ot()},_.set(y.node,L)),w(L.writes)},k=y=>{R(y,w=>{o?.sourceLocal?w.rowOwnerLocal=!0:o!==void 0&&w.writes.add(o.sourceKey)})},W=y=>{if(o===void 0)return null;let w=y.split(".").slice(1);return o.itemPath.some((L,ie)=>w[ie]!==L)?null:w.slice(o.itemPath.length)},T=(y,w)=>{R(y,L=>{w!==void 0&&n!==null&&ho(e,n,o,w,L)||(L.rowLocal=!0,L.rootFallback=!0)})},ee=(y,w)=>{R(y,L=>{(n===null||!ho(e,n,o,w,L))&&(o===void 0?(n!==null&&Kt(L,w.root),L.rootFallback=!0):(L.rowLocal=!0,L.rootFallback=!0))})},oe=(y,w)=>{if(o===void 0||Re(w)!==o.itemParam)return!1;let L=Pe(w);if(L===null)return o.itemPath.length===0?k(y):T(y),!0;let ie=L.split(".").slice(1);return o.itemPath.some((Ae,Ne)=>ie[Ne]!==Ae)?!1:(ie.splice(0,o.itemPath.length),Xt(ie,o.keyPath)?k(y):(R(y,Ae=>{Ae.rowLocal=!0}),ri(e,n,o)&&k(y)),!0)},ue=(y,w)=>{if(w.locality==="instance"){R(y,L=>{C(L,w.root)});return}if(w.locality==="row"){if(o===void 0){R(y,ie=>{ie.rootFallback=!0});return}if(w.key===null){o.itemPath.length===0?k(y):T(y);return}let L=W(w.key);if(L===null){T(y,w);return}Xt(L,o.keyPath)?k(y):(R(y,ie=>{ie.rowLocal=!0}),ri(e,n,o)&&k(y));return}if(w.locality==="prop"){ee(y,w);return}if(w.stateKind==="computed")throw y.buildCodeFrameError(`memo-dom: cannot mutate computed '${w.root}' (R13) - it is derived; write its SOURCE state instead`);if(w.stateKind!=="store"){R(y,L=>{L.writes.add(w.root)});return}w.key!==null&&w.key.includes(".")?R(y,L=>{L.writes.add(w.key)}):R(y,L=>{L.writes.add(w.root)})},me=(y,w)=>{if(w.locality==="instance"){R(y,L=>{C(L,w.root)});return}if(w.locality==="row"){if(o===void 0){R(y,Ae=>{Ae.rootFallback=!0});return}if(w.key===null){o.itemPath.length===0?k(y):T(y);return}let L=W(w.key);if(L===null){T(y,w);return}L.length===0&&(o.keyPath===null||o.keyPath.length>0)?k(y):ue(y,w);return}if(w.locality==="prop"){ee(y,w);return}if(w.stateKind==="computed"){R(y,L=>{L.writes.add(w.root)});return}R(y,L=>{L.writes.add(w.key??w.root)})},de=(y,w)=>{if(!(s&&y.getFunctionParent()?.node===l))for(let L of In(w)){if(!M.isIdentifier(L))continue;let ie=f.resolveExpression(y.scope,L);ie!==null&&(g(ie)||me(y,ie))}},G=(y,w)=>{let L=Re(w);if(L!==void 0&&u?.has(L??"")===!0){let Ne=h?.get(L),We=Ne===void 0?null:Ba(w,Ne);R(y,bn=>{C(bn,L,We===null?"structural":"targeted")}),Ne!==void 0&&We!==null&&N(y,Ne,We);return}if(L!==null&&c?.has(L)&&!m.has(L))throw y.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${L}' (R14) \u2014 write its source instead`);if(oe(y,w))return;let ie=f.resolveExpression(y.scope,w);if(ie!==null){ue(y,ie);return}if(L!==null&&E.has(L)){ee(y,{locality:"prop",root:L,key:Pe(w)});return}if(L!==null&&b.has(L)||!L||!e.state.has(L))return;let Ae=e.state.get(L);if(Ae==="computed")throw y.buildCodeFrameError(`memo-dom: cannot mutate computed '${L}' (R13) \u2014 it is derived; write its SOURCE state instead`);R(y,Ne=>{if(Ae!=="store"){Ne.writes.add(L);return}let We=Pe(w);We!==null&&We.includes(".")?Ne.writes.add(We):Ne.writes.add(L)})};oi(d,{VariableDeclarator(y){if(!M.isIdentifier(y.node.id)&&y.node.init!==null)for(let w of f.referencedOrigins(y.scope,y.node.init))me(y,w)},AssignmentExpression(y){let w=y.node.left;if(M.isIdentifier(w)){if(v.has(w.name)){if(M.isIdentifier(y.node.right)){let ie=f.resolveExpression(y.scope,y.node.right);ie!==null&&me(y,ie)}return}if(c?.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot assign per-instance derivation '${w.name}' (R14) \u2014 write its source instead`);if(u?.has(w.name)===!0){R(y,ie=>{C(ie,w.name)});return}if(E.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot assign prop '${w.name}' \u2014 copy it to component-local let state first`);if(b.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot assign component-local const '${w.name}'`);let L=e.state.get(w.name);if(!L)throw y.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 y.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 y.buildCodeFrameError(`memo-dom: cannot reassign store '${w.name}' \u2014 assign a property (${w.name}.field = \u2026) instead`);if(L==="const")throw y.buildCodeFrameError(`memo-dom: cannot reassign mutable const root '${w.name}' - mutate the object instead`);if(L==="computed")throw y.buildCodeFrameError(`memo-dom: cannot assign computed '${w.name}' (R13) \u2014 it is derived; write its SOURCE state instead and the derivation recomputes`);R(y,ie=>{ie.writes.add(w.name)})}else if(M.isMemberExpression(w))G(y,w);else for(let L of f.referencedOrigins(y.scope,y.node.right))me(y,L)},UpdateExpression(y){let w=y.node.argument;if(M.isIdentifier(w)){if(v.has(w.name))return;if(c?.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot update per-instance derivation '${w.name}' (R14) \u2014 write its source instead`);if(u?.has(w.name)===!0){R(y,ie=>{C(ie,w.name)});return}if(E.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot update prop '${w.name}' \u2014 copy it to component-local let state first`);if(b.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot update component-local const '${w.name}'`);let L=e.state.get(w.name);if(!L)throw y.buildCodeFrameError(`memo-dom: handler updates '${w.name}', which is neither module state nor a handler local`);if(e.importedState.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot update imported state '${w.name}' - ES module imports are read-only; call an exported mutator instead`);if(L!=="let")throw y.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`);R(y,ie=>{ie.writes.add(w.name)})}else M.isMemberExpression(w)&&G(y,w)},UnaryExpression(y){y.node.operator==="delete"&&M.isMemberExpression(y.node.argument)&&G(y,y.node.argument)},CallExpression(y){let w=y.node.callee;if(M.isMemberExpression(w)){let L=Fn(w);if(L==="assign"&&M.isIdentifier(w.object,{name:"Object"})){let Ne=y.node.arguments[0],We=Ne!==void 0&&M.isExpression(Ne)?f.resolveExpression(y.scope,Ne):null;if(We!==null)if(We.locality==="module"&&We.stateKind==="store"){let bn=Rn(We,y.node.arguments.slice(1));bn===null?me(y,We):R(y,ys=>{for(let xs of bn)ys.writes.add(xs)})}else ue(y,We);return}if(L!==null&&Ta.has(L)&&M.isIdentifier(w.object)&&u?.has(w.object.name)===!0&&h?.has(w.object.name)===!0){let Ne=w.object.name;R(y,We=>{C(We,Ne,"topology")});return}let ie=M.isIdentifier(w.object)?w.object.name:M.isMemberExpression(w.object)?Re(w.object):null;if(ie!==null&&c?.has(ie)&&!m.has(ie)){R(y,Ne=>{C(Ne,ie)});return}let Ae=M.isExpression(w.object)?f.resolveExpression(y.scope,w.object):null;Ae!==null?me(y,Ae):de(y,y.node.arguments);return}if(M.isIdentifier(w)&&!b.has(w.name)&&(e.helpers.has(w.name)||e.importedFunctions.has(w.name))){let L=e.importedFunctions.get(w.name)??Be(e,w.name);R(y,ie=>{for(let Ne of L.writes)ie.writes.add(Ne);for(let Ne of L.boundedWrites)ie.writes.add(Ne);let Ae=s&&y.getFunctionParent()?.node===l;L.unbounded&&!Ae&&(ie.rootFallback=!0)});for(let ie of L.parameterWrites){let Ae=y.node.arguments[ie.index];if(Ae===void 0||!M.isExpression(Ae))continue;let Ne=f.resolveExpression(y.scope,Ae);if(Ne!==null){if(g(Ne))continue;me(y,vt(Ne,ie.path))}}return}de(y,y.node.arguments)}}),Wa(e,t,a,l,$,_,n,o,r,i,s)}function ii(e){let t=0,n=e;for(;n.parentPath!==null;)t++,n=n.parentPath;return t}function za(e,t,n){if(t.isAssignmentExpression({operator:"="})&&(M.isIdentifier(t.node.left)||M.isMemberExpression(t.node.left)&&!M.isSuper(t.node.left.object)&&!M.isPrivateName(t.node.left.property))){let r=t.node,i=J(e,"previousValue"),s=J(e,"assignedValue"),a=[i,s],l,d,u;if(M.isIdentifier(r.left))l=M.identifier(r.left.name),d=M.cloneNode(r,!0),u=M.identifier(r.left.name);else if(M.isMemberExpression(r.left)){let c=J(e,"assignmentReceiver"),m=J(e,"assignmentProperty");a.push(c,m);let E=()=>M.memberExpression(M.cloneNode(c),M.cloneNode(m),!0),b=r.left.computed?M.cloneNode(r.left.property,!0):M.stringLiteral(r.left.property.name);l=M.sequenceExpression([M.assignmentExpression("=",M.cloneNode(c),M.cloneNode(r.left.object,!0)),M.assignmentExpression("=",M.cloneNode(m),b),E()]),d=M.assignmentExpression("=",E(),M.cloneNode(r.right,!0)),u=E()}else return[];return t.replaceWith(M.sequenceExpression([M.assignmentExpression("=",M.cloneNode(i),l),M.assignmentExpression("=",M.cloneNode(s),d),M.assignmentExpression("=",M.cloneNode(n),M.logicalExpression("||",M.cloneNode(n),M.callExpression(ne(e,"effectAssignmentChanged"),[M.cloneNode(i),u]))),M.cloneNode(s)])),a}let o=M.assignmentExpression("=",M.cloneNode(n),M.booleanLiteral(!0));if(t.isVariableDeclarator()){let r=t.node.init;if(r===null||!M.isExpression(r))throw new Error("memo-dom: execution-aware variable site has no expression initializer");return t.node.init=M.sequenceExpression([o,r]),[]}if(!t.isExpression())throw new Error(`memo-dom: unsupported execution-aware write site '${t.node.type}'`);return t.replaceWith(M.sequenceExpression([o,t.node])),[]}import*as gt from"@babel/types";function si(e,t){let n=!1,o=!0,r=i=>{if(o&&!(i!==e&>.isFunction(i))){if((gt.isCallExpression(i)||gt.isOptionalCallExpression(i))&&(n=!0,!gt.isIdentifier(i.callee)||!t(i.callee.name))){o=!1;return}for(let s of gt.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&&r(l);else a!==null&&typeof a=="object"&&"type"in a&&r(a)}}};return r(e),n&&o}function St(e,t){let o=e.scope.getBinding(t)?.path;if(!o||o.getFunctionParent()!==e)return null;if(o.isFunctionDeclaration())return o.node;if(!o.isVariableDeclarator())return null;let r=o.node.init;return r&&(Ie.isArrowFunctionExpression(r)||Ie.isFunctionExpression(r))?r:null}function ct(e,t,n,o,r,i=!1){e.analyzedFunctions.has(n)||(yo(e,t,n,o,r),e.analyzedFunctions.add(n),cn(e,n,o,r,!1,void 0,i))}function un(e,t,n=!1){e.analyzedFunctions.has(t)||(e.analyzedFunctions.add(t),cn(e,t,null,void 0,!1,void 0,n))}function yo(e,t,n,o,r){let i=new Set;Oe(n.body,s=>{Ie.isCallExpression(s)&&Ie.isIdentifier(s.callee)&&i.add(s.callee.name)});for(let s of i){let a=St(t,s);a===null||e.analyzedFunctions.has(a)||(e.analyzedFunctions.add(a),yo(e,t,a,o,r),cn(e,a,o,r,!1))}}function xo(e,t,n,o,r,i,s){let a=null,l=!1,d=e.componentProps.get(r),u=d===void 0?null:qe(d);if(d!==void 0&&(Ie.isIdentifier(n)&&Ye(d,n.name)!==null||Ie.isMemberExpression(n)&&u!==null&&Re(n)===u))return Ut(e,n,Ft(e,r,i,s));if(Ie.isArrowFunctionExpression(n)||Ie.isFunctionExpression(n))a=n;else if(Ie.isIdentifier(n)){let m=e.importedFunctions.get(n.name);if(m!==void 0){let f=Ot();for(let g of m.writes)f.writes.add(g);for(let g of m.boundedWrites)f.writes.add(g);return f.rootFallback=m.unbounded,Ut(e,n,Ht(e,f,null)??Ft(e,r,i,s))}let E=t.scope.getBinding(n.name),b=E?.path;if(b&&b.isVariableDeclarator()){let f=b.node.init;f&&(Ie.isArrowFunctionExpression(f)||Ie.isFunctionExpression(f))&&(a=f,l=E?.scope.path.isProgram()===!0&&e.helpers.has(n.name))}else b&&b.isFunctionDeclaration()&&(e.helpers.has(n.name)?(a=b.node,l=!0):a=St(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 ${o} handler form \u2014 expected an arrow function or a function reference (L1)`);if(Ie.isBlockStatement(a.body)||(a.body=Ie.blockStatement([Ie.expressionStatement(a.body)])),!e.analyzedFunctions.has(a)){l||yo(e,t,a,r,i);let m=!l&&!Ie.isIdentifier(n)&&si(a,E=>{let b=St(t,E);return b!==null&&e.handlerHasRootCommit.get(b)===!0});e.analyzedFunctions.add(a),cn(e,a,l?null:r,l?void 0:i,!l&&!Ie.isIdentifier(n)&&!m,s)}if(l){let m=Be(e,n.name);if(a.async){let E=Ot();for(let b of m.writes)E.writes.add(b);for(let b of m.boundedWrites)E.writes.add(b);return E.rootFallback=m.unbounded,Ut(e,n,Ht(e,E,null)??Ft(e,r,i,s))}if(m.writes.size===0&&m.boundedWrites.size===0&&!m.unbounded)return Ut(e,n,Ft(e,r,i,s))}return Ie.isIdentifier(n)&&!l&&(e.handlerHasRootCommit.get(a)===!1||a.async)?Ut(e,n,Ft(e,r,i,s)):Ie.isIdentifier(n)?n:a}import*as Me from"@babel/types";function So(e,t){let n=[];for(let o of e){if(Me.isJSXText(o)){let a=ro(o.value);a!==""&&n.push({type:"node",variable:t.emitText(Me.stringLiteral(a))});continue}if(Me.isJSXElement(o)||Me.isJSXFragment(o)){n.push({type:"node",variable:t.emitNode(o)});continue}if(Me.isJSXExpressionContainer(o)||t.fail("memo-dom: spread children are not supported"),Me.isJSXEmptyExpression(o.expression))continue;Me.isExpression(o.expression)||t.fail("memo-dom: unsupported expression in JSX child position");let r=o.expression;if(t.isForwarded(r)){n.push({type:"slot",expression:Me.cloneNode(r)});continue}if(Me.isNullLiteral(r)||Me.isBooleanLiteral(r)||Me.isIdentifier(r,{name:"undefined"}))continue;let i=Ke(r);if(i!==null){n.push({type:"list",expression:i});continue}let s=vn(r);if(s!==null&&fe(s)){n.push({type:"condition",expression:s});continue}n.push({type:"node",variable:t.emitText(Me.cloneNode(r))})}return n}import*as q from"@babel/types";var Ka=new Set(["innerHTML","checked","value","selected","disabled","hidden","multiple","required","readOnly","muted","open","controls","loop","autoFocus","autoPlay","tabIndex"]),ai={htmlFor:"for",crossOrigin:"crossorigin"};function Co(e,t){return!t&&Ka.has(e)?e:null}function wo(e,t){return!t&&e in ai}function Po(e,t,n){let o=q.identifier(e);if(t==="tabIndex")return q.isStringLiteral(n)?q.expressionStatement(q.assignmentExpression("=",q.memberExpression(o,q.identifier(t)),q.cloneNode(n))):q.expressionStatement(q.conditionalExpression(q.binaryExpression("==",q.cloneNode(n),q.nullLiteral()),q.callExpression(q.memberExpression(q.cloneNode(o),q.identifier("removeAttribute")),[q.stringLiteral("tabindex")]),q.assignmentExpression("=",q.memberExpression(q.cloneNode(o),q.identifier(t)),q.cloneNode(n))));let r=t==="value"||t==="innerHTML"?q.stringLiteral(""):q.booleanLiteral(!1),i=q.isStringLiteral(n)?q.cloneNode(n):q.conditionalExpression(q.binaryExpression("==",q.cloneNode(n),q.nullLiteral()),r,q.cloneNode(n));return q.expressionStatement(q.assignmentExpression("=",q.memberExpression(o,q.identifier(t)),i))}function Kn(e,t,n){let o=q.identifier(e),r=ai[t]??t;return q.isStringLiteral(n)?q.expressionStatement(q.callExpression(q.memberExpression(o,q.identifier("setAttribute")),[q.stringLiteral(r),q.cloneNode(n)])):q.expressionStatement(q.conditionalExpression(q.logicalExpression("||",q.binaryExpression("==",q.cloneNode(n),q.nullLiteral()),q.binaryExpression("===",q.cloneNode(n),q.booleanLiteral(!1))),q.callExpression(q.memberExpression(q.cloneNode(o),q.identifier("removeAttribute")),[q.stringLiteral(r)]),q.callExpression(q.memberExpression(o,q.identifier("setAttribute")),[q.stringLiteral(r),q.conditionalExpression(q.binaryExpression("===",q.cloneNode(n),q.booleanLiteral(!0)),q.stringLiteral(""),q.callExpression(q.identifier("String"),[q.cloneNode(n)]))])))}import*as Ge from"@babel/types";var Ha="http://www.w3.org/2000/svg",Ua=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 li(e,t){return t||e==="svg"||Ua.has(e)}function di(e,t){return t?Ge.callExpression(Ge.memberExpression(Ge.identifier("document"),Ge.identifier("createElementNS")),[Ge.stringLiteral(Ha),Ge.stringLiteral(e)]):Ge.callExpression(Ge.memberExpression(Ge.identifier("document"),Ge.identifier("createElement")),[Ge.stringLiteral(e)])}import*as Ee from"@babel/types";function Hn(e,t,n){let o=e.componentProps.get(t);if(o?.mode==="object"){if(!o.acceptsUnknown){for(let s of n)if(!o.names.includes(s.name))throw new Error(`memo-dom: unknown prop '${s.name}' on <${t}> - declared props: ${o.names.length>0?o.names.join(", "):"(none)"}`)}return n.length===0&&o.hasWholeDefault?[Ee.identifier("undefined")]:[Ee.objectExpression(n.map(s=>Ee.objectProperty(Ee.identifier(s.name),s.value,!1,Ee.isIdentifier(s.value)&&s.value.name===s.name)))]}let r=o?.names;if(r===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(!r.includes(s))throw new Error(`memo-dom: unknown prop '${s}' on <${t}> - declared props: ${r.length>0?r.join(", "):"(none)"}`);return r.map(s=>i.get(s)??Ee.identifier("undefined"))}function qt(e,t,n){let o=e.componentProps.get(t);return o?.mode==="object"?[Ee.cloneNode(n)]:(o?.names??[]).map(r=>Ee.memberExpression(Ee.cloneNode(n),Ee.isValidIdentifier(r)?Ee.identifier(r):Ee.stringLiteral(r),!Ee.isValidIdentifier(r)))}function ci(e,t,n,o,r){let i=J(e,`${t}Props`);return Ee.blockStatement([Ee.variableDeclaration("const",[Ee.variableDeclarator(Ee.cloneNode(i),Ee.cloneNode(r))]),Ee.expressionStatement(Ee.callExpression(ne(e,"setProps"),[Ee.binaryExpression("+",Ee.cloneNode(n),Ee.stringLiteral(o)),Ee.arrayExpression(qt(e,t,i))]))])}import*as Le from"@babel/types";function _t(e){return(Le.isArrowFunctionExpression(e)||Le.isFunctionExpression(e))&&!qa(e.body)}function vo(e,t,n,o="callback"){let r=J(e,o);return t.creation.push(Le.variableDeclaration("const",[Le.variableDeclarator(Le.cloneNode(r),Le.cloneNode(n,!0))])),r}function ko(e,t,n,o="callback"){let r=J(e,o);return t.push(Le.variableDeclaration("const",[Le.variableDeclarator(Le.cloneNode(r),Le.cloneNode(n,!0))])),r}function qa(e){let t=!1;return Le.traverseFast(e,n=>{if(Le.isJSXElement(n)||Le.isJSXFragment(n))return t=!0,Le.traverseFast.stop}),t}import*as te from"@babel/types";function ui(e,t,n,o,r,i,s,a=!1,l=Te(e,r),d=!1){let u=kn(n,i,t.usedConds),c=J(e,u.suffix).name,m=te.binaryExpression("+",te.cloneNode(l),te.stringLiteral(`/${u.suffix}`)),E=te.arrowFunctionExpression([],te.cloneNode(u.pickExpr)),b=u.branches.map(f=>f!==null?pn(e,f,r,i,m,s,a,m,!1,t.usedConds):te.nullLiteral());t.creation.push(ft(e,te.cloneNode(m),te.cloneNode(l),te.arrowFunctionExpression([],te.callExpression(te.memberExpression(te.identifier(c),te.identifier("update")),[])))),t.creation.push(te.variableDeclaration("const",[te.variableDeclarator(te.identifier(c),te.callExpression(ne(e,"createCondRegion"),[te.identifier(o),te.cloneNode(m),E,te.arrayExpression(b)]))])),(d||e.volatileComponents.has(r)||qo(e,n,r))&&t.updaters.push(()=>te.expressionStatement(te.callExpression(te.memberExpression(te.identifier(c),te.identifier("update")),[]))),t.disposableRegions.push(c),t.disposableEntities.push(te.cloneNode(m))}function pn(e,t,n,o,r,i,s=!1,a=r,l=!1,d){let u=st(e,!0);d!==void 0&&(u.usedConds=d);let c=i(e,u,t,n,o,l?null:"cond",void 0,r,s,a),m=[te.objectProperty(te.identifier("nodes"),te.callExpression(ne(e,"rootNodes"),[te.identifier(c)])),te.objectProperty(te.identifier("update"),te.identifier(u.updateVar))];if(u.disposableRegions.length>0||u.disposableEntities.length>0||u.disposableCallbacks.length>0){let E=[...[...u.disposableCallbacks].reverse().map(b=>te.ifStatement(te.binaryExpression("!==",te.cloneNode(b),te.nullLiteral()),te.expressionStatement(te.callExpression(te.cloneNode(b),[])))),...u.disposableRegions.map(b=>te.expressionStatement(te.callExpression(te.memberExpression(te.identifier(b),te.identifier("dispose")),[]))),...u.disposableEntities.map(b=>te.expressionStatement(te.callExpression(ne(e,"unregisterSubtree"),[te.cloneNode(b)])))];m.push(te.objectProperty(te.identifier("dispose"),te.arrowFunctionExpression([],te.blockStatement(E))))}return te.arrowFunctionExpression([],te.blockStatement([at(u),lt(u),...u.creation,...u.mounts,te.returnStatement(te.objectExpression(m))]))}import*as p from"@babel/types";import*as H from"@babel/types";function Ct(e,t,n,o){return H.isArrayExpression(o)?H.arrayExpression(o.elements.map(r=>{if(r===null)return null;if(H.isSpreadElement(r))throw t.buildCodeFrameError("memo-dom: ref arrays must have a static shape; nested arrays are supported but array spreads are not");return Ct(e,t,n,r)})):_a(e,n,o)?H.cloneNode(o,!0):Ga(t,o)||H.isMemberExpression(o)?pi(e,o):H.cloneNode(o,!0)}function No(e,t,n,o,r){let i=J(e,"refDispose");t.mounts.push(H.variableDeclaration("const",[H.variableDeclarator(H.cloneNode(i),H.callExpression(ne(e,"mountRef"),[H.cloneNode(n,!0),H.cloneNode(r,!0)]))])),t.manualDisposal?t.disposableCallbacks.push(i):t.mounts.push(H.expressionStatement(H.callExpression(ne(e,"cleanup"),[H.cloneNode(o,!0),H.cloneNode(i)])))}function _a(e,t,n){let o=yt(e,t,n);return o!==null&&e.componentProps.get(t)?.refProps.includes(o)===!0}function Ga(e,t){if(!H.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 r=n.path.node.init;if(H.isFunctionExpression(r)||H.isArrowFunctionExpression(r))return!1}return n.kind!=="param"}function pi(e,t){let n=J(e,"refNode");if(H.isMemberExpression(t)){let o=J(e,"refTarget"),r=t.computed?J(e,"refKey"):null,i=()=>H.memberExpression(H.cloneNode(o),r===null?H.cloneNode(t.property,!0):H.cloneNode(r),t.computed);return H.arrowFunctionExpression([H.cloneNode(n)],H.blockStatement([H.variableDeclaration("const",[H.variableDeclarator(H.cloneNode(o),H.cloneNode(t.object,!0)),...r===null?[]:[H.variableDeclarator(H.cloneNode(r),H.cloneNode(t.property,!0))]]),H.expressionStatement(H.assignmentExpression("=",i(),H.cloneNode(n))),H.returnStatement(H.arrowFunctionExpression([],H.blockStatement([H.ifStatement(H.binaryExpression("===",i(),H.cloneNode(n)),H.expressionStatement(H.assignmentExpression("=",i(),H.identifier("undefined"))))])))]))}return H.arrowFunctionExpression([H.cloneNode(n)],H.blockStatement([H.expressionStatement(H.assignmentExpression("=",H.cloneNode(t,!0),H.cloneNode(n))),H.returnStatement(H.arrowFunctionExpression([],H.blockStatement([H.ifStatement(H.binaryExpression("===",H.cloneNode(t,!0),H.cloneNode(n)),H.expressionStatement(H.assignmentExpression("=",H.cloneNode(t,!0),H.identifier("undefined"))))])))]))}import*as V from"@babel/types";var Za=new Set(["setClassValue","setStyleValue","setDomValue"]);function Gt(e,t,n){if(t.mounts.length!==0||t.disposableRegions.length!==0||t.disposableEntities.length!==0||t.disposableCallbacks.length!==0)return!1;let o=[],r=new Set;for(let h of t.creation){if(!V.isVariableDeclaration(h))continue;let C=Qa(h);if(C===null)return!1;o.push(C),r.add(C.name)}if(!r.has(n)||o.length<2)return!1;let i=new Map,s=new Map;for(let h of t.creation){let C=fi(h);if(C===null)continue;if(!r.has(C.parent)||!r.has(C.child))return!1;let N=s.get(C.parent)??0;s.set(C.parent,N+1),i.set(C.child,{parent:C.parent,index:N})}let a=new Map;for(let h of r){let C=el(h,n,i);if(C===null)return!1;a.set(h,C)}let l=[],d=[];for(let h of t.creation)V.isVariableDeclaration(h)||nl(h,r)?l.push(V.cloneNode(h,!0)):d.push(h);let u=J(e,`${n}Template`);e.header.push(V.variableDeclaration("let",[V.variableDeclarator(V.cloneNode(u))]));let c=V.callExpression(V.arrowFunctionExpression([],V.blockStatement([...l,V.returnStatement(V.identifier(n))])),[]),m=V.conditionalExpression(V.binaryExpression("===",V.cloneNode(u),V.unaryExpression("void",V.numericLiteral(0))),V.assignmentExpression("=",V.cloneNode(u),c),V.cloneNode(u)),E=V.callExpression(V.memberExpression(m,V.identifier("cloneNode")),[V.booleanLiteral(!0)]),b=new Set([n]);for(let h of d)Oe(h,C=>{V.isIdentifier(C)&&r.has(C.name)&&b.add(C.name)});let f=[],g=o.filter(({name:h})=>b.has(h)).sort((h,C)=>a.get(h.name).length-a.get(C.name).length).map(({name:h})=>{let C=a.get(h),N;if(h===n)N=V.cloneNode(E,!0);else{let v=f[0];for(let $ of f)$.path.length>v.path.length&&Ya($.path,C)&&(v=$);N=tl(v.name,C.slice(v.path.length))}return f.push({name:h,path:C}),V.variableDeclaration("const",[V.variableDeclarator(V.identifier(h),N)])});return t.creation=[...g,...d],!0}function Ya(e,t){return e.length<=t.length&&e.every((n,o)=>t[o]===n)}function Qa(e){if(e.declarations.length!==1)return null;let t=e.declarations[0];if(!V.isIdentifier(t.id)||!V.isCallExpression(t.init)||!V.isMemberExpression(t.init.callee)||!V.isIdentifier(t.init.callee.object,{name:"document"})||!V.isIdentifier(t.init.callee.property))return null;let n=t.init.callee.property.name;if(n!=="createElement"&&n!=="createElementNS"&&n!=="createTextNode")return null;let o=t.init.arguments.at(-1);return(n==="createElement"||n==="createElementNS")&&V.isStringLiteral(o)&&o.value.includes("-")?null:{name:t.id.name,statement:e}}function fi(e){return!V.isExpressionStatement(e)||!V.isCallExpression(e.expression)||!V.isMemberExpression(e.expression.callee)||!V.isIdentifier(e.expression.callee.object)||!V.isIdentifier(e.expression.callee.property,{name:"appendChild"})||e.expression.arguments.length!==1||!V.isIdentifier(e.expression.arguments[0])?null:{parent:e.expression.callee.object.name,child:e.expression.arguments[0].name}}function el(e,t,n){if(e===t)return[];let o=[],r=new Set,i=e;for(;i!==t;){if(r.has(i))return null;r.add(i);let s=n.get(i);if(s===void 0)return null;o.push(s.index),i=s.parent}return o.reverse(),o}function tl(e,t){let n=V.identifier(e);for(let o of t){n=V.memberExpression(n,V.identifier("firstChild"));for(let r=0;r<o;r++)n=V.memberExpression(n,V.identifier("nextSibling"))}return n}function nl(e,t){let n=fi(e);if(n!==null)return t.has(n.parent)&&t.has(n.child);if(!V.isExpressionStatement(e))return!1;let o=e.expression;return!!(V.isCallExpression(o)&&V.isMemberExpression(o.callee)&&(V.isIdentifier(o.callee.object)&&t.has(o.callee.object.name)&&V.isIdentifier(o.callee.property,{name:"setAttribute"})&&o.arguments.every(r=>V.isExpression(r)&&Un(r))||V.isIdentifier(o.callee.object)&&V.isIdentifier(o.callee.property)&&Za.has(o.callee.property.name)&&o.arguments.length>=2&&V.isIdentifier(o.arguments[0])&&t.has(o.arguments[0].name)&&o.arguments.slice(1).every(r=>V.isExpression(r)&&Un(r))))}function Un(e){return V.isStringLiteral(e)||V.isNumericLiteral(e)||V.isBooleanLiteral(e)||V.isNullLiteral(e)?!0:V.isArrayExpression(e)?e.elements.every(t=>t===null||V.isExpression(t)&&Un(t)):V.isObjectExpression(e)?e.properties.every(t=>V.isObjectProperty(t)&&!t.computed&&V.isExpression(t.value)&&Un(t.value)):!1}function fn(e,t){let n=p.cloneNode(e);return t?p.logicalExpression("??",n,p.arrayExpression([])):n}function mi(e,t,n,o,r,i,s,a,l=!1,d=Te(e,r),u){let c=At(e,n,i,r,t.usedPrefixes,u===void 0?void 0:{itemParam:u.itemParam,sourceKey:u.sourceKey,sourceLocal:u.sourceLocal??!1}),m=J(e,`region${t.regionCounter++}`).name,E=new Map,b=c.form==="inline"?zt(c.jsx):c.form==="component"&&Nt(e,c.rowComp)?e.importedComponents.get(c.rowComp)?.delegatedEvents??e.componentHostEvents.get(c.rowComp)??[]:[];for(let $ of b){let _=J(e,`${$}Binding`);E.set($,_),t.creation.push(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(_),p.callExpression(ne(e,"createDelegatedEventBinding"),[p.identifier(o),p.stringLiteral($)]))]))}let f=c.form==="callback"?rl(e,c):c.form==="component"?sl(e,c,r,i,a,l,d,E):al(e,c,r,i,s,l,d,E),g=[p.identifier(o),p.binaryExpression("+",p.cloneNode(d),p.stringLiteral(`/${c.suffix}`)),f];if(c.form==="callback"){let $=p.memberExpression(p.cloneNode(c.renderCallback,!0),p.identifier("key"));g.push(p.arrowFunctionExpression([p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]],p.conditionalExpression(p.binaryExpression("==",p.cloneNode($),p.nullLiteral()),p.cloneNode(c.itemPattern,!0),p.callExpression(p.cloneNode($),[p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]]))))}else c.keyExpr!==null&&g.push(p.arrowFunctionExpression([p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]],p.cloneNode(c.keyExpr)));c.form==="component"&&Nt(e,c.rowComp)&&(g.length===3&&g.push(p.identifier("undefined")),g.push(p.booleanLiteral(!1))),t.creation.push(p.variableDeclaration("const",[p.variableDeclarator(p.identifier(m),p.callExpression(ne(e,"createListRegion"),g))])),t.disposableRegions.push(m);let h=e.targetedListDependencies.get(n)??[],C=e.keyedListMutations.get(n);C!==void 0&&t.creation.push(p.variableDeclaration("const",[p.variableDeclarator(p.identifier(C.keysVariable),p.newExpression(p.identifier("Set"),[]))]));let N=h.map($=>({dependency:$,cache:J(e,`${$.value}ListKey`).name}));N.length>0&&t.creation.push(p.variableDeclaration("let",N.map(({dependency:$,cache:_})=>p.variableDeclarator(p.identifier(_),p.identifier($.value)))));let v=()=>p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(m),p.identifier("reconcile")),[fn(c.sourceExpr,c.optional)]));t.creation.push(v()),N.length===0&&C===void 0||t.reasonVar===null?t.updaters.push(v):t.updaters.push(()=>ol(e,r,t.reasonVar,m,c.sourceExpr,c.optional,N,C,c.indexParam===null))}function ut(e,t){let n=()=>p.identifier(e),o=()=>p.valueToNode(t);return p.logicalExpression("||",p.binaryExpression("===",n(),o()),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")),[o()]))))}function Ro(e,t){return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(e),p.identifier("refreshKey")),[t]))}function ol(e,t,n,o,r,i,s,a,l){let d=e.instanceReasonIds.get(t);if(d===void 0)return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(o),p.identifier("reconcile")),[fn(r,i)]));let u=a?.source??s[0]?.dependency.source,c=u===void 0?void 0:d.get(u);if(c===void 0)return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(o),p.identifier("reconcile")),[fn(r,i)]));let m=[p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(o),p.identifier("reconcile")),[fn(r,i)])),...s.map(({dependency:h,cache:C})=>p.expressionStatement(p.assignmentExpression("=",p.identifier(C),p.identifier(h.value)))),...a===void 0?[]:[p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(a.keysVariable),p.identifier("clear")),[]))]],E=null;if(a!==void 0&&l){let h=d.get(a.topologyReason);if(h!==void 0){let C=ut(n,h);for(let N of[d.get(a.targetedReason),d.get(a.structuralReason),...s.map(({dependency:v})=>d.get(v.value))])N!==void 0&&(C=p.logicalExpression("&&",C,p.unaryExpression("!",ut(n,N))));E=p.ifStatement(C,p.blockStatement([p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(o),p.identifier("reconcile")),[fn(r,i),p.booleanLiteral(!1)]))]))}}let b=[];if(a!==void 0){let h=d.get(a.targetedReason);if(h!==void 0){let C=J(e,"changedListKey");b.push(p.ifStatement(ut(n,h),p.blockStatement([p.forOfStatement(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(C))]),p.identifier(a.keysVariable),p.blockStatement([Ro(o,p.cloneNode(C))])),p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(a.keysVariable),p.identifier("clear")),[]))])))}}for(let{dependency:h,cache:C}of s){let N=d.get(h.value);if(N===void 0)continue;let v=J(e,"previousListKey");b.push(p.ifStatement(ut(n,N),p.blockStatement([p.variableDeclaration("const",[p.variableDeclarator(v,p.identifier(C))]),p.expressionStatement(p.assignmentExpression("=",p.identifier(C),p.identifier(h.value))),Ro(o,p.cloneNode(v)),p.ifStatement(p.unaryExpression("!",p.callExpression(p.memberExpression(p.identifier("Object"),p.identifier("is")),[p.cloneNode(v),p.identifier(C)])),Ro(o,p.identifier(C)))])))}let f=p.binaryExpression("===",p.identifier(n),p.nullLiteral());if(f=p.logicalExpression("||",f,ut(n,-1)),a!==void 0){let h=d.get(a.structuralReason),C=d.get(a.topologyReason),N=d.get(a.targetedReason);h!==void 0&&(f=p.logicalExpression("||",f,ut(n,h))),C!==void 0&&(f=p.logicalExpression("||",f,ut(n,C))),f=p.logicalExpression("||",f,N===void 0?ut(n,c):p.logicalExpression("&&",ut(n,c),p.unaryExpression("!",ut(n,N))))}else f=p.logicalExpression("||",f,ut(n,c));let g=p.ifStatement(f,p.blockStatement(m),b.length===0?void 0:p.blockStatement(b));return E===null?g:(E.alternate=g,E)}function rl(e,t){let n=J(e,"renderRowId");return p.arrowFunctionExpression([p.cloneNode(t.itemPattern,!0),p.cloneNode(n),...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(n),...t.indexParam===null?[]:[p.identifier(t.indexParam)]]))}function il({ctx:e,site:t,rowComponent:n,rowId:o,nextItem:r,nextIndex:i,rowRefresh:s,rowScope:a,result:l,lightweight:d,needsUpdateProps:u,reuseLightweightEntry:c,lightweightPushProps:m,ownerId:E,eventBindings:b,prefixStatements:f,callProps:g,updateStatements:h}){let C=d?[p.objectProperty(p.identifier("nodes"),p.memberExpression(p.cloneNode(l),p.identifier("nodes"))),p.objectProperty(p.identifier("entities"),p.arrayExpression([])),p.objectProperty(p.identifier("update"),p.memberExpression(p.cloneNode(l),p.identifier("update"))),p.objectProperty(p.identifier("dispose"),p.memberExpression(p.cloneNode(l),p.identifier("dispose")))]:[p.objectProperty(p.identifier("nodes"),p.callExpression(ne(e,"rootNodes"),[p.cloneNode(l)])),p.objectProperty(p.identifier("entities"),p.arrayExpression([p.cloneNode(o)]))];return u&&!c&&C.push(p.objectProperty(p.identifier("updateProps"),p.arrowFunctionExpression([p.cloneNode(r),...i===null?[]:[p.cloneNode(i)]],p.blockStatement(h)))),p.arrowFunctionExpression([p.cloneNode(t.itemPattern,!0),p.cloneNode(o),...t.indexParam===null?[]:[p.identifier(t.indexParam)]],p.blockStatement([...a.updaters.length>0?[at(a),lt(a)]:[],...a.creation,...a.mounts,...f,p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(l),d?p.callExpression(p.identifier(n),[...g.map(N=>p.cloneNode(N)),p.cloneNode(o),...t.sourceLocal?[p.cloneNode(E)]:[],...[...b.values()].map(N=>p.cloneNode(N))]):p.callExpression(p.identifier(n),[p.cloneNode(o),p.cloneNode(E),...g.length>0?[p.arrayExpression(g)]:[]]))]),...a.updaters.length>0?[p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(s),p.arrowFunctionExpression([],p.blockStatement([p.expressionStatement(d?p.callExpression(p.memberExpression(p.cloneNode(l),p.identifier("update")),[]):p.callExpression(ne(e,"markDirty"),[p.cloneNode(o)])),p.expressionStatement(p.callExpression(p.identifier(a.updateVar),[]))])))])]:[],...m===null?[]:[p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(m),p.memberExpression(p.cloneNode(l),p.identifier("updateProps")))]),p.expressionStatement(p.assignmentExpression("=",p.memberExpression(p.cloneNode(l),p.identifier("updateProps")),p.arrowFunctionExpression([p.cloneNode(r),...i===null?[]:[p.cloneNode(i)]],p.blockStatement(h))))],p.returnStatement(c?p.cloneNode(l):p.objectExpression(C))]))}function sl(e,t,n,o,r,i=!1,s=Te(e,n),a=new Map){let l=t.rowComp,d=J(e,"rowId"),u=J(e,"nextItem"),c=t.indexParam===null?null:J(e,"nextIndex"),m=J(e,"refreshRow"),E=st(e),b=Nt(e,l),f={itemParam:t.itemParam,itemPath:[],rowIdVar:d.name,refreshVar:m.name,keyPath:it(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal&&p.isIdentifier(s)?{ownerIdVar:s.name}:{}},g=t.jsx.openingElement.attributes.filter(G=>p.isJSXSpreadAttribute(G)||De(G.name)!=="key"),h=g.some(G=>p.isJSXSpreadAttribute(G)),C=[],N=[],v=null,$=e.componentProps.get(l),_=b&&(e.linkedComponentRows.get(l)?.length??0)===0&&$!==void 0?Sn($):null,B=()=>{for(let{name:y}of C)if(!_.some(w=>w.name===y))throw o.buildCodeFrameError(`memo-dom: unknown prop '${y}' on <${l}> - declared props: ${_.map(w=>w.name).join(", ")}`);let G=new Map(C.map(({name:y,value:w})=>[y,w]));return _.map(({name:y})=>p.cloneNode(G.get(y)??p.identifier("undefined")))},R=G=>_.map(({name:y})=>p.memberExpression(p.cloneNode(G),p.isValidIdentifier(y)?p.identifier(y):p.stringLiteral(y),!p.isValidIdentifier(y))),k=G=>{let y=p.isJSXElement(G)||p.isJSXFragment(G)?[G]:[p.jsxExpressionContainer(G)];return r(e,E,y,n,o,"row",f,d,i,d)};if(h){v=an(g,{attributeValue:(G,y)=>G==="ref"||$?.refProps.includes(G)===!0?Ct(e,o,n,y):y,fail:G=>{throw o.buildCodeFrameError(G)}}).expression;for(let G of v.properties){if(!p.isObjectProperty(G)||G.computed||!p.isExpression(G.value))continue;let y=p.isIdentifier(G.key)?G.key.name:p.isStringLiteral(G.key)?G.key.value:null;if(y!==null)if($?.renderProps.includes(y)===!0){if(dt(e,n,G.value))continue;if(!fe(G.value))throw o.buildCodeFrameError(`memo-dom: render prop '${y}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);G.value=k(G.value)}else{if(fe(G.value))throw o.buildCodeFrameError(`memo-dom: JSX prop '${y}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);y!=="ref"&&$?.refProps.includes(y)!==!0&&_t(G.value)&&(ct(e,o,G.value,n,f,!0),G.value=ko(e,N,G.value,`${y}Callback`))}}}else for(let G of g){let y=G,w=De(y.name),L=y.value==null?p.booleanLiteral(!0):ze(y.value);if(L===null)throw o.buildCodeFrameError(`memo-dom: prop '${De(y.name)}' on <${l}> must be an expression`);if($?.renderProps.includes(w)===!0){if(dt(e,n,L)){C.push({name:w,value:p.cloneNode(L)});continue}if(!fe(L))throw o.buildCodeFrameError(`memo-dom: render prop '${w}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);C.push({name:w,value:k(L)});continue}if(w==="ref"||$?.refProps.includes(w)===!0){C.push({name:w,value:Ct(e,o,n,L)});continue}if(fe(L))throw o.buildCodeFrameError(`memo-dom: JSX prop '${w}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);let ie=_t(L);if(ie)ct(e,o,L,n,f,!0);else if(p.isIdentifier(L)){let Ae=St(o,L.name);Ae!==null&&!fe(Ae.body)&&ct(e,o,Ae,n,f,!0)}C.push({name:w,value:ie?ko(e,N,L,`${w}Callback`):p.cloneNode(L)})}if(nn(t.jsx.children)){if(g.some(y=>p.isJSXAttribute(y)&&De(y.name)==="children"))throw o.buildCodeFrameError(`memo-dom: <${l}> cannot use both a children prop and nested JSX children`);let G=r(e,E,t.jsx.children,n,o,"row",f,d,i,d);v!==null?v.properties.push(p.objectProperty(p.identifier("children"),p.cloneNode(G))):C.push({name:"children",value:p.cloneNode(G)})}let W;if(v!==null){let G=J(e,`${l}Props`);N.push(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(G),p.cloneNode(v))])),W=_===null?qt(e,l,G):R(G)}else W=_===null?Hn(e,l,C):B();let T=[p.expressionStatement(p.assignmentExpression("=",p.cloneNode(t.itemPattern,!0),p.cloneNode(u)))];c!==null&&t.indexParam!==null&&T.push(p.expressionStatement(p.assignmentExpression("=",p.identifier(t.indexParam),p.cloneNode(c))));let ee=W.map(G=>p.cloneNode(G));if(v!==null){let G=J(e,`next${l}Props`);T.push(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(G),p.cloneNode(v))])),ee=_===null?qt(e,l,G):R(G)}let oe=J(e,b?"entry":"rowElement"),ue=W.length>0||E.updaters.length>0,me=b&&ue,de=me?J(e,"pushRowProps"):null;return b?T.push(p.expressionStatement(p.callExpression(de===null?p.memberExpression(p.cloneNode(oe),p.identifier("updateProps")):p.cloneNode(de),ee))):T.push(p.expressionStatement(p.callExpression(ne(e,"setProps"),[p.cloneNode(d),p.arrayExpression(ee)])),p.expressionStatement(p.callExpression(ne(e,"markDirty"),[p.cloneNode(d)]))),E.updaters.length>0&&T.push(p.expressionStatement(p.callExpression(p.identifier(E.updateVar),[]))),il({ctx:e,site:t,rowComponent:l,rowId:d,nextItem:u,nextIndex:c,rowRefresh:m,rowScope:E,result:oe,lightweight:b,needsUpdateProps:ue,reuseLightweightEntry:me,lightweightPushProps:de,ownerId:s,eventBindings:a,prefixStatements:N,callProps:W,updateStatements:T})}function al(e,t,n,o,r,i=!1,s=Te(e,n),a=new Map){t.jsx.openingElement.attributes=t.jsx.openingElement.attributes.filter(f=>p.isJSXSpreadAttribute(f)||f.name.name!=="key");let l=st(e);for(let[f,g]of a)l.delegatedEventBindings.set(f,g.name);let d=J(e,"rowId").name,u=J(e,"nextItem"),c=t.indexParam===null?null:J(e,"nextIndex"),m={itemParam:t.itemParam,itemPath:[],rowIdVar:d,keyPath:it(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal?{ownerIdVar:p.isIdentifier(s)?s.name:Te(e,n).name}:{}},E=r(e,l,t.jsx,n,o,"row",m,p.identifier(d),i,p.identifier(d));Gt(e,l,E);let b=[p.expressionStatement(p.assignmentExpression("=",p.cloneNode(t.itemPattern,!0),p.cloneNode(u)))];return c!==null&&t.indexParam!==null&&b.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([at(l),lt(l),ft(e,p.identifier(d),p.cloneNode(s),p.identifier(l.updateVar)),...l.creation,...l.mounts,p.returnStatement(p.objectExpression([p.objectProperty(p.identifier("nodes"),p.arrayExpression([p.identifier(E)])),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(b))),p.objectProperty(p.identifier("update"),p.identifier(l.updateVar))]))]))}import*as F from"@babel/types";function ll(e){return F.isJSXElement(e.body)?e.body:F.isBlockStatement(e.body)&&e.body.body.length===1&&F.isReturnStatement(e.body.body[0])&&F.isJSXElement(e.body.body[0].argument)?e.body.body[0].argument:null}function Io(e,t,n,o,r,i,s,a){if(!F.isArrowFunctionExpression(n)&&!F.isFunctionExpression(n)||n.async||n.generator)throw r.buildCodeFrameError("memo-dom: render callbacks must be synchronous inline arrows or function expressions");let l=ll(n),d=n.params[0],u=n.params[1];if(l===null||n.params.length<1||n.params.length>2||!F.isIdentifier(d)&&!F.isObjectPattern(d)&&!F.isArrayPattern(d)||u!==void 0&&!F.isIdentifier(u))throw r.buildCodeFrameError("memo-dom: render callbacks take an item binding pattern and optional index, then return one JSX element");let c=xn(d),m=Object.keys(F.getBindingIdentifiers(c));if(m.length===0)throw r.buildCodeFrameError("memo-dom: render callback item patterns must bind at least one name");let E=F.isIdentifier(c)?c.name:m[0],b=u===void 0?null:u.name,f=null;l.openingElement.attributes=l.openingElement.attributes.filter(oe=>{if(F.isJSXSpreadAttribute(oe)||!F.isJSXIdentifier(oe.name)||oe.name.name!=="key")return!0;if(f=ze(oe.value),f===null)throw r.buildCodeFrameError("memo-dom: key={...} needs an expression");return!1});let g=J(e,"renderCallback"),h=J(e,"renderRows"),C=J(e,"renderNextUpdate"),N=J(e,"renderRowId"),v=J(e,"refreshRenderRow"),$=J(e,"renderNextItem"),_=b===null?null:J(e,"renderNextIndex"),B=st(e),R={itemParam:E,itemPath:[],rowIdVar:N.name,keyPath:it(f,E),sourceKey:"$render-callback",sourceLocal:!0,...F.isIdentifier(a)?{ownerIdVar:a.name}:{}},k=i(e,B,l,o,r,"row",R,N,s,N);Gt(e,B,k),t.creation.push(F.variableDeclaration("const",[F.variableDeclarator(F.cloneNode(h),F.newExpression(F.identifier("Set"),[]))])),t.updaters.push(()=>F.forOfStatement(F.variableDeclaration("const",[F.variableDeclarator(F.cloneNode(C))]),F.cloneNode(h),F.expressionStatement(F.callExpression(F.cloneNode(C),[]))));let W=[F.expressionStatement(F.assignmentExpression("=",F.cloneNode(c,!0),F.cloneNode($)))];_!==null&&b!==null&&W.push(F.expressionStatement(F.assignmentExpression("=",F.identifier(b),F.cloneNode(_))));let T=F.arrowFunctionExpression([F.cloneNode(c,!0),F.cloneNode(N),...b===null?[]:[F.identifier(b)]],F.blockStatement([at(B),lt(B),F.variableDeclaration("const",[F.variableDeclarator(F.cloneNode(v),F.arrowFunctionExpression([],F.blockStatement([F.expressionStatement(F.callExpression(F.identifier(B.updateVar),[])),F.expressionStatement(F.callExpression(ne(e,"renderDescendants"),[F.cloneNode(N)]))])))]),ft(e,F.cloneNode(N),F.cloneNode(a,!0),F.cloneNode(v)),...B.creation,...B.mounts,F.expressionStatement(F.callExpression(F.memberExpression(F.cloneNode(h),F.identifier("add")),[F.cloneNode(v)])),F.returnStatement(F.objectExpression([F.objectProperty(F.identifier("nodes"),F.callExpression(ne(e,"rootNodes"),[F.identifier(k)])),F.objectProperty(F.identifier("entities"),F.arrayExpression([F.cloneNode(N)])),F.objectProperty(F.identifier("updateProps"),F.arrowFunctionExpression([F.cloneNode($),..._===null?[]:[F.cloneNode(_)]],F.blockStatement(W))),F.objectProperty(F.identifier("update"),F.cloneNode(v)),F.objectProperty(F.identifier("dispose"),F.arrowFunctionExpression([],F.callExpression(F.memberExpression(F.cloneNode(h),F.identifier("delete")),[F.cloneNode(v)])))]))])),ee=f===null?F.nullLiteral():F.arrowFunctionExpression([F.cloneNode(c,!0),...b===null?[]:[F.identifier(b)]],F.cloneNode(f));return t.creation.push(F.variableDeclaration("const",[F.variableDeclarator(F.cloneNode(g),F.objectExpression([F.objectProperty(F.identifier("create"),T),F.objectProperty(F.identifier("key"),ee)]))])),g}import*as K from"@babel/types";function gi(e,t,n,o,r,i,s,a,l){let d=J(e,"routeFragment"),u=J(e,"routeRegion"),c=J(e,"routeUnsubscribe"),m=J(e,"routeDispose"),E=J(e,"currentRoute"),b=J(e,"routeMatch"),f=t.regionCounter++,g=K.binaryExpression("+",K.cloneNode(l),K.stringLiteral(`/route${f}`));e.routeElements.delete(n);let h;try{h=pn(e,n,r,i,g,s,a,g,!0,t.usedConds)}finally{e.routeElements.set(n,o)}let C=K.arrowFunctionExpression([K.cloneNode(E)],K.callExpression(K.memberExpression(K.memberExpression(K.cloneNode(E),K.identifier("matches")),K.identifier("some")),[K.arrowFunctionExpression([K.cloneNode(b)],K.binaryExpression("===",K.memberExpression(K.cloneNode(b),K.identifier("id")),K.stringLiteral(o.id)))])),N=K.arrowFunctionExpression([],K.callExpression(K.memberExpression(K.cloneNode(u),K.identifier("update")),[]));return t.creation.push(K.variableDeclaration("const",[K.variableDeclarator(K.cloneNode(d),K.callExpression(K.memberExpression(K.identifier("document"),K.identifier("createDocumentFragment")),[]))]),ft(e,K.cloneNode(g),K.cloneNode(l),K.cloneNode(N)),K.variableDeclaration("const",[K.variableDeclarator(K.cloneNode(u),K.callExpression(ne(e,"createCondRegion"),[K.cloneNode(d),K.cloneNode(g),K.arrowFunctionExpression([],K.conditionalExpression(K.callExpression(C,[bt(e,"route")]),K.numericLiteral(0),K.numericLiteral(1))),K.arrayExpression([h,K.nullLiteral()])]))]),K.variableDeclaration("const",[K.variableDeclarator(K.cloneNode(c),K.callExpression(bt(e,"subscribeRouteSelected"),[K.cloneNode(C),K.cloneNode(N)]))]),K.variableDeclaration("const",[K.variableDeclarator(K.cloneNode(m),K.arrowFunctionExpression([],K.blockStatement([K.expressionStatement(K.callExpression(K.cloneNode(c),[])),K.expressionStatement(K.callExpression(K.memberExpression(K.cloneNode(u),K.identifier("dispose")),[]))])))])),t.manualDisposal?(t.disposableCallbacks.push(m),t.disposableEntities.push(K.cloneNode(g))):t.creation.push(K.expressionStatement(K.callExpression(ne(e,"cleanup"),[K.cloneNode(l),K.cloneNode(m)]))),d.name}function dl(e){return S.conditionalExpression(S.logicalExpression("||",S.binaryExpression("==",S.cloneNode(e),S.nullLiteral()),S.binaryExpression("===",S.unaryExpression("typeof",S.cloneNode(e),!0),S.stringLiteral("boolean"))),S.stringLiteral(""),S.callExpression(S.identifier("String"),[S.cloneNode(e)]))}function cl(e,t,n,o){return()=>jt(e,t,S.cloneNode(o),r=>S.expressionStatement(S.assignmentExpression("=",S.memberExpression(S.identifier(n),S.identifier("data")),dl(r))))}function Fo(e,t,n){let o=J(e,`text${t.textCounter++}`).name;if(S.isStringLiteral(n))return t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.identifier(o),S.callExpression(S.memberExpression(S.identifier("document"),S.identifier("createTextNode")),[S.stringLiteral(n.value)]))])),o;let r=no(e,t);t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.identifier(o),S.callExpression(S.memberExpression(S.identifier("document"),S.identifier("createTextNode")),[S.stringLiteral("")]))]));let i=cl(t,r,o,n);return t.creation.push(i()),t.updaters.push(i),o}function bi(e,t){let n=!1;return S.traverseFast(e,o=>{S.isIdentifier(o,{name:t})&&(n=!0)}),n}function pt(e,t,n,o,r,i=null,s,a,l=!1,d=Te(e,o)){return S.isJSXFragment(n)?ul(e,t,n,o,r,i,s,a,l,d):pl(e,t,n,o,r,i,s,a,l,d)}function ul(e,t,n,o,r,i,s,a,l=!1,d=Te(e,o)){let u=So(n.children,{emitText:m=>Fo(e,t,m),emitNode:m=>pt(e,t,m,o,r,i,s,a,l,d),isForwarded:m=>dt(e,o,m),fail:m=>{throw r.buildCodeFrameError(m)}}),c=oo(e,t,"fragment");return t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.identifier(c),S.callExpression(S.memberExpression(S.identifier("document"),S.identifier("createDocumentFragment")),[]))])),hi(e,t,u,c,o,r,i,s,l,d),c}function hi(e,t,n,o,r,i,s=null,a,l=!1,d=Te(e,r)){for(let u of n)u.type==="node"?t.creation.push(S.expressionStatement(S.callExpression(S.memberExpression(S.identifier(o),S.identifier("appendChild")),[S.identifier(u.variable)]))):u.type==="slot"?io(e,t,u.expression,o,d):u.type==="list"?yi(e,t,u.expression,o,r,i,l,d,a):xi(e,t,u.expression,o,r,i,l,d,s!==null)}function Mo(e,t,n,o,r,i,s,a,l,d){return or(e,t,d,(u,c,m)=>{rr(u,n,c.name,{emitText:E=>Fo(e,u,E),emitNode:E=>pt(e,u,E,o,r,i,s,a,l,m),emitList:(E,b)=>yi(e,u,E,b,o,r,l,m,s),emitCondition:(E,b)=>xi(e,u,E,b,o,r,l,m,i!==null),isForwarded:E=>dt(e,o,E),emitForwarded:(E,b)=>io(e,u,E,b,m),fail:E=>{throw r.buildCodeFrameError(E)}})})}function Ei(e,t,n,o,r,i,s,a,l,d){let u=S.isJSXElement(n)||S.isJSXFragment(n)?[n]:[S.jsxExpressionContainer(n)];return Mo(e,t,u,o,r,i,s,a,l,d)}function pl(e,t,n,o,r,i=null,s,a,l=!1,d=Te(e,o)){let u=e.routeElements.get(n);if(u!==void 0)return gi(e,t,n,u,o,r,pt,l,d);let c=n.openingElement,m=c.name.name;if(/^[A-Z]/.test(m)){let N=t.childCounts.get(m)??0;t.childCounts.set(m,N+1);let v=m.charAt(0).toLowerCase()+m.slice(1),$=N===0?v:`${v}${N}`,_=J(e,$).name,B=N===0?`/${m}`:`/${m}[${N}]`,R=[],k=e.componentProps.get(m);if(nn(n.children)&&c.attributes.some(me=>S.isJSXAttribute(me)&&De(me.name)==="children"))throw r.buildCodeFrameError(`memo-dom: <${m}> cannot use both a children prop and nested JSX children`);let W=c.attributes.some(me=>S.isJSXSpreadAttribute(me)),T=null,ee=!1;if(W){T=an(c.attributes,{attributeValue:(de,G)=>de==="ref"||k?.refProps.includes(de)===!0?Ct(e,r,o,G):G,fail:de=>{throw r.buildCodeFrameError(de)}}).expression;for(let de of T.properties){if(!S.isObjectProperty(de)||de.computed||!S.isExpression(de.value))continue;let G=S.isIdentifier(de.key)?de.key.name:S.isStringLiteral(de.key)?de.key.value:null;if(G!==null)if(k?.renderCallbacks.includes(G)===!0)de.value=Io(e,t,de.value,o,r,pt,l,d);else if(k?.renderProps.includes(G)===!0){if(dt(e,o,de.value))continue;if(!fe(de.value))throw r.buildCodeFrameError(`memo-dom: render prop '${G}' on <${m}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);de.value=Ei(e,t,de.value,o,r,i,s,a,l,d)}else{if(fe(de.value))throw r.buildCodeFrameError(`memo-dom: JSX prop '${G}' on <${m}> is not rendered by the callee; interpolate that prop in <${m}> to declare a render slot`);G!=="ref"&&k?.refProps.includes(G)!==!0&&_t(de.value)&&(ct(e,r,de.value,o,s,!0),de.value=vo(e,t,de.value,`${G}Callback`))}}ee=eo(e,T,o)||s!==void 0&&bi(T,s.itemParam)}else for(let me of c.attributes){let de=me,G=De(de.name),y=de.value==null?S.booleanLiteral(!0):ze(de.value);if(y==null)throw r.buildCodeFrameError(`memo-dom: prop '${De(de.name)}' on <${m}> must be an expression`);if(k?.renderCallbacks.includes(G)===!0){R.push({name:G,value:Io(e,t,y,o,r,pt,l,d)});continue}if(G==="ref"||k?.refProps.includes(G)===!0){R.push({name:G,value:Ct(e,r,o,y)});continue}if(k?.renderProps.includes(G)===!0){if(dt(e,o,y)){R.push({name:G,value:S.cloneNode(y)});continue}if(!fe(y))throw r.buildCodeFrameError(`memo-dom: render prop '${G}' on <${m}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);R.push({name:G,value:Ei(e,t,y,o,r,i,s,a,l,d)});continue}if(fe(y))throw r.buildCodeFrameError(`memo-dom: JSX prop '${G}' on <${m}> is not rendered by the callee; interpolate that prop in <${m}> to declare a render slot`);let w=_t(y);if(!w&&(eo(e,y,o)||s!==void 0&&bi(y,s.itemParam))&&(ee=!0),w)ct(e,r,y,o,s,!0);else if(S.isIdentifier(y)){let L=St(r,y.name);L!==null&&!fe(L.body)&&ct(e,r,L,o,s,!0)}R.push({name:G,value:w?vo(e,t,y,`${G}Callback`):S.cloneNode(y)})}if(nn(n.children)){if(c.attributes.some(de=>S.isJSXAttribute(de)&&De(de.name)==="children"))throw r.buildCodeFrameError(`memo-dom: <${m}> cannot use both a children prop and nested JSX children`);let me=Mo(e,t,n.children,o,r,i,s,a,l,d);T!==null?T.properties.push(S.objectProperty(S.identifier("children"),S.cloneNode(me))):R.push({name:"children",value:S.cloneNode(me)})}let oe;if(T!==null){let me=J(e,`${v}Props`);t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.cloneNode(me),S.cloneNode(T))])),oe=qt(e,m,me)}else oe=Hn(e,m,R);let ue=S.binaryExpression("+",S.cloneNode(d),S.stringLiteral(B));return t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.identifier(_),S.callExpression(S.identifier(m),[ue,S.cloneNode(d),...oe.length>0?[S.arrayExpression(oe)]:[]]))])),t.disposableEntities.push(S.cloneNode(ue)),ee&&t.updaters.push(()=>T===null?S.expressionStatement(S.callExpression(ne(e,"setProps"),[S.binaryExpression("+",S.cloneNode(d),S.stringLiteral(B)),S.arrayExpression(oe.map(me=>S.cloneNode(me)))])):ci(e,m,d,B,T)),_}let E=li(m,l),b=E&&m!=="foreignObject";if(c.attributes.find(N=>S.isJSXAttribute(N)&&De(N.name)==="innerHTML")!==void 0){if(E)throw r.buildCodeFrameError("memo-dom: innerHTML is only supported on HTML elements");if(n.children.some(v=>!S.isJSXText(v)||v.value.trim()!==""))throw r.buildCodeFrameError("memo-dom: an element using innerHTML cannot also have JSX children")}let g=So(n.children,{emitText:N=>Fo(e,t,N),emitNode:N=>pt(e,t,N,o,r,i,s,a,b,d),isForwarded:N=>dt(e,o,N),fail:N=>{throw r.buildCodeFrameError(N)}}),h=oo(e,t,m);if(t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.identifier(h),di(m,E))])),c.attributes.some(N=>S.isJSXSpreadAttribute(N))){let N=an(c.attributes,{attributeValue:(_,B)=>_==="ref"?Ct(e,r,o,B):B,eventValue:(_,B)=>{let R=xo(e,r,B,_,o,s,a),k=J(e,`${_}Handler`);return t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.cloneNode(k),R)])),k},fail:_=>{throw r.buildCodeFrameError(_)}}),v=J(e,`${m}Props`);t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.cloneNode(v),S.cloneNode(N.expression))]));let $=_=>S.expressionStatement(S.callExpression(ne(e,"patchDomProps"),[S.identifier(h),S.cloneNode(_),S.stringLiteral(e.rootId),S.arrayExpression(N.safeEventKeys.map(B=>S.stringLiteral(B)))]));t.creation.push($(v)),No(e,t,S.identifier(h),d,S.memberExpression(S.cloneNode(v),S.identifier("ref"))),t.updaters.push(()=>$(N.expression))}else for(let N of c.attributes){let v=N,$=De(v.name);if($==="ref"){let T=ze(v.value);if(T===null)throw r.buildCodeFrameError("memo-dom: ref needs an expression");No(e,t,S.identifier(h),d,Ct(e,r,o,T));continue}if($==="key")throw r.buildCodeFrameError("memo-dom: key={...} is only meaningful on list rows: items.map(item => <Row key={item.id} />)");if(/^on[A-Z]/.test($)){let T=ze(v.value);if(T==null)throw r.buildCodeFrameError(`memo-dom: ${$} needs a handler expression (L1)`);let ee=xo(e,r,T,$,o,s,a),oe=t.delegatedEventBindings.get($);t.creation.push(oe===void 0?S.expressionStatement(S.assignmentExpression("=",S.memberExpression(S.identifier(h),S.identifier($.toLowerCase())),ee)):S.expressionStatement(S.callExpression(ne(e,"setDelegatedEvent"),[S.identifier(oe),S.identifier(h),ee])));continue}if(S.isStringLiteral(v.value)){$==="class"||$==="className"?t.creation.push(S.expressionStatement(S.callExpression(ne(e,"setClassValue"),[S.identifier(h),S.stringLiteral(v.value.value)]))):$==="style"?t.creation.push(S.expressionStatement(S.callExpression(ne(e,"setStyleValue"),[S.identifier(h),S.stringLiteral(v.value.value)]))):Co($,E)!==null?t.creation.push(Po(h,$,S.stringLiteral(v.value.value))):wo($,E)?t.creation.push(Kn(h,$,S.stringLiteral(v.value.value))):E?t.creation.push(S.expressionStatement(S.callExpression(ne(e,"setDomValue"),[S.identifier(h),S.stringLiteral($),S.stringLiteral(v.value.value)]))):t.creation.push(S.expressionStatement(S.callExpression(S.memberExpression(S.identifier(h),S.identifier("setAttribute")),[S.stringLiteral($),S.stringLiteral(v.value.value)])));continue}let _=v.value==null?S.booleanLiteral(!0):ze(v.value);if(_==null)throw r.buildCodeFrameError(`memo-dom: attribute '${$}' needs a string or an expression (L1)`);let B=S.cloneNode(_);if($==="style"){let T=()=>S.expressionStatement(S.callExpression(ne(e,"setStyleValue"),[S.identifier(h),S.cloneNode(B)]));t.creation.push(T()),t.updaters.push(T);continue}let R=no(e,t),k=Co($,E),W=()=>$==="class"||$==="className"?jt(t,R,S.callExpression(ne(e,"classValue"),[S.cloneNode(B)]),T=>S.expressionStatement(S.callExpression(ne(e,"setClassValue"),[S.identifier(h),T]))):k!==null?jt(t,R,S.cloneNode(B),T=>Po(h,k,T)):wo($,E)?jt(t,R,S.cloneNode(B),T=>Kn(h,$,T)):E?jt(t,R,S.cloneNode(B),T=>S.expressionStatement(S.callExpression(ne(e,"setDomValue"),[S.identifier(h),S.stringLiteral($),T]))):jt(t,R,S.cloneNode(B),T=>Kn(h,$,T));t.creation.push(W()),t.updaters.push(W)}return hi(e,t,g,h,o,r,i,s,b,d),h}function yi(e,t,n,o,r,i,s=!1,a=Te(e,r),l){mi(e,t,n,o,r,i,pt,Mo,s,a,l)}function xi(e,t,n,o,r,i,s=!1,a=Te(e,r),l=!1){ui(e,t,n,o,r,i,pt,s,a,l)}function Si(e,t,n,o,r,i=!1,s=r,a=!1,l){return pn(e,t,n,o,r,pt,i,s,a,l)}import*as je from"@babel/types";function Pi(e){if(e.isFunctionDeclaration())return e.node;if(!e.isVariableDeclarator())return null;let t=e.node.init;return t&&(je.isArrowFunctionExpression(t)||je.isFunctionExpression(t))?t:null}function vi(e,t,n,o,r,i=!1){let s=St(t,n);if(s!==null){ct(e,t,s,o,r,i);return}let a=t.scope.getBinding(n);if(a===void 0||a.scope.path.isProgram()!==!0||!e.helpers.has(n))return;let l=Pi(a.path);l!==null&&un(e,l,i)}function Ci(e,t,n,o,r,i=!1){if(je.isArrowFunctionExpression(n)||je.isFunctionExpression(n)){if(fe(n.body))return;ct(e,t,n,o,r,i)}else je.isIdentifier(n)&&vi(e,t,n.name,o,r,i)}function ki(e,t,n,o=!1){let r=t.scope.getBinding(n);if(r===void 0||r.scope.path.isProgram()!==!0||!e.helpers.has(n))return;let i=Pi(r.path);i!==null&&un(e,i,o)}function wi(e,t,n,o=!1){if(je.isArrowFunctionExpression(n)||je.isFunctionExpression(n)){if(fe(n.body))return;un(e,n,o)}else je.isIdentifier(n)&&ki(e,t,n.name,o)}function Ni(e,t,n,o,r){t.traverse({CallExpression(i){let s=i.getFunctionParent()===t,a=i.node.callee,l=je.isIdentifier(a,{name:"effect"})&&i.scope.getBinding("effect")===void 0;if(je.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||!je.isExpression(d))throw i.buildCodeFrameError("memo-dom: cleanup(disposer) requires exactly one disposer expression");i.node.callee=ne(e,"cleanup"),i.node.arguments.unshift(je.identifier(o))}if(s){je.isIdentifier(a)&&vi(e,t,a.name,n,r);for(let d of i.node.arguments)Ci(e,t,d,n,r,l)}},NewExpression(i){if(i.getFunctionParent()===t)for(let s of i.node.arguments)Ci(e,t,s,n,r)}})}function Ri(e,t){t.traverse({CallExpression(n){if(n.getFunctionParent()!==null)return;let o=je.isIdentifier(n.node.callee,{name:"effect"})&&n.scope.getBinding("effect")===void 0;je.isIdentifier(n.node.callee)&&ki(e,t,n.node.callee.name);for(let r of n.node.arguments)wi(e,t,r,o)},NewExpression(n){if(n.getFunctionParent()===null)for(let o of n.node.arguments)wi(e,t,o)}})}function Ii(e){for(let t of e.helpers.values())t.node.async&&un(e,t.node)}function Fi(e){e.traverse({CallExpression(t){if(je.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 Ue from"@babel/types";import*as he from"@babel/types";function Mi(e){return e.reduce((t,n)=>he.logicalExpression("||",t,n))}function Di(e,t){let n=()=>he.identifier(e),o=he.logicalExpression("||",he.binaryExpression("===",n(),he.unaryExpression("-",he.numericLiteral(1))),he.logicalExpression("&&",he.binaryExpression("!==",he.unaryExpression("typeof",n()),he.stringLiteral("number")),he.callExpression(he.memberExpression(n(),he.identifier("has")),[he.unaryExpression("-",he.numericLiteral(1))]))),r=Mi(t.map(s=>he.binaryExpression("===",n(),he.numericLiteral(s)))),i=Mi(t.map(s=>he.callExpression(he.memberExpression(n(),he.identifier("has")),[he.numericLiteral(s)])));return he.logicalExpression("||",he.binaryExpression("===",n(),he.nullLiteral()),he.logicalExpression("||",o,he.conditionalExpression(he.binaryExpression("===",he.unaryExpression("typeof",n()),he.stringLiteral("number")),r,i)))}function Li(e,t,n,o,r,i){let s=new Map(o.map((c,m)=>[c,m])),a=0,l=[...r.map(c=>({order:s.get(c.declaration)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:c.sources,statement:Go(c)})),...i.map(c=>({order:s.get(c.statement)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:c.sources,statement:Ue.blockStatement([...c.resets.map(m=>Ue.expressionStatement(Ue.assignmentExpression("=",Ue.identifier(m.binding),Ue.cloneNode(m.source,!0)))),Ue.cloneNode(c.statement,!0)])}))].sort((c,m)=>c.order-m.order||c.sequence-m.sequence),d=e.instanceReasonIds.get(t),u=[];for(let c of l){let m=n===null||d===void 0?null:c.sources.map(h=>d.get(h)).filter(h=>h!==void 0).sort((h,C)=>h-C),E=m===null||m.length===c.sources.length?m:null,b=E?.join(" ")??"*",f=u.at(-1),g=f?.reasons?.join(" ")??"*";f!==void 0&&g===b?f.statements.push(c.statement):u.push({reasons:E,statements:[c.statement]})}return Ue.blockStatement(u.map(c=>c.reasons===null||n===null?Ue.blockStatement(c.statements):Ue.ifStatement(Di(n,c.reasons),Ue.blockStatement(c.statements))))}import*as Z from"@babel/types";function mn(e){return!Z.isReturnStatement(e)||!Z.isJSXElement(e.argument)&&!Z.isJSXFragment(e.argument)?null:{jsx:e.argument,statement:e}}function Do(e){return Z.isBlockStatement(e)?e.body.length===1?mn(e.body[0]):null:mn(e)}function fl(e){let t=[];return e.get("body").traverse({ReturnStatement(n){t.push(n.node)},Function(n){n.skip()}}),t}function ml(e){if(Z.isFunctionDeclaration(e))return!0;if(Z.isVariableDeclaration(e))return e.declarations.every(t=>t.init==null||Z.isFunction(t.init)||gl(t.init));if(Z.isSwitchStatement(e)||Z.isIfStatement(e)){let t=!0;return Z.traverseFast(e,n=>{(Z.isCallExpression(n)||Z.isOptionalCallExpression(n)||Z.isNewExpression(n)||Z.isAwaitExpression(n)||Z.isYieldExpression(n)||Z.isThrowStatement(n)||Z.isTaggedTemplateExpression(n)||Z.isUpdateExpression(n))&&(t=!1)}),t}return Z.isTypeScript(e)}function gl(e){let t=!0;return Z.traverseFast(e,n=>{(Z.isCallExpression(n)||Z.isOptionalCallExpression(n)||Z.isNewExpression(n)||Z.isAwaitExpression(n)||Z.isYieldExpression(n)||Z.isTaggedTemplateExpression(n)||Z.isAssignmentExpression(n)||Z.isUpdateExpression(n))&&(t=!1)}),t}function bl(e){if(!e.cases.some(o=>o.test==null))return null;let t=[],n=[];for(let o of e.cases){if(o.consequent.length!==1)return null;let r=mn(o.consequent[0]);if(r===null)return null;let i=t.length;t.push(r.jsx),n.push(Z.switchCase(o.test===null?null:Z.cloneNode(o.test),[Z.returnStatement(Z.numericLiteral(i))]))}return{pick:Z.arrowFunctionExpression([],Z.blockStatement([Z.switchStatement(Z.cloneNode(e.discriminant),n)])),branches:t,statements:new Set([e])}}function Ai(e,t){let n=e.node.body.body,o=fl(e),r=n.at(-1);if(o.length===1&&r!==void 0){let s=mn(r);if(s!==null)return s}if(r&&Z.isIfStatement(r)&&r.alternate!=null){let s=r.alternate,a=Do(r.consequent),l=Do(s);if(a!==null&&l!==null&&o.length===2)return{pick:Z.arrowFunctionExpression([],Z.conditionalExpression(Z.cloneNode(r.test),Z.numericLiteral(0),Z.numericLiteral(1))),branches:[a.jsx,l.jsx],statements:new Set([r])}}if(r&&Z.isSwitchStatement(r)){let s=bl(r);if(s!==null&&s.branches.length===o.length)return s}let i=r===void 0?null:mn(r);if(i!==null){let s=[],a=[],l=new Set([r]),d=-1,u=!0;for(let c=0;c<n.length-1;c++){let m=n[c];if(Z.isIfStatement(m)&&m.alternate==null){let E=Do(m.consequent);if(E!==null){d===-1&&(d=c),s.push(Z.cloneNode(m.test)),a.push(E.jsx),l.add(m);continue}}if(d!==-1&&!ml(m)){u=!1;break}}if(a.push(i.jsx),u&&a.length===o.length&&a.length>1){let c=Z.numericLiteral(a.length-1);for(let m=s.length-1;m>=0;m--)c=Z.conditionalExpression(s[m],Z.numericLiteral(m),c);return{pick:Z.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 El(e){return e?.some(t=>t.localReads.size>0||t.localDerivationReads.size>0||t.conditionLocalReads.size>0||t.conditionLocalDerivationReads.size>0)===!0}function hl(e,t,n,o,r,i,s,a,l){if(t.length===0&&n.length===0||e.bindings.length===0)return;let d=[...t.map(b=>it(b.keyExpr??null,b.itemParam??"")),...n.map(b=>b.keyPath)],u=JSON.stringify(d[0]),c=d.every(b=>JSON.stringify(b)===u)?d[0]:null,m=wn(e,"item"),E=qe(e);return{itemParam:m??E??e.bindings[0],itemPath:m===null&&E!==null?["item"]:[],rowIdVar:s,...r?{refreshVar:i}:{},keyPath:c,sourceKey:t[0]?.sourceKey??n[0]?.sourceKey??"",sourceLocal:o,...o?{ownerIdVar:a??l}:{}}}function yl(e,t,n,o,r,i,s){let a=Array.from({length:r},(d,u)=>J(e,`nextProp${u}`)),l=o===null?to(n,a):o.map(({local:d},u)=>A.expressionStatement(A.assignmentExpression("=",A.identifier(d),A.cloneNode(a[u]))));return A.returnStatement(A.objectExpression([A.objectProperty(A.identifier("nodes"),s?A.identifier(i):A.callExpression(ne(e,"rootNodes"),[A.identifier(i)])),A.objectProperty(A.identifier("entities"),A.arrayExpression([])),A.objectProperty(A.identifier("update"),A.identifier(t.updateVar)),...r>0?[A.objectProperty(A.identifier("updateProps"),A.arrowFunctionExpression(a,A.blockStatement(l)))]:[],...t.disposableCallbacks.length>0?[A.objectProperty(A.identifier("dispose"),A.arrowFunctionExpression([],A.blockStatement([...t.disposableCallbacks].reverse().map(d=>A.ifStatement(A.binaryExpression("!==",A.cloneNode(d),A.nullLiteral()),A.expressionStatement(A.callExpression(A.cloneNode(d),[])))))))]:[]]))}function xl(e,t,n,o,r,i,s,a,l){return n?[...t===null?e.params.map(Zo):t.map(({local:d})=>A.identifier(d)),A.identifier(r),...s===null?[]:[A.identifier(s)],...[...a.values()].map(d=>A.identifier(d))]:o>0?[A.identifier(r),A.identifier(i),A.identifier(l)]:[A.identifier(r),A.identifier(i)]}function ji(e,t,n){let o=t.node,r=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(oe=>oe.sourceLocal===!0)||l.some(oe=>oe.sourceLocal),u=Nt(e,n),c=u&&l.length===0?Sn(i):null,m=c?.length??s,E=st(e,u),b=e.instanceDerivations.get(n),f=e.instanceControlFlow.get(n),g=e.effects.get(n),h=El(g);(e.selectiveDerivationComponents.has(n)||e.targetedListComponents.has(n)||h)&&(E.reasonVar=J(e,"reasons").name);let C=J(e,"id").name,N=u?null:J(e,"parent").name,v=u&&d?J(e,"owner").name:null,$=new Map;if(u)for(let oe of e.componentHostEvents.get(n)??[]){let ue=J(e,`${oe}Binding`).name;$.set(oe,ue),E.delegatedEventBindings.set(oe,ue)}let _=s>0&&!u?J(e,"props").name:null;Et(e).registerComponentId(n,C);let B=hl(i,a,l,d,u,E.updateVar,C,v,N);Ni(e,t,n,C,B);let R="jsx"in r?pt(e,E,r.jsx,n,t,null,B):Sl(e,E,r,n,t,C),k=u&&"jsx"in r&&A.isJSXElement(r.jsx);if(u&&Gt(e,E,R),b!==void 0)for(let oe of b)oe.declaration.kind="let";(b!==void 0||f!==void 0)&&E.updaters.unshift(()=>Li(e,n,E.reasonVar,o.body.body,b??[],f??[])),g!==void 0&&h&&E.updaters.push(()=>mr(e,n,C,E.reasonVar,g,E));let W=new Set(g?.map(oe=>oe.statement)??[]),T=o.body.body.filter(oe=>!("jsx"in r?oe===r.statement:r.statements.has(oe))&&!W.has(oe));s>0&&!u&&E.updaters.unshift(()=>A.blockStatement(to(i,i.params.map((oe,ue)=>A.memberExpression(A.identifier(_),A.numericLiteral(ue),!0)))));let ee=[at(E)];if(s>0&&!u){let oe=_o(i,i.params.map((ue,me)=>A.memberExpression(A.identifier(_),A.numericLiteral(me),!0)));oe!==null&&ee.push(oe)}ee.push(...T,lt(E),...u?[]:[ft(e,A.identifier(C),A.identifier(N),A.identifier(E.updateVar),e.volatileComponents.has(n))]),s>0&&!u&&ee.push(A.expressionStatement(A.callExpression(ne(e,"registerProps"),[A.identifier(C),A.identifier(_)]))),ee.push(...E.creation,...E.mounts),g!==void 0&&ee.push(...gr(e,C,g)),e.hot&&!u&&ee.push(A.expressionStatement(A.callExpression(ne(e,"registerHotComponent"),[A.identifier(n),A.identifier(C),A.identifier(N),A.callExpression(ne(e,"rootNodes"),[A.identifier(R)]),_===null?A.nullLiteral():A.identifier(_)]))),ee.push(u?yl(e,E,i,c,m,R,k):A.returnStatement(A.identifier(R))),o.params=xl(i,c,u,s,C,N,v,$,_),o.body=A.blockStatement(ee)}function Sl(e,t,n,o,r,i){let s=J(e,"returnRoot").name,a=J(e,"returnRegion").name,l=A.identifier(i),d=A.binaryExpression("+",A.cloneNode(l),A.stringLiteral("/$return"));return t.creation.push(A.variableDeclaration("const",[A.variableDeclarator(A.identifier(s),A.callExpression(A.memberExpression(A.identifier("document"),A.identifier("createDocumentFragment")),[]))])),t.creation.push(A.variableDeclaration("const",[A.variableDeclarator(A.identifier(a),A.callExpression(ne(e,"createCondRegion"),[A.identifier(s),A.cloneNode(d),A.cloneNode(n.pick),A.arrayExpression(n.branches.map(u=>Si(e,u,o,r,d,!1,l,!0,t.usedConds)))]))])),t.updaters.push(()=>A.expressionStatement(A.callExpression(A.memberExpression(A.identifier(a),A.identifier("update")),[]))),s}import*as pe from"@babel/types";function Cl(e){return!pe.isIdentifier(e.id)||!/^[A-Z]/.test(e.id.name)||!pe.isArrowFunctionExpression(e.init)&&!pe.isFunctionExpression(e.init)||!fe(e.init.body)?null:e.init}function wl(e,t,n){if(t.async||t.generator)throw n.buildCodeFrameError(`memo-dom: component '${e}' must be synchronous`);if(pe.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 o=pe.functionDeclaration(pe.identifier(e),t.params.map(r=>pe.cloneNode(r,!0)),pe.isBlockStatement(t.body)?pe.cloneNode(t.body,!0):pe.blockStatement([pe.returnStatement(pe.cloneNode(t.body,!0))]));return o.returnType=t.returnType==null?null:pe.cloneNode(t.returnType,!0),o.typeParameters=t.typeParameters==null?null:pe.cloneNode(t.typeParameters,!0),o.loc=t.loc,o}function Ji(e,t,n){if(e.kind!=="const")return[t?pe.exportNamedDeclaration(pe.cloneNode(e,!0)):pe.cloneNode(e,!0)];let o=[];for(let r of e.declarations){let i=Cl(r),s;i===null?s=pe.variableDeclaration("const",[pe.cloneNode(r,!0)]):s=wl(r.id.name,i,n),o.push(t?pe.exportNamedDeclaration(s):s)}return o.length>0&&pe.inheritsComments(o[0],e),o}function gn(e){let t=[],n=!1;for(let o of e.get("body")){let r=o.node;if(pe.isVariableDeclaration(r)){let i=Ji(r,!1,o);n||=i.some(s=>pe.isFunctionDeclaration(s)),t.push(...i);continue}if(pe.isExportNamedDeclaration(r)&&pe.isVariableDeclaration(r.declaration)){let i=Ji(r.declaration,!0,o);n||=i.some(s=>pe.isExportNamedDeclaration(s)&&pe.isFunctionDeclaration(s.declaration)),t.push(...i);continue}t.push(r)}n&&(e.set("body",t),e.scope.crawl())}import*as j from"@babel/types";var Pl=/^:([A-Za-z_$][A-Za-z0-9_$]*)$/;function Lo(e,t){return e.openingElement.attributes.find(n=>j.isJSXAttribute(n)&&De(n.name)===t)}function Ao(e){return j.isStringLiteral(e.value)?e.value.value:j.isJSXExpressionContainer(e.value)&&j.isStringLiteral(e.value.expression)?e.value.expression.value:null}function $i(e,t,n){let o=t.openingElement.loc?.start.line,r=t.openingElement.loc?.start.column;return o===void 0||r===void 0?`${e}#route:${n}`:`${e}#route:${o}:${r}`}function jo(e){return e.split("/").filter(Boolean)}function _n(e){if(!e.startsWith("/"))throw new TypeError(`route pattern '${e}' must begin with '/'`);if(e.includes("?")||e.includes("#"))throw new TypeError(`route pattern '${e}' must not contain a query or hash`);if(e.includes("//"))throw new TypeError(`route pattern '${e}' contains an empty path segment`);let t=e.replace(/\/+$/g,""),n=t===""?"/":t,o=new Set,r=jo(n);for(let i=0;i<r.length;i++){let s=r[i];if(s==="*"){if(i!==r.length-1)throw new TypeError(`route wildcard must be terminal in '${e}'`);continue}if(!s.startsWith(":"))continue;let a=Pl.exec(s);if(a===null)throw new TypeError(`invalid route parameter segment '${s}' in '${e}'`);let l=a[1];if(o.has(l))throw new TypeError(`duplicate route parameter '${l}' in '${e}'`);o.add(l)}return n}function Zt(e){let t=[];for(let n of jo(e))n==="*"?t.push("*"):n.startsWith(":")&&t.push(n.slice(1));return t}function Xi(e,t){if(e.endsWith("/*"))throw new TypeError(`catch-all route '${e}' cannot have child routes`);return t==="/"?e:e==="/"?t:`${e}${t}`}function vl(e,t){let n=[],o=0,r=(i,s)=>{if(j.isJSXElement(i)){let a=s,l=Lo(i,"route");if(l!==void 0){let d=Ao(l);if(d!==null){let u=_n(d),c=s===null?u:Xi(s.fullPattern,u),m=new Set(s===null?[]:Zt(s.fullPattern));for(let E of Zt(u))if(m.has(E))throw new TypeError(`route '${c}' shadows active parameter '${E}'`);a={id:$i(t,i,o++),moduleId:t,pattern:u,fullPattern:c,...s===null?{}:{parentId:s.id},...i.openingElement.loc?.start.line===void 0?{}:{line:i.openingElement.loc.start.line},...i.openingElement.loc?.start.column===void 0?{}:{column:i.openingElement.loc.start.column}},n.push(a)}}for(let d of i.openingElement.attributes)r(d,a);for(let d of i.children)r(d,a);return}if(j.isJSXFragment(i)){for(let a of i.children)r(a,s);return}for(let a of j.VISITOR_KEYS[i.type]??[]){let l=i[a];if(Array.isArray(l))for(let d of l)d!==null&&typeof d=="object"&&"type"in d&&r(d,s);else l!==null&&typeof l=="object"&&"type"in l&&r(l,s)}};return r(e,null),n}function Ti(e,t){return vl(e.program,t)}function kl(e){return jo(e).map(t=>t==="*"?"*":t.startsWith(":")?":param":t).join("/")}function Oi(e,t,n){let o=t.parentId;for(;o!==void 0;){if(o===e.id)return!0;o=n.get(o)?.parentId}return!1}function Jo(e){let t=new Map(e.map(o=>[o.id,o])),n=new Map;for(let o of e){if(o.parentId!==void 0&&!t.has(o.parentId))throw new TypeError(`route '${o.fullPattern}' references a missing compiler parent`);let r=kl(o.fullPattern),i=n.get(r);if(i!==void 0&&!Oi(i,o,t)&&!Oi(o,i,t))throw new TypeError(`ambiguous routes '${i.fullPattern}' and '${o.fullPattern}' share '${r}'`);n.set(r,o)}}function qn(e){return!e.computed&&j.isIdentifier(e.key)?e.key.name:j.isStringLiteral(e.key)?e.key.value:null}function Nl(e,t){let n=e.node,o=Ao(n),r,i=null;if(o!==null)try{r=_n(o)}catch(l){throw e.buildCodeFrameError(`memo-dom: ${l.message}`)}else if(j.isJSXExpressionContainer(n.value)&&j.isObjectExpression(n.value.expression)){let l=n.value.expression;if(l.properties.some(b=>j.isSpreadElement(b)))throw e.buildCodeFrameError("memo-dom: route-to objects must have statically known keys; object spreads are not supported");let d=new Map;for(let b of l.properties){if(!j.isObjectProperty(b))continue;let f=qn(b);if(f===null)throw e.buildCodeFrameError("memo-dom: route-to object keys must be static");if(d.has(f))throw e.buildCodeFrameError(`memo-dom: route-to contains duplicate '${f}' fields`);d.set(f,b)}let u=new Set(["path","params","query","hash","replace"]);for(let b of d.keys())if(!u.has(b))throw e.buildCodeFrameError(`memo-dom: route-to does not support '${b}'`);let c=d.get("path");if(c===void 0||!j.isStringLiteral(c.value))throw e.buildCodeFrameError("memo-dom: route-to requires a static string 'path'");try{r=_n(c.value.value)}catch(b){throw e.buildCodeFrameError(`memo-dom: ${b.message}`)}i=j.objectExpression(l.properties.filter(b=>j.isObjectProperty(b)&&qn(b)!=="path").map(b=>j.cloneNode(b,!0)));let m=Zt(r),E=d.get("params");if(m.length>0&&E===void 0)throw e.buildCodeFrameError(`memo-dom: route-to '${r}' requires params { ${m.join(", ")} }`);if(E!==void 0){if(!j.isObjectExpression(E.value))throw e.buildCodeFrameError("memo-dom: route-to params must be an object literal with static keys");if(E.value.properties.some(N=>j.isSpreadElement(N)))throw e.buildCodeFrameError("memo-dom: route-to params do not support object spreads");let b=E.value.properties.map(N=>j.isObjectProperty(N)?qn(N):null);if(b.some(N=>N===null))throw e.buildCodeFrameError("memo-dom: route-to param names must be static");let f=b,g=f.find((N,v)=>f.indexOf(N)!==v);if(g!==void 0)throw e.buildCodeFrameError(`memo-dom: route-to params contain duplicate '${g}'`);let h=m.filter(N=>!f.includes(N)),C=f.filter(N=>!m.includes(N));if(h.length>0||C.length>0)throw e.buildCodeFrameError(`memo-dom: route-to '${r}' params mismatch`+(h.length===0?"":`; missing ${h.join(", ")}`)+(C.length===0?"":`; unknown ${C.join(", ")}`))}}else throw e.buildCodeFrameError("memo-dom: route-to must be a static route string or a statically shaped destination object");let s=t.get(r);if(s===void 0)throw e.buildCodeFrameError(`memo-dom: route-to references undeclared route '${r}'`);let a=Zt(s.fullPattern);if(o!==null&&a.length>0)throw e.buildCodeFrameError(`memo-dom: route-to '${r}' requires params { ${a.join(", ")} }; use the object form`);return{path:r,options:i}}function Rl(e,t){if(t.options===null)return j.stringLiteral(t.path);let n=new Map;for(let r of t.options.properties){if(!j.isObjectProperty(r)||!j.isExpression(r.value))continue;let i=qn(r);i!==null&&n.set(i,r.value)}let o=r=>j.cloneNode(n.get(r)??j.identifier("undefined"),!0);return j.callExpression(bt(e,"buildRoutePath"),[j.stringLiteral(t.path),o("params"),o("query"),o("hash")])}function Il(e,t){return j.callExpression(bt(e,"navigateRoute"),[j.stringLiteral(t.path),...t.options===null?[]:[j.cloneNode(t.options,!0)]])}function Fl(e,t,n,o){let r=t.node.openingElement;if(!j.isJSXIdentifier(r.name))throw n.buildCodeFrameError("memo-dom: route-to currently requires a statically named JSX element");let i=r.name.name;if(/^[A-Z]/.test(i))throw n.buildCodeFrameError("memo-dom: route-to currently targets intrinsic elements; put it on the interactive host rendered by this component");if(r.attributes.some(u=>j.isJSXSpreadAttribute(u)))throw n.buildCodeFrameError("memo-dom: route-to cannot be combined with JSX prop spreads because navigation ownership must be static");if(i==="a"){if(Lo(t.node,"href")!==void 0)throw n.buildCodeFrameError("memo-dom: an anchor using route-to must not also declare href");let u=Rl(e,o);r.attributes.push(j.jsxAttribute(j.jsxIdentifier("href"),j.isStringLiteral(u)?u:j.jsxExpressionContainer(u)));return}let s=Lo(t.node,"onClick"),a=J(e,"routeEvent"),l=[],d=null;if(s!==void 0){let u=null;if(j.isJSXExpressionContainer(s.value)&&j.isExpression(s.value.expression)&&(u=s.value.expression),u===null)throw n.buildCodeFrameError("memo-dom: onClick used with route-to must contain a handler expression");d=J(e,"routeClickResult"),l.push(j.variableDeclaration("const",[j.variableDeclarator(j.cloneNode(d),j.callExpression(j.cloneNode(u,!0),[j.cloneNode(a)]))])),r.attributes=r.attributes.filter(c=>c!==s)}l.push(j.ifStatement(j.unaryExpression("!",j.memberExpression(j.cloneNode(a),j.identifier("defaultPrevented"))),j.expressionStatement(Il(e,o)))),d!==null&&l.push(j.returnStatement(j.cloneNode(d))),r.attributes.push(j.jsxAttribute(j.jsxIdentifier("onClick"),j.jsxExpressionContainer(j.arrowFunctionExpression([j.cloneNode(a)],j.blockStatement(l)))))}function Bi(e,t){let n=[],o=0;t.traverse({JSXElement(s){let a=s.get("openingElement").get("attributes").find(f=>f.isJSXAttribute()&&De(f.node.name)==="route");if(a===void 0)return;let l=Ao(a.node);if(l===null)throw a.buildCodeFrameError("memo-dom: route must be a static string beginning with /");let d;try{d=_n(l)}catch(f){throw a.buildCodeFrameError(`memo-dom: ${f.message}`)}let u=s.findParent(f=>f.isJSXElement()&&e.routeElements.has(f.node)),c=u===null?null:e.routeElements.get(u.node),m;try{m=c===null?d:Xi(c.fullPattern,d)}catch(f){throw a.buildCodeFrameError(`memo-dom: ${f.message}`)}let E=new Set(c===null?[]:Zt(c.fullPattern));for(let f of Zt(d))if(E.has(f))throw a.buildCodeFrameError(`memo-dom: route '${m}' shadows active parameter '${f}'`);let b={id:$i(e.moduleId,s.node,o++),moduleId:e.moduleId,pattern:d,fullPattern:m,...c===null?{}:{parentId:c.id},...s.node.openingElement.loc?.start.line===void 0?{}:{line:s.node.openingElement.loc.start.line},...s.node.openingElement.loc?.start.column===void 0?{}:{column:s.node.openingElement.loc.start.column}};e.routeElements.set(s.node,b),n.push(b),e.localRoutes.push(b),e.usesRouter=!0,a.remove()}});let r=e.linkedRoutes??n;Jo(r);let i=new Map(r.map(s=>[s.fullPattern,s]));t.traverse({JSXElement(s){let a=s.get("openingElement").get("attributes").find(d=>d.isJSXAttribute()&&De(d.node.name)==="route-to");if(a===void 0)return;let l=Nl(a,i);e.usesRouter=!0,a.remove(),Fl(e,s,a,l)}})}function Vi(e){if(!e.emitRouteManifest)return[];let t=e.linkedRoutes??e.localRoutes;if(t.length===0)return[];e.usesRouter=!0;let n=J(e,"routeManifest");return[j.variableDeclaration("const",[j.variableDeclarator(j.cloneNode(n),j.callExpression(bt(e,"createRouteManifest"),[j.arrayExpression(t.map(o=>j.objectExpression([j.objectProperty(j.identifier("id"),j.stringLiteral(o.id)),j.objectProperty(j.identifier("pattern"),j.stringLiteral(o.pattern)),...o.parentId===void 0?[]:[j.objectProperty(j.identifier("parentId"),j.stringLiteral(o.parentId))]])))]))]),j.expressionStatement(j.callExpression(bt(e,"replaceRouteResolver"),[j.memberExpression(j.cloneNode(n),j.identifier("resolve"))])),j.expressionStatement(j.callExpression(bt(e,"ensureRouterConnected"),[]))]}import*as Ce from"@babel/types";function Ki(e){if(!Ce.isJSXIdentifier(e.name))return null;let t=e.name.name;return t==="if"||t==="else-if"||t==="else"?t:null}function Oo(e,t){let n=null;for(let o of e.openingElement.attributes){if(!Ce.isJSXAttribute(o))continue;let r=Ki(o);if(r!==null){if(n!==null)throw t.buildCodeFrameError("memo-dom: a JSX element may have only one of if, else-if, or else");if(r==="else"){if(o.value!==null)throw t.buildCodeFrameError("memo-dom: the JSX else directive does not accept a value; write <Element else>");n={kind:r,condition:null};continue}if(!Ce.isJSXExpressionContainer(o.value)||Ce.isJSXEmptyExpression(o.value.expression)||!Ce.isExpression(o.value.expression))throw t.buildCodeFrameError(`memo-dom: the JSX ${r} directive requires an expression, for example ${r}={condition}`);n={kind:r,condition:Ce.cloneNode(o.value.expression,!0)}}}return n}function Gn(e){e.openingElement.attributes=e.openingElement.attributes.filter(t=>!Ce.isJSXAttribute(t)||Ki(t)===null)}function Wi(e){return Ce.isJSXText(e)&&e.value.trim()===""||Ce.isJSXExpressionContainer(e)&&Ce.isJSXEmptyExpression(e.expression)}function zi(e){let t=e.node.children;if(t.length===0)return;let n=e.get("children"),o=new Map(n.map(a=>[a.node,a])),r=a=>o.get(a)??e,i=[],s=0;for(;s<t.length;){let a=t[s];if(!Ce.isJSXElement(a)){i.push(a),s++;continue}let l=Oo(a,r(a));if(l?.kind==="else-if"||l?.kind==="else")throw r(a).buildCodeFrameError(`memo-dom: JSX ${l.kind} must immediately follow an if or else-if sibling`);if(l?.kind!=="if"){i.push(a),s++;continue}Gn(a);let d=[{condition:l.condition,element:a}],u=null,c=s+1,m=[];for(;c<t.length;){let b=[];for(;c<t.length&&Wi(t[c]);)b.push(t[c]),c++;if(c>=t.length){m=b;break}let f=t[c];if(!Ce.isJSXElement(f)){m=b;break}let g=Oo(f,r(f));if(g?.kind==="else-if"){Gn(f),d.push({condition:g.condition,element:f}),c++;continue}if(g?.kind==="else")for(Gn(f),u=f,c++;c<t.length&&Wi(t[c]);)m.push(t[c]),c++;else m=b;break}let E=u??Ce.nullLiteral();for(let b=d.length-1;b>=0;b--){let f=d[b];E=Ce.conditionalExpression(f.condition,f.element,E)}i.push(Ce.jsxExpressionContainer(E),...m),s=c}e.node.children=i}function Hi(e){e.traverse({JSXElement:{exit(t){zi(t)}},JSXFragment:{exit(t){zi(t)}}}),e.traverse({JSXElement(t){let n=Oo(t.node,t);if(n===null)return;if(n.kind!=="if")throw t.buildCodeFrameError(`memo-dom: JSX ${n.kind} must immediately follow an if or else-if sibling`);Gn(t.node);let o=t.node;t.replaceWith(Ce.jsxFragment(Ce.jsxOpeningFragment(),Ce.jsxClosingFragment(),[Ce.jsxExpressionContainer(Ce.conditionalExpression(n.condition,o,Ce.nullLiteral()))])),t.skip()}})}function Ml(e,t){let n=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#`;for(let o of t.get("body")){let r=o.node;if(O.isExportNamedDeclaration(r)&&(r=r.declaration),!(!O.isVariableDeclaration(r)||r.kind!=="const"))for(let i of r.declarations){if(!O.isIdentifier(i.id)||i.init==null)continue;let s=i.id.name;if(!e.computeds.has(s))continue;r.kind="let";let a=O.cloneNode(i.init),l=J(e,`${s}Next`),d=O.expressionStatement(O.callExpression(ne(e,"register"),[O.objectExpression([O.objectProperty(O.identifier("id"),O.stringLiteral(`${n}${s}`)),O.objectProperty(O.identifier("parent"),O.nullLiteral()),O.objectProperty(O.identifier("depth"),O.unaryExpression("-",O.numericLiteral(1))),O.objectProperty(O.identifier("render"),O.arrowFunctionExpression([],O.blockStatement([O.variableDeclaration("const",[O.variableDeclarator(l,a)]),O.ifStatement(O.callExpression(ne(e,"computedChanged"),[O.identifier(s),O.cloneNode(l)]),O.blockStatement([O.expressionStatement(O.assignmentExpression("=",O.identifier(s),O.cloneNode(l))),O.expressionStatement(O.callExpression(ne(e,"commitWrites"),[Qt(e,[s])]))]))])))])]));o.insertAfter(d)}}}function Dl(e,t){let n=new Map(t.get("body").map(o=>[o.node,o]));for(let o of e.moduleControlFlow){let r=n.get(o.statement);if(r===void 0)continue;let i=new Map(o.bindings.map(a=>[a,J(e,`${a}Previous`)])),s=[O.variableDeclaration("const",o.bindings.map(a=>O.variableDeclarator(O.cloneNode(i.get(a)),O.identifier(a)))),O.cloneNode(o.statement,!0),...o.bindings.map(a=>O.ifStatement(O.callExpression(ne(e,"computedChanged"),[O.cloneNode(i.get(a)),O.identifier(a)]),O.blockStatement([O.expressionStatement(O.callExpression(ne(e,"commitWrites"),[Qt(e,[a])]))])))];r.insertAfter(O.expressionStatement(O.callExpression(ne(e,"register"),[O.objectExpression([O.objectProperty(O.identifier("id"),O.stringLiteral(o.entityId)),O.objectProperty(O.identifier("parent"),O.nullLiteral()),O.objectProperty(O.identifier("depth"),O.unaryExpression("-",O.numericLiteral(1))),O.objectProperty(O.identifier("render"),O.arrowFunctionExpression([],O.blockStatement(s)))])])))}}function $o(e,t={}){let n=En(t),o=new WeakSet;return{name:"memo-dom",visitor:{Program:{enter(i){gn(i),Xn(n,i),Hi(i),hn(n,i),Bi(n,i),Wn(n,i),Ri(n,i),Ii(n)},exit(i){br(n,i),Fi(i),Er(i),n.header.unshift(...Vi(n)),i.traverse({JSXElement(l){throw l.buildCodeFrameError("memo-dom: JSX outside a component or compile-time render helper; components must use a supported top-level declaration")},JSXFragment(l){throw l.buildCodeFrameError("memo-dom: JSX outside a component or compile-time render helper; components must use a supported top-level declaration")}});let s=ln(n);n.computeds.size>0&&Ml(n,i),n.moduleControlFlow.length>0&&Dl(n,i),s&&n.header.push(s);for(let l=n.header.length-1;l>=0;l--)i.unshiftContainer("body",n.header[l]);let a=[O.importDeclaration([O.importNamespaceSpecifier(O.identifier(Et(n).runtimeId))],O.stringLiteral(n.runtimePath))];n.usesRouter&&a.push(O.importDeclaration([O.importNamespaceSpecifier(O.identifier(Et(n).routerId))],O.stringLiteral(n.routerPath))),i.unshiftContainer("body",a),n.rootComponent!==null&&i.pushContainer("body",O.expressionStatement(O.callExpression(ne(n,"registerRootFactory"),[O.identifier(n.rootComponent),O.objectExpression([O.objectProperty(O.identifier("id"),O.stringLiteral(n.rootId)),O.objectProperty(O.identifier("create"),O.arrowFunctionExpression([],O.callExpression(O.identifier(n.rootComponent),[O.stringLiteral(n.rootId),O.nullLiteral(),O.arrayExpression([])])))])])))}},FunctionDeclaration(i){let s=i.node.id?.name;!s||!n.comps.has(s)||o.has(i.node)||(o.add(i.node),ji(n,i,s),i.skip())}}}}function qi(e,t,n,o){let r=t.moduleId??"./component.tsx",i={filename:r,sourceFileName:r,sourceMaps:n,plugins:[[jl,{}],[$o,t],[Jl,{isTSX:!0}]],configFile:!1,babelrc:!1};return o===void 0?Al(e,i):Ll(Ui.cloneNode(o,!0),e,i)}function Xo(e,t={}){return To(e,t)}function To(e,t,n){let o=qi(e,t,!1,n);if(!o||o.code==null)throw new Error("memo-dom: compilation produced no output");return o.code}function Ol(e,t={}){return Bo(e,t)}function Bo(e,t,n){let o=qi(e,t,!0,n);if(!o||o.code==null||o.map==null)throw new Error("memo-dom: compilation produced no output or source map");return{code:o.code,map:o.map}}import{posix as Yt}from"node:path";import{parseSync as Ul,transformFromAstSync as ss}from"@babel/core";import as from"@babel/plugin-syntax-jsx";import ls from"@babel/plugin-transform-typescript";import*as z from"@babel/types";function $l(e,t,n){let o=e.get(t);o===void 0&&(o=new Map,e.set(t,o));let r=o.get(n);return r===void 0&&(r={keys:new Set,rootFallback:!1},o.set(n,r)),r}function Xl(e,t,n,o){if(n.type==="state"){o.keys.add(n.key);return}if(n.type==="root"){o.rootFallback=!0;return}if(n.type==="local")return;let r=e.get(t)?.get(n.name);if(r===void 0){o.rootFallback=!0;return}o.rootFallback||=r.rootFallback;let i=n.path.length===0?"":`.${n.path.join(".")}`;for(let s of r.keys)o.keys.add(`${s}${i}`)}function _i(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 o=new Map,r=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=$l(o,a.target,d);for(let m of u)Xl(o,s,m,c)}let l=(r.get(a.target)??1)-1;r.set(a.target,l),l===0&&i.push(a.target)}}return new Map([...o].map(([s,a])=>[s,new Map([...a].map(([l,d])=>[l,{keys:[...d.keys].sort(),rootFallback:d.rootFallback}]))]))}function Tl(e){let t=new Set,n=new Set,o=r=>{if(n.has(r))throw new Error(`memo-dom: recursive cross-module component graph at '${r}'`);if(!t.has(r)){n.add(r);for(let i of e.get(r)?.edges??[])o(i.target);n.delete(r),t.add(r)}};for(let r of e.keys())o(r)}function Gi(e,t){let n=new Map(e.map(c=>[c.key,c]));Tl(n);let o=new Map,r=new Map;for(let c of n.values())for(let m of c.edges){if(!n.has(m.target))throw new Error(`memo-dom: component '${c.key}' references unknown factory '${m.target}'`);let E=o.get(m.target)??new Set;if(E.add(m.mode),o.set(m.target,E),m.mode==="row"){let b=r.get(m.target)??[];b.push({keyPath:m.keyPath===void 0||m.keyPath===null?null:[...m.keyPath],sourceKey:m.sourceKey??"",sourceLocal:m.sourceLocal??!1}),r.set(m.target,b)}}for(let[c,m]of o)if(m.size>1)throw new Error(`memo-dom: component '${c}' is used both as a keyed row and a static child`);let i=new Map,s=[...n.keys()].filter(c=>!o.has(c)),a=t===void 0?s:[t.key];if(t!==void 0&&!n.has(t.key))throw new Error(`memo-dom: mounted component '${t.key}' is missing from the linked component graph`);for(let c of a)i.set(c,new Set([t?.rootId??"App"]));let l=[...a];for(;l.length>0;){let c=l.shift(),m=i.get(c);if(m!==void 0)for(let E of n.get(c)?.edges??[]){let b=i.get(E.target)??new Set,f=b.size;for(let g of m)b.add(`${g}${E.suffix}`);i.set(E.target,b),b.size!==f&&l.push(E.target)}}let d=new Map;for(let c of n.keys())d.set(c,[...i.get(c)??[]].sort());let u=_i(n,a);return{paths:d,rows:r,propSources:u}}import"@babel/types";import*as xe from"@babel/types";function Zi(e){let t=e;for(;xe.isTSAsExpression(t)||xe.isTSTypeAssertion(t)||xe.isTSNonNullExpression(t)||xe.isTSSatisfiesExpression(t);)t=t.expression;return t}function Bl(e,t,n){let o=Zi(n);if(xe.isIdentifier(o))return!e.state.has(o.name)||t.getBinding(o.name)?.scope.path.isProgram()!==!0?null:tt(e,o.name);if(!xe.isMemberExpression(o))return null;let r=Re(o);return r===null||!e.state.has(r)||t.getBinding(r)?.scope.path.isProgram()!==!0?null:tt(e,Pe(o)??r)}function Vl(e,t){let n=Zi(t);if(xe.isIdentifier(n)){let a=Ye(e,n.name);return a===null?null:{type:"prop",name:a,path:[]}}if(!xe.isMemberExpression(n))return null;let o=Re(n),r=Pe(n);if(o===null||r===null)return null;if(qe(e)===o){let[a,...l]=r.split(".").slice(1);return a===void 0?null:{type:"prop",name:a,path:l}}let s=Ye(e,o);return s===null?null:{type:"prop",name:s,path:r.split(".").slice(1)}}function Wl(e,t){let n=!1,o=qe(e);return Oe(t,r=>{xe.isIdentifier(r)&&(r.name===o||Ye(e,r.name)!==null)&&(n=!0)}),n}function zl(e){return xe.isStringLiteral(e)||xe.isNumericLiteral(e)||xe.isBooleanLiteral(e)||xe.isNullLiteral(e)||xe.isBigIntLiteral(e)||xe.isTemplateLiteral(e)}function Kl(e,t,n,o){let r=Bl(e,n,o);if(r!==null)return{type:"state",key:r};let i=e.componentProps.get(t),s=Vl(i,o);if(s!==null)return s;let a=xe.isIdentifier(o)?o.name:xe.isMemberExpression(o)?Re(o):null;return a!==null&&(e.instanceState.get(t)?.has(a)===!0||e.instanceDerivedBindings.get(t)?.has(a)===!0)||yn(e,o).size>0||Wl(i,o)?{type:"root"}:zl(o)?{type:"local"}:{type:"root"}}function Vo(e,t,n,o){let r=e.get(t)??{},i=r[n]??[],s=JSON.stringify(o);i.some(a=>JSON.stringify(a)===s)||(i.push(o),i.sort((a,l)=>JSON.stringify(a).localeCompare(JSON.stringify(l)))),r[n]=i,e.set(t,r)}function Hl(e){return xe.isJSXIdentifier(e.name)?e.name.name:null}function Yi(e,t){let n=new Map;return e.compPaths.get(t).traverse({JSXOpeningElement(o){let r=o.node.name;if(!xe.isJSXIdentifier(r)||!/^[A-Z]/.test(r.name))return;let i=e.componentProps.get(r.name);for(let s of o.get("attributes")){if(s.isJSXSpreadAttribute()){for(let d of i?.names??[])d==="ref"||i?.refProps.includes(d)||Vo(n,r.name,d,{type:"root"});continue}if(!s.isJSXAttribute())continue;let a=Hl(s.node);if(a===null||a==="key"||a==="ref"||i?.refProps.includes(a)===!0)continue;let l=s.node.value;if(!xe.isJSXExpressionContainer(l)||!xe.isExpression(l.expression)){Vo(n,r.name,a,{type:"local"});continue}Vo(n,r.name,a,Kl(e,t,s.scope,l.expression))}}}),n}function Qi(e,t){let n=new Map;return e.traverse({FunctionDeclaration(o){let r=o.node.id?.name;if(r!==void 0&&/^[A-Z]/.test(r)&&o.scope.parent?.path.isProgram()===!0&&$e(o)){let i=Cn(o.node.params);n.set(r,{key:`${t}#${r}`,props:[...i.names],objectProps:i.mode==="object",acceptsUnknownProps:i.acceptsUnknown,hasWholeDefault:i.hasWholeDefault,listLightweight:!1,delegatedEvents:zt(o.node.body),renderProps:[],renderCallbacks:[],refProps:[],subtreeReads:[]})}o.skip()}}),n}function es(e,t,n){let o=e.componentProps.get(n);return{key:`${t}#${n}`,props:[...o.names],objectProps:o.mode==="object",acceptsUnknownProps:o.acceptsUnknown,hasWholeDefault:o.hasWholeDefault,listLightweight:Jn(e,n),delegatedEvents:[...e.componentHostEvents.get(n)??[]],renderProps:[...o.renderProps],renderCallbacks:[...o.renderCallbacks],refProps:[...o.refProps],subtreeReads:[...Bn(e,n)].map(r=>tt(e,r)).sort()}}function Zn(e,t){return e.importedComponents.get(t)?.key??`${e.moduleId}#${t}`}function ts(e,t){let n=[];for(let o of t.comps.keys()){let r=[],i=Yi(t,o);for(let[s,a]of t.childRefCounts.get(o)??[]){let l=Zn(t,s),d=i.get(s);r.push({target:l,suffix:`/${s}`,mode:"static",...d===void 0?{}:{propSources:d}}),a>1&&r.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!==o)continue;let d=i.get(s);r.push({target:Zn(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!==o)continue;let d=i.get(s);r.push({target:Zn(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===o&&r.push({target:Zn(t,s),suffix:`/${l.suffix}/Row[*]`,mode:"row",keyPath:it(l.keyExpr??null,l.itemParam??""),sourceKey:l.sourceLocal===!0?l.sourceKey??"":tt(t,l.sourceKey??""),sourceLocal:l.sourceLocal??!1,...i.get(s)===void 0?{}:{propSources:i.get(s)}});n.push({key:`${e}#${o}`,moduleId:e,local:o,edges:r})}return n}function ds(e){let t=e.replace(/\\/g,"/"),n=Yt.normalize(t);return t.startsWith("./")&&!n.startsWith("../")?`./${n}`:n}function ql(e,t){let n=Ul(t,{filename:e,sourceType:"module",parserOpts:{plugins:["typescript","jsx"]},configFile:!1,babelrc:!1});if(n===null)throw new Error(`memo-dom: failed to parse module '${e}'`);return n}function cs(e,t="App"){return{...e.runtimePath===void 0?{}:{runtimePath:e.runtimePath},...e.hot===void 0?{}:{hot:e.hot},rootId:t}}function _l(e){let t=new Map,n=(o,r,i)=>{t.set(`${o}\0${r}\0${i}`,{target:o,prop:r,kind:i})};for(let[o,r]of e.compPaths)r.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)&&(fe(c.expression)||dt(e,o,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((o,r)=>o.target.localeCompare(r.target)||o.prop.localeCompare(r.prop)||o.kind.localeCompare(r.kind))}function ns(e,t){return[...new Set(t.flatMap(n=>{let o=e.importedComponents.get(n);return o!==void 0?[o.key]:e.comps.has(n)?[`${e.moduleId}#${n}`]:[]}))].sort()}function Mt(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)){Mt(e.consequent,t,n),Mt(e.alternate,t,n);return}if(z.isLogicalExpression(e)){Mt(e.right,t,n);return}if(z.isObjectExpression(e)){for(let o of e.properties)z.isObjectProperty(o)&&z.isExpression(o.value)&&Mt(o.value,t,n);return}if(z.isArrayExpression(e))for(let o of e.elements)o!=null&&!z.isSpreadElement(o)&&Mt(o,t,n)}function os(e,t){let n=new Set;if(z.isExpression(e.body))return Mt(e.body,t,n),[...n];let o=r=>{if(!z.isFunction(r)){if(z.isReturnStatement(r)){z.isExpression(r.argument)&&Mt(r.argument,t,n);return}for(let i of z.VISITOR_KEYS[r.type]??[]){let s=r[i];if(Array.isArray(s))for(let a of s)a!=null&&typeof a=="object"&&"type"in a&&o(a);else s!=null&&typeof s=="object"&&"type"in s&&o(s)}}};for(let r of e.body.body)o(r);return[...n]}function us(e){let t=[];for(let n of e.body)if(!(!z.isImportDeclaration(n)||n.importKind==="type"))for(let o of n.specifiers)if(z.isImportSpecifier(o)){if(o.importKind==="type")continue;let r=z.isIdentifier(o.imported)?o.imported.name:o.imported.value;t.push({local:o.local.name,imported:r,source:n.source.value})}else z.isImportDefaultSpecifier(o)?t.push({local:o.local.name,imported:"default",source:n.source.value}):t.push({local:o.local.name,imported:"*",source:n.source.value});return t}function ps(e,t){let n=new Set;for(let r of e.body)if(!(!z.isImportDeclaration(r)||r.source.value!==t))for(let i of r.specifiers)z.isImportSpecifier(i)&&(z.isIdentifier(i.imported,{name:"mount"})||z.isStringLiteral(i.imported,{value:"mount"}))&&n.add(i.local.name);let o=[];for(let r of e.body){if(!z.isExpressionStatement(r))continue;let i=r.expression;if(!z.isCallExpression(i)||!z.isIdentifier(i.callee)||!n.has(i.callee.name))continue;let s=i.arguments[1];if(s===void 0||!z.isIdentifier(s))throw new Error("memo-dom: mount() must receive a statically imported component identifier");o.push(s.name)}return o}function fs(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 o=n.declaration;if(z.isVariableDeclaration(o))for(let r of o.declarations)z.isIdentifier(r.id)&&t.set(r.id.name,r.id.name);else z.isFunctionDeclaration(o)&&o.id!=null&&t.set(o.id.name,o.id.name);for(let r of n.specifiers){if(!z.isExportSpecifier(r))continue;let i=r.local.name,s=z.isIdentifier(r.exported)?r.exported.name:r.exported.value;t.set(s,i)}}return t}function Gl(e,t,n,o){let r,i=()=>({visitor:{Program(s){gn(s);let a=us(s.node),l=En({...cs(n,o),moduleId:e.id,linkedImports:t});Xn(l,s),hn(l,s),Wn(l,s),ln(l);let d={},u=go(s.node);for(let[c,m]of fs(s.node)){if(l.comps.has(m)){d[c]={type:"component",...es(l,e.id,m)};continue}let E=l.state.get(m);if(E!==void 0){d[c]={type:"state",kind:E,key:l.stateKeys.get(m)??`${e.id}#${m}`,tagCandidates:[...l.stateTagCandidates.get(m)??[]],componentCandidates:ns(l,l.stateComponentCandidates.get(m)??[])};continue}let b=l.importedFunctions.get(m)??(l.helpers.has(m)?Be(l,m):void 0);b!==void 0&&(d[c]={type:"function",tagCandidates:[...u.get(m)??l.functionTagCandidates.get(m)??[]],componentCandidates:ns(l,l.functionComponentCandidates.get(m)??[]),reads:[...b.reads].map(f=>tt(l,f)).sort(),writes:[...b.writes].map(f=>tt(l,f)).sort(),boundedWrites:[...b.boundedWrites].map(f=>tt(l,f)).sort(),parameterWrites:b.parameterWrites.map(f=>({index:f.index,path:[...f.path]})).sort((f,g)=>f.index-g.index||f.path.join(".").localeCompare(g.path.join("."))),unbounded:b.unbounded})}r={exports:d,imports:a,mounts:ps(s.node,n.runtimePath??"@memoized-dom/runtime"),components:ts(e.id,l),componentUsages:_l(l),readers:Object.fromEntries([...l.readers.entries()].sort(([c],[m])=>c.localeCompare(m)).map(([c,m])=>[c,[...m].sort()]))}}}});if(ss(z.cloneNode(e.ast,!0),e.source,{filename:e.id,plugins:[[as,{}],i,[ls,{isTSX:!0}]],configFile:!1,babelrc:!1}),r===void 0)throw new Error(`memo-dom: failed to analyze module '${e.id}'`);return r}function Zl(e,t){let n,o=()=>({visitor:{Program(r){gn(r);let i=new Map,s=Tn(r.node),a=go(r.node),l=Qi(r,e.id),d=new Set(l.keys());for(let[c,m]of l)i.set(c,{type:"component",...m});for(let c of r.node.body){let m=z.isExportNamedDeclaration(c)?c.declaration:c;if(z.isVariableDeclaration(m))for(let E of m.declarations){if(!z.isIdentifier(E.id))continue;let b=E.init!==null&&z.isExpression(E.init)?$t(E.init):E.init;if(z.isArrowFunctionExpression(b)||z.isFunctionExpression(b)){let g=os(b,d).map(h=>`${e.id}#${h}`);i.set(E.id.name,{type:"function",tagCandidates:[...a.get(E.id.name)??[]],componentCandidates:g,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0});continue}let f;if(m.kind==="let"||m.kind==="var"?f="let":Dt(b)?f="store":Lt(b)&&(f="const"),f!==void 0){let g=new Set;z.isExpression(b)&&Mt(b,d,g),i.set(E.id.name,{type:"state",kind:f,key:`${e.id}#${E.id.name}`,tagCandidates:[...s.get(E.id.name)??[]],componentCandidates:[...g].map(h=>`${e.id}#${h}`)})}}else if(z.isFunctionDeclaration(m)&&m.id!=null&&!l.has(m.id.name)){let E=os(m,d).map(b=>`${e.id}#${b}`);i.set(m.id.name,{type:"function",tagCandidates:[...a.get(m.id.name)??[]],componentCandidates:E,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0})}}let u={};for(let[c,m]of fs(r.node)){let E=i.get(m);E!==void 0&&(u[c]=E)}n={exports:u,imports:us(r.node),mounts:ps(r.node,t.runtimePath??"@memoized-dom/runtime"),components:[],componentUsages:[],readers:{}}}}});if(ss(z.cloneNode(e.ast,!0),e.source,{filename:e.id,plugins:[[as,{}],o,[ls,{isTSX:!0}]],configFile:!1,babelrc:!1}),n===void 0)throw new Error(`memo-dom: failed to discover module '${e.id}'`);return n}function Yn(e,t,n,o){let i=o.resolveImport?.(t,e);if(i===void 0){let l=Object.entries(o.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=Yt.normalize(Yt.join(Yt.dirname(e),t));i=e.startsWith("./")&&!l.startsWith("../")?`./${l}`:l}else i=t;let s=ds(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 rs(e,t,n){let o=[];for(let r of e.values()){let i=t.get(r.id);for(let s of i.mounts){let a=i.imports.find(c=>c.local===s);if(a===void 0||a.imported==="*")throw new Error(`memo-dom: mount root '${s}' must be a statically imported component`);let l=Yn(r.id,a.source,e,n),d=l===void 0?void 0:t.get(l.id)?.exports[a.imported];if(l===void 0||d?.type!=="component")throw new Error(`memo-dom: mount root '${s}' does not resolve to a compiled component`);let u=d.key.slice(d.key.lastIndexOf("#")+1);o.push({key:d.key,moduleId:l.id,mountModuleId:r.id,local:u,rootId:u})}}if(o.length>1)throw new Error("memo-dom: one connected application graph may contain only one top-level mount() call");return o[0]}function Yl(e,t){if(!t.startsWith("."))return t;let n=Yt.relative(Yt.dirname(e),t);return n.startsWith(".")?n:`./${n}`}function Wo(e,t,n){return t.map(o=>{for(let[r,i]of n)for(let[s,a]of Object.entries(i.exports))if(!(a.type!=="component"||a.key!==o))return{key:a.key,source:Yl(e.id,r),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 '${o}' is not exported; export the component so consuming modules can link it`)})}function ms(e,t,n,o,r,i){let s={};for(let a of t.imports){let l=Yn(e.id,a.source,o,r);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:Wo(e,d.componentCandidates,n)};else if(d.type==="component"){let u=i?.get(d.key),c=d.renderProps.filter(m=>u?.scalar.has(m)!==!0||u.jsx.has(m));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{if(r.linkFunctionSummaries===!1){s[a.local]={type:"function",tagCandidates:[...d.tagCandidates],componentCandidates:Wo(e,d.componentCandidates,n),reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}s[a.local]={type:"function",tagCandidates:[...d.tagCandidates],componentCandidates:Wo(e,d.componentCandidates,n),reads:[...d.reads],writes:[...d.writes],boundedWrites:[...d.boundedWrites],parameterWrites:[...d.parameterWrites],unbounded:d.unbounded}}}return s}function is(e){return JSON.stringify(e)}function Ql(e,t,n){let o=new Map;for(let r of e.keys())o.set(r,new Set);for(let r of e.values()){let i=t.get(r.id);for(let s of i.imports){let a=Yn(r.id,s.source,e,n);a!==void 0&&o.get(a.id).add(r.id)}}return o}function ed(e,t,n,o){let r=new Map(t),i=Ql(e,r,n),s=[...e.keys()],a=new Set(s),l=Math.max(16,e.size*e.size*4),d=0;for(;s.length>0;){let u=s.shift();a.delete(u);let c=e.get(u),m=r.get(u),E=ms(c,m,r,e,n),b=Gl(c,E,n,o);if(d++,d>l)throw new Error("memo-dom: cross-module export summaries did not converge");if(is(b)!==is(m)){r.set(u,b);for(let f of i.get(u)??[])a.has(f)||(a.add(f),s.push(f))}}return r}function gs(e,t,n){let o=new Map;for(let[g,h]of Object.entries(e)){let C=ds(g);if(o.has(C))throw new Error(`memo-dom: duplicate module id after normalization: '${C}'`);o.set(C,{originalId:g,id:C,source:h,ast:ql(C,h)})}let r=new Map;for(let g of o.values())r.set(g.id,Zl(g,t));let s=rs(o,r,t)?.rootId??"App",a=ed(o,r,t,s),l=rs(o,a,t),d=[...o.values()].flatMap(g=>{try{return Ti(g.ast,g.id)}catch(h){throw new Error(`${g.id}: memo-dom: ${h.message}`)}});try{Jo(d)}catch(g){throw new Error(`memo-dom: ${g.message}`)}let u=l?.moduleId??o.values().next().value?.id,c=new Map;for(let g of a.values())for(let h of g.componentUsages){let C=c.get(h.target);C===void 0&&(C={jsx:new Set,scalar:new Set},c.set(h.target,C)),C[h.kind].add(h.prop)}for(let[g,h]of c)for(let C of h.jsx)if(h.scalar.has(C))throw new Error(`memo-dom: component '${g}' prop '${C}' is used as both scalar data and JSX content; split the prop or component contract`);let m=Gi([...a.values()].flatMap(g=>g.components),l),E={},b={},f={};for(let g of o.values()){let h=a.get(g.id);f[g.originalId]={componentExports:Object.entries(h.exports).filter(R=>R[1].type==="component").map(([R,k])=>({exported:R,local:h.components.find(W=>W.key===k.key)?.local??k.key.slice(k.key.lastIndexOf("#")+1),listLightweight:k.listLightweight})).sort((R,k)=>R.local.localeCompare(k.local)),stateExports:Object.entries(h.exports).filter(R=>R[1].type==="state").map(([R,k])=>({exported:R,kind:k.kind,key:k.key})).sort((R,k)=>R.exported.localeCompare(k.exported)),functionExports:Object.entries(h.exports).filter(R=>R[1].type==="function").map(([R,k])=>({exported:R,reads:[...k.reads],writes:[...k.writes],boundedWrites:[...k.boundedWrites],parameterWrites:k.parameterWrites.map(W=>({index:W.index,path:[...W.path]})),unbounded:k.unbounded})).sort((R,k)=>R.exported.localeCompare(k.exported)),readers:Object.fromEntries(Object.entries(h.readers).map(([R,k])=>[R,[...k]]))};let C=ms(g,h,a,o,t,c);for(let R of h.imports){let k=Yn(g.id,R.source,o,t);if(k!==void 0&&a.get(k.id)?.exports[R.imported]===void 0)throw new Error(`memo-dom: '${R.imported}' is not a linkable state, function, or component export of '${R.source}'`)}let N={},v={},$={},_={};for(let R of h.components){N[R.local]=[...m.paths.get(R.key)??[]];let k=m.rows.get(R.key);k!==void 0&&(v[R.local]=k.map(ee=>({keyPath:ee.keyPath===null?null:[...ee.keyPath],sourceKey:ee.sourceKey,sourceLocal:ee.sourceLocal})));let W=m.propSources.get(R.key);W!==void 0&&($[R.local]=Object.fromEntries([...W].map(([ee,oe])=>[ee,{keys:[...oe.keys],rootFallback:oe.rootFallback}])));let T=Object.values(h.exports).find(ee=>ee.type==="component"&&ee.key===R.key);if(T?.type==="component"){let ee=c.get(R.key);_[R.local]=T.renderProps.filter(oe=>ee?.scalar.has(oe)!==!0||ee.jsx.has(oe))}}let B={...cs(t,s),moduleId:g.id,linkedImports:C,linkedComponentPaths:N,linkedComponentRows:v,linkedComponentPropSources:$,linkedComponentRenderProps:_,linkedRoutes:d,emitRouteManifest:g.id===u,...l?.moduleId===g.id?{rootComponent:l.local}:{}};if(n){let R=Bo(g.source,B,g.ast);E[g.originalId]=R.code,b[g.originalId]=R.map}else E[g.originalId]=To(g.source,B,g.ast)}return{output:E,maps:b,metadata:f,...l===void 0?{}:{applicationRoot:l}}}function td(e,t={}){return gs(e,t,!0)}function zo(e,t={}){return gs(e,t,!1).output}var Es=98e3,hs="memoized-dom",nd=/\x1B\[[0-?]*[ -/]*[@-~]/g;function od(e){return e.replace(nd,"")}function bs(e){return e.replaceAll("\\","/").replace(/^\.\//,"")}function rd(e,t){let n=bs(e);return[...t].sort((o,r)=>r.length-o.length).find(o=>n.endsWith(bs(o)))}function Ko(e,t=[]){let n=e,o=od(typeof n?.message=="string"?n.message:String(e)),r=o.indexOf(": memo-dom:"),i=o.match(/\((\d+):(\d+)\)/),s=n?.loc,a=typeof s?.line=="number"?s.line:i===null?void 0:Number(i[1]),l=typeof s?.column=="number"?s.column:i===null?void 0:Number(i[2]),d=r===-1?"":o.slice(0,r),u=rd(d,t)??(t.length===1?t[0]:void 0),c=r===-1?o:o.slice(r+2);return{code:Es,source:hs,severity:"error",message:c,...u===void 0?{}:{moduleId:u},...a===void 0?{}:{line:a},...l===void 0?{}:{column:l}}}function id(e,t={}){try{return Xo(e,t),[]}catch(n){return[Ko(n,[t.moduleId??"./component.tsx"])]}}function sd(e,t={}){try{return zo(e,t),[]}catch(n){return[Ko(n,Object.keys(e))]}}export{Xo as compile,Ol as compileDetailed,zo as compileModules,td as compileModulesDetailed,Es as compilerDiagnosticCode,hs as compilerDiagnosticSource,id as diagnose,sd as diagnoseModules,Ko as toCompilerDiagnostic};
|