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