@memoized-dom/compiler 0.0.1
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 +28 -0
- package/dist/analysis/access-table.d.ts +5 -0
- package/dist/analysis/access-table.d.ts.map +1 -0
- package/dist/analysis/component-graph.d.ts +10 -0
- package/dist/analysis/component-graph.d.ts.map +1 -0
- package/dist/analysis/component-reads.d.ts +10 -0
- package/dist/analysis/component-reads.d.ts.map +1 -0
- package/dist/analysis/computed.d.ts +11 -0
- package/dist/analysis/computed.d.ts.map +1 -0
- package/dist/analysis/instance-control-flow.d.ts +9 -0
- package/dist/analysis/instance-control-flow.d.ts.map +1 -0
- package/dist/analysis/instance.d.ts +9 -0
- package/dist/analysis/instance.d.ts.map +1 -0
- package/dist/analysis/runtime-pattern.d.ts +9 -0
- package/dist/analysis/runtime-pattern.d.ts.map +1 -0
- package/dist/analysis/slot-paths.d.ts +11 -0
- package/dist/analysis/slot-paths.d.ts.map +1 -0
- package/dist/analysis/type-candidates.d.ts +14 -0
- package/dist/analysis/type-candidates.d.ts.map +1 -0
- package/dist/analysis.d.ts +52 -0
- package/dist/analysis.d.ts.map +1 -0
- package/dist/compile.d.ts +17 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/component-linker.d.ts +32 -0
- package/dist/component-linker.d.ts.map +1 -0
- package/dist/components/callback-props.d.ts +14 -0
- package/dist/components/callback-props.d.ts.map +1 -0
- package/dist/components/calls.d.ts +17 -0
- package/dist/components/calls.d.ts.map +1 -0
- package/dist/components/children.d.ts +43 -0
- package/dist/components/children.d.ts.map +1 -0
- package/dist/components/declarations.d.ts +16 -0
- package/dist/components/declarations.d.ts.map +1 -0
- package/dist/components/jsx-values.d.ts +7 -0
- package/dist/components/jsx-values.d.ts.map +1 -0
- package/dist/components/local-derived.d.ts +6 -0
- package/dist/components/local-derived.d.ts.map +1 -0
- package/dist/components/manifest.d.ts +31 -0
- package/dist/components/manifest.d.ts.map +1 -0
- package/dist/components/prop-effects.d.ts +11 -0
- package/dist/components/prop-effects.d.ts.map +1 -0
- package/dist/components/prop-linker.d.ts +8 -0
- package/dist/components/prop-linker.d.ts.map +1 -0
- package/dist/components/prop-origins.d.ts +17 -0
- package/dist/components/prop-origins.d.ts.map +1 -0
- package/dist/components/prop-projections.d.ts +5 -0
- package/dist/components/prop-projections.d.ts.map +1 -0
- package/dist/components/props.d.ts +73 -0
- package/dist/components/props.d.ts.map +1 -0
- package/dist/components/ref-props.d.ts +11 -0
- package/dist/components/ref-props.d.ts.map +1 -0
- package/dist/components/render-callbacks.d.ts +19 -0
- package/dist/components/render-callbacks.d.ts.map +1 -0
- package/dist/components/render-functions.d.ts +4 -0
- package/dist/components/render-functions.d.ts.map +1 -0
- package/dist/components/render-prelude.d.ts +13 -0
- package/dist/components/render-prelude.d.ts.map +1 -0
- package/dist/components/return-plan.d.ts +27 -0
- package/dist/components/return-plan.d.ts.map +1 -0
- package/dist/conds.d.ts +21 -0
- package/dist/conds.d.ts.map +1 -0
- package/dist/context/ast.d.ts +51 -0
- package/dist/context/ast.d.ts.map +1 -0
- package/dist/context/model.d.ts +309 -0
- package/dist/context/model.d.ts.map +1 -0
- package/dist/context.d.ts +9 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/effects.d.ts +26 -0
- package/dist/effects.d.ts.map +1 -0
- package/dist/emission/component.d.ts +12 -0
- package/dist/emission/component.d.ts.map +1 -0
- package/dist/emission/conditional-region.d.ts +13 -0
- package/dist/emission/conditional-region.d.ts.map +1 -0
- package/dist/emission/dom-template.d.ts +11 -0
- package/dist/emission/dom-template.d.ts.map +1 -0
- package/dist/emission/list-region.d.ts +10 -0
- package/dist/emission/list-region.d.ts.map +1 -0
- package/dist/emission/node-emitter.d.ts +8 -0
- package/dist/emission/node-emitter.d.ts.map +1 -0
- package/dist/emission/render-callback.d.ts +14 -0
- package/dist/emission/render-callback.d.ts.map +1 -0
- package/dist/emission/scope.d.ts +47 -0
- package/dist/emission/scope.d.ts.map +1 -0
- package/dist/emit.d.ts +29 -0
- package/dist/emit.d.ts.map +1 -0
- package/dist/handler-commits.d.ts +30 -0
- package/dist/handler-commits.d.ts.map +1 -0
- package/dist/handler-origin.d.ts +13 -0
- package/dist/handler-origin.d.ts.map +1 -0
- package/dist/handlers/analyze.d.ts +4 -0
- package/dist/handlers/analyze.d.ts.map +1 -0
- package/dist/handlers/local-calls.d.ts +11 -0
- package/dist/handlers/local-calls.d.ts.map +1 -0
- package/dist/handlers.d.ts +40 -0
- package/dist/handlers.d.ts.map +1 -0
- package/dist/helper-summaries.d.ts +12 -0
- package/dist/helper-summaries.d.ts.map +1 -0
- package/dist/identifiers.d.ts +29 -0
- package/dist/identifiers.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/jsx/attributes.d.ts +24 -0
- package/dist/jsx/attributes.d.ts.map +1 -0
- package/dist/jsx/children.d.ts +32 -0
- package/dist/jsx/children.d.ts.map +1 -0
- package/dist/jsx/dom-attributes.d.ts +13 -0
- package/dist/jsx/dom-attributes.d.ts.map +1 -0
- package/dist/jsx/dynamic-tags.d.ts +20 -0
- package/dist/jsx/dynamic-tags.d.ts.map +1 -0
- package/dist/jsx/events.d.ts +4 -0
- package/dist/jsx/events.d.ts.map +1 -0
- package/dist/jsx/refs.d.ts +15 -0
- package/dist/jsx/refs.d.ts.map +1 -0
- package/dist/jsx/svg.d.ts +11 -0
- package/dist/jsx/svg.d.ts.map +1 -0
- package/dist/lifecycle.d.ts +31 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/linker.d.ts +19 -0
- package/dist/linker.d.ts.map +1 -0
- package/dist/lists/calculated-sources.d.ts +8 -0
- package/dist/lists/calculated-sources.d.ts.map +1 -0
- package/dist/lists/map-site.d.ts +50 -0
- package/dist/lists/map-site.d.ts.map +1 -0
- package/dist/lists/source-shapes.d.ts +6 -0
- package/dist/lists/source-shapes.d.ts.map +1 -0
- package/dist/lists.d.ts +7 -0
- package/dist/lists.d.ts.map +1 -0
- package/dist/module-control-flow.d.ts +8 -0
- package/dist/module-control-flow.d.ts.map +1 -0
- package/dist/mutation-analysis.d.ts +42 -0
- package/dist/mutation-analysis.d.ts.map +1 -0
- package/dist/plugin.d.ts +27 -0
- package/dist/plugin.d.ts.map +1 -0
- package/package.json +30 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{transformSync as ia}from"@babel/core";import sa from"@babel/plugin-syntax-jsx";import aa from"@babel/plugin-transform-typescript";import*as j from"@babel/types";import"@babel/types";function Yt(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[y,p]of Object.entries(e.linkedImports??{}))p.type==="state"?(n.set(y,p.kind),o.set(y,p.key),p.tagCandidates!==void 0&&r.set(y,[...p.tagCandidates]),p.componentCandidates!==void 0&&l.set(y,p.componentCandidates.map(f=>({...f}))),d.add(y)):p.type==="function"?(p.tagCandidates!==void 0&&i.set(y,[...p.tagCandidates]),p.componentCandidates!==void 0&&l.set(y,p.componentCandidates.map(f=>({...f}))),u.set(y,{reads:new Set(p.reads),writes:new Set(p.writes),boundedWrites:new Set(p.boundedWrites),parameterWrites:p.parameterWrites.map(f=>({index:f.index,path:[...f.path]})),unbounded:p.unbounded})):c.set(y,{...p,props:[...p.props]});let g=new Map;for(let[y,p]of c)g.set(y,{mode:p.objectProps?"object":"positional",names:[...p.props],acceptsUnknown:p.acceptsUnknownProps,bindings:[],params:[],hasWholeDefault:p.hasWholeDefault,renderProps:[...p.renderProps??[]],renderCallbacks:[...p.renderCallbacks??[]],refProps:[...p.refProps??[]]});let S=new Map(Object.entries(e.linkedComponentRenderProps??{}).map(([y,p])=>[y,[...p]]));return{runtimePath:e.runtimePath??"@memoized-dom/runtime",rootId:e.rootId??"App",moduleId:t,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(([y,p])=>[y,[...p]])),linkedComponentRows:new Map(Object.entries(e.linkedComponentRows??{}).map(([y,p])=>[y,p.map(f=>({keyPath:f.keyPath===null?null:[...f.keyPath],sourceKey:f.sourceKey,sourceLocal:f.sourceLocal}))])),linkedComponentPropSources:new Map(Object.entries(e.linkedComponentPropSources??{}).map(([y,p])=>[y,new Map(Object.entries(p).map(([f,v])=>[f,{keys:[...v.keys],rootFallback:v.rootFallback}]))])),comps:new Map,compPaths:new Map,helpers:new Map,jsxHelpers:new Map,helperSummaries:new Map,compReads:new Map,childRefCounts:new Map,renderSlotOwners:new Set,listedSites:new Map,componentsWithHostEvents:new Set,conditionalComponentSites:new Map,rowComponentSites:new Map,componentProps:g,linkedComponentRenderProps:S,lightweightCache:new Map,rowReads:new Map,condReads:new Map,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 q from"@babel/types";import*as nt from"@babel/types";var Fn=class{constructor(t,n){this.scope=t;xi(n.node,o=>this.reserved.add(o)),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 nt.identifier(n)}runtimeMember(t){return nt.memberExpression(nt.identifier(this.runtimeId),nt.identifier(t))}};function Qt(e,t){let n=new Fn(t.scope,t);return e.identifiers=n,n}function $(e,t){return xt(e).generate(t)}function Le(e,t){return xt(e).componentId(t)}function Z(e,t){return xt(e).runtimeMember(t)}function xt(e){if(e.identifiers===null)throw new Error("memo-dom: generated identifier allocator was not initialized");return e.identifiers}function xi(e,t){let n=o=>{nt.isIdentifier(o)&&t(o.name);for(let r of nt.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 pt(e,t,n){e.state.set(t,n),e.stateKeys.has(t)||e.stateKeys.set(t,`${e.moduleId}#${t}`)}function Ue(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 Ot(e,t){let n=[...new Set(t.map(s=>Ue(e,s)))].sort(),o=n.join(" "),r=e.writeConsts.get(o);if(r!==void 0)return q.identifier(r);let i=$(e,`WRITES_${e.writeConstCounter++}`);return e.writeConsts.set(o,i.name),e.header.push(q.variableDeclaration("const",[q.variableDeclarator(i,q.arrayExpression(n.map(s=>q.stringLiteral(s))))])),i}function bo(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 q.identifier(r);let i=$(e,`REASONS_${e.reasonConstCounter++}`);return e.reasonConsts.set(o,i.name),e.header.push(q.variableDeclaration("const",[q.variableDeclarator(i,q.arrayExpression(n.map(s=>q.numericLiteral(s))))])),i}function ye(e){let t=[],n=e;for(;q.isMemberExpression(n);){if(n.computed){if(!q.isStringLiteral(n.property))return null;t.unshift(n.property.value)}else{if(!q.isIdentifier(n.property))return null;t.unshift(n.property.name)}if(q.isSuper(n.object))return null;n=n.object}for(;q.isTSNonNullExpression(n)||q.isTSAsExpression(n);)n=n.expression;return q.isIdentifier(n)?(t.unshift(n.name),t.join(".")):null}function at(e,t){if(e===null)return[];let n=[],o=e;for(;q.isMemberExpression(o)&&!o.computed;){if(!q.isIdentifier(o.property)||(n.unshift(o.property.name),q.isSuper(o.object)))return null;o=o.object}return!q.isIdentifier(o,{name:t})||n.length===0?null:n}function Rn(e,t){return t===null?!0:t.length===0||e.length>t.length?!1:e.every((n,o)=>t[o]===n)}function Pe(e){let t=e;for(;;){if(q.isMemberExpression(t)){if(q.isSuper(t.object))return null;t=t.object;continue}if(q.isTSNonNullExpression(t)||q.isTSAsExpression(t)){t=t.expression;continue}break}return q.isIdentifier(t)?t.name:null}function Ct(e){return!e||!q.isObjectExpression(e)?!1:e.properties.every(t=>q.isObjectProperty(t)&&!t.computed&&(q.isIdentifier(t.key)||q.isStringLiteral(t.key)))}function Pt(e){return e?q.isArrayExpression(e)||q.isNewExpression(e):!1}function $e(e){return e==null?null:q.isStringLiteral(e)?e:q.isJSXExpressionContainer(e)?q.isJSXEmptyExpression(e.expression)?null:e.expression:null}function Dn(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(q.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 q.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 ho(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 Xe(t,i=>q.isIdentifier(i)&&o.has(i.name)?(r=!0,!1):r?!1:void 0),r}function Xe(e,t){let n=(o,r)=>{if(t(o,r)!==!1)for(let i of q.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 ue(e){let t=!1;return Xe(e,n=>{(q.isJSXElement(n)||q.isJSXFragment(n))&&(t=!0)}),t}function en(e,t){let n=new Set;return Xe(t,o=>{if(q.isJSXAttribute(o)&&q.isJSXIdentifier(o.name,{name:"ref"}))return!1;q.isIdentifier(o)&&e.state.has(o.name)&&n.add(o.name)}),n}import*as k from"@babel/types";import*as ce from"@babel/types";import*as Ke from"@babel/types";function tn(e){let t=Ke.cloneNode(e,!0);return Ke.traverseFast(t,n=>{(Ke.isIdentifier(n)||Ke.isObjectPattern(n)||Ke.isArrayPattern(n)||Ke.isRestElement(n)||Ke.isAssignmentPattern(n))&&(n.typeAnnotation=null)}),t}import*as xe from"@babel/types";import*as U from"@babel/types";function nn(e){if(e.some(i=>U.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=ft(t[0]);if(t.length===1&&(U.isObjectPattern(n)||U.isIdentifier(n)&&n.name==="props"))return{mode:"object",names:U.isObjectPattern(n)?Ci(n):[],acceptsUnknown:U.isIdentifier(n)||n.properties.some(s=>U.isRestElement(s)),bindings:Tt(n),params:t.map(s=>U.cloneNode(s)),hasWholeDefault:U.isAssignmentPattern(t[0]),renderProps:[],renderCallbacks:[],refProps:[]};let r=[];for(let i of t){let s=ft(i);if(!U.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=>Tt(ft(i))),params:t.map(i=>U.cloneNode(i)),hasWholeDefault:!1,renderProps:[],renderCallbacks:[],refProps:[]}}function Eo(e,t){return e.params.length===0?null:U.variableDeclaration("let",e.params.map((n,o)=>U.variableDeclarator(Pi(ft(n)),xo(n,t[o]??U.identifier("undefined")))))}function Mn(e,t){return e.params.map((n,o)=>U.expressionStatement(U.assignmentExpression("=",Co(ft(n)),xo(n,t[o]??U.identifier("undefined")))))}function yo(e){return U.expressionStatement(U.assignmentExpression("=",Co(e.target),U.cloneNode(e.source)))}function Tt(e){return Object.keys(U.getBindingIdentifiers(e))}function Be(e){if(e.mode!=="object"||e.params.length!==1)return null;let t=ft(e.params[0]);return U.isIdentifier(t)?t.name:null}function on(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=ft(e.params[0]);if(!U.isObjectPattern(n))return null;for(let o of n.properties){if(!U.isObjectProperty(o)||o.computed||(U.isIdentifier(o.key)?o.key.name:U.isStringLiteral(o.key)?o.key.value:null)!==t)continue;let i=U.isAssignmentPattern(o.value)?o.value.left:o.value;return U.isIdentifier(i)?i.name:null}return null}function He(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=ft(e.params[0]);if(!U.isObjectPattern(n))return null;for(let o of n.properties)if(!(!U.isObjectProperty(o)||o.computed)&&Object.keys(U.getBindingIdentifiers(o.value)).includes(t)){if(U.isIdentifier(o.key))return o.key.name;if(U.isStringLiteral(o.key))return o.key.value}return null}function ft(e){if(U.isRestElement(e))throw new Error("rest component parameters are not supported");let t=U.isAssignmentPattern(e)?e.left:e;if(!U.isIdentifier(t)&&!U.isObjectPattern(t)&&!U.isArrayPattern(t))throw new Error("unsupported component parameter target");return t}function So(e){let t=U.cloneNode(e);return Bt(t),t}function xo(e,t){return U.isAssignmentPattern(e)?U.conditionalExpression(U.binaryExpression("===",U.cloneNode(t),U.identifier("undefined")),U.cloneNode(e.right),U.cloneNode(t)):U.cloneNode(t)}function Ci(e){let t=[];for(let n of e.properties)if(!U.isRestElement(n)){if(n.computed)throw new Error("computed keys are not supported in component prop patterns");if(U.isIdentifier(n.key))t.push(n.key.name);else if(U.isStringLiteral(n.key))t.push(n.key.value);else throw new Error("component prop pattern keys must be identifiers or strings")}return t}function Pi(e){let t=U.cloneNode(e);return Bt(t),t}function Co(e){let t=U.cloneNode(e);return Bt(t),t}function Bt(e){let t=e;"typeAnnotation"in t&&(t.typeAnnotation=null),"optional"in t&&(t.optional=null);for(let n of U.VISITOR_KEYS[e.type]??[]){let o=e[n];if(Array.isArray(o))for(let r of o)r&&typeof r=="object"&&"type"in r&&Bt(r);else o&&typeof o=="object"&&"type"in o&&Bt(o)}}function Po(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&&xe.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()||!xe.isJSXIdentifier(a.node.name))return!1;let l=xe.isJSXIdentifier(s.node.name)?s.node.name.name:s.node.name.name.name;return e.componentProps.get(a.node.name.name)?.renderCallbacks.includes(l)===!0||/^[A-Z]/.test(a.node.name.name)}function wi(e){return xe.isMemberExpression(e.callee)&&!e.callee.computed&&xe.isIdentifier(e.callee.property,{name:"map"})}function vi(e,t,n){let o=e.componentProps.get(t);if(o===void 0)return null;let r=Be(o);return r!==null&&xe.isMemberExpression(n)&&!n.computed&&xe.isIdentifier(n.object,{name:r})&&xe.isIdentifier(n.property)?n.property.name:xe.isIdentifier(n)?He(o,n.name)??(on(o,n.name)!==null?n.name:null):null}function ki(e){return xe.isExpression(e.body)?e.body:e.body.body.length===1&&xe.isReturnStatement(e.body.body[0])&&xe.isExpression(e.body.body[0].argument)?e.body.body[0].argument:null}function Ft(e,t,n){if(!wi(n)||n.arguments.length!==1)return null;let o=n.arguments[0];if(!xe.isArrowFunctionExpression(o))return null;let r=ki(o);if(r===null||!xe.isCallExpression(r)||!xe.isExpression(r.callee)||r.arguments.some(s=>!xe.isExpression(s)))return null;let i=vi(e,t,r.callee);return i===null?null:{propName:i,target:xe.cloneNode(r.callee,!0),arguments:r.arguments.map(s=>xe.cloneNode(s,!0))}}function wo(e){for(let[t,n]of e.compPaths){let o=e.componentProps.get(t);n.traverse({CallExpression(r){let i=Ft(e,t,r.node);i!==null&&!o.renderCallbacks.includes(i.propName)&&o.renderCallbacks.push(i.propName)}})}}import*as ke from"@babel/types";function Ln(e){for(;ke.isTSAsExpression(e)||ke.isTSTypeAssertion(e)||ke.isTSNonNullExpression(e)||ke.isTSInstantiationExpression(e);)e=e.expression;return e}function rn(e){let t=Ln(e);return ke.isArrayExpression(t)&&t.elements.every(n=>n!==null&&!ke.isSpreadElement(n)&&(ke.isStringLiteral(n)||ke.isNumericLiteral(n)||ke.isBooleanLiteral(n)||ke.isNullLiteral(n)||ke.isBigIntLiteral(n)))}function Oe(e){if(!ce.isCallExpression(e))return null;let t=e.callee;return ce.isMemberExpression(t)&&!t.computed&&ce.isIdentifier(t.property,{name:"map"})?e:null}function De(e){let t=!1;return e.traverse({JSXElement(){t=!0},JSXFragment(){t=!0}}),t}function wt(e,t,n,o,r,i){let s=g=>{throw n.buildCodeFrameError(g)},a=t.callee,l=Ni(e,a.object,o,i,s),d=Ri(e,t,o,s),u=Di(e,d,s),c=Ai(l.suffixBase,r);return{sourceKey:l.key,sourceExpr:ce.cloneNode(l.expression),sourceLocal:l.local,itemPattern:d.itemPattern,itemParam:d.itemParam,indexParam:d.indexParam,keyExpr:Li(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 Ni(e,t,n,o,r){return ce.isIdentifier(t)?Ii(e,t,n,r):ce.isMemberExpression(t)?Fi(e,t,n,o,r):ce.isExpression(t)&&rn(t)?{expression:t,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 Ii(e,t,n,o){let r=e.componentProps.get(n)?.bindings??[],i=e.instanceState.get(n)?.has(t.name)===!0||e.instanceDerivedBindings.get(n)?.has(t.name)===!0||r.includes(t.name),s=e.state.get(t.name);return!i&&s!=="let"&&s!=="const"&&s!=="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:i,suffixBase:t.name}}function Fi(e,t,n,o,r){let i=Pe(t),s=ye(t),a=e.componentProps.get(n)?.bindings??[],l=i!==null&&(e.instanceState.get(n)?.has(i)===!0||a.includes(i)),d=i!==null&&s!==null&&o!==void 0&&i===o.itemParam;return i===null||s===null||!s.includes(".")||!d&&!l&&e.state.get(i)!=="store"?r("memo-dom: list member views must be a static path on reactive module state, component props, or component state"):{expression:t,key:d?o.sourceKey:s,local:d?o.sourceLocal:l,suffixBase:s.slice(s.lastIndexOf(".")+1)}}function Ri(e,t,n,o){if(t.arguments.length!==1||!ce.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||!ce.isIdentifier(i)&&!ce.isObjectPattern(i)&&!ce.isArrayPattern(i)||s!==void 0&&!ce.isIdentifier(s))return o("memo-dom: list callback must take an item binding pattern and optional index identifier \u2014 R7 L1");let a=tn(i),l=Object.keys(ce.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=ce.isIdentifier(a)?a.name:l[0],u=ce.isIdentifier(s)?s.name:null,c=ce.isBlockStatement(r.body)&&r.body.body.length===1&&ce.isReturnStatement(r.body.body[0])?r.body.body[0].argument:null,g=ce.isJSXElement(r.body)?r.body:ce.isJSXElement(c)?c:null,S=Ft(e,n,t);return g===null&&S===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:g,renderInvocation:S}}function Di(e,t,n){let o=t.jsx?.openingElement??null;if(o!==null&&!ce.isJSXIdentifier(o.name))return n("memo-dom: namespaced JSX tags are not supported (L1)");let r=o!==null&&ce.isJSXIdentifier(o.name)?o.name.name:null;return t.renderInvocation!==null?(Mi(t,n),{form:"callback",rowComp:null,renderCallback:ce.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 Mi(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 Li(e,t){let n=null;for(let o of e?.attributes??[])if(ce.isJSXAttribute(o)&&ce.isJSXIdentifier(o.name,{name:"key"})&&(n=$e(o.value),n===null))return t("memo-dom: key={...} needs an expression");return n}function Ai(e,t){let n=t.get(e)??0;return t.set(e,n+1),n===0?e:`${e}${n}`}import*as te from"@babel/types";function sn(e){return te.isConditionalExpression(e)||te.isLogicalExpression(e)&&(e.operator==="&&"||e.operator==="||")?e:null}function ji(e){return te.isNullLiteral(e)||te.isBooleanLiteral(e,{value:!1})||te.isIdentifier(e,{name:"undefined"})}function Ji(e,t){let n=[e];for(;n.length>0;){let o=n.pop();if(te.isJSXElement(o)){for(let r of o.openingElement.attributes)!te.isJSXSpreadAttribute(r)&&r.name.name==="key"&&t("memo-dom: key={...} is only meaningful on list rows");n.push(...o.children)}else if(te.isJSXFragment(o))n.push(...o.children);else if(te.isJSXExpressionContainer(o)&&te.isExpression(o.expression)){let r=o.expression;if(Oe(r)!==null&&ue(r))continue}}}function an(e,t,n){let o=l=>{throw t.buildCodeFrameError(l)},r,i;if(te.isConditionalExpression(e)){let l=[];i=[];let d=e;for(;te.isConditionalExpression(d);)l.push(te.cloneNode(d.test)),i.push(d.consequent),d=d.alternate;i.push(d),r=te.numericLiteral(i.length-1);for(let u=l.length-1;u>=0;u--)r=te.conditionalExpression(l[u],te.numericLiteral(u),r)}else e.operator==="&&"?(r=te.conditionalExpression(te.cloneNode(e.left),te.numericLiteral(0),te.numericLiteral(1)),i=[e.right,null]):(r=te.conditionalExpression(te.cloneNode(e.left),te.numericLiteral(1),te.numericLiteral(0)),i=[e.right,null]);let s=l=>l===null||ji(l)?null:te.isJSXElement(l)||te.isJSXFragment(l)?l:te.isExpression(l)?te.jsxFragment(te.jsxOpeningFragment(),te.jsxClosingFragment(),[te.jsxExpressionContainer(te.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&&Ji(l,o);return{pickExpr:r,branches:a,suffix:`when${n.count++}`}}import*as Fe from"@babel/types";import*as ge from"@babel/types";var Rt=class{constructor(t){this.fallback=t}fallback;origins=new WeakMap;trackDeclarator(t,n){if(!ge.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(ge.isIdentifier(i)||ge.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 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&&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=vo(n);if(ge.isIdentifier(o))return this.resolveName(t,o.name);if(!ge.isMemberExpression(o))return null;let r=$i(o);if(r===null)return null;let i=this.resolveName(t,r);if(i===null)return null;let s=ye(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 ln(e,t){return{locality:"module",root:e,key:e,stateKind:t}}function mt(e,t){return e.key===null?e:{...e,key:[e.key,...t].join(".")}}function dn(e,t){if(e.key===null)return null;let n=[];for(let o of t){if(!ge.isObjectExpression(o))return null;for(let r of o.properties){if(!ge.isObjectProperty(r)||r.computed||!ge.isIdentifier(r.key)&&!ge.isStringLiteral(r.key))return null;let i=ge.isIdentifier(r.key)?r.key.name:r.key.value;n.push(`${e.key}.${i}`)}}return n}function cn(e){let t=[];for(let n of e)ge.isExpression(n)?t.push(n):ge.isSpreadElement(n)&&t.push(n.argument);return t}function un(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=vo(t.object)}return ge.isIdentifier(t)?t.name:null}function vo(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 Ve(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((p,f)=>Fe.isIdentifier(p)?[[p.name,f]]:[])),a={reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!1},l=new Rt((p,f)=>{if(s.has(p)&&f?.scope.block===r.node)return{locality:"prop",root:p,key:p};let v=e.state.get(p);return v===void 0||f!==void 0&&!f.scope.path.isProgram()?null:ln(p,v)}),d=p=>p.stateKind==="computed"||e.state.get(p.root)==="computed";n.add(t),r.traverse({VariableDeclarator(p){Fe.isIdentifier(p.node.id)&&(i.add(p.node.id.name),p.parentPath.isVariableDeclaration()&&l.trackDeclarator(p.scope,p.node))},Function(p){for(let f of p.node.params)Fe.isIdentifier(f)&&i.add(f.name)}});let u=(p,f)=>{a.parameterWrites.some(v=>v.index===p&&v.path.length===f.length&&v.path.every((x,I)=>x===f[I]))||a.parameterWrites.push({index:p,path:f})},c=p=>{if(!d(p)){if(p.locality==="module"){a.boundedWrites.add(p.key??p.root);return}if(p.locality==="prop"){let f=s.get(p.root);if(f!==void 0){let v=p.key===null?[]:p.key.split(".").slice(1);u(f,v);return}}a.unbounded=!0}},g=p=>{p.locality==="prop"?c(p):p.locality!=="module"?a.unbounded=!0:p.stateKind!=="store"?a.writes.add(p.root):p.key!==null&&p.key.includes(".")?a.writes.add(p.key):a.boundedWrites.add(p.root)},S=(p,f)=>{let v=l.resolveExpression(p.scope,f);v!==null&&g(v)},y=(p,f)=>{for(let v of cn(f)){if(!Fe.isIdentifier(v))continue;let x=l.resolveExpression(p.scope,v);x!==null&&!d(x)&&c(x)}};return r.traverse({VariableDeclarator(p){if(!Fe.isIdentifier(p.node.id)&&p.node.init!==null)for(let f of l.referencedOrigins(p.scope,p.node.init))c(f)},AssignmentExpression(p){let f=p.node.left;if(Fe.isIdentifier(f))if(i.has(f.name)){if(Fe.isIdentifier(p.node.right)){let v=l.resolveExpression(p.scope,p.node.right);v!==null&&c(v)}}else e.state.has(f.name)&&a.writes.add(f.name);else if(Fe.isMemberExpression(f))S(p,f);else for(let v of l.referencedOrigins(p.scope,p.node.right))c(v)},UpdateExpression(p){let f=p.node.argument;Fe.isIdentifier(f)?!i.has(f.name)&&e.state.has(f.name)&&a.writes.add(f.name):Fe.isMemberExpression(f)&&S(p,f)},UnaryExpression(p){p.node.operator==="delete"&&Fe.isMemberExpression(p.node.argument)&&S(p,p.node.argument)},CallExpression(p){let f=p.node.callee;if(Fe.isMemberExpression(f)){if(un(f)==="assign"&&Fe.isIdentifier(f.object,{name:"Object"})){let I=p.node.arguments[0],J=I!==void 0&&Fe.isExpression(I)?l.resolveExpression(p.scope,I):null;if(J!==null){let F=dn(J,p.node.arguments.slice(1));if(F===null)c(J);else for(let N of F)g({...J,key:N})}return}let x=Fe.isExpression(f.object)?l.resolveExpression(p.scope,f.object):null;x!==null?c(x):y(p,p.node.arguments);return}if(Fe.isIdentifier(f)&&(e.helpers.has(f.name)||e.importedFunctions.has(f.name))){let v=e.importedFunctions.get(f.name)??Ve(e,f.name,n);for(let x of v.reads)a.reads.add(x);for(let x of v.writes)a.writes.add(x);for(let x of v.boundedWrites)a.boundedWrites.add(x);for(let x of v.parameterWrites){let I=p.node.arguments[x.index];if(I===void 0||!Fe.isExpression(I))continue;let J=l.resolveExpression(p.scope,I);J!==null&&c(mt(J,x.path))}v.unbounded&&(a.unbounded=!0);return}y(p,p.node.arguments)},Identifier(p){let f=p.node.name;if(!e.state.has(f)||i.has(f))return;let v=p.parentPath;v.isAssignmentExpression({operator:"="})&&v.node.left===p.node||a.reads.add(f)},MemberExpression(p){let f=Xi(e,p);f!==null&&a.reads.add(f)}}),n.delete(t),e.helperSummaries.set(t,a),a}function Xi(e,t){let n=ye(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||Oi(t)?null:n}function Oi(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}import*as b from"@babel/types";import*as le from"@babel/types";function Ze(e,t=!1){return{slots:[],tempVar:$(e,"value").name,updateVar:$(e,"update").name,reasonVar:null,delegatedEventRootVar:null,creation:[],mounts:[],updaters:[],tagCounters:new Map,childCounts:new Map,usedPrefixes:new Map,usedConds:{count:0},textCounter:0,regionCounter:0,disposableRegions:[],disposableEntities:[],disposableCallbacks:[],forwardedSlotCounter:0,manualDisposal:t}}function Ye(e){return le.variableDeclaration("let",[...e.slots.map(t=>le.variableDeclarator(le.identifier(t))),le.variableDeclarator(le.identifier(e.tempVar))])}function An(e,t){let n=$(e,`slot${t.slots.length}`).name;return t.slots.push(n),n}function jn(e,t,n){let o=t.tagCounters.get(n)??0;return t.tagCounters.set(n,o+1),$(e,`${n}${o}`).name}function vt(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 Qe(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 gt(e,t,n,o){return le.expressionStatement(le.callExpression(Z(e,"register"),[le.objectExpression([le.objectProperty(le.identifier("id"),t),le.objectProperty(le.identifier("parent"),n),le.objectProperty(le.identifier("render"),o)])]))}function Jn(e){let t=e.replace(/\s+/g," ");return/^\s*\n/.test(e)&&(t=t.replace(/^ /,"")),/\n\s*$/.test(e)&&(t=t.replace(/ $/,"")),t}function Vt(e){return e.some(t=>!b.isJSXText(t)||t.value.trim()!=="")}function lt(e,t,n){let o=e.componentProps.get(t);if(o===void 0)return null;let r=Be(o);if(r!==null&&b.isMemberExpression(n)&&!n.computed&&b.isIdentifier(n.object,{name:r})&&b.isIdentifier(n.property))return n.property.name;if(b.isIdentifier(n)){let i=He(o,n.name);if(i!==null)return i;if(n.name==="children"&&e.instanceDerivedBindings.get(t)?.has("children")===!0)return"children"}return null}function et(e,t,n){let o=lt(e,t,n);return o!==null&&e.componentProps.get(t)?.renderProps.includes(o)===!0}function ko(e,t,n,o){let r=Ze(e,!0);r.childCounts=t.childCounts,r.usedPrefixes=t.usedPrefixes,r.usedConds=t.usedConds;let i=$(e,"childrenUpdate"),s=$(e,"childrenUpdates"),a=$(e,"childrenMountSequence"),l=$(e,"children"),d=$(e,"childrenParent"),u=$(e,"childrenOwner"),c=$(e,"childrenKey"),g=$(e,"childrenSlot"),S=$(e,"childrenNextUpdate"),y=$(e,"childrenActive"),p=$(e,"childrenDispose");return o(r,d,g),t.creation.push(b.variableDeclaration("let",[b.variableDeclarator(b.cloneNode(i),b.nullLiteral()),b.variableDeclarator(b.cloneNode(s),b.nullLiteral()),b.variableDeclarator(b.cloneNode(a),b.numericLiteral(0))]),b.variableDeclaration("const",[b.variableDeclarator(b.cloneNode(l),b.arrowFunctionExpression([b.cloneNode(d),b.cloneNode(u),b.cloneNode(c)],b.blockStatement([b.variableDeclaration("const",[b.variableDeclarator(b.cloneNode(g),b.conditionalExpression(b.binaryExpression("===",b.cloneNode(a),b.numericLiteral(0)),b.cloneNode(n,!0),b.binaryExpression("+",b.binaryExpression("+",b.cloneNode(n,!0),b.stringLiteral("/$slot[")),b.binaryExpression("+",b.cloneNode(a),b.stringLiteral("]")))))]),b.expressionStatement(b.updateExpression("++",b.cloneNode(a))),b.variableDeclaration("let",[b.variableDeclarator(b.cloneNode(y),b.booleanLiteral(!0))]),Ye(r),Qe(r),...r.creation,...r.mounts,b.ifStatement(b.binaryExpression("===",b.cloneNode(i),b.nullLiteral()),b.expressionStatement(b.assignmentExpression("=",b.cloneNode(i),b.identifier(r.updateVar))),b.blockStatement([b.ifStatement(b.binaryExpression("===",b.cloneNode(s),b.nullLiteral()),b.expressionStatement(b.assignmentExpression("=",b.cloneNode(s),b.newExpression(b.identifier("Set"),[])))),b.expressionStatement(b.callExpression(b.memberExpression(b.cloneNode(s),b.identifier("add")),[b.identifier(r.updateVar)]))])),b.variableDeclaration("const",[b.variableDeclarator(b.cloneNode(p),b.arrowFunctionExpression([],b.blockStatement([b.ifStatement(b.unaryExpression("!",b.cloneNode(y)),b.returnStatement()),b.expressionStatement(b.assignmentExpression("=",b.cloneNode(y),b.booleanLiteral(!1))),b.ifStatement(b.binaryExpression("===",b.cloneNode(i),b.identifier(r.updateVar)),b.expressionStatement(b.assignmentExpression("=",b.cloneNode(i),b.nullLiteral())),b.ifStatement(b.binaryExpression("!==",b.cloneNode(s),b.nullLiteral()),b.expressionStatement(b.callExpression(b.memberExpression(b.cloneNode(s),b.identifier("delete")),[b.identifier(r.updateVar)])))),...r.disposableRegions.map(f=>b.expressionStatement(b.callExpression(b.memberExpression(b.identifier(f),b.identifier("dispose")),[]))),...[...r.disposableCallbacks].reverse().map(f=>b.ifStatement(b.binaryExpression("!==",b.cloneNode(f),b.nullLiteral()),b.expressionStatement(b.callExpression(b.cloneNode(f),[])))),...r.disposableEntities.map(f=>b.expressionStatement(b.callExpression(Z(e,"unregisterSubtree"),[b.cloneNode(f,!0)])))])))]),b.expressionStatement(b.callExpression(Z(e,"cleanup"),[b.cloneNode(u),b.cloneNode(p)])),b.returnStatement(b.cloneNode(p))])))])),t.updaters.push(()=>b.blockStatement([b.ifStatement(b.binaryExpression("!==",b.cloneNode(i),b.nullLiteral()),b.expressionStatement(b.callExpression(b.cloneNode(i),[]))),b.ifStatement(b.binaryExpression("!==",b.cloneNode(s),b.nullLiteral()),b.forOfStatement(b.variableDeclaration("const",[b.variableDeclarator(b.cloneNode(S))]),b.cloneNode(s),b.expressionStatement(b.callExpression(b.cloneNode(S),[]))))])),l}function $n(e,t,n,o,r){let i=$(e,"slotDispose"),s=t.forwardedSlotCounter++;t.creation.push(b.variableDeclaration("const",[b.variableDeclarator(b.cloneNode(i),b.conditionalExpression(b.binaryExpression("==",b.cloneNode(n,!0),b.nullLiteral()),b.nullLiteral(),b.callExpression(b.cloneNode(n,!0),[b.identifier(o),b.cloneNode(r,!0),b.stringLiteral(String(s))])))])),t.disposableCallbacks.push(i)}function No(e,t,n,o){let r=i=>{e.creation.push(b.expressionStatement(b.callExpression(b.memberExpression(b.identifier(n),b.identifier("appendChild")),[b.identifier(i)])))};for(let i of t){if(b.isJSXText(i)){let d=Jn(i.value);d!==""&&r(o.emitText(b.stringLiteral(d)));continue}if(b.isJSXElement(i)||b.isJSXFragment(i)){r(o.emitNode(i));continue}if(b.isJSXExpressionContainer(i)||o.fail("memo-dom: spread children are not supported (L1)"),b.isJSXEmptyExpression(i.expression))continue;b.isExpression(i.expression)||o.fail("memo-dom: unsupported expression in component children");let s=i.expression;if(b.isNullLiteral(s)||b.isBooleanLiteral(s)||b.isIdentifier(s,{name:"undefined"}))continue;if(o.isForwarded(s)){o.emitForwarded(s,n);continue}let a=Oe(s);if(a!==null){o.emitList(a,n);continue}let l=sn(s);if(l!==null&&ue(l)){o.emitCondition(l,n);continue}r(o.emitText(b.cloneNode(s)))}}import*as L from"@babel/types";function mn(e){return L.isIdentifier(e.node.callee,{name:"effect"})&&e.scope.getBinding("effect")===void 0}function fn(e,t){return L.binaryExpression("+",L.identifier(e),L.stringLiteral(`/$effects/${t}`))}function Ti(e,t){return L.binaryExpression("+",fn(e,t),L.stringLiteral("/$active"))}function Bi(e){if(e.isFunctionDeclaration())return e;if(!e.isVariableDeclarator())return null;let t=e.get("init");return t.isArrowFunctionExpression()||t.isFunctionExpression()?t:null}function Mo(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:Bi(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(ue(s.node.body))throw s.buildCodeFrameError("memo-dom: a JSX component cannot be used as an effect callback");return{expression:L.cloneNode(o.node),path:s,importedReads:new Set}}function Io(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 f of e.instanceDerivations.get(t)??[])for(let v of f.bindings)l.set(v,f.sources);for(let f of e.instanceControlFlow.get(t)??[])for(let v of f.bindings)l.set(v,f.sources);for(let f of a){let v=n.scope.getBinding(f);v!==void 0&&s.set(v,{source:f,local:!0})}for(let f of l.keys()){let v=n.scope.getBinding(f);v!==void 0&&s.set(v,{source:f,local:!0})}for(let f of e.state.keys()){let v=n.scope.getBinding(f);v?.scope.path.isProgram()===!0&&s.set(v,{source:f,local:!1})}let d=f=>{let v=f.scope.getBinding(f.node.name),x=v===void 0?void 0:s.get(v);if(x===void 0)return;let I=f.parentPath;!x.local&&e.state.get(x.source)==="store"&&I?.isMemberExpression()&&I.node.object===f.node||(x.local?i.add(x.source):r.add(x.source))},u=f=>{let v=ye(f.node),x=Pe(f.node);v===null||x===null||e.state.get(x)!=="store"||f.scope.getBinding(x)?.scope.path.isProgram()!==!0||r.add(v)},c=f=>{let v=f.node.callee;if(!L.isIdentifier(v)||f.scope.getBinding(v.name)?.scope.path.isProgram()!==!0||!e.helpers.has(v.name)&&!e.importedFunctions.has(v.name))return;let x=e.importedFunctions.get(v.name)??Ve(e,v.name);for(let I of x.reads)r.add(I)};o.isIdentifier()&&o.isReferencedIdentifier()&&d(o),o.isMemberExpression()&&u(o),o.isCallExpression()&&c(o),o.traverse({Function(f){f.skip()},ReferencedIdentifier(f){f.isIdentifier()&&d(f)},MemberExpression(f){u(f)},CallExpression(f){c(f)}});let g=new Set,S=new Set,y=new Set;for(let f of i)a.has(f)&&y.add(f);let p=(f,v)=>{if(v.has(f))return;let x=l.get(f);if(x===void 0){a.has(f)?g.add(f):e.state.has(f)&&r.add(f);return}v.add(f),x.some(J=>y.has(J))||S.add(f);for(let J of x)p(J,v);v.delete(f)};for(let f of i)p(f,new Set);return{moduleReads:r,localReads:g,localDerivationReads:S}}function Fo(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=ye(s.node),l=Pe(s.node);a!==null&&l!==null&&e.state.get(l)==="store"&&s.scope.getBinding(l)?.scope.path.isProgram()===!0&&n.add(a)},i=s=>{let a=s.node.callee;if(!L.isIdentifier(a)||s.scope.getBinding(a.name)?.scope.path.isProgram()!==!0||!e.helpers.has(a.name)&&!e.importedFunctions.has(a.name))return;let l=e.importedFunctions.get(a.name)??Ve(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 Xn(e){if(!e.isExpressionStatement())return null;let t=e.get("expression");return t.isCallExpression()&&mn(t)?t:null}function Lo(e){if(Xn(e)!==null)return!0;let t=!1;return e.traverse({Function(n){n.skip()},CallExpression(n){mn(n)&&(t=!0,n.stop())}}),t}function pn(e,t,n,o){let r=Xn(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(!Lo(i))throw i.buildCodeFrameError("memo-dom: a conditional effect branch may contain only effect() calls, nested if statements, or empty statements");pn(i,t,n,o)}return}if(e.isIfStatement()){let i=e.get("test");pn(e.get("consequent"),t,[...n,{path:i,negated:!1}],o);let s=e.get("alternate");s.node!==null&&pn(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 Ao(e){let t=[];for(let n of e){let o=Xn(n);if(o!==null){t.push({callPath:o,rootStatement:n.node,conditions:[]});continue}!n.isIfStatement()||!Lo(n)||pn(n,n.node,[],t)}return t}function jo(e){return e.length===0?null:e.map(({path:n,negated:o})=>o?L.unaryExpression("!",L.cloneNode(n.node,!0)):L.cloneNode(n.node,!0)).reduce((n,o)=>L.logicalExpression("&&",n,o))}function Vi(e,t){let n=[],o=Ao(t.get("body"));for(let r of o){let i=Mo(e,r.callPath),s=i.path===null?i.importedReads:Fo(e,i.path),a=new Set;for(let d of r.conditions)for(let u of Fo(e,d.path))a.add(u);let l=n.length;n.push({index:l,statement:r.rootStatement,callback:i.expression,moduleReads:s,condition:jo(r.conditions),conditionModuleReads:a,entityId:`${e.rootId}/$module-effects/${encodeURIComponent(e.moduleId)}/${l}`})}e.moduleEffects.push(...n)}function Jo(e,t){Vi(e,t);for(let[n,o]of e.compPaths){let r=[],i=new Set,s=Ao(o.get("body").get("body"));for(let l of s){let d=Mo(e,l.callPath),u=d.path===null?{moduleReads:d.importedReads,localReads:new Set,localDerivationReads:new Set}:Io(e,n,o,d.path),c=new Set,g=new Set,S=new Set;for(let y of l.conditions){let p=Io(e,n,o,y.path);for(let f of p.moduleReads)c.add(f);for(let f of p.localReads)g.add(f);for(let f of p.localDerivationReads)S.add(f)}r.push({index:r.length,statement:l.rootStatement,callback:d.expression,...u,condition:jo(l.conditions),conditionModuleReads:c,conditionLocalReads:g,conditionLocalDerivationReads:S}),i.add(l.callPath.node)}if(o.traverse({CallExpression(l){if(!(!mn(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 Ro(e){return e.reduce((t,n)=>L.logicalExpression("||",t,n))}function Wi(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=()=>L.identifier(n),a=Ro(i.map(d=>L.binaryExpression("===",s(),L.numericLiteral(d)))),l=Ro(i.map(d=>L.callExpression(L.memberExpression(s(),L.identifier("has")),[L.numericLiteral(d)])));return L.logicalExpression("||",L.binaryExpression("===",s(),L.nullLiteral()),L.conditionalExpression(L.binaryExpression("===",L.unaryExpression("typeof",s()),L.stringLiteral("number")),a,l))}function $o(e,t,n,o,r,i){let s=(l,d,u,c,g)=>{if(u.size===0&&c.size===0)return null;let S=L.expressionStatement(L.callExpression(Z(e,"markDirty"),[d]));if(c.size>0&&i!==void 0){let p=[],f=[];for(let x of c){let I=$(e,`eff${l.index}_${g}_${x}`).name;i.creation.push(L.variableDeclaration("let",[L.variableDeclarator(L.identifier(I),L.identifier(x))])),p.push(L.binaryExpression("!==",L.identifier(I),L.identifier(x))),f.push(L.expressionStatement(L.assignmentExpression("=",L.identifier(I),L.identifier(x))))}let v=p.length===1?p[0]:p.reduce((x,I)=>L.logicalExpression("||",x,I));S=L.ifStatement(v,L.blockStatement([...f,S]))}if(o===null)return S;let y=Wi(e,t,o,u);return y===null?S:L.ifStatement(y,S)},a=r.flatMap(l=>{let d=l.condition===null?null:s(l,fn(n,l.index),l.conditionLocalReads,l.conditionLocalDerivationReads,"condition"),u=s(l,l.condition===null?fn(n,l.index):Ti(n,l.index),l.localReads,l.localDerivationReads,"callback");return[d,u].filter(c=>c!==null)});return L.blockStatement(a)}function Xo(e,t,n){return n.map(o=>L.expressionStatement(L.callExpression(Z(e,o.condition===null?"registerEffect":"registerConditionalEffect"),[fn(t,o.index),L.identifier(t),...o.condition===null?[]:[L.arrowFunctionExpression([],L.cloneNode(o.condition,!0))],L.cloneNode(o.callback,!0)])))}function Do(){return L.memberExpression(L.metaProperty(L.identifier("import"),L.identifier("meta")),L.identifier("hot"))}function Oo(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(L.expressionStatement(L.callExpression(Z(e,l.condition===null?"registerEffect":"registerConditionalEffect"),[L.stringLiteral(l.entityId),L.nullLiteral(),...l.condition===null?[]:[L.arrowFunctionExpression([],L.cloneNode(l.condition,!0))],L.cloneNode(l.callback,!0)])),L.ifStatement(Do(),L.expressionStatement(L.callExpression(L.memberExpression(Do(),L.identifier("dispose")),[L.arrowFunctionExpression([],L.callExpression(Z(e,"unregisterSubtree"),[L.stringLiteral(l.entityId)]))]))));s.replaceWithMultiple(a)}}function To(e){e.traverse({CallExpression(t){if(mn(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 _e from"@babel/types";function Bo(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function Vo(e){let t=new Set,n=[];for(let o of e){let r=gn(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 gn(e){if(_e.isExpressionStatement(e)&&_e.isAssignmentExpression(e.expression,{operator:"="})&&_e.isIdentifier(e.expression.left))return{bindings:new Set([e.expression.left.name]),expressions:[e.expression.right]};if(_e.isBlockStatement(e))return Vo(e.body);if(_e.isIfStatement(e)){let t=e.alternate;if(t==null)return null;let n=gn(e.consequent),o=gn(t);return n===null||o===null||!Bo(n.bindings,o.bindings)?null:{bindings:n.bindings,expressions:[e.test,...n.expressions,...o.expressions]}}return null}function zi(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)&&_e.isBreakStatement(i.at(-1))&&i.pop(),i.some(a=>_e.isBreakStatement(a)))return null;let s=Vo(i);if(s===null)return null;if(n=!1,t===null)t=s.bindings;else if(!Bo(t,s.bindings))return null;o.push(...s.expressions)}return t===null||n?null:{bindings:t,expressions:o}}function Ki(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function Hi(e,t){let n=e;for(;n?.parentPath!==t;)n=n?.parentPath??null;return n}function Wo(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()?gn(s):zi(s);if(a===null)continue;let l=!0,d=[];for(let y of a.bindings){let p=t.scope.getBinding(y),f=p?.path,v=f?.parentPath,x=f===void 0?null:Hi(f,t);if(p===void 0||!f?.isVariableDeclarator()||!v?.isVariableDeclaration()||v.node.kind!=="let"&&v.node.kind!=="var"||x===null||(r.get(x.node)??Number.MAX_SAFE_INTEGER)>=(r.get(s)??-1)){l=!1;break}d.push(...p.constantViolations.filter(I=>!Ki(I,s)))}if(!l)continue;let u=new Set,c=null;for(let y of a.expressions){let p=n(e,y);for(let f of p.reads)u.add(f);p.impure&&c===null&&(c=p.reason??"cannot be analyzed")}if(u.size===0)continue;if(c!==null)throw i.buildCodeFrameError(`memo-dom: module control-flow derivation ${c}`);for(let y of a.bindings)if(u.has(y))throw i.buildCodeFrameError(`memo-dom: module control-flow derivation '${y}' reads its own previous value`);if(d.length>0)throw d[0].buildCodeFrameError(`memo-dom: cannot assign module control-flow computed '${[...a.bindings].sort().join(", ")}' outside its derivation`);let g=e.moduleControlFlow.length,S=[...a.bindings].sort();for(let y of S)pt(e,y,"computed");e.moduleControlFlow.push({statement:s,bindings:S,sources:[...u].sort(),entityId:`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#$flow${g}`})}}import*as pe from"@babel/types";function On(e,t){let n=new Set,o=!1,r,i=new Set,s=l=>{o||(o=!0,r=l)},a=l=>{pe.isIdentifier(l)?i.add(l.name):Xe(l,d=>{pe.isIdentifier(d)&&i.add(d.name)})};return Xe(t,(l,d)=>{if(pe.isFunction(l)){if(!(d!==null&&(pe.isCallExpression(d)||pe.isNewExpression(d))))return!1;for(let c of l.params)pe.isLVal(c)&&a(c);return}if(pe.isVariableDeclarator(l)&&pe.isLVal(l.id)){a(l.id);return}if(pe.isAssignmentExpression(l)){let u=pe.isIdentifier(l.left)?l.left.name:pe.isMemberExpression(l.left)?Pe(l.left):null;(u===null||!i.has(u))&&s("contains an assignment \u2014 writes belong in handlers, not derivations");return}if(pe.isUpdateExpression(l)){let u=l.argument,c=pe.isIdentifier(u)?u.name:pe.isMemberExpression(u)?Pe(u):null;(c===null||!i.has(c))&&s("contains an update (++/--) \u2014 writes belong in handlers, not derivations");return}if(pe.isAwaitExpression(l)||pe.isYieldExpression(l)){s("uses await/yield \u2014 derivations must be synchronous");return}if(pe.isCallExpression(l)){let u=l.callee;if(pe.isIdentifier(u)&&(e.helpers.has(u.name)||e.importedFunctions.has(u.name))){let c=e.importedFunctions.get(u.name)??Ve(e,u.name);for(let g of c.reads)n.add(g);if(c.writes.size>0){for(let g of c.writes)n.add(g);s(`calls helper '${u.name}' which writes state \u2014 writes belong in handlers`)}else c.unbounded&&e.helpers.has(u.name)&&s(`calls recursive helper '${u.name}' which cannot be analyzed`)}return}if(pe.isIdentifier(l)){!i.has(l.name)&&e.state.has(l.name)&&n.add(l.name);return}if(pe.isMemberExpression(l)&&!l.computed){let u=ye(l);if(u!==null&&u.includes(".")){let c=u.split(".")[0];!i.has(c)&&e.state.get(c)==="store"&&n.add(u)}}}),{reads:n,impure:o,reason:r}}function zo(e,t){for(let n of t.node.body){let o=pe.isExportNamedDeclaration(n)?n.declaration:n;if(!(!pe.isVariableDeclaration(o)||o.kind!=="const"))for(let r of o.declarations){if(!pe.isIdentifier(r.id)||r.init==null)continue;let i=r.id.name;if(e.state.get(i)==="let"||e.state.get(i)==="computed"||pe.isFunction(r.init)||pe.isJSX(r.init))continue;let s=On(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&&(pt(e,i,"computed"),e.computeds.set(i,{reads:s.reads}))}}}import*as Me from"@babel/types";function Ko(e){for(let[t,n]of e.compPaths){let o=new Set;for(let r of n.node.body.body)if(Me.isVariableDeclaration(r)&&!(r.kind!=="let"&&r.kind!=="var"&&r.kind!=="const"))for(let i of r.declarations)Me.isIdentifier(i.id)&&(r.kind==="let"||r.kind==="var"||Ct(i.init)||Pt(i.init))&&o.add(i.id.name);o.size>0&&e.instanceState.set(t,o)}}function Ho(e){for(let[t,n]of e.compPaths){let o=new Map;for(let c of e.componentProps.get(t)?.bindings??[]){let g=n.scope.getBinding(c);g&&o.set(g,c)}for(let c of e.instanceState.get(t)??[]){let g=n.scope.getBinding(c);g&&o.set(g,c)}for(let c of e.state.keys()){let g=n.scope.getBinding(c);g?.scope.path.isProgram()&&o.set(g,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 g of c.get("declarations")){let S=g.node;if(!Me.isIdentifier(S.id)&&!Me.isObjectPattern(S.id)&&!Me.isArrayPattern(S.id)||S.init==null||Me.isFunction(S.init)||Me.isIdentifier(S.id)&&e.instanceState.get(t)?.has(S.id.name)===!0&&(Ct(S.init)||Pt(S.init)))continue;let y=g.get("init");if(!y.isExpression())continue;let p=new Set,f=null,v=(N,K)=>{let _=K.scope.getBinding(N);return _!==void 0&&o.has(_)},x=N=>{if(!Me.isIdentifier(N.node))return;let K=N.scope.getBinding(N.node.name),_=K===void 0?void 0:o.get(K);_!==void 0&&p.add(_)},I=N=>Me.isIdentifier(N)?N.name:Me.isMemberExpression(N)?Pe(N):null;if(y.isReferencedIdentifier()&&x(y),y.isAssignmentExpression()){let N=I(y.node.left);N!==null&&v(N,y)&&(f="contains an assignment to reactive state")}else if(y.isUpdateExpression()){let N=I(y.node.argument);N!==null&&v(N,y)&&(f="contains an update (++/--) to reactive state")}else y.isAwaitExpression()?f="uses await; per-instance derivations must be synchronous":y.isYieldExpression()&&(f="uses yield; per-instance derivations must be synchronous");if(y.traverse({Function(N){N.skip()},ReferencedIdentifier(N){x(N)},AssignmentExpression(N){let K=I(N.node.left);K!==null&&v(K,N)&&(f="contains an assignment to reactive state")},UpdateExpression(N){let K=I(N.node.argument);K!==null&&v(K,N)&&(f="contains an update (++/--) to reactive state")},AwaitExpression(){f="uses await; per-instance derivations must be synchronous"},YieldExpression(){f="uses yield; per-instance derivations must be synchronous"}}),p.size===0)continue;if(y.traverse({ReferencedIdentifier(N){x(N)},AssignmentExpression(N){let K=I(N.node.left);K!==null&&v(K,N)&&(f="contains an assignment to reactive state")},UpdateExpression(N){let K=I(N.node.argument);K!==null&&v(K,N)&&(f="contains an update (++/--) to reactive state")}}),f!==null){let N=Tt(S.id);throw g.buildCodeFrameError(`memo-dom: local const '${N.join(", ")||"<pattern>"}' is a per-instance derivation but ${f}`)}let J=Tt(S.id),F=new Set;for(let N of p){let K=s.get(N);if(K===void 0)F.add(N);else for(let _ of K)F.add(_)}r.push({declaration:c.node,target:Me.cloneNode(S.id),source:Me.cloneNode(S.init),bindings:J,sources:[...F].sort()});for(let N of J){i.add(N),s.set(N,new Set(F));let K=n.scope.getBinding(N);K&&o.set(K,N),e.instanceState.get(t)?.delete(N)}}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(g=>!g.sources.includes(c))))continue;let u=new Set([...l,...r.flatMap(c=>c.sources)]);e.instanceReasonIds.set(t,new Map([...u].sort().map((c,g)=>[c,g]))),e.selectiveDerivationComponents.add(t)}}import*as fe from"@babel/types";function zt(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 o=n.callee;t=t&&fe.isMemberExpression(o)&&!o.computed&&fe.isIdentifier(o.object,{name:"Math"})&&fe.isIdentifier(o.property)}}),t}function Ui(e){return!fe.isExpressionStatement(e)||!fe.isAssignmentExpression(e.expression,{operator:"="})||!fe.isIdentifier(e.expression.left)||!zt(e.expression.right)?null:e.expression.left.name}function Uo(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function Wt(e){if(fe.isExpressionStatement(e)){let t=Ui(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 o of e.body){let r=Wt(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(fe.isIfStatement(e)){if(!zt(e.test))return null;let t=Wt(e.consequent);if(t===null)return null;if(e.alternate==null)return{bindings:t.bindings,partial:new Set([...t.bindings,...t.partial])};let n=Wt(e.alternate);return n===null||!Uo(t.bindings,n.bindings)?null:{bindings:t.bindings,partial:new Set([...t.partial,...n.partial])}}return null}function _i(e){if(!zt(e.discriminant))return null;let t=null;for(let n of e.cases){if(n.test!=null&&!zt(n.test))return null;let o=[...n.consequent];if(o.at(-1)&&fe.isBreakStatement(o.at(-1))&&o.pop(),o.some(i=>fe.isBreakStatement(i)))return null;let r=Wt(fe.blockStatement(o));if(r===null)return null;if(t===null)t=r;else{if(!Uo(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 qi(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function _o(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()?Wt(a.node):_i(a.node);if(l===null)continue;let d=!0,u=[],c=[];for(let p of l.bindings){let f=n.scope.getBinding(p),v=f?.path,x=v?.parentPath;if(f===void 0||!v?.isVariableDeclarator()||!x?.isVariableDeclaration()||x.node.kind!=="let"&&x.node.kind!=="var"||f.constantViolations.some(I=>!qi(I,a.node))){d=!1;break}if(l.partial.has(p)){let I=v.get("init");if(!I.isExpression()||!zt(I.node)){d=!1;break}u.push({binding:p,source:I.node}),c.push(I)}}if(!d)continue;let g=new Set,S=p=>{let f=p.scope.getBinding(p.node.name),v=f===void 0?void 0:o.get(f);v!==void 0&&g.add(v)},y={Function(p){p.skip()},ReferencedIdentifier(p){p.isIdentifier()&&S(p)}};a.traverse(y);for(let p of c)p.isReferencedIdentifier()&&S(p),p.traverse(y);if(g.size!==0){for(let p of l.bindings)if(g.has(p))throw a.buildCodeFrameError(`memo-dom: reactive control-flow derivation '${p}' reads its own previous value`);r.push({statement:a.node,bindings:[...l.bindings].sort(),resets:u,sources:[...g].sort()});for(let p of l.bindings){i.add(p);let f=n.scope.getBinding(p);f&&o.set(f,p),e.instanceState.get(t)?.delete(p)}}}r.length>0&&(e.instanceControlFlow.set(t,r),e.instanceDerivedBindings.set(t,i))}}function qo(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 g=r.get(u);if(g===void 0)return new Set([u]);if(c.has(u))return new Set([u]);let S=new Set(c).add(u),y=new Set;for(let p of g)for(let f of i(p,S))y.add(f);return y};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 Kt from"@babel/types";function Gi(e){let t=e.indexOf("[");return t<0?e:e.slice(0,t)}function bt(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(Gi(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 qe(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=>qe(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 qe(e,d.owner,n))l.push(`${u}/${d.suffix}`);for(let d of a)for(let u of qe(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 qe(e,d,n))u>1?l.push(`${c}/${t}`,`${c}/${t}[*]`):l.push(`${c}/${t}`)}return n.delete(t),l}function Tn(e,t){let n=e.linkedComponentPaths.get(t);if(n!==void 0)return bt(e,n.flatMap(i=>[i,`${i}/*`]));let o=e.listedSites.get(t),r=[];if(o&&o.length>0){if(Dt(e,t)){for(let i of o){let s=i.suffix.lastIndexOf("/"),a=s<0?"":`/${i.suffix.slice(0,s)}`;for(let l of qe(e,i.owner))r.push(`${l}${a}`,`${l}${a}/*`)}return bt(e,r)}for(let i of o)for(let s of qe(e,i.owner))r.push(`${s}/${i.suffix}/Row[*]`,`${s}/${i.suffix}/Row[*]/*`);return bt(e,r)}for(let i of qe(e,t))r.push(i,`${i}/*`);return bt(e,r)}function Dt(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&&bn(e,t)&&(r=!0),e.lightweightCache.set(t,r),r}function bn(e,t){if((e.instanceState.get(t)?.size??0)>0)return!1;let n=!0;return e.compPaths.get(t).traverse({JSXElement(r){let i=r.node.openingElement.name;Kt.isJSXIdentifier(i)&&/^[A-Z]/.test(i.name)&&(n=!1)},CallExpression(r){(Kt.isIdentifier(r.node.callee,{name:"cleanup"})&&r.scope.getBinding("cleanup")===void 0||Kt.isIdentifier(r.node.callee,{name:"effect"})&&r.scope.getBinding("effect")===void 0)&&(n=!1),Oe(r.node)&&De(r)&&(n=!1)},ConditionalExpression(r){De(r)&&(n=!1)},LogicalExpression(r){De(r)&&(n=!1)}}),n}import*as W from"@babel/types";function Go(e,t){let n=e.findParent(o=>o.isFunctionDeclaration()||o.isFunctionExpression()||o.isArrowFunctionExpression());return n===t?!0:n?.findParent(o=>o===t)!==null}function Bn(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(!W.isJSXIdentifier(s)||!/^[A-Z]/.test(s.name))return!1;let a=W.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 Zi(e,t){if(W.isArrayExpression(e))return e;if(!W.isIdentifier(e))return null;let n=t.scope.getBinding(e.name);return n?.path.isVariableDeclarator()&&W.isArrayExpression(n.path.node.init)?n.path.node.init:null}function Vn(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||W.isNullLiteral(r)||W.isBooleanLiteral(r))){if(W.isSpreadElement(r)){if(!W.isExpression(r.argument))throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");let i=Zi(r.argument,t);if(i===null)throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");o.push(...Vn(i,t,n));continue}if(W.isArrayExpression(r)){o.push(...Vn(r,t,n));continue}if(W.isJSXElement(r)||W.isJSXFragment(r)){o.push(W.cloneNode(r,!0));continue}if(!W.isExpression(r))throw t.buildCodeFrameError("memo-dom: JSX arrays require renderable expression entries");o.push(W.jsxExpressionContainer(W.cloneNode(r,!0)))}}finally{n.delete(e)}return o}function Zo(e,t){return W.jsxFragment(W.jsxOpeningFragment(),W.jsxClosingFragment(),Vn(e,t))}function Yi(e,t){return W.isArrayExpression(e)?e.elements.map((n,o)=>{if(n==null||W.isSpreadElement(n))throw t.buildCodeFrameError("memo-dom: JSX arrays cannot contain holes or spread elements");return{key:W.numericLiteral(o),value:n}}):e.properties.map(n=>{if(!W.isObjectProperty(n)||n.computed||!W.isExpression(n.value))throw t.buildCodeFrameError("memo-dom: JSX objects require static data properties without spreads");let o=W.isIdentifier(n.key)?W.stringLiteral(n.key.name):W.isStringLiteral(n.key)||W.isNumericLiteral(n.key)?W.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 Qi(e,t){let n=e.node,o=null;if(!n.computed&&W.isIdentifier(n.property)?o=n.property.name:n.computed&&(W.isStringLiteral(n.property)||W.isNumericLiteral(n.property))&&(o=n.property.value),o!==null){let i=t.find(s=>(W.isStringLiteral(s.key)||W.isNumericLiteral(s.key))&&s.key.value===o);if(i===void 0)throw e.buildCodeFrameError(`memo-dom: JSX collection has no entry for '${o}'`);return W.cloneNode(i.value,!0)}if(!n.computed||!W.isExpression(n.property))throw e.buildCodeFrameError("memo-dom: JSX collection selection requires a static or expression key");let r=W.nullLiteral();for(let i=t.length-1;i>=0;i--){let s=t[i];r=W.conditionalExpression(W.binaryExpression("===",W.cloneNode(n.property,!0),W.cloneNode(s.key,!0)),W.cloneNode(s.value,!0),r)}return r}function Yo(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()||!ue(i.node)||(r.replaceWith(Zo(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(!W.isIdentifier(a.id)||l==null||!ue(l))continue;let d=s.scope.getBinding(a.id.name);if(d?.path!==s)continue;let u=[...d.referencePaths];if(W.isObjectExpression(l)||W.isArrayExpression(l))for(let c of u){if(!c.isIdentifier()||!Go(c,t))throw c.buildCodeFrameError(`memo-dom: JSX collection '${a.id.name}' is used outside its component`);if(c.parentPath?.isMemberExpression()&&c.parentPath.node.object===c.node){let g=c.parentPath;if(!Bn(g,e))throw g.buildCodeFrameError(`memo-dom: JSX collection '${a.id.name}' is used outside a render position`);g.replaceWith(Qi(g,Yi(l,s)));continue}if(W.isArrayExpression(l)&&c.parentPath?.isSpreadElement()&&c.parentPath.parentPath?.isArrayExpression()){c.replaceWith(W.cloneNode(l,!0));continue}if(W.isArrayExpression(l)&&Bn(c,e)){c.replaceWith(Zo(l,c));continue}throw c.buildCodeFrameError(W.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()||!Go(c,t))){if(!Bn(c,e))throw c.buildCodeFrameError(`memo-dom: JSX value '${a.id.name}' is used outside a render position`);c.replaceWith(W.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)&&(W.isJSXElement(i)||W.isJSXFragment(i))&&r.replaceWith(i)}}),t.scope.crawl())}}import*as R from"@babel/types";function Wn(e){return R.isReturnStatement(e)&&R.isExpression(e.argument)?e.argument:R.isBlockStatement(e)&&e.body.length===1?Wn(e.body[0]):null}function Mt(e){let t=Wn(e);if(t!==null)return t;if(R.isIfStatement(e)&&e.alternate!=null){let n=Mt(e.consequent),o=Mt(e.alternate);return n===null||o===null?null:R.conditionalExpression(R.cloneNode(e.test,!0),R.cloneNode(n,!0),R.cloneNode(o,!0))}if(R.isSwitchStatement(e)){let n=e.cases.find(r=>r.test==null);if(n===void 0||n.consequent.length!==1)return null;let o=Mt(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=Mt(i.consequent[0]);if(s===null)return null;o=R.conditionalExpression(R.binaryExpression("===",R.cloneNode(e.discriminant,!0),R.cloneNode(i.test,!0)),R.cloneNode(s,!0),o)}return o}return null}function es(e,t){if(R.isExpression(e.body))return{expression:R.cloneNode(e.body,!0),locals:new Map};let n=new Map,o=[];for(let s of e.body.body){if(R.isVariableDeclaration(s,{kind:"const"})){for(let a of s.declarations)(!R.isIdentifier(a.id)||a.init==null||!R.isExpression(a.init))&&t("memo-dom: JSX render functions require identifier const declarations with expression initializers"),n.set(a.id.name,R.cloneNode(a.init,!0));continue}R.isTypeScript(s)||R.isEmptyStatement(s)||o.push(s)}if(o.length===1){let s=Mt(o[0]);if(s!==null)return{expression:s,locals:n}}let r=o.at(-1),i=r===void 0?null:Wn(r);if(i!==null){let s=R.cloneNode(i,!0);for(let a=o.length-2;a>=0;a--){let l=o[a];if(R.isIfStatement(l)&&l.alternate==null){let d=Mt(l.consequent);if(d!==null){s=R.conditionalExpression(R.cloneNode(l.test,!0),R.cloneNode(d,!0),s);continue}}t("memo-dom: JSX render functions support pure const setup, JSX return expressions, tail early-return if statements, exhaustive return if/else, or exhaustive return switch statements")}return{expression:s,locals:n}}return t("memo-dom: JSX render function does not have supported exhaustive return control flow")}function ts(e,t){return(R.isMemberExpression(e)||R.isOptionalMemberExpression(e))&&t==="property"&&!e.computed||(R.isObjectProperty(e)||R.isObjectMethod(e)||R.isClassMethod(e))&&t==="key"&&!e.computed||R.isVariableDeclarator(e)&&t==="id"||(R.isFunction(e)||R.isCatchClause(e))&&(t==="params"||t==="param"||t==="id")||R.isLabeledStatement(e)&&t==="label"}function Qo(e,t,n=new Set){let o=R.cloneNode(e,!0),r=(i,s,a,l)=>{if(R.isIdentifier(i)&&!l.has(i.name)&&t.has(i.name)&&(s===null||!ts(s,a)))return R.cloneNode(t.get(i.name),!0);let d=l;if(R.isFunction(i)&&i!==o){let u=i.params.flatMap(c=>Object.keys(R.getBindingIdentifiers(c)));d=new Set([...l,...u])}for(let u of R.VISITOR_KEYS[i.type]??[]){let c=i[u];Array.isArray(c)?i[u]=c.map(g=>g!=null&&typeof g=="object"&&"type"in g?r(g,i,u,d):g):c!=null&&typeof c=="object"&&"type"in c&&(i[u]=r(c,i,u,d))}return R.isObjectProperty(i)&&i.shorthand&&!R.isIdentifier(i.value,{name:R.isIdentifier(i.key)?i.key.name:""})&&(i.shorthand=!1),i};return r(o,null,"",n)}function ns(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=>R.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&&R.isExpression(d)?d:R.identifier("undefined");if(R.isIdentifier(l)){r.set(l.name,R.cloneNode(u,!0));continue}if(R.isAssignmentPattern(l)&&R.isIdentifier(l.left)){r.set(l.left.name,R.conditionalExpression(R.binaryExpression("===",R.cloneNode(u,!0),R.identifier("undefined")),R.cloneNode(l.right,!0),R.cloneNode(u,!0)));continue}n("memo-dom: JSX render functions currently require identifier parameters with optional defaults")}let i=es(o,n);for(let[a,l]of i.locals)r.set(a,Qo(l,r));let s=Qo(i.expression,r);return ue(s)||n("memo-dom: JSX render function expansion did not produce JSX"),s}function os(e,t){let n=t.get("callee");return Array.isArray(n)||!n.isIdentifier()?null:er(e,n)}function er(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()&&ue(r.path.node))return{node:r.path.node,bindingPath:r.path};if(r?.path.isVariableDeclarator()){let i=r.path.node.init;if((R.isFunctionExpression(i)||R.isArrowFunctionExpression(i))&&ue(i.body))return{node:i,bindingPath:r.path}}return null}function tr(e){return R.isMemberExpression(e.callee)&&!e.callee.computed&&R.isIdentifier(e.callee.property,{name:"map"})}function rs(e){let t=e.parentPath;return t?.isCallExpression()===!0&&(t.node.callee===e.node||tr(t.node)&&t.node.arguments[0]===e.node)}function is(e,t){let n=e.node;if(n.async||n.generator)throw t.buildCodeFrameError("memo-dom: JSX render callbacks must be synchronous");return R.arrowFunctionExpression(n.params.map(o=>R.cloneNode(o,!0)),R.cloneNode(n.body,!0))}function hn(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()&&hn(t)}}}function ss(e,t){let n=t.findParent(o=>o.isProgram());if(n===null||!n.isProgram()){hn(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()&&R.isIdentifier(a.node.id,{name:e}));if(s!==void 0){i.length===1?o.remove():s.remove();return}}hn(t)}function as(e,t){let n=e.parentPath,o=n?.parentPath;if((R.isJSXElement(t)||R.isJSXFragment(t))&&n?.isJSXExpressionContainer()&&(o?.isJSXElement()||o?.isJSXFragment())&&o.node.children.includes(n.node)){n.replaceWith(t);return}e.replaceWith(t)}function nr(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()&&!rs(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(!tr(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=er(e,i);s!==null&&(i.replaceWith(is(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=os(e,i);s!==null&&(as(i,ns(s,i)),t.add(s.bindingPath),o=!0)}}}for(let[n,o]of e.jsxHelpers)ss(n,o);for(let n of t)hn(n)}import*as We from"@babel/types";function ls(e){let t=Ln(e);return We.isIdentifier(t)||We.isMemberExpression(t)||rn(t)}function ds(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 cs(e,t){return e.findParent(n=>n.isFunctionDeclaration()||n.isFunctionExpression()||n.isArrowFunctionExpression())===t}function or(e){for(let[,t]of e.compPaths){let n=[];if(t.traverse({CallExpression(s){if(Oe(s.node)===null||!We.isMemberExpression(s.node.callee)||!We.isExpression(s.node.callee.object)||ls(s.node.callee.object)||!cs(s,t))return;let a=ds(s,t);a!==null&&n.push({path:s,source:We.cloneNode(s.node.callee.object,!0),statement:a})}}),n.length===0)continue;let o=t.get("body").get("body"),r=new Map(o.map((s,a)=>[s.node,a]));n.sort((s,a)=>(r.get(s.statement.node)??0)-(r.get(a.statement.node)??0));let i=[];for(let s of n){let a=$(e,"listView");i.push(We.variableDeclarator(We.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(We.cloneNode(a))}n[0].statement.insertBefore(We.variableDeclaration("const",i)),t.scope.crawl()}}import*as P from"@babel/types";function us(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 En(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 g=1;for(;n.has(u);)u=`${c}${g++}`;n.add(u),o.set(d.key,u);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(u,S),e.componentProps.set(u,us(S)),r.push(P.importDeclaration(d.imported==="default"?[P.importDefaultSpecifier(P.identifier(u))]:[P.importSpecifier(P.identifier(u),P.isValidIdentifier(d.imported)?P.identifier(d.imported):P.stringLiteral(d.imported))],P.stringLiteral(d.source)))}a.push(u)}let l=[...new Set(a)];e.state.has(i)?e.stateComponentCandidates.set(i,l):e.functionComponentCandidates.set(i,l)}for(let i of r.reverse())t.unshiftContainer("body",i);t.scope.crawl()}function zn(e){let t=e;for(;P.isTSAsExpression(t)||P.isTSTypeAssertion(t)||P.isTSNonNullExpression(t);)t=t.expression;return t}function rr(e){return P.isJSXIdentifier(e)?P.identifier(e.name):P.memberExpression(rr(e.object),P.identifier(e.property.name))}function ir(e,t){let n=ye(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=zn(s),!P.isObjectExpression(s))return null;let l=s.properties.find(d=>!P.isObjectProperty(d)||d.computed?!1:(P.isIdentifier(d.key)?d.key.name:P.isStringLiteral(d.key)?d.key.value:null)===a);if(l===void 0||!P.isObjectProperty(l)||!P.isExpression(l.value))return null;s=l.value}return s}function ps(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()&&(P.isFunctionExpression(n.path.node.init)||P.isArrowFunctionExpression(n.path.node.init))&&(o=n.path.node.init),o===null?[]:sr(o)}function sr(e){if(P.isExpression(e.body))return[e.body];let t=[],n=o=>{if(!P.isFunction(o)){if(P.isReturnStatement(o)){P.isExpression(o.argument)&&t.push(o.argument);return}for(let r of P.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 ht(e,t,n,o=new Set){let r=zn(t);if(!o.has(r)){if(o.add(r),P.isIdentifier(r)&&(e.comps.has(r.name)||e.importedComponents.has(r.name))){n.add(r.name);return}if(P.isIdentifier(r)){for(let i of e.stateComponentCandidates.get(r.name)??e.functionComponentCandidates.get(r.name)??[])n.add(i);return}if(P.isConditionalExpression(r)){ht(e,r.consequent,n,o),ht(e,r.alternate,n,o);return}if(P.isLogicalExpression(r)){ht(e,r.right,n,o);return}if(P.isObjectExpression(r)){for(let i of r.properties)P.isObjectProperty(i)&&P.isExpression(i.value)&&ht(e,i.value,n,o);return}if(P.isArrayExpression(r)){for(let i of r.elements)i!=null&&!P.isSpreadElement(i)&&ht(e,i,n,o);return}if(P.isCallExpression(r)&&P.isIdentifier(r.callee)){for(let i of e.functionComponentCandidates.get(r.callee.name)??[])n.add(i);return}if(P.isMemberExpression(r)){let i=Pe(r);if(i!==null)for(let s of e.stateComponentCandidates.get(i)??[])n.add(s)}}}function ar(e,t){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)||i.init==null)continue;let s=new Set;ht(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;(P.isFunctionDeclaration(a)||P.isFunctionExpression(a)||P.isArrowFunctionExpression(a))&&(s=sr(a));for(let l of s)ht(e,l,i);i.size>0&&i.size!==(e.functionComponentCandidates.get(o)?.length??0)&&(e.functionComponentCandidates.set(o,[...i]),n=!0)}}}function Ge(e,t,n,o,r=new Set){let i=zn(n);if(!r.has(i)){if(r.add(i),P.isConditionalExpression(i)){Ge(e,t,i.consequent,o,r),Ge(e,t,i.alternate,o,r);return}if(P.isStringLiteral(i)){if(!/^[A-Za-z][A-Za-z0-9:_-]*$/.test(i.value))throw t.buildCodeFrameError(`memo-dom: '${i.value}' is not a valid dynamic intrinsic tag name`);o.push({compare:P.cloneNode(i),tag:P.jsxIdentifier(i.value)});return}if(P.isIdentifier(i)){if(e.comps.has(i.name)||e.importedComponents.has(i.name)){o.push({compare:P.cloneNode(i),tag:P.jsxIdentifier(i.name)});return}let s=e.stateTagCandidates.get(i.name);if(s!==void 0)for(let l of s)Ge(e,t,P.stringLiteral(l),o,r);let a=t.scope.getBinding(i.name);a?.path.isVariableDeclarator()&&a.path.node.init!=null&&Ge(e,t,a.path.node.init,o,r);return}if(P.isCallExpression(i)&&P.isIdentifier(i.callee)){for(let s of e.functionTagCandidates.get(i.callee.name)??[])Ge(e,t,P.stringLiteral(s),o,r);for(let s of ps(t,i.callee.name))Ge(e,t,s,o,r);for(let s of e.functionComponentCandidates.get(i.callee.name)??[])Ge(e,t,P.identifier(s),o,r);return}if(P.isMemberExpression(i)){let s=ir(t,i);if(s!==null){Ge(e,t,s,o,r);return}let a=Pe(i);if(a===null)return;let l=t.scope.getBinding(a);if(l?.path.isVariableDeclarator()&&l.path.node.init!=null){let d=new Set;ht(e,l.path.node.init,d);for(let u of d)Ge(e,t,P.identifier(u),o,r)}for(let d of e.stateTagCandidates.get(a)??[])Ge(e,t,P.stringLiteral(d),o,r);for(let d of e.stateComponentCandidates.get(a)??[])Ge(e,t,P.identifier(d),o,r)}}}function fs(e){return P.isStringLiteral(e.compare)?`string:${e.compare.value}`:P.isIdentifier(e.compare)?`component:${e.compare.name}`:JSON.stringify(e.compare)}function ms(e,t){if(P.isIdentifier(t)){let n=e.scope.getBinding(t.name);return n?.path.isVariableDeclarator()?[...n.path.node.init==null?[]:[n.path.node.init],...n.constantViolations.flatMap(o=>o.isAssignmentExpression()&&o.node.operator==="="&&P.isExpression(o.node.right)?[o.node.right]:[])]:[]}if(P.isMemberExpression(t)){let n=ir(e,t),o=ye(t),r=[];return o!==null&&(e.getFunctionParent()??e.findParent(a=>a.isProgram()))?.traverse({AssignmentExpression(a){a.node.operator==="="&&P.isMemberExpression(a.node.left)&&ye(a.node.left)===o&&P.isExpression(a.node.right)&&r.push(a.node.right)}}),[...n===null?[]:[n],...r]}return[]}function lr(e,t){let n=P.cloneNode(e,!0);n.openingElement.name=P.cloneNode(t);let o=n.closingElement;return o!=null&&(o.name=P.cloneNode(t)),n}function gs(e,t,n){let o=P.nullLiteral();for(let r=n.length-1;r>=0;r--){let i=n[r];o=P.conditionalExpression(P.binaryExpression("===",P.cloneNode(e,!0),P.cloneNode(i.compare,!0)),lr(t,i.tag),o)}return o}function bs(e){return P.isIdentifier(e)?e.name:P.isMemberExpression(e)?ye(e)??"<member expression>":"<expression>"}function dr(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(P.isJSXNamespacedName(i))throw r.buildCodeFrameError("memo-dom: namespaced JSX tags are not supported");if(P.isJSXIdentifier(i)&&(!/^[A-Z]/.test(i.name)||e.comps.has(i.name)||e.importedComponents.has(i.name)))continue;let s=rr(i),a=ms(r,s),l=[];for(let u of a)Ge(e,r,u,l);let d=[...new Map(l.map(u=>[fs(u),u])).values()];if(d.length===0)throw r.buildCodeFrameError(`memo-dom: dynamic JSX tag '${bs(s)}' has no finite string or linked-component candidates`);for(let u of d){if(!P.isJSXIdentifier(u.tag))continue;let c=e.componentProps.get(u.tag.name);if(c===void 0||c.renderProps.length===0)continue;let g=t.get(u.tag.name);g===void 0&&(g=new Map,t.set(u.tag.name,g));for(let S of r.node.openingElement.attributes){if(P.isJSXSpreadAttribute(S)||!P.isJSXIdentifier(S.name)||!c.renderProps.includes(S.name.name))continue;let y=$e(S.value),p=g.get(S.name.name)??{scalar:!1,jsx:!1,at:r};y!==null&&ue(y)?p.jsx=!0:p.scalar=!0,g.set(S.name.name,p)}}if(d.length===1){r.replaceWith(lr(r.node,d[0].tag));continue}r.replaceWith(P.jsxFragment(P.jsxOpeningFragment(),P.jsxClosingFragment(),[P.jsxExpressionContainer(gs(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 ee from"@babel/types";function Kn(e){return ee.isExportNamedDeclaration(e)?e.declaration??null:ee.isDeclaration(e)?e:null}function cr(e){let t=new Map;for(let n of e.body){let o=Kn(n);ee.isTSTypeAliasDeclaration(o)&&t.set(o.id.name,o.typeAnnotation)}return t}function dt(e,t,n=new Set){if(ee.isTSLiteralType(e)&&ee.isStringLiteral(e.literal))return[e.literal.value];if(ee.isTSUnionType(e))return e.types.flatMap(o=>dt(o,t,n));if(ee.isTSIntersectionType(e))return e.types.flatMap(o=>dt(o,t,n));if(ee.isTSParenthesizedType(e))return dt(e.typeAnnotation,t,n);if(ee.isTSTypeLiteral(e))return e.members.flatMap(o=>(ee.isTSPropertySignature(o)||ee.isTSIndexSignature(o))&&ee.isTSTypeAnnotation(o.typeAnnotation)&&ee.isTSType(o.typeAnnotation.typeAnnotation)?dt(o.typeAnnotation.typeAnnotation,t,n):[]);if(ee.isTSMappedType(e)&&e.typeAnnotation!=null&&ee.isTSType(e.typeAnnotation))return dt(e.typeAnnotation,t,n);if(ee.isTSTypeReference(e)&&ee.isIdentifier(e.typeName)){let o=e.typeName.name;if((o==="Record"||o==="Readonly"||o==="Partial")&&ee.isTSTypeParameterInstantiation(e.typeArguments)){let s=o==="Record"?e.typeArguments.params[1]:e.typeArguments.params[0];if(s!==void 0&&ee.isTSType(s))return dt(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),dt(r,t,i)}return[]}function yn(e){let t=cr(e),n=new Map;for(let o of e.body){let r=Kn(o);if(ee.isVariableDeclaration(r))for(let i of r.declarations){if(!ee.isIdentifier(i.id)||!ee.isTSTypeAnnotation(i.id.typeAnnotation))continue;let s=[...new Set(dt(i.id.typeAnnotation.typeAnnotation,t))];s.length>0&&n.set(i.id.name,s)}}return n}function Hn(e){let t=cr(e),n=new Map,o=(r,i)=>{if(!ee.isTSTypeAnnotation(i)||!ee.isTSType(i.typeAnnotation))return;let s=[...new Set(dt(i.typeAnnotation,t))];s.length>0&&n.set(r,s)};for(let r of e.body){let i=Kn(r);if(ee.isFunctionDeclaration(i)&&i.id!=null){o(i.id.name,i.returnType);continue}if(ee.isVariableDeclaration(i))for(let s of i.declarations)ee.isIdentifier(s.id)&&(ee.isArrowFunctionExpression(s.init)||ee.isFunctionExpression(s.init))&&o(s.id.name,s.init.returnType)}return n}import*as ot from"@babel/types";import*as Ee from"@babel/types";function Ht(e,t){let n=[],o=[],r=-1;for(let s=0;s<e.length;s++)Ee.isJSXSpreadAttribute(e[s])&&(r=s);let i=[];for(let s=0;s<e.length;s++){let a=e[s];if(Ee.isJSXSpreadAttribute(a)){n.push(Ee.spreadElement(Ee.cloneNode(a.argument))),o.push(Ee.cloneNode(a.argument));continue}let l=Ae(a.name);if(l==="key"&&t.skipKey)continue;let d=hs(a,t.fail),u=t.attributeValue?.(l,d)??d,c=/^on[A-Z]/.test(l)&&t.eventValue!==void 0?t.eventValue(l,u):u;n.push(Ee.objectProperty(Ee.isValidIdentifier(l)?Ee.identifier(l):Ee.stringLiteral(l),c,!1,Ee.isIdentifier(c)&&c.name===l)),o.push(Ee.cloneNode(d)),/^on[A-Z]/.test(l)&&s>r&&i.push(l)}return{expression:Ee.objectExpression(n),sources:o,safeEventKeys:i}}function Ae(e){return Ee.isJSXIdentifier(e)?e.name:`${e.namespace.name}:${e.name.name}`}function hs(e,t){return e.value==null?Ee.booleanLiteral(!0):Ee.isStringLiteral(e.value)?Ee.cloneNode(e.value):Ee.isJSXExpressionContainer(e.value)&&Ee.isExpression(e.value.expression)?Ee.cloneNode(e.value.expression):t(`memo-dom: attribute '${Ae(e.name)}' must contain a JavaScript expression`)}function Sn(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(!(!ot.isJSXIdentifier(a)||!/^[A-Z]/.test(a.name)))for(let l of Sn(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(!ot.isJSXIdentifier(s))return;let a=Ae(r.node.name);if(e.componentProps.get(s.name)?.renderCallbacks.includes(a)!==!0)return;let l=r.node.value;!ot.isJSXExpressionContainer(l)||!ot.isExpression(l.expression)||Xe(l.expression,d=>{if(ot.isJSXOpeningElement(d)&&ot.isJSXIdentifier(d.name)&&/^[A-Z]/.test(d.name.name))for(let u of Sn(e,d.name.name))o.add(u)})}})}}import*as Et from"@babel/types";function pr(e){for(let[t,n]of e.compPaths){let o=e.componentProps.get(t);n.traverse({JSXAttribute(r){if(Ae(r.node.name)!=="ref")return;let i=r.node.value;if(!(!Et.isJSXExpressionContainer(i)||!Et.isExpression(i.expression)))for(let s of fr(e,t,i.expression))o.refProps.includes(s)||o.refProps.push(s)}})}}function fr(e,t,n){let o=lt(e,t,n);if(o!==null)return[o];if(!Et.isArrayExpression(n))return[];let r=[];for(let i of n.elements)i===null||Et.isSpreadElement(i)||r.push(...fr(e,t,i));return r}import*as kt from"@babel/types";function xn(e){let t=!1;return Xe(e,n=>{if(t||!kt.isJSXOpeningElement(n))return;let o=n.name;!kt.isJSXIdentifier(o)||!/^[a-z]/.test(o.name)||(t=n.attributes.some(r=>kt.isJSXAttribute(r)&&kt.isJSXIdentifier(r.name)&&/^on[A-Z]/.test(r.name.name)))}),t}import*as je from"@babel/types";function Un(e){let t=(o,r)=>{let i=Ue(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=Tn(e,o);for(let s of r)t(s,i)}for(let{owner:o,suffix:r,vars:i}of e.rowReads.values()){let s=bt(e,qe(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=bt(e,qe(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=Tn(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])=>je.objectProperty(je.stringLiteral(o),je.arrayExpression([...r].sort().map(i=>je.stringLiteral(i)))));return je.expressionStatement(je.callExpression(Z(e,"installAccessTable"),[je.objectExpression([je.objectProperty(je.identifier("readers"),je.objectExpression(n))]),je.stringLiteral(e.rootId)]))}function gr(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(!k.isJSXIdentifier(r)||!/^[A-Z]/.test(r.name))return!1;let i=n.node.name,s=k.isJSXIdentifier(i)?i.name:i.name.name;return e.componentProps.get(r.name)?.renderProps.includes(s)===!0}function mr(e,t){let n=t.parentPath,o=n?.parentPath;if(!n?.isJSXExpressionContainer()||!o?.isJSXElement()&&!o?.isJSXFragment()&&!gr(e,n))throw t.buildCodeFrameError("memo-dom: conditional rendering must be a direct JSX child: <div>{cond ? <A/> : <B/>}</div>");t.skip()}function Es(e,t){for(let n of t.get("body"))if(!(!n.isImportDeclaration()||n.node.importKind==="type"))for(let o of n.node.specifiers){if(k.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 ys(e,t){let n=yn(t.node);for(let o of t.node.body){let r=k.isExportNamedDeclaration(o)?o.declaration:o;if(k.isVariableDeclaration(r)){for(let i of r.declarations)if(k.isIdentifier(i.id)&&(r.kind==="let"||r.kind==="var"?pt(e,i.id.name,"let"):r.kind==="const"&&(Ct(i.init)?pt(e,i.id.name,"store"):Pt(i.init)&&pt(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 Ss(e,t){t.traverse({FunctionDeclaration(n){let o=n.node.id?.name;if(o&&!e.comps.has(o)&&!e.helpers.has(o)&&!e.jsxHelpers.has(o))if(De(n))if(/^[A-Z]/.test(o)){e.comps.set(o,{parents:new Set,jsxCount:0}),e.compPaths.set(o,n),xn(n.node.body)&&e.componentsWithHostEvents.add(o);try{e.componentProps.set(o,nn(n.node.params))}catch(r){throw n.buildCodeFrameError(`memo-dom: invalid props for component '${o}': ${r instanceof Error?r.message:String(r)}`)}}else e.jsxHelpers.set(o,n);else e.helpers.set(o,n);n.skip()},VariableDeclarator(n){if(!n.scope.path.isProgram()||!k.isIdentifier(n.node.id))return;let o=n.get("init");(o.isArrowFunctionExpression()||o.isFunctionExpression())&&(ue(o.node.body)?/^[A-Z]/.test(n.node.id.name)||e.jsxHelpers.set(n.node.id.name,o):e.helpers.set(n.node.id.name,o),o.skip())}});for(let n of t.get("body")){let o=n.isExportNamedDeclaration()?n.get("declaration"):n;if(!(Array.isArray(o)||!o.isVariableDeclaration()))for(let r of o.get("declarations")){if(!r.isVariableDeclarator())continue;let i=r.node.id,s=r.get("init");!k.isIdentifier(i)||/^[A-Z]/.test(i.name)||Array.isArray(s)||!s.isArrowFunctionExpression()&&!s.isFunctionExpression()||!ue(s.node.body)||(e.helpers.delete(i.name),e.jsxHelpers.set(i.name,s))}}}function Cn(e,t,n=new Set){if(k.isTSStringKeyword(e)||k.isTSNumberKeyword(e)||k.isTSBooleanKeyword(e)||k.isTSBigIntKeyword(e)||k.isTSSymbolKeyword(e)||k.isTSNullKeyword(e)||k.isTSUndefinedKeyword(e)||k.isTSLiteralType(e))return!0;if(k.isTSParenthesizedType(e))return Cn(e.typeAnnotation,t,n);if(k.isTSUnionType(e))return e.types.every(o=>Cn(o,t,n));if(k.isTSTypeReference(e)&&k.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=k.isExportNamedDeclaration(i)?i.declaration:i;if(k.isTSTypeAliasDeclaration(s)&&s.id.name===o)return Cn(s.typeAnnotation,t,r)}}return!1}function xs(e,t){let n=l=>k.isStringLiteral(l)||k.isNumericLiteral(l)||k.isBooleanLiteral(l)||k.isBigIntLiteral(l)||k.isUnaryExpression(l)&&(l.operator==="+"||l.operator==="-")&&k.isNumericLiteral(l.argument);for(let l of e.node.params){if(k.isTSParameterProperty(l))continue;if(k.isAssignmentPattern(l)&&k.isIdentifier(l.left,{name:t})&&n(l.right))return!0;if(k.isAssignmentPattern(l)&&k.isObjectPattern(l.left)&&k.isObjectExpression(l.right)){let u=l.right.properties.find(c=>!k.isObjectProperty(c)||c.computed?!1:(k.isIdentifier(c.key)?c.key.name:k.isStringLiteral(c.key)?c.key.value:null)===t);if(k.isObjectProperty(u)&&k.isExpression(u.value)&&n(u.value))return!0}let d=k.isAssignmentPattern(l)?l.left:l;if(k.isObjectPattern(d))for(let u of d.properties){if(!k.isObjectProperty(u)||u.computed)continue;if((k.isIdentifier(u.key)?u.key.name:k.isStringLiteral(u.key)?u.key.value:null)===t&&k.isAssignmentPattern(u.value)&&n(u.value.right))return!0}}let o=e.node.params[0];if(o==null||k.isTSParameterProperty(o))return!1;let r=k.isAssignmentPattern(o)?o.left:o;if(!k.isIdentifier(r)&&!k.isObjectPattern(r)&&!k.isArrayPattern(r))return!1;let i=r.typeAnnotation;if(!k.isTSTypeAnnotation(i))return!1;let s=e.findParent(l=>l.isProgram());if(!s?.isProgram())return!1;let a=i.typeAnnotation;if(k.isTSTypeReference(a)&&k.isIdentifier(a.typeName)){let l=a.typeName.name,d=s.node.body.map(u=>k.isExportNamedDeclaration(u)?u.declaration:u).find(u=>(k.isTSInterfaceDeclaration(u)||k.isTSTypeAliasDeclaration(u))&&u.id.name===l);k.isTSInterfaceDeclaration(d)?a=k.tsTypeLiteral(d.body.body):k.isTSTypeAliasDeclaration(d)&&(a=d.typeAnnotation)}if(!k.isTSTypeLiteral(a))return!1;for(let l of a.members){if(!k.isTSPropertySignature(l)||l.computed)continue;if((k.isIdentifier(l.key)?l.key.name:k.isStringLiteral(l.key)?l.key.value:null)===t&&k.isTSTypeAnnotation(l.typeAnnotation))return Cn(l.typeAnnotation.typeAnnotation,s.node)}return!1}function _n(e,t=new Set){if(ue(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?_n(o,t):!1}}if(e.isMemberExpression()){let n=e.get("object");return!Array.isArray(n)&&_n(n,t)}return!1}function Cs(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(!k.isExpression(l))return;let d=lt(e,r,l);d!==null&&(xs(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(!k.isJSXIdentifier(a)||!e.comps.has(a.name))return;let l=e.componentProps.get(a.name),d=t.get(a.name);if(d===void 0)return;let u=n.get(a.name);u===void 0&&(u=new Map,n.set(a.name,u)),d.has("children")&&s.node.children.some(c=>!k.isJSXText(c)||c.value.trim()!=="")&&!l.renderProps.includes("children")&&(l.renderProps.push("children"),u.set("children",{scalar:!1,jsx:!0,at:s}));for(let c of s.get("openingElement").get("attributes")){if(!c.isJSXAttribute())continue;let g=c.node.name,S=k.isJSXIdentifier(g)?g.name:g.name.name;if(!d.has(S))continue;let y=u.get(S)??{scalar:!1,jsx:!1,at:c},p=c.get("value"),f=!1;if(p.isJSXExpressionContainer()&&k.isExpression(p.node.expression)){let v=p.get("expression");!Array.isArray(v)&&(_n(v)||k.isExpression(v.node)&<(e,r,v.node)!==null)&&(f=!0)}f?y.jsx=!0:y.scalar=!0,u.set(S,y)}}});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()||!k.isExpression(l.node.expression))return;let d=lt(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(!k.isJSXIdentifier(c)||!/^[A-Z]/.test(c.name))return;let g=e.componentProps.get(c.name),S=a.node.name,y=k.isJSXIdentifier(S)?S.name:S.name.name;g?.renderProps.includes(y)===!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 Ps(e,t){let n=e.compPaths.get(t),o=e.comps.get(t);n.traverse({JSXElement(r){let i=r.node.openingElement;if(!k.isJSXIdentifier(i.name))throw r.buildCodeFrameError("memo-dom: namespaced or member-expression JSX tags are not supported (L1)");for(let a of i.attributes)if(!k.isJSXSpreadAttribute(a)&&a.name.name==="key"){if(Po(e,r))continue;throw r.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 r.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),(r.node.children.some(d=>!k.isJSXText(d)||d.value.trim()!=="")||i.attributes.some(d=>{if(k.isJSXSpreadAttribute(d)||e.componentProps.get(s)?.renderProps.includes(k.isJSXIdentifier(d.name)?d.name.name:d.name.name.name)!==!0)return!1;let u=$e(d.value);return u!==null&&ue(u)}))&&e.renderSlotOwners.add(t);return}o.jsxCount++},ConditionalExpression(r){De(r)&&mr(e,r)},LogicalExpression(r){if(De(r)){if(r.node.operator!=="&&"&&r.node.operator!=="||")throw r.buildCodeFrameError("memo-dom: only && / || conditionals are supported (R8 L1), not ??");mr(e,r)}},CallExpression(r){let i=Oe(r.node);if(i&&(De(r)||Ft(e,t,i)!==null)){let s=r.parentPath,a=s?.parentPath;if(!s?.isJSXExpressionContainer()||!a?.isJSXElement()&&!a?.isJSXFragment()&&!gr(e,s))throw r.buildCodeFrameError("memo-dom: list rendering must be a direct JSX child: <ul>{items.map(item => <Row />)}</ul>");r.skip()}}})}function ws(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}function vs(e,t){let n=ye(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||ws(t)?null:n}function ks(e){for(let[a]of e.comps){let g=function(x,I,J){let F=Oe(x.node);if(F===null||!De(x))return;let N=wt(e,F,x,a,J),K=`${I}/${N.suffix}`;if(N.form==="component"){let _=e.listedSites.get(N.rowComp)??[];_.some(H=>H.owner===a&&H.suffix===K)||_.push({owner:a,suffix:K,itemParam:N.itemParam,keyExpr:N.keyExpr,sourceKey:N.sourceKey,sourceLocal:N.sourceLocal}),e.listedSites.set(N.rowComp,_)}else f(x,N,K);x.skip()},S=function(x,I,J){let F=x.node.openingElement.name;if(!k.isJSXIdentifier(F)||!/^[A-Z]/.test(F.name))return;if(!e.comps.has(F.name)&&!e.importedComponents.has(F.name))throw x.buildCodeFrameError(`memo-dom: <${F.name} /> is not a linked component factory`);let N=J.get(F.name)??0;J.set(F.name,N+1);let K=N===0?F.name:`${F.name}[${N}]`,_=`${I}/${K}`,H=e.conditionalComponentSites.get(F.name)??[];H.some(T=>T.owner===a&&T.suffix===_)||H.push({owner:a,suffix:_}),e.conditionalComponentSites.set(F.name,H)},y=function(x,I,J){let F=x.node.openingElement.name;if(!k.isJSXIdentifier(F)||!/^[A-Z]/.test(F.name))return;if(!e.comps.has(F.name)&&!e.importedComponents.has(F.name))throw x.buildCodeFrameError(`memo-dom: <${F.name} /> is not a linked component factory`);let N=J.get(F.name)??0;J.set(F.name,N+1);let K=N===0?F.name:`${F.name}[${N}]`,_=`${I}/Row[*]/${K}`,H=e.rowComponentSites.get(F.name)??[];H.some(T=>T.owner===a&&T.suffix===_)||H.push({owner:a,suffix:_}),e.rowComponentSites.set(F.name,H)},p=function(x,I){let J=e.listedSites.get(x.rowComp)??[];J.some(F=>F.owner===a&&F.suffix===I)||J.push({owner:a,suffix:I,itemParam:x.itemParam,keyExpr:x.keyExpr,sourceKey:x.sourceKey,sourceLocal:x.sourceLocal}),e.listedSites.set(x.rowComp,J)},f=function(x,I,J){let F=x.get("arguments")[0];if(F===void 0)return;let N=new Set,K=new Map,_=new Map;F.traverse({Identifier(H){H.node.name!==I.itemParam&&e.state.has(H.node.name)&&H.scope.getBinding(H.node.name)?.scope.path.isProgram()===!0&&N.add(H.node.name)},JSXElement(H){y(H,J,K)},CallExpression(H){let T=Oe(H.node);if(T!==null&&De(H)){let ne=wt(e,T,H,a,_,I),G=`${J}/Row[*]/${ne.suffix}`;ne.form==="component"?p(ne,G):f(H,ne,G),H.skip();return}let re=H.node.callee;if(k.isIdentifier(re)&&(e.helpers.has(re.name)||e.importedFunctions.has(re.name))){let ne=e.importedFunctions.get(re.name)??Ve(e,re.name);for(let G of ne.reads)N.add(G)}}}),N.size>0&&e.rowReads.set(`${a}/${J}`,{owner:a,suffix:J,vars:N})},v=function(x,I=null){let J=x.node;if(!De(x))return;let F=an(J,x,c),N=I===null?F.suffix:`${I}/${F.suffix}`,K=[];if(x.isConditionalExpression()){let H=x;for(;H.isConditionalExpression();)K.push(H.get("consequent")),H=H.get("alternate");K.push(H)}else K.push(x.get("right"));for(let H of K){let T=new Map,re=new Map;if((H.isConditionalExpression()||H.isLogicalExpression())&&De(H)){v(H,N);continue}H.isJSXElement()&&S(H,N,re),H.traverse({ConditionalExpression(ne){De(ne)&&(v(ne,N),ne.skip())},LogicalExpression(ne){De(ne)&&(v(ne,N),ne.skip())},JSXElement(ne){S(ne,N,re)},CallExpression(ne){g(ne,N,T)}})}let _=en(e,J);_.size>0&&I===null&&e.condReads.set(`${a}/${N}`,{owner:a,suffix:N,vars:_}),x.skip()};var t=g,n=S,o=y,r=p,i=f,s=v;let l=e.compPaths.get(a),d=new Set,u=new Map,c={count:0};l.traverse({JSXAttribute(x){let I=x.node.name;(k.isJSXIdentifier(I,{name:"ref"})||k.isJSXNamespacedName(I)&&I.namespace.name==="ref")&&x.skip()},ConditionalExpression(x){v(x)},LogicalExpression(x){v(x)},CallExpression(x){if(k.isIdentifier(x.node.callee,{name:"effect"})&&x.scope.getBinding("effect")===void 0){x.skip();return}let I=Oe(x.node);if(I&&(De(x)||Ft(e,a,I)!==null)){let F=wt(e,I,x,a,u);if(F.sourceLocal||d.add(F.sourceKey),F.form==="component"){for(let K of F.jsx.openingElement.attributes){if(k.isJSXSpreadAttribute(K))continue;let _=K,H=k.isJSXIdentifier(_.name)?_.name.name:`${_.name.namespace.name}:${_.name.name.name}`;if(H==="key"||H==="ref"||e.componentProps.get(F.rowComp)?.refProps.includes(H)===!0)continue;let T=$e(_.value);T&&Xe(T,re=>{if(k.isIdentifier(re)&&e.state.has(re.name)&&x.scope.getBinding(re.name)?.scope.path.isProgram()===!0&&d.add(re.name),k.isMemberExpression(re)){let ne=ye(re);if(ne!==null&&ne.includes(".")){let G=ne.split(".")[0];e.state.get(G)==="store"&&x.scope.getBinding(G)?.scope.path.isProgram()===!0&&d.add(ne)}}})}let N=e.listedSites.get(F.rowComp)??[];N.some(K=>K.owner===a&&K.suffix===F.suffix)||N.push({owner:a,suffix:F.suffix,itemParam:F.itemParam,keyExpr:F.keyExpr,sourceKey:F.sourceKey,sourceLocal:F.sourceLocal}),e.listedSites.set(F.rowComp,N)}else f(x,F,F.suffix);x.skip();return}let J=x.node.callee;if(k.isIdentifier(J)&&(e.helpers.has(J.name)||e.importedFunctions.has(J.name))&&x.scope.getBinding(J.name)?.scope.path.isProgram()===!0){let F=e.importedFunctions.get(J.name)??Ve(e,J.name);for(let N of F.reads)d.add(N)}},Identifier(x){if(!e.state.has(x.node.name)||x.scope.getBinding(x.node.name)?.scope.path.isProgram()!==!0)return;let I=x.parentPath;I.isAssignmentExpression({operator:"="})&&I.node.left===x.node||d.add(x.node.name)},MemberExpression(x){let I=vs(e,x);I!==null&&d.add(I)}}),e.compReads.set(a,d)}}function Pn(e,t){Es(e,t),ys(e,t),Ss(e,t),pr(e),wo(e),nr(e),ar(e,t),Cs(e),Yo(e),dr(e),or(e),Ko(e),zo(e,t),Wo(e,t,On),Ho(e),_o(e),qo(e),Jo(e,t);for(let[o]of e.comps)Ps(e,o);ks(e),ur(e);for(let[o]of e.comps)qe(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 D from"@babel/types";import*as h from"@babel/types";import*as Ce from"@babel/types";import*as se from"@babel/types";function Nt(){return{writes:new Set,rootFallback:!1,rowLocal:!1,rowOwnerLocal:!1,instanceLocal:!1,instanceWrites:new Set,eventOrigin:null}}function ct(e,t){e.instanceLocal=!0,e.instanceWrites.add(t)}function Lt(e,t,n,o){let r=t.rowLocal&&o!==void 0?se.expressionStatement(o.refreshVar!==void 0?se.callExpression(se.identifier(o.refreshVar),[]):se.callExpression(Z(e,"markDirty"),[se.identifier(o.rowIdVar)])):null,i=null;if(t.instanceLocal&&n!==null){let d=e.instanceReasonIds.get(n),u=[...t.instanceWrites].map(g=>d?.get(g)).filter(g=>g!==void 0).sort((g,S)=>g-S),c=t.instanceWrites.size>0&&u.length===t.instanceWrites.size;i=se.expressionStatement(se.callExpression(Z(e,"markDirty"),[Le(e,n),...c?[u.length===1?se.numericLiteral(u[0]):bo(e,u)]:[]]))}let s=t.rowOwnerLocal&&o?.ownerIdVar!==void 0?se.expressionStatement(se.callExpression(Z(e,"markDirty"),[se.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]:se.blockStatement(u)};if(t.rootFallback)return a(se.expressionStatement(se.callExpression(Z(e,"markDirtySubtree"),[se.stringLiteral(e.rootId)])));if(t.writes.size===0)return a(null);let l=[...t.writes].sort();return a(se.expressionStatement(se.callExpression(Z(e,"commitWrites"),[Ot(e,l)])))}function br(e,t,n){if(se.isBlockStatement(t.body)){qn(t.body,n),t.body.body.push(n);return}let o=$(e,"returnValue");t.body=se.blockStatement([se.variableDeclaration("const",[se.variableDeclarator(o,t.body)]),n,se.returnStatement(se.cloneNode(o))])}function qn(e,t){if(!se.isFunction(e))for(let n of se.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)||se.isFunction(i)||(se.isReturnStatement(i)?(o.splice(r,0,se.cloneNode(t)),r++):qn(i,t))}else if(o&&typeof o=="object"&&"type"in o){if(se.isFunction(o))continue;se.isReturnStatement(o)?e[n]=se.blockStatement([se.cloneNode(t),o]):qn(o,t)}}}import*as Se from"@babel/types";function yt(e,t,n,o){if(o===void 0&&n?.refreshVar!==void 0)return Se.expressionStatement(Se.callExpression(Se.identifier(n.refreshVar),[]));let r=o??(n!==void 0?Se.identifier(n.rowIdVar):t!==null?Le(e,t):Se.stringLiteral(e.rootId));return Se.expressionStatement(Se.callExpression(Z(e,"markDirty"),[Se.cloneNode(r)]))}function At(e,t,n){let o=$(e,"event"),r=$(e,"returnValue");return Se.arrowFunctionExpression([o],Se.blockStatement([Se.variableDeclaration("const",[Se.variableDeclarator(r,Se.callExpression(Se.cloneNode(t),[Se.cloneNode(o)]))]),n,Se.returnStatement(Se.cloneNode(r))]))}import yr from"@babel/traverse";import*as Y from"@babel/types";function Ns(e,t,n){if(n.key===null)return null;let o=e.componentProps.get(t);if(o===void 0)return null;let r=Be(o);if(n.root===r){let[s,...a]=n.key.split(".").slice(1);return s===void 0?null:{name:s,path:a}}let i=He(o,n.root);return i===null?null:{name:i,path:n.key.split(".").slice(1)}}function Gn(e,t,n,o,r){let i=Ns(e,t,o);if(i===null)return!1;n===void 0?ct(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 he from"@babel/types";function wn(e){return he.isIdentifier(e)||he.isObjectPattern(e)||he.isArrayPattern(e)||he.isAssignmentPattern(e)||he.isRestElement(e)}function Is(e){let t=e;for(;he.isTSAsExpression(t)||he.isTSTypeAssertion(t)||he.isTSNonNullExpression(t)||he.isTSSatisfiesExpression(t);)t=t.expression;return t}function Ut(e,t,n){if(he.isIdentifier(t)){e.set(t.name,n);return}if(he.isAssignmentPattern(t)){wn(t.left)&&Ut(e,t.left,n);return}if(!he.isRestElement(t)){if(he.isArrayPattern(t)){for(let o=0;o<t.elements.length;o++){let r=t.elements[o];wn(r)&&Ut(e,r,mt(n,[String(o)]))}return}if(he.isObjectPattern(t))for(let o of t.properties){if(he.isRestElement(o))continue;if(o.computed||!he.isIdentifier(o.key)&&!he.isStringLiteral(o.key)&&!he.isNumericLiteral(o.key)){wn(o.value)&&Ut(e,o.value,{...n,key:null});continue}let r=he.isIdentifier(o.key)?o.key.name:String(o.key.value);wn(o.value)&&Ut(e,o.value,mt(n,[r]))}}}function hr(e,t,n,o){let r=Is(o),i=e.componentProps.get(t);if(i===void 0)return null;if(he.isIdentifier(r)){let d=n.get(r.name);return d!==void 0?d:Be(i)===r.name?{locality:"prop",root:r.name,key:r.name}:He(i,r.name)===null?null:{locality:"prop",root:r.name,key:r.name}}if(!he.isMemberExpression(r))return null;let s=Pe(r),a=ye(r);if(s===null)return null;let l=hr(e,t,n,he.identifier(s));return l===null?null:a===null?{...l,key:null}:mt(l,a.split(".").slice(1))}function Er(e,t){let n=new Map;for(let o of e.instanceDerivations.get(t)??[]){let r=hr(e,t,n,o.source);r!==null&&Ut(n,o.target,r)}return n}var Sr=yr.default??yr;function Fs(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 xr(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 Fs(e,o))if(i==="__rows__"||i==="__regions__"||!r.has(i))return!0;return!1}function _t(e,t,n,o,r=!1,i,s=!1){let a=Y.cloneNode(t),l=a,d=Y.file(Y.program([Y.isFunctionDeclaration(a)?a:Y.expressionStatement(a)])),u=n!==null?e.instanceState.get(n):void 0,c=n!==null?e.instanceDerivedBindings.get(n):void 0,g=n===null?new Map:Er(e,n),S=n!==null?new Set(e.componentProps.get(n)?.bindings??[]):new Set,y=new Set([...S,...u??[],...c??[]]);if(n!==null)for(let E of e.compPaths.get(n)?.node.body.body??[])if(Y.isVariableDeclaration(E))for(let C of E.declarations)for(let M of Object.keys(Y.getBindingIdentifiers(C.id)))y.add(M);else Y.isFunctionDeclaration(E)&&E.id&&y.add(E.id.name);let p=new Rt((E,C)=>{if(C!==void 0)return null;let M=g.get(E);if(M!==void 0)return M;if(o!==void 0&&E===o.itemParam)return{locality:"row",root:E,key:E};if(u?.has(E)===!0)return{locality:"instance",root:E,key:E};if(S.has(E))return{locality:"prop",root:E,key:E};if(y.has(E))return null;let ie=e.state.get(E);return ie===void 0?null:ln(E,ie)}),f=E=>E.stateKind==="computed"||e.state.get(E.root)==="computed",v=new Set;for(let E of a.params)Y.isIdentifier(E)&&v.add(E.name);Sr(d,{VariableDeclarator(E){Y.isIdentifier(E.node.id)&&(v.add(E.node.id.name),E.parentPath.isVariableDeclaration()&&p.trackDeclarator(E.scope,E.node))},Function(E){for(let C of E.node.params)Y.isIdentifier(C)&&v.add(C.name)}});let x=new Map,I=new Map,J=E=>{let C=E.getFunctionParent()?.node??l,M=x.get(C);return M||x.set(C,M=Nt()),M},F=(E,C)=>{if(C(J(E)),!s||E.getFunctionParent()?.node!==l)return;let M=I.get(E.node);M===void 0&&(M={path:E,writes:Nt()},I.set(E.node,M)),C(M.writes)},N=E=>{F(E,C=>{o?.sourceLocal?C.rowOwnerLocal=!0:o!==void 0&&C.writes.add(o.sourceKey)})},K=E=>{if(o===void 0)return null;let C=E.split(".").slice(1);return o.itemPath.some((M,ie)=>C[ie]!==M)?null:C.slice(o.itemPath.length)},_=(E,C)=>{F(E,M=>{C!==void 0&&n!==null&&Gn(e,n,o,C,M)||(M.rowLocal=!0,M.rootFallback=!0)})},H=(E,C)=>{F(E,M=>{(n===null||!Gn(e,n,o,C,M))&&(o===void 0?(n!==null&&ct(M,C.root),M.rootFallback=!0):(M.rowLocal=!0,M.rootFallback=!0))})},T=(E,C)=>{if(o===void 0||Pe(C)!==o.itemParam)return!1;let M=ye(C);if(M===null)return o.itemPath.length===0?N(E):_(E),!0;let ie=M.split(".").slice(1);return o.itemPath.some((Je,Re)=>ie[Re]!==Je)?!1:(ie.splice(0,o.itemPath.length),Rn(ie,o.keyPath)?N(E):(F(E,Je=>{Je.rowLocal=!0}),xr(e,n,o)&&N(E)),!0)},re=(E,C)=>{if(C.locality==="instance"){F(E,M=>{ct(M,C.root)});return}if(C.locality==="row"){if(o===void 0){F(E,ie=>{ie.rootFallback=!0});return}if(C.key===null){o.itemPath.length===0?N(E):_(E);return}let M=K(C.key);if(M===null){_(E,C);return}Rn(M,o.keyPath)?N(E):(F(E,ie=>{ie.rowLocal=!0}),xr(e,n,o)&&N(E));return}if(C.locality==="prop"){H(E,C);return}if(C.stateKind==="computed")throw E.buildCodeFrameError(`memo-dom: cannot mutate computed '${C.root}' (R13) - it is derived; write its SOURCE state instead`);if(C.stateKind!=="store"){F(E,M=>{M.writes.add(C.root)});return}C.key!==null&&C.key.includes(".")?F(E,M=>{M.writes.add(C.key)}):F(E,M=>{M.writes.add(C.root)})},ne=(E,C)=>{if(C.locality==="instance"){F(E,M=>{ct(M,C.root)});return}if(C.locality==="row"){if(o===void 0){F(E,Je=>{Je.rootFallback=!0});return}if(C.key===null){o.itemPath.length===0?N(E):_(E);return}let M=K(C.key);if(M===null){_(E,C);return}M.length===0&&(o.keyPath===null||o.keyPath.length>0)?N(E):re(E,C);return}if(C.locality==="prop"){H(E,C);return}if(C.stateKind==="computed")throw E.buildCodeFrameError(`memo-dom: cannot mutate computed '${C.root}' (R13) - write its SOURCE state instead`);F(E,M=>{M.writes.add(C.key??C.root)})},G=(E,C)=>{if(!(s&&E.getFunctionParent()?.node===l))for(let M of cn(C)){if(!Y.isIdentifier(M))continue;let ie=p.resolveExpression(E.scope,M);ie!==null&&(f(ie)||ne(E,ie))}},oe=(E,C)=>{let M=Pe(C);if(M!==void 0&&u?.has(M??"")===!0){F(E,Re=>{ct(Re,M)});return}if(M!==null&&c?.has(M)&&!g.has(M))throw E.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${M}' (R14) \u2014 write its source instead`);if(T(E,C))return;let ie=p.resolveExpression(E.scope,C);if(ie!==null){re(E,ie);return}if(M!==null&&S.has(M)){H(E,{locality:"prop",root:M,key:ye(C)});return}if(M!==null&&y.has(M)||!M||!e.state.has(M))return;let Je=e.state.get(M);if(Je==="computed")throw E.buildCodeFrameError(`memo-dom: cannot mutate computed '${M}' (R13) \u2014 it is derived; write its SOURCE state instead`);F(E,Re=>{if(Je!=="store"){Re.writes.add(M);return}let tt=ye(C);tt!==null&&tt.includes(".")?Re.writes.add(tt):Re.writes.add(M)})};Sr(d,{VariableDeclarator(E){if(!Y.isIdentifier(E.node.id)&&E.node.init!==null)for(let C of p.referencedOrigins(E.scope,E.node.init))ne(E,C)},AssignmentExpression(E){let C=E.node.left;if(Y.isIdentifier(C)){if(v.has(C.name)){if(Y.isIdentifier(E.node.right)){let ie=p.resolveExpression(E.scope,E.node.right);ie!==null&&ne(E,ie)}return}if(c?.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot assign per-instance derivation '${C.name}' (R14) \u2014 write its source instead`);if(u?.has(C.name)===!0){F(E,ie=>{ct(ie,C.name)});return}if(S.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot assign prop '${C.name}' \u2014 copy it to component-local let state first`);if(y.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot assign component-local const '${C.name}'`);let M=e.state.get(C.name);if(!M)throw E.buildCodeFrameError(`memo-dom: handler assigns '${C.name}', which is neither module state nor a handler local \u2014 declare it at module level (let) or inside the handler`);if(e.importedState.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot reassign imported state '${C.name}' - ES module imports are read-only; export a mutator or mutate an imported store property`);if(M==="store")throw E.buildCodeFrameError(`memo-dom: cannot reassign store '${C.name}' \u2014 assign a property (${C.name}.field = \u2026) instead`);if(M==="const")throw E.buildCodeFrameError(`memo-dom: cannot reassign mutable const root '${C.name}' - mutate the object instead`);if(M==="computed")throw E.buildCodeFrameError(`memo-dom: cannot assign computed '${C.name}' (R13) \u2014 it is derived; write its SOURCE state instead and the derivation recomputes`);F(E,ie=>{ie.writes.add(C.name)})}else if(Y.isMemberExpression(C))oe(E,C);else for(let M of p.referencedOrigins(E.scope,E.node.right))ne(E,M)},UpdateExpression(E){let C=E.node.argument;if(Y.isIdentifier(C)){if(v.has(C.name))return;if(c?.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot update per-instance derivation '${C.name}' (R14) \u2014 write its source instead`);if(u?.has(C.name)===!0){F(E,ie=>{ct(ie,C.name)});return}if(S.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot update prop '${C.name}' \u2014 copy it to component-local let state first`);if(y.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot update component-local const '${C.name}'`);let M=e.state.get(C.name);if(!M)throw E.buildCodeFrameError(`memo-dom: handler updates '${C.name}', which is neither module state nor a handler local`);if(e.importedState.has(C.name))throw E.buildCodeFrameError(`memo-dom: cannot update imported state '${C.name}' - ES module imports are read-only; call an exported mutator instead`);if(M!=="let")throw E.buildCodeFrameError(M==="computed"?`memo-dom: cannot update computed '${C.name}' (R13) \u2014 it is derived; write its SOURCE state instead`:`memo-dom: cannot update '${C.name}' \u2014 it is a const binding; mutate its contents instead`);F(E,ie=>{ie.writes.add(C.name)})}else Y.isMemberExpression(C)&&oe(E,C)},UnaryExpression(E){E.node.operator==="delete"&&Y.isMemberExpression(E.node.argument)&&oe(E,E.node.argument)},CallExpression(E){let C=E.node.callee;if(Y.isMemberExpression(C)){if(un(C)==="assign"&&Y.isIdentifier(C.object,{name:"Object"})){let Re=E.node.arguments[0],tt=Re!==void 0&&Y.isExpression(Re)?p.resolveExpression(E.scope,Re):null;if(tt!==null)if(tt.locality==="module"&&tt.stateKind==="store"){let go=dn(tt,E.node.arguments.slice(1));go===null?ne(E,tt):F(E,yi=>{for(let Si of go)yi.writes.add(Si)})}else re(E,tt);return}let ie=Y.isIdentifier(C.object)?C.object.name:Y.isMemberExpression(C.object)?Pe(C.object):null;if(ie!==null&&c?.has(ie)&&!g.has(ie))throw E.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${ie}' (R14) - write its source instead`);let Je=Y.isExpression(C.object)?p.resolveExpression(E.scope,C.object):null;Je!==null?ne(E,Je):G(E,E.node.arguments);return}if(Y.isIdentifier(C)&&!y.has(C.name)&&(e.helpers.has(C.name)||e.importedFunctions.has(C.name))){let M=e.importedFunctions.get(C.name)??Ve(e,C.name);F(E,ie=>{for(let Re of M.writes)ie.writes.add(Re);for(let Re of M.boundedWrites)ie.writes.add(Re);let Je=s&&E.getFunctionParent()?.node===l;M.unbounded&&!Je&&(ie.rootFallback=!0)});for(let ie of M.parameterWrites){let Je=E.node.arguments[ie.index];if(Je===void 0||!Y.isExpression(Je))continue;let Re=p.resolveExpression(E.scope,Je);if(Re!==null){if(f(Re))continue;ne(E,mt(Re,ie.path))}}return}G(E,E.node.arguments)}});let Q=x.has(l);if(e.handlerHasRootCommit.set(t,Q),r&&!x.has(l)){let E=Nt();E.eventOrigin=yt(e,n,o,i),x.set(l,E)}let ae=[];if(s)for(let E of I.values()){let C=Lt(e,E.writes,n,o);C!==null&&ae.push({...E,commit:C})}for(let E of ae)E.flag=$(e,"didWrite");ae.sort((E,C)=>Cr(C.path)-Cr(E.path)).forEach(E=>Rs(E.path,E.flag));for(let[E,C]of x){let M=s&&E===l?ae.length===0?null:Y.blockStatement(ae.map(ie=>Y.ifStatement(Y.cloneNode(ie.flag),Y.cloneNode(ie.commit)))):Lt(e,C,n,o);M&&br(e,E,M)}if(ae.length>0){if(!Y.isBlockStatement(a.body))throw new Error("memo-dom: execution-aware callback commit did not produce a block body");a.body.body.unshift(Y.variableDeclaration("let",ae.map(E=>Y.variableDeclarator(Y.cloneNode(E.flag),Y.booleanLiteral(!1)))))}t.body=a.body}function Cr(e){let t=0,n=e;for(;n.parentPath!==null;)t++,n=n.parentPath;return t}function Rs(e,t){let n=Y.assignmentExpression("=",Y.cloneNode(t),Y.booleanLiteral(!0));if(e.isVariableDeclarator()){let o=e.node.init;if(o===null||!Y.isExpression(o))throw new Error("memo-dom: execution-aware variable site has no expression initializer");e.node.init=Y.sequenceExpression([n,o]);return}if(!e.isExpression())throw new Error(`memo-dom: unsupported execution-aware write site '${e.node.type}'`);e.replaceWith(Y.sequenceExpression([n,e.node]))}import*as rt from"@babel/types";function Pr(e,t){let n=!1,o=!0,r=i=>{if(o&&!(i!==e&&rt.isFunction(i))){if((rt.isCallExpression(i)||rt.isOptionalCallExpression(i))&&(n=!0,!rt.isIdentifier(i.callee)||!t(i.callee.name))){o=!1;return}for(let s of rt.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 It(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&&(Ce.isArrowFunctionExpression(r)||Ce.isFunctionExpression(r))?r:null}function it(e,t,n,o,r,i=!1){e.analyzedFunctions.has(n)||(Zn(e,t,n,o,r),e.analyzedFunctions.add(n),_t(e,n,o,r,!1,void 0,i))}function qt(e,t,n=!1){e.analyzedFunctions.has(t)||(e.analyzedFunctions.add(t),_t(e,t,null,void 0,!1,void 0,n))}function Zn(e,t,n,o,r){let i=new Set;Xe(n.body,s=>{Ce.isCallExpression(s)&&Ce.isIdentifier(s.callee)&&i.add(s.callee.name)});for(let s of i){let a=It(t,s);a===null||e.analyzedFunctions.has(a)||(e.analyzedFunctions.add(a),Zn(e,t,a,o,r),_t(e,a,o,r,!1))}}function Yn(e,t,n,o,r,i,s){let a=null,l=!1,d=e.componentProps.get(r),u=d===void 0?null:Be(d);if(d!==void 0&&(Ce.isIdentifier(n)&&He(d,n.name)!==null||Ce.isMemberExpression(n)&&u!==null&&Pe(n)===u))return At(e,n,yt(e,r,i,s));if(Ce.isArrowFunctionExpression(n)||Ce.isFunctionExpression(n))a=n;else if(Ce.isIdentifier(n)){let g=e.importedFunctions.get(n.name);if(g!==void 0){let p=Nt();for(let f of g.writes)p.writes.add(f);for(let f of g.boundedWrites)p.writes.add(f);return p.rootFallback=g.unbounded,At(e,n,Lt(e,p,null)??yt(e,r,i,s))}let S=t.scope.getBinding(n.name),y=S?.path;if(y&&y.isVariableDeclarator()){let p=y.node.init;p&&(Ce.isArrowFunctionExpression(p)||Ce.isFunctionExpression(p))&&(a=p,l=S?.scope.path.isProgram()===!0&&e.helpers.has(n.name))}else y&&y.isFunctionDeclaration()&&(e.helpers.has(n.name)?(a=y.node,l=!0):a=It(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(Ce.isBlockStatement(a.body)||(a.body=Ce.blockStatement([Ce.expressionStatement(a.body)])),!e.analyzedFunctions.has(a)){l||Zn(e,t,a,r,i);let g=!l&&!Ce.isIdentifier(n)&&Pr(a,S=>{let y=It(t,S);return y!==null&&e.handlerHasRootCommit.get(y)===!0});e.analyzedFunctions.add(a),_t(e,a,l?null:r,l?void 0:i,!l&&!Ce.isIdentifier(n)&&!g,s)}if(l){let g=Ve(e,n.name);if(a.async){let S=Nt();for(let y of g.writes)S.writes.add(y);for(let y of g.boundedWrites)S.writes.add(y);return S.rootFallback=g.unbounded,At(e,n,Lt(e,S,null)??yt(e,r,i,s))}if(g.writes.size===0&&g.boundedWrites.size===0&&!g.unbounded)return At(e,n,yt(e,r,i,s))}return Ce.isIdentifier(n)&&!l&&(e.handlerHasRootCommit.get(a)===!1||a.async)?At(e,n,yt(e,r,i,s)):Ce.isIdentifier(n)?n:a}import*as ve from"@babel/types";function Qn(e,t){let n=[];for(let o of e){if(ve.isJSXText(o)){let a=Jn(o.value);a!==""&&n.push({type:"node",variable:t.emitText(ve.stringLiteral(a))});continue}if(ve.isJSXElement(o)||ve.isJSXFragment(o)){n.push({type:"node",variable:t.emitNode(o)});continue}if(ve.isJSXExpressionContainer(o)||t.fail("memo-dom: spread children are not supported"),ve.isJSXEmptyExpression(o.expression))continue;ve.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:ve.cloneNode(r)});continue}if(ve.isNullLiteral(r)||ve.isBooleanLiteral(r)||ve.isIdentifier(r,{name:"undefined"}))continue;let i=Oe(r);if(i!==null){n.push({type:"list",expression:i});continue}let s=sn(r);if(s!==null&&ue(s)){n.push({type:"condition",expression:s});continue}n.push({type:"node",variable:t.emitText(ve.cloneNode(r))})}return n}import*as O from"@babel/types";var Ds=new Set(["innerHTML","checked","value","selected","disabled","hidden","multiple","required","readOnly","muted","open","controls","loop","autoFocus","autoPlay","tabIndex"]),wr={htmlFor:"for",crossOrigin:"crossorigin"};function eo(e,t){return!t&&Ds.has(e)?e:null}function to(e,t){return!t&&e in wr}function no(e,t,n){let o=O.identifier(e);if(t==="tabIndex")return O.isStringLiteral(n)?O.expressionStatement(O.assignmentExpression("=",O.memberExpression(o,O.identifier(t)),O.cloneNode(n))):O.expressionStatement(O.conditionalExpression(O.binaryExpression("==",O.cloneNode(n),O.nullLiteral()),O.callExpression(O.memberExpression(O.cloneNode(o),O.identifier("removeAttribute")),[O.stringLiteral("tabindex")]),O.assignmentExpression("=",O.memberExpression(O.cloneNode(o),O.identifier(t)),O.cloneNode(n))));let r=t==="value"||t==="innerHTML"?O.stringLiteral(""):O.booleanLiteral(!1),i=O.isStringLiteral(n)?O.cloneNode(n):O.conditionalExpression(O.binaryExpression("==",O.cloneNode(n),O.nullLiteral()),r,O.cloneNode(n));return O.expressionStatement(O.assignmentExpression("=",O.memberExpression(o,O.identifier(t)),i))}function vn(e,t,n){let o=O.identifier(e),r=wr[t]??t;return O.isStringLiteral(n)?O.expressionStatement(O.callExpression(O.memberExpression(o,O.identifier("setAttribute")),[O.stringLiteral(r),O.cloneNode(n)])):O.expressionStatement(O.conditionalExpression(O.logicalExpression("||",O.binaryExpression("==",O.cloneNode(n),O.nullLiteral()),O.binaryExpression("===",O.cloneNode(n),O.booleanLiteral(!1))),O.callExpression(O.memberExpression(O.cloneNode(o),O.identifier("removeAttribute")),[O.stringLiteral(r)]),O.callExpression(O.memberExpression(o,O.identifier("setAttribute")),[O.stringLiteral(r),O.conditionalExpression(O.binaryExpression("===",O.cloneNode(n),O.booleanLiteral(!0)),O.stringLiteral(""),O.callExpression(O.identifier("String"),[O.cloneNode(n)]))])))}import*as ze from"@babel/types";var Ms="http://www.w3.org/2000/svg",Ls=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 vr(e,t){return t||e==="svg"||Ls.has(e)}function kr(e,t){return t?ze.callExpression(ze.memberExpression(ze.identifier("document"),ze.identifier("createElementNS")),[ze.stringLiteral(Ms),ze.stringLiteral(e)]):ze.callExpression(ze.memberExpression(ze.identifier("document"),ze.identifier("createElement")),[ze.stringLiteral(e)])}import*as me from"@babel/types";function kn(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?[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 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)??me.identifier("undefined"))}function jt(e,t,n){let o=e.componentProps.get(t);return o?.mode==="object"?[me.cloneNode(n)]:(o?.names??[]).map(r=>me.memberExpression(me.cloneNode(n),me.isValidIdentifier(r)?me.identifier(r):me.stringLiteral(r),!me.isValidIdentifier(r)))}function Nr(e,t,n,o,r){let i=$(e,`${t}Props`);return me.blockStatement([me.variableDeclaration("const",[me.variableDeclarator(me.cloneNode(i),me.cloneNode(r))]),me.expressionStatement(me.callExpression(Z(e,"setProps"),[me.binaryExpression("+",me.cloneNode(n),me.stringLiteral(o)),me.arrayExpression(jt(e,t,i))]))])}import*as Ne from"@babel/types";function Jt(e){return(Ne.isArrowFunctionExpression(e)||Ne.isFunctionExpression(e))&&!As(e.body)}function oo(e,t,n,o="callback"){let r=$(e,o);return t.creation.push(Ne.variableDeclaration("const",[Ne.variableDeclarator(Ne.cloneNode(r),Ne.cloneNode(n,!0))])),r}function ro(e,t,n,o="callback"){let r=$(e,o);return t.push(Ne.variableDeclaration("const",[Ne.variableDeclarator(Ne.cloneNode(r),Ne.cloneNode(n,!0))])),r}function As(e){let t=!1;return Ne.traverseFast(e,n=>{if(Ne.isJSXElement(n)||Ne.isJSXFragment(n))return t=!0,Ne.traverseFast.stop}),t}import*as z from"@babel/types";function Ir(e,t,n,o,r,i,s,a=!1,l=Le(e,r),d=!1){let u=an(n,i,t.usedConds),c=$(e,u.suffix).name,g=z.binaryExpression("+",z.cloneNode(l),z.stringLiteral(`/${u.suffix}`)),S=z.arrowFunctionExpression([],z.cloneNode(u.pickExpr)),y=u.branches.map(p=>p!==null?io(e,p,r,i,g,s,a,g,!1,t.usedConds):z.nullLiteral());t.creation.push(gt(e,z.cloneNode(g),z.cloneNode(l),z.arrowFunctionExpression([],z.callExpression(z.memberExpression(z.identifier(c),z.identifier("update")),[])))),t.creation.push(z.variableDeclaration("const",[z.variableDeclarator(z.identifier(c),z.callExpression(Z(e,"createCondRegion"),[z.identifier(o),z.cloneNode(g),S,z.arrayExpression(y)]))])),(d||ho(e,n,r))&&t.updaters.push(()=>z.expressionStatement(z.callExpression(z.memberExpression(z.identifier(c),z.identifier("update")),[]))),t.disposableRegions.push(c),t.disposableEntities.push(z.cloneNode(g))}function io(e,t,n,o,r,i,s=!1,a=r,l=!1,d){let u=Ze(e,!0);d!==void 0&&(u.usedConds=d);let c=i(e,u,t,n,o,l?null:"cond",void 0,r,s,a),g=[z.objectProperty(z.identifier("nodes"),z.callExpression(Z(e,"rootNodes"),[z.identifier(c)])),z.objectProperty(z.identifier("update"),z.identifier(u.updateVar))];if(u.disposableRegions.length>0||u.disposableEntities.length>0||u.disposableCallbacks.length>0){let S=[...[...u.disposableCallbacks].reverse().map(y=>z.ifStatement(z.binaryExpression("!==",z.cloneNode(y),z.nullLiteral()),z.expressionStatement(z.callExpression(z.cloneNode(y),[])))),...u.disposableRegions.map(y=>z.expressionStatement(z.callExpression(z.memberExpression(z.identifier(y),z.identifier("dispose")),[]))),...u.disposableEntities.map(y=>z.expressionStatement(z.callExpression(Z(e,"unregisterSubtree"),[z.cloneNode(y)])))];g.push(z.objectProperty(z.identifier("dispose"),z.arrowFunctionExpression([],z.blockStatement(S))))}return z.arrowFunctionExpression([],z.blockStatement([Ye(u),Qe(u),...u.creation,...u.mounts,z.returnStatement(z.objectExpression(g))]))}import*as m from"@babel/types";import*as X from"@babel/types";function ut(e,t,n,o){return X.isArrayExpression(o)?X.arrayExpression(o.elements.map(r=>{if(r===null)return null;if(X.isSpreadElement(r))throw t.buildCodeFrameError("memo-dom: ref arrays must have a static shape; nested arrays are supported but array spreads are not");return ut(e,t,n,r)})):js(e,n,o)?X.cloneNode(o,!0):Js(t,o)||X.isMemberExpression(o)?Fr(e,o):X.cloneNode(o,!0)}function so(e,t,n,o,r){let i=$(e,"refDispose");t.mounts.push(X.variableDeclaration("const",[X.variableDeclarator(X.cloneNode(i),X.callExpression(Z(e,"mountRef"),[X.cloneNode(n,!0),X.cloneNode(r,!0)]))])),t.manualDisposal?t.disposableCallbacks.push(i):t.mounts.push(X.expressionStatement(X.callExpression(Z(e,"cleanup"),[X.cloneNode(o,!0),X.cloneNode(i)])))}function js(e,t,n){let o=lt(e,t,n);return o!==null&&e.componentProps.get(t)?.refProps.includes(o)===!0}function Js(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 r=n.path.node.init;if(X.isFunctionExpression(r)||X.isArrowFunctionExpression(r))return!1}return n.kind!=="param"}function Fr(e,t){let n=$(e,"refNode");if(X.isMemberExpression(t)){let o=$(e,"refTarget"),r=t.computed?$(e,"refKey"):null,i=()=>X.memberExpression(X.cloneNode(o),r===null?X.cloneNode(t.property,!0):X.cloneNode(r),t.computed);return X.arrowFunctionExpression([X.cloneNode(n)],X.blockStatement([X.variableDeclaration("const",[X.variableDeclarator(X.cloneNode(o),X.cloneNode(t.object,!0)),...r===null?[]:[X.variableDeclarator(X.cloneNode(r),X.cloneNode(t.property,!0))]]),X.expressionStatement(X.assignmentExpression("=",i(),X.cloneNode(n))),X.returnStatement(X.arrowFunctionExpression([],X.blockStatement([X.ifStatement(X.binaryExpression("===",i(),X.cloneNode(n)),X.expressionStatement(X.assignmentExpression("=",i(),X.identifier("undefined"))))])))]))}return X.arrowFunctionExpression([X.cloneNode(n)],X.blockStatement([X.expressionStatement(X.assignmentExpression("=",X.cloneNode(t,!0),X.cloneNode(n))),X.returnStatement(X.arrowFunctionExpression([],X.blockStatement([X.ifStatement(X.binaryExpression("===",X.cloneNode(t,!0),X.cloneNode(n)),X.expressionStatement(X.assignmentExpression("=",X.cloneNode(t,!0),X.identifier("undefined"))))])))]))}import*as A from"@babel/types";var $s=new Set(["setClassValue","setStyleValue","setDomValue"]);function $t(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 p of t.creation){if(!A.isVariableDeclaration(p))continue;let f=Xs(p);if(f===null)return!1;o.push(f),r.add(f.name)}if(!r.has(n)||o.length<2)return!1;let i=new Map,s=new Map;for(let p of t.creation){let f=Rr(p);if(f===null)continue;if(!r.has(f.parent)||!r.has(f.child))return!1;let v=s.get(f.parent)??0;s.set(f.parent,v+1),i.set(f.child,{parent:f.parent,index:v})}let a=new Map;for(let p of r){let f=Os(p,n,i);if(f===null)return!1;a.set(p,f)}let l=[],d=[];for(let p of t.creation)A.isVariableDeclaration(p)||Bs(p,r)?l.push(A.cloneNode(p,!0)):d.push(p);let u=$(e,`${n}Template`);e.header.push(A.variableDeclaration("let",[A.variableDeclarator(A.cloneNode(u))]));let c=A.callExpression(A.arrowFunctionExpression([],A.blockStatement([...l,A.returnStatement(A.identifier(n))])),[]),g=A.conditionalExpression(A.binaryExpression("===",A.cloneNode(u),A.unaryExpression("void",A.numericLiteral(0))),A.assignmentExpression("=",A.cloneNode(u),c),A.cloneNode(u)),S=A.callExpression(A.memberExpression(g,A.identifier("cloneNode")),[A.booleanLiteral(!0)]),y=[...o].sort((p,f)=>a.get(p.name).length-a.get(f.name).length).map(({name:p})=>A.variableDeclaration("const",[A.variableDeclarator(A.identifier(p),p===n?A.cloneNode(S,!0):Ts(n,a.get(p)))]));return t.creation=[...y,...d],!0}function Xs(e){if(e.declarations.length!==1)return null;let t=e.declarations[0];if(!A.isIdentifier(t.id)||!A.isCallExpression(t.init)||!A.isMemberExpression(t.init.callee)||!A.isIdentifier(t.init.callee.object,{name:"document"})||!A.isIdentifier(t.init.callee.property))return null;let n=t.init.callee.property.name;if(n!=="createElement"&&n!=="createElementNS"&&n!=="createTextNode")return null;let o=t.init.arguments.at(-1);return(n==="createElement"||n==="createElementNS")&&A.isStringLiteral(o)&&o.value.includes("-")?null:{name:t.id.name,statement:e}}function Rr(e){return!A.isExpressionStatement(e)||!A.isCallExpression(e.expression)||!A.isMemberExpression(e.expression.callee)||!A.isIdentifier(e.expression.callee.object)||!A.isIdentifier(e.expression.callee.property,{name:"appendChild"})||e.expression.arguments.length!==1||!A.isIdentifier(e.expression.arguments[0])?null:{parent:e.expression.callee.object.name,child:e.expression.arguments[0].name}}function Os(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 Ts(e,t){let n=A.identifier(e);for(let o of t){n=A.memberExpression(n,A.identifier("firstChild"));for(let r=0;r<o;r++)n=A.memberExpression(n,A.identifier("nextSibling"))}return n}function Bs(e,t){let n=Rr(e);if(n!==null)return t.has(n.parent)&&t.has(n.child);if(!A.isExpressionStatement(e))return!1;let o=e.expression;return!!(A.isCallExpression(o)&&A.isMemberExpression(o.callee)&&(A.isIdentifier(o.callee.object)&&t.has(o.callee.object.name)&&A.isIdentifier(o.callee.property,{name:"setAttribute"})&&o.arguments.every(r=>A.isExpression(r)&&Nn(r))||A.isIdentifier(o.callee.object)&&A.isIdentifier(o.callee.property)&&$s.has(o.callee.property.name)&&o.arguments.length>=2&&A.isIdentifier(o.arguments[0])&&t.has(o.arguments[0].name)&&o.arguments.slice(1).every(r=>A.isExpression(r)&&Nn(r))))}function Nn(e){return A.isStringLiteral(e)||A.isNumericLiteral(e)||A.isBooleanLiteral(e)||A.isNullLiteral(e)?!0:A.isArrayExpression(e)?e.elements.every(t=>t===null||A.isExpression(t)&&Nn(t)):A.isObjectExpression(e)?e.properties.every(t=>A.isObjectProperty(t)&&!t.computed&&A.isExpression(t.value)&&Nn(t.value)):!1}function Dr(e,t,n,o,r,i,s,a,l=!1,d=Le(e,r),u){let c=wt(e,n,i,r,t.usedPrefixes,u===void 0?void 0:{itemParam:u.itemParam,sourceKey:u.sourceKey,sourceLocal:u.sourceLocal??!1}),g=$(e,`region${t.regionCounter++}`).name,S=c.form==="callback"?Vs(e,c,o):c.form==="component"?Ws(e,c,o,r,i,a,l,d):zs(e,c,o,r,i,s,l,d),y=[m.identifier(o),m.binaryExpression("+",m.cloneNode(d),m.stringLiteral(`/${c.suffix}`)),S];if(c.form==="callback"){let f=m.memberExpression(m.cloneNode(c.renderCallback,!0),m.identifier("key"));y.push(m.arrowFunctionExpression([m.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[m.identifier(c.indexParam)]],m.conditionalExpression(m.binaryExpression("==",m.cloneNode(f),m.nullLiteral()),m.cloneNode(c.itemPattern,!0),m.callExpression(m.cloneNode(f),[m.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[m.identifier(c.indexParam)]]))))}else c.keyExpr!==null&&y.push(m.arrowFunctionExpression([m.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[m.identifier(c.indexParam)]],m.cloneNode(c.keyExpr)));t.creation.push(m.variableDeclaration("const",[m.variableDeclarator(m.identifier(g),m.callExpression(Z(e,"createListRegion"),y))])),t.disposableRegions.push(g);let p=()=>m.expressionStatement(m.callExpression(m.memberExpression(m.identifier(g),m.identifier("reconcile")),[m.cloneNode(c.sourceExpr)]));t.creation.push(p()),t.updaters.push(p)}function Vs(e,t,n){let o=$(e,"renderRowId");return m.arrowFunctionExpression([m.cloneNode(t.itemPattern,!0),m.cloneNode(o),...t.indexParam===null?[]:[m.identifier(t.indexParam)]],m.callExpression(m.memberExpression(m.cloneNode(t.renderCallback,!0),m.identifier("create")),[m.cloneNode(t.itemPattern,!0),m.cloneNode(o),...t.indexParam===null?[]:[m.identifier(t.indexParam)],m.identifier(n)]))}function Ws(e,t,n,o,r,i,s=!1,a=Le(e,o)){let l=t.rowComp,d=$(e,"rowId"),u=$(e,"nextItem"),c=t.indexParam===null?null:$(e,"nextIndex"),g=$(e,"refreshRow"),S=Ze(e),y=Dt(e,l),p=e.importedComponents.get(l)?.delegatedEvents===!0||e.componentsWithHostEvents.has(l),f={itemParam:t.itemParam,itemPath:[],rowIdVar:d.name,refreshVar:g.name,keyPath:at(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal&&m.isIdentifier(a)?{ownerIdVar:a.name}:{}},v=t.jsx.openingElement.attributes.filter(G=>m.isJSXSpreadAttribute(G)||Ae(G.name)!=="key"),x=v.some(G=>m.isJSXSpreadAttribute(G)),I=[],J=[],F=null,N=e.componentProps.get(l),K=G=>{let oe=m.isJSXElement(G)||m.isJSXFragment(G)?[G]:[m.jsxExpressionContainer(G)];return i(e,S,oe,o,r,"row",f,d,s,d)};if(x){F=Ht(v,{attributeValue:(G,oe)=>G==="ref"||N?.refProps.includes(G)===!0?ut(e,r,o,oe):oe,fail:G=>{throw r.buildCodeFrameError(G)}}).expression;for(let G of F.properties){if(!m.isObjectProperty(G)||G.computed||!m.isExpression(G.value))continue;let oe=m.isIdentifier(G.key)?G.key.name:m.isStringLiteral(G.key)?G.key.value:null;if(oe!==null)if(N?.renderProps.includes(oe)===!0){if(et(e,o,G.value))continue;if(!ue(G.value))throw r.buildCodeFrameError(`memo-dom: render prop '${oe}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);G.value=K(G.value)}else{if(ue(G.value))throw r.buildCodeFrameError(`memo-dom: JSX prop '${oe}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);oe!=="ref"&&N?.refProps.includes(oe)!==!0&&Jt(G.value)&&(it(e,r,G.value,o,f),G.value=ro(e,J,G.value,`${oe}Callback`))}}}else for(let G of v){let oe=G,Q=Ae(oe.name),ae=oe.value==null?m.booleanLiteral(!0):$e(oe.value);if(ae===null)throw r.buildCodeFrameError(`memo-dom: prop '${Ae(oe.name)}' on <${l}> must be an expression`);if(N?.renderProps.includes(Q)===!0){if(et(e,o,ae)){I.push({name:Q,value:m.cloneNode(ae)});continue}if(!ue(ae))throw r.buildCodeFrameError(`memo-dom: render prop '${Q}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);I.push({name:Q,value:K(ae)});continue}if(Q==="ref"||N?.refProps.includes(Q)===!0){I.push({name:Q,value:ut(e,r,o,ae)});continue}if(ue(ae))throw r.buildCodeFrameError(`memo-dom: JSX prop '${Q}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);let E=Jt(ae);E&&it(e,r,ae,o,f),I.push({name:Q,value:E?ro(e,J,ae,`${Q}Callback`):m.cloneNode(ae)})}if(Vt(t.jsx.children)){if(v.some(oe=>m.isJSXAttribute(oe)&&Ae(oe.name)==="children"))throw r.buildCodeFrameError(`memo-dom: <${l}> cannot use both a children prop and nested JSX children`);let G=i(e,S,t.jsx.children,o,r,"row",f,d,s,d);F!==null?F.properties.push(m.objectProperty(m.identifier("children"),m.cloneNode(G))):I.push({name:"children",value:m.cloneNode(G)})}let _;if(F!==null){let G=$(e,`${l}Props`);J.push(m.variableDeclaration("const",[m.variableDeclarator(m.cloneNode(G),m.cloneNode(F))])),_=jt(e,l,G)}else _=kn(e,l,I);let H=[m.expressionStatement(m.assignmentExpression("=",m.cloneNode(t.itemPattern,!0),m.cloneNode(u)))];c!==null&&t.indexParam!==null&&H.push(m.expressionStatement(m.assignmentExpression("=",m.identifier(t.indexParam),m.cloneNode(c))));let T=_.map(G=>m.cloneNode(G));if(F!==null){let G=$(e,`next${l}Props`);H.push(m.variableDeclaration("const",[m.variableDeclarator(m.cloneNode(G),m.cloneNode(F))])),T=jt(e,l,G)}let re=$(e,y?"entry":"rowElement");y?H.push(m.expressionStatement(m.callExpression(m.memberExpression(m.cloneNode(re),m.identifier("updateProps")),T))):H.push(m.expressionStatement(m.callExpression(Z(e,"setProps"),[m.cloneNode(d),m.arrayExpression(T)])),m.expressionStatement(m.callExpression(Z(e,"markDirty"),[m.cloneNode(d)]))),S.updaters.length>0&&H.push(m.expressionStatement(m.callExpression(m.identifier(S.updateVar),[])));let ne=y?[m.objectProperty(m.identifier("nodes"),m.memberExpression(m.cloneNode(re),m.identifier("nodes"))),m.objectProperty(m.identifier("entities"),m.arrayExpression([])),m.objectProperty(m.identifier("update"),m.memberExpression(m.cloneNode(re),m.identifier("update"))),m.objectProperty(m.identifier("dispose"),m.memberExpression(m.cloneNode(re),m.identifier("dispose")))]:[m.objectProperty(m.identifier("nodes"),m.callExpression(Z(e,"rootNodes"),[m.cloneNode(re)])),m.objectProperty(m.identifier("entities"),m.arrayExpression([m.cloneNode(d)]))];return(_.length>0||S.updaters.length>0)&&ne.push(m.objectProperty(m.identifier("updateProps"),m.arrowFunctionExpression([m.cloneNode(u),...c===null?[]:[m.cloneNode(c)]],m.blockStatement(H)))),m.arrowFunctionExpression([m.cloneNode(t.itemPattern,!0),m.cloneNode(d),...t.indexParam===null?[]:[m.identifier(t.indexParam)]],m.blockStatement([...S.updaters.length>0?[Ye(S),Qe(S)]:[],...S.creation,...S.mounts,...J,m.variableDeclaration("const",[m.variableDeclarator(m.cloneNode(re),y?m.callExpression(m.identifier(l),[..._.map(G=>m.cloneNode(G)),m.cloneNode(d),...t.sourceLocal?[m.cloneNode(a)]:[],...p?[m.identifier(n)]:[]]):m.callExpression(m.identifier(l),[m.cloneNode(d),m.cloneNode(a),..._.length>0?[m.arrayExpression(_)]:[]]))]),...S.updaters.length>0?[m.variableDeclaration("const",[m.variableDeclarator(m.cloneNode(g),m.arrowFunctionExpression([],m.blockStatement([m.expressionStatement(y?m.callExpression(m.memberExpression(m.cloneNode(re),m.identifier("update")),[]):m.callExpression(Z(e,"markDirty"),[m.cloneNode(d)])),m.expressionStatement(m.callExpression(m.identifier(S.updateVar),[]))])))])]:[],m.returnStatement(m.objectExpression(ne))]))}function zs(e,t,n,o,r,i,s=!1,a=Le(e,o)){t.jsx.openingElement.attributes=t.jsx.openingElement.attributes.filter(p=>m.isJSXSpreadAttribute(p)||p.name.name!=="key");let l=Ze(e);l.delegatedEventRootVar=n;let d=$(e,"rowId").name,u=$(e,"nextItem"),c=t.indexParam===null?null:$(e,"nextIndex"),g={itemParam:t.itemParam,itemPath:[],rowIdVar:d,keyPath:at(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal?{ownerIdVar:m.isIdentifier(a)?a.name:Le(e,o).name}:{}},S=i(e,l,t.jsx,o,r,"row",g,m.identifier(d),s,m.identifier(d));$t(e,l,S);let y=[m.expressionStatement(m.assignmentExpression("=",m.cloneNode(t.itemPattern,!0),m.cloneNode(u)))];return c!==null&&t.indexParam!==null&&y.push(m.expressionStatement(m.assignmentExpression("=",m.identifier(t.indexParam),m.cloneNode(c)))),m.arrowFunctionExpression([m.cloneNode(t.itemPattern,!0),m.identifier(d),...t.indexParam===null?[]:[m.identifier(t.indexParam)]],m.blockStatement([Ye(l),Qe(l),gt(e,m.identifier(d),m.cloneNode(a),m.identifier(l.updateVar)),...l.creation,...l.mounts,m.returnStatement(m.objectExpression([m.objectProperty(m.identifier("nodes"),m.arrayExpression([m.identifier(S)])),m.objectProperty(m.identifier("entities"),m.arrayExpression([m.identifier(d)])),m.objectProperty(m.identifier("updateProps"),m.arrowFunctionExpression([m.cloneNode(u),...c===null?[]:[m.cloneNode(c)]],m.blockStatement(y))),m.objectProperty(m.identifier("update"),m.identifier(l.updateVar))]))]))}import*as w from"@babel/types";function Ks(e){return w.isJSXElement(e.body)?e.body:w.isBlockStatement(e.body)&&e.body.body.length===1&&w.isReturnStatement(e.body.body[0])&&w.isJSXElement(e.body.body[0].argument)?e.body.body[0].argument:null}function ao(e,t,n,o,r,i,s,a){if(!w.isArrowFunctionExpression(n)&&!w.isFunctionExpression(n)||n.async||n.generator)throw r.buildCodeFrameError("memo-dom: render callbacks must be synchronous inline arrows or function expressions");let l=Ks(n),d=n.params[0],u=n.params[1];if(l===null||n.params.length<1||n.params.length>2||!w.isIdentifier(d)&&!w.isObjectPattern(d)&&!w.isArrayPattern(d)||u!==void 0&&!w.isIdentifier(u))throw r.buildCodeFrameError("memo-dom: render callbacks take an item binding pattern and optional index, then return one JSX element");let c=tn(d),g=Object.keys(w.getBindingIdentifiers(c));if(g.length===0)throw r.buildCodeFrameError("memo-dom: render callback item patterns must bind at least one name");let S=w.isIdentifier(c)?c.name:g[0],y=u===void 0?null:u.name,p=null;l.openingElement.attributes=l.openingElement.attributes.filter(oe=>{if(w.isJSXSpreadAttribute(oe)||!w.isJSXIdentifier(oe.name)||oe.name.name!=="key")return!0;if(p=$e(oe.value),p===null)throw r.buildCodeFrameError("memo-dom: key={...} needs an expression");return!1});let f=$(e,"renderCallback"),v=$(e,"renderRows"),x=$(e,"renderNextUpdate"),I=$(e,"renderRowId"),J=$(e,"renderEventRoot"),F=$(e,"refreshRenderRow"),N=$(e,"renderNextItem"),K=y===null?null:$(e,"renderNextIndex"),_=Ze(e);_.delegatedEventRootVar=J.name;let H={itemParam:S,itemPath:[],rowIdVar:I.name,keyPath:at(p,S),sourceKey:"$render-callback",sourceLocal:!0,...w.isIdentifier(a)?{ownerIdVar:a.name}:{}},T=i(e,_,l,o,r,"row",H,I,s,I);$t(e,_,T),t.creation.push(w.variableDeclaration("const",[w.variableDeclarator(w.cloneNode(v),w.newExpression(w.identifier("Set"),[]))])),t.updaters.push(()=>w.forOfStatement(w.variableDeclaration("const",[w.variableDeclarator(w.cloneNode(x))]),w.cloneNode(v),w.expressionStatement(w.callExpression(w.cloneNode(x),[]))));let re=[w.expressionStatement(w.assignmentExpression("=",w.cloneNode(c,!0),w.cloneNode(N)))];K!==null&&y!==null&&re.push(w.expressionStatement(w.assignmentExpression("=",w.identifier(y),w.cloneNode(K))));let ne=w.arrowFunctionExpression([w.cloneNode(c,!0),w.cloneNode(I),...y===null?[]:[w.identifier(y)],w.cloneNode(J)],w.blockStatement([Ye(_),Qe(_),w.variableDeclaration("const",[w.variableDeclarator(w.cloneNode(F),w.arrowFunctionExpression([],w.blockStatement([w.expressionStatement(w.callExpression(w.identifier(_.updateVar),[])),w.expressionStatement(w.callExpression(Z(e,"renderDescendants"),[w.cloneNode(I)]))])))]),gt(e,w.cloneNode(I),w.cloneNode(a,!0),w.cloneNode(F)),..._.creation,..._.mounts,w.expressionStatement(w.callExpression(w.memberExpression(w.cloneNode(v),w.identifier("add")),[w.cloneNode(F)])),w.returnStatement(w.objectExpression([w.objectProperty(w.identifier("nodes"),w.callExpression(Z(e,"rootNodes"),[w.identifier(T)])),w.objectProperty(w.identifier("entities"),w.arrayExpression([w.cloneNode(I)])),w.objectProperty(w.identifier("updateProps"),w.arrowFunctionExpression([w.cloneNode(N),...K===null?[]:[w.cloneNode(K)]],w.blockStatement(re))),w.objectProperty(w.identifier("update"),w.cloneNode(F)),w.objectProperty(w.identifier("dispose"),w.arrowFunctionExpression([],w.callExpression(w.memberExpression(w.cloneNode(v),w.identifier("delete")),[w.cloneNode(F)])))]))])),G=p===null?w.nullLiteral():w.arrowFunctionExpression([w.cloneNode(c,!0),...y===null?[]:[w.identifier(y)]],w.cloneNode(p));return t.creation.push(w.variableDeclaration("const",[w.variableDeclarator(w.cloneNode(f),w.objectExpression([w.objectProperty(w.identifier("create"),ne),w.objectProperty(w.identifier("key"),G)]))])),f}function Hs(e){return h.conditionalExpression(h.logicalExpression("||",h.binaryExpression("==",h.cloneNode(e),h.nullLiteral()),h.binaryExpression("===",h.unaryExpression("typeof",h.cloneNode(e),!0),h.stringLiteral("boolean"))),h.stringLiteral(""),h.callExpression(h.identifier("String"),[h.cloneNode(e)]))}function Us(e,t,n,o){return()=>vt(e,t,h.cloneNode(o),r=>h.expressionStatement(h.assignmentExpression("=",h.memberExpression(h.identifier(n),h.identifier("data")),Hs(r))))}function lo(e,t,n){let o=$(e,`text${t.textCounter++}`).name;if(h.isStringLiteral(n))return t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(o),h.callExpression(h.memberExpression(h.identifier("document"),h.identifier("createTextNode")),[h.stringLiteral(n.value)]))])),o;let r=An(e,t);t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(o),h.callExpression(h.memberExpression(h.identifier("document"),h.identifier("createTextNode")),[h.stringLiteral("")]))]));let i=Us(t,r,o,n);return t.creation.push(i()),t.updaters.push(i),o}function Mr(e,t){let n=!1;return h.traverseFast(e,o=>{h.isIdentifier(o,{name:t})&&(n=!0)}),n}function st(e,t,n,o,r,i=null,s,a,l=!1,d=Le(e,o)){return h.isJSXFragment(n)?_s(e,t,n,o,r,i,s,a,l,d):qs(e,t,n,o,r,i,s,a,l,d)}function _s(e,t,n,o,r,i,s,a,l=!1,d=Le(e,o)){let u=Qn(n.children,{emitText:g=>lo(e,t,g),emitNode:g=>st(e,t,g,o,r,i,s,a,l,d),isForwarded:g=>et(e,o,g),fail:g=>{throw r.buildCodeFrameError(g)}}),c=jn(e,t,"fragment");return t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(c),h.callExpression(h.memberExpression(h.identifier("document"),h.identifier("createDocumentFragment")),[]))])),Ar(e,t,u,c,o,r,i,s,l,d),c}function Ar(e,t,n,o,r,i,s=null,a,l=!1,d=Le(e,r)){for(let u of n)u.type==="node"?t.creation.push(h.expressionStatement(h.callExpression(h.memberExpression(h.identifier(o),h.identifier("appendChild")),[h.identifier(u.variable)]))):u.type==="slot"?$n(e,t,u.expression,o,d):u.type==="list"?jr(e,t,u.expression,o,r,i,l,d,a):Jr(e,t,u.expression,o,r,i,l,d,s!==null)}function co(e,t,n,o,r,i,s,a,l,d){return ko(e,t,d,(u,c,g)=>{No(u,n,c.name,{emitText:S=>lo(e,u,S),emitNode:S=>st(e,u,S,o,r,i,s,a,l,g),emitList:(S,y)=>jr(e,u,S,y,o,r,l,g,s),emitCondition:(S,y)=>Jr(e,u,S,y,o,r,l,g,i!==null),isForwarded:S=>et(e,o,S),emitForwarded:(S,y)=>$n(e,u,S,y,g),fail:S=>{throw r.buildCodeFrameError(S)}})})}function Lr(e,t,n,o,r,i,s,a,l,d){let u=h.isJSXElement(n)||h.isJSXFragment(n)?[n]:[h.jsxExpressionContainer(n)];return co(e,t,u,o,r,i,s,a,l,d)}function qs(e,t,n,o,r,i=null,s,a,l=!1,d=Le(e,o)){let u=n.openingElement,c=u.name.name;if(/^[A-Z]/.test(c)){let x=t.childCounts.get(c)??0;t.childCounts.set(c,x+1);let I=c.charAt(0).toLowerCase()+c.slice(1),J=x===0?I:`${I}${x}`,F=$(e,J).name,N=x===0?`/${c}`:`/${c}[${x}]`,K=[],_=e.componentProps.get(c);if(Vt(n.children)&&u.attributes.some(oe=>h.isJSXAttribute(oe)&&Ae(oe.name)==="children"))throw r.buildCodeFrameError(`memo-dom: <${c}> cannot use both a children prop and nested JSX children`);let H=u.attributes.some(oe=>h.isJSXSpreadAttribute(oe)),T=null,re=!1;if(H){T=Ht(u.attributes,{attributeValue:(Q,ae)=>Q==="ref"||_?.refProps.includes(Q)===!0?ut(e,r,o,ae):ae,fail:Q=>{throw r.buildCodeFrameError(Q)}}).expression;for(let Q of T.properties){if(!h.isObjectProperty(Q)||Q.computed||!h.isExpression(Q.value))continue;let ae=h.isIdentifier(Q.key)?Q.key.name:h.isStringLiteral(Q.key)?Q.key.value:null;if(ae!==null)if(_?.renderCallbacks.includes(ae)===!0)Q.value=ao(e,t,Q.value,o,r,st,l,d);else if(_?.renderProps.includes(ae)===!0){if(et(e,o,Q.value))continue;if(!ue(Q.value))throw r.buildCodeFrameError(`memo-dom: render prop '${ae}' on <${c}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);Q.value=Lr(e,t,Q.value,o,r,i,s,a,l,d)}else{if(ue(Q.value))throw r.buildCodeFrameError(`memo-dom: JSX prop '${ae}' on <${c}> is not rendered by the callee; interpolate that prop in <${c}> to declare a render slot`);ae!=="ref"&&_?.refProps.includes(ae)!==!0&&Jt(Q.value)&&(it(e,r,Q.value,o,s),Q.value=oo(e,t,Q.value,`${ae}Callback`))}}re=Dn(e,T,o)||s!==void 0&&Mr(T,s.itemParam)}else for(let oe of u.attributes){let Q=oe,ae=Ae(Q.name),E=Q.value==null?h.booleanLiteral(!0):$e(Q.value);if(E==null)throw r.buildCodeFrameError(`memo-dom: prop '${Ae(Q.name)}' on <${c}> must be an expression`);if(_?.renderCallbacks.includes(ae)===!0){K.push({name:ae,value:ao(e,t,E,o,r,st,l,d)});continue}if(ae==="ref"||_?.refProps.includes(ae)===!0){K.push({name:ae,value:ut(e,r,o,E)});continue}if(_?.renderProps.includes(ae)===!0){if(et(e,o,E)){K.push({name:ae,value:h.cloneNode(E)});continue}if(!ue(E))throw r.buildCodeFrameError(`memo-dom: render prop '${ae}' on <${c}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);K.push({name:ae,value:Lr(e,t,E,o,r,i,s,a,l,d)});continue}if(ue(E))throw r.buildCodeFrameError(`memo-dom: JSX prop '${ae}' on <${c}> is not rendered by the callee; interpolate that prop in <${c}> to declare a render slot`);let C=Jt(E);if(!C&&(Dn(e,E,o)||s!==void 0&&Mr(E,s.itemParam))&&(re=!0),C)it(e,r,E,o,s);else if(h.isIdentifier(E)){let M=It(r,E.name);M!==null&&!ue(M.body)&&it(e,r,M,o,s)}K.push({name:ae,value:C?oo(e,t,E,`${ae}Callback`):h.cloneNode(E)})}if(Vt(n.children)){if(u.attributes.some(Q=>h.isJSXAttribute(Q)&&Ae(Q.name)==="children"))throw r.buildCodeFrameError(`memo-dom: <${c}> cannot use both a children prop and nested JSX children`);let oe=co(e,t,n.children,o,r,i,s,a,l,d);T!==null?T.properties.push(h.objectProperty(h.identifier("children"),h.cloneNode(oe))):K.push({name:"children",value:h.cloneNode(oe)})}let ne;if(T!==null){let oe=$(e,`${I}Props`);t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(oe),h.cloneNode(T))])),ne=jt(e,c,oe)}else ne=kn(e,c,K);let G=h.binaryExpression("+",h.cloneNode(d),h.stringLiteral(N));return t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(F),h.callExpression(h.identifier(c),[G,h.cloneNode(d),...ne.length>0?[h.arrayExpression(ne)]:[]]))])),t.disposableEntities.push(h.cloneNode(G)),re&&t.updaters.push(()=>T===null?h.expressionStatement(h.callExpression(Z(e,"setProps"),[h.binaryExpression("+",h.cloneNode(d),h.stringLiteral(N)),h.arrayExpression(ne.map(oe=>h.cloneNode(oe)))])):Nr(e,c,d,N,T)),F}let g=vr(c,l),S=g&&c!=="foreignObject";if(u.attributes.find(x=>h.isJSXAttribute(x)&&Ae(x.name)==="innerHTML")!==void 0){if(g)throw r.buildCodeFrameError("memo-dom: innerHTML is only supported on HTML elements");if(n.children.some(I=>!h.isJSXText(I)||I.value.trim()!==""))throw r.buildCodeFrameError("memo-dom: an element using innerHTML cannot also have JSX children")}let p=Qn(n.children,{emitText:x=>lo(e,t,x),emitNode:x=>st(e,t,x,o,r,i,s,a,S,d),isForwarded:x=>et(e,o,x),fail:x=>{throw r.buildCodeFrameError(x)}}),f=jn(e,t,c);if(t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.identifier(f),kr(c,g))])),u.attributes.some(x=>h.isJSXSpreadAttribute(x))){let x=Ht(u.attributes,{attributeValue:(F,N)=>F==="ref"?ut(e,r,o,N):N,eventValue:(F,N)=>{let K=Yn(e,r,N,F,o,s,a),_=$(e,`${F}Handler`);return t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(_),K)])),_},fail:F=>{throw r.buildCodeFrameError(F)}}),I=$(e,`${c}Props`);t.creation.push(h.variableDeclaration("const",[h.variableDeclarator(h.cloneNode(I),h.cloneNode(x.expression))]));let J=F=>h.expressionStatement(h.callExpression(Z(e,"patchDomProps"),[h.identifier(f),h.cloneNode(F),h.stringLiteral(e.rootId),h.arrayExpression(x.safeEventKeys.map(N=>h.stringLiteral(N)))]));t.creation.push(J(I)),so(e,t,h.identifier(f),d,h.memberExpression(h.cloneNode(I),h.identifier("ref"))),t.updaters.push(()=>J(x.expression))}else for(let x of u.attributes){let I=x,J=Ae(I.name);if(J==="ref"){let T=$e(I.value);if(T===null)throw r.buildCodeFrameError("memo-dom: ref needs an expression");so(e,t,h.identifier(f),d,ut(e,r,o,T));continue}if(J==="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(J)){let T=$e(I.value);if(T==null)throw r.buildCodeFrameError(`memo-dom: ${J} needs a handler expression (L1)`);let re=Yn(e,r,T,J,o,s,a);t.creation.push(t.delegatedEventRootVar===null?h.expressionStatement(h.assignmentExpression("=",h.memberExpression(h.identifier(f),h.identifier(J.toLowerCase())),re)):h.expressionStatement(h.callExpression(Z(e,"setDelegatedEvent"),[h.identifier(t.delegatedEventRootVar),h.identifier(f),h.stringLiteral(J),re])));continue}if(h.isStringLiteral(I.value)){J==="class"||J==="className"?t.creation.push(h.expressionStatement(h.callExpression(Z(e,"setClassValue"),[h.identifier(f),h.stringLiteral(I.value.value)]))):J==="style"?t.creation.push(h.expressionStatement(h.callExpression(Z(e,"setStyleValue"),[h.identifier(f),h.stringLiteral(I.value.value)]))):eo(J,g)!==null?t.creation.push(no(f,J,h.stringLiteral(I.value.value))):to(J,g)?t.creation.push(vn(f,J,h.stringLiteral(I.value.value))):g?t.creation.push(h.expressionStatement(h.callExpression(Z(e,"setDomValue"),[h.identifier(f),h.stringLiteral(J),h.stringLiteral(I.value.value)]))):t.creation.push(h.expressionStatement(h.callExpression(h.memberExpression(h.identifier(f),h.identifier("setAttribute")),[h.stringLiteral(J),h.stringLiteral(I.value.value)])));continue}let F=I.value==null?h.booleanLiteral(!0):$e(I.value);if(F==null||h.isStringLiteral(F))throw r.buildCodeFrameError(`memo-dom: attribute '${J}' needs a string or an expression (L1)`);let N=h.cloneNode(F);if(J==="style"){let T=()=>h.expressionStatement(h.callExpression(Z(e,"setStyleValue"),[h.identifier(f),h.cloneNode(N)]));t.creation.push(T()),t.updaters.push(T);continue}let K=An(e,t),_=eo(J,g),H=()=>J==="class"||J==="className"?vt(t,K,h.callExpression(Z(e,"classValue"),[h.cloneNode(N)]),T=>h.expressionStatement(h.callExpression(Z(e,"setClassValue"),[h.identifier(f),T]))):_!==null?vt(t,K,h.cloneNode(N),T=>no(f,_,T)):to(J,g)?vt(t,K,h.cloneNode(N),T=>vn(f,J,T)):g?vt(t,K,h.cloneNode(N),T=>h.expressionStatement(h.callExpression(Z(e,"setDomValue"),[h.identifier(f),h.stringLiteral(J),T]))):vt(t,K,h.cloneNode(N),T=>vn(f,J,T));t.creation.push(H()),t.updaters.push(H)}return Ar(e,t,p,f,o,r,i,s,S,d),f}function jr(e,t,n,o,r,i,s=!1,a=Le(e,r),l){Dr(e,t,n,o,r,i,st,co,s,a,l)}function Jr(e,t,n,o,r,i,s=!1,a=Le(e,r),l=!1){Ir(e,t,n,o,r,i,st,s,a,l)}function $r(e,t,n,o,r,i=!1,s=r,a=!1,l){return io(e,t,n,o,r,st,i,s,a,l)}import*as Ie from"@babel/types";function Tr(e){if(e.isFunctionDeclaration())return e.node;if(!e.isVariableDeclarator())return null;let t=e.node.init;return t&&(Ie.isArrowFunctionExpression(t)||Ie.isFunctionExpression(t))?t:null}function Br(e,t,n,o,r,i=!1){let s=It(t,n);if(s!==null){it(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=Tr(a.path);l!==null&&qt(e,l,i)}function Xr(e,t,n,o,r,i=!1){if(Ie.isArrowFunctionExpression(n)||Ie.isFunctionExpression(n)){if(ue(n.body))return;it(e,t,n,o,r,i)}else Ie.isIdentifier(n)&&Br(e,t,n.name,o,r,i)}function Vr(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=Tr(r.path);i!==null&&qt(e,i,o)}function Or(e,t,n,o=!1){if(Ie.isArrowFunctionExpression(n)||Ie.isFunctionExpression(n)){if(ue(n.body))return;qt(e,n,o)}else Ie.isIdentifier(n)&&Vr(e,t,n.name,o)}function Wr(e,t,n,o,r){t.traverse({CallExpression(i){let s=i.getFunctionParent()===t,a=i.node.callee,l=Ie.isIdentifier(a,{name:"effect"})&&i.scope.getBinding("effect")===void 0;if(Ie.isIdentifier(a,{name:"cleanup"})&&i.scope.getBinding("cleanup")===void 0){if(!s)throw i.buildCodeFrameError("memo-dom: cleanup(disposer) must run directly during component factory initialization");let d=i.node.arguments[0];if(i.node.arguments.length!==1||d===void 0||!Ie.isExpression(d))throw i.buildCodeFrameError("memo-dom: cleanup(disposer) requires exactly one disposer expression");i.node.callee=Z(e,"cleanup"),i.node.arguments.unshift(Ie.identifier(o))}if(s){Ie.isIdentifier(a)&&Br(e,t,a.name,n,r);for(let d of i.node.arguments)Xr(e,t,d,n,r,l)}},NewExpression(i){if(i.getFunctionParent()===t)for(let s of i.node.arguments)Xr(e,t,s,n,r)}})}function zr(e,t){t.traverse({CallExpression(n){if(n.getFunctionParent()!==null)return;let o=Ie.isIdentifier(n.node.callee,{name:"effect"})&&n.scope.getBinding("effect")===void 0;Ie.isIdentifier(n.node.callee)&&Vr(e,t,n.node.callee.name);for(let r of n.node.arguments)Or(e,t,r,o)},NewExpression(n){if(n.getFunctionParent()===null)for(let o of n.node.arguments)Or(e,t,o)}})}function Kr(e){for(let t of e.helpers.values())t.node.async&&qt(e,t.node)}function Hr(e){e.traverse({CallExpression(t){if(Ie.isIdentifier(t.node.callee,{name:"cleanup"})&&t.scope.getBinding("cleanup")===void 0)throw t.buildCodeFrameError("memo-dom: cleanup(disposer) is only valid directly inside a component factory")}})}import*as Te from"@babel/types";import*as we from"@babel/types";function Ur(e){return e.reduce((t,n)=>we.logicalExpression("||",t,n))}function _r(e,t){let n=()=>we.identifier(e),o=Ur(t.map(i=>we.binaryExpression("===",n(),we.numericLiteral(i)))),r=Ur(t.map(i=>we.callExpression(we.memberExpression(n(),we.identifier("has")),[we.numericLiteral(i)])));return we.logicalExpression("||",we.binaryExpression("===",n(),we.nullLiteral()),we.conditionalExpression(we.binaryExpression("===",we.unaryExpression("typeof",n()),we.stringLiteral("number")),o,r))}function qr(e,t,n,o,r,i){let s=new Map(o.map((c,g)=>[c,g])),a=0,l=[...r.map(c=>({order:s.get(c.declaration)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:c.sources,statement:yo(c)})),...i.map(c=>({order:s.get(c.statement)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:c.sources,statement:Te.blockStatement([...c.resets.map(g=>Te.expressionStatement(Te.assignmentExpression("=",Te.identifier(g.binding),Te.cloneNode(g.source,!0)))),Te.cloneNode(c.statement,!0)])}))].sort((c,g)=>c.order-g.order||c.sequence-g.sequence),d=e.instanceReasonIds.get(t),u=[];for(let c of l){let g=n===null||d===void 0?null:c.sources.map(v=>d.get(v)).filter(v=>v!==void 0).sort((v,x)=>v-x),S=g===null||g.length===c.sources.length?g:null,y=S?.join(" ")??"*",p=u.at(-1),f=p?.reasons?.join(" ")??"*";p!==void 0&&f===y?p.statements.push(c.statement):u.push({reasons:S,statements:[c.statement]})}return Te.blockStatement(u.map(c=>c.reasons===null||n===null?Te.blockStatement(c.statements):Te.ifStatement(_r(n,c.reasons),Te.blockStatement(c.statements))))}import*as B from"@babel/types";function Gt(e){return!B.isReturnStatement(e)||!B.isJSXElement(e.argument)&&!B.isJSXFragment(e.argument)?null:{jsx:e.argument,statement:e}}function uo(e){return B.isBlockStatement(e)?e.body.length===1?Gt(e.body[0]):null:Gt(e)}function Gs(e){let t=[];return e.get("body").traverse({ReturnStatement(n){t.push(n.node)},Function(n){n.skip()}}),t}function Zs(e){if(B.isFunctionDeclaration(e))return!0;if(B.isVariableDeclaration(e))return e.declarations.every(t=>t.init==null||B.isFunction(t.init)||Ys(t.init));if(B.isSwitchStatement(e)||B.isIfStatement(e)){let t=!0;return B.traverseFast(e,n=>{(B.isCallExpression(n)||B.isOptionalCallExpression(n)||B.isNewExpression(n)||B.isAwaitExpression(n)||B.isYieldExpression(n)||B.isThrowStatement(n)||B.isTaggedTemplateExpression(n)||B.isUpdateExpression(n))&&(t=!1)}),t}return B.isTypeScript(e)}function Ys(e){let t=!0;return B.traverseFast(e,n=>{(B.isCallExpression(n)||B.isOptionalCallExpression(n)||B.isNewExpression(n)||B.isAwaitExpression(n)||B.isYieldExpression(n)||B.isTaggedTemplateExpression(n)||B.isAssignmentExpression(n)||B.isUpdateExpression(n))&&(t=!1)}),t}function Qs(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=Gt(o.consequent[0]);if(r===null)return null;let i=t.length;t.push(r.jsx),n.push(B.switchCase(o.test===null?null:B.cloneNode(o.test),[B.returnStatement(B.numericLiteral(i))]))}return{pick:B.arrowFunctionExpression([],B.blockStatement([B.switchStatement(B.cloneNode(e.discriminant),n)])),branches:t,statements:new Set([e])}}function Gr(e,t){let n=e.node.body.body,o=Gs(e),r=n.at(-1);if(o.length===1&&r!==void 0){let s=Gt(r);if(s!==null)return s}if(r&&B.isIfStatement(r)&&r.alternate!=null){let s=r.alternate,a=uo(r.consequent),l=uo(s);if(a!==null&&l!==null&&o.length===2)return{pick:B.arrowFunctionExpression([],B.conditionalExpression(B.cloneNode(r.test),B.numericLiteral(0),B.numericLiteral(1))),branches:[a.jsx,l.jsx],statements:new Set([r])}}if(r&&B.isSwitchStatement(r)){let s=Qs(r);if(s!==null&&s.branches.length===o.length)return s}let i=r===void 0?null:Gt(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 g=n[c];if(B.isIfStatement(g)&&g.alternate==null){let S=uo(g.consequent);if(S!==null){d===-1&&(d=c),s.push(B.cloneNode(g.test)),a.push(S.jsx),l.add(g);continue}}if(d!==-1&&!Zs(g)){u=!1;break}}if(a.push(i.jsx),u&&a.length===o.length&&a.length>1){let c=B.numericLiteral(a.length-1);for(let g=s.length-1;g>=0;g--)c=B.conditionalExpression(s[g],B.numericLiteral(g),c);return{pick:B.arrowFunctionExpression([],c),branches:a,statements:l}}}throw e.buildCodeFrameError(`memo-dom: component '${t}' has unsupported JSX return control flow; use a tail chain of JSX early returns, a terminal JSX if/else, or an exhaustive JSX switch`)}function Zr(e,t,n){let o=t.node,r=Gr(t,n),i=e.componentProps.get(n),s=i.params.length,a=e.listedSites.get(n)??[],l=e.linkedComponentRows.get(n)??[],d=a.some(T=>T.sourceLocal===!0)||l.some(T=>T.sourceLocal),u=Dt(e,n),c=Ze(e,u),g=e.instanceDerivations.get(n),S=e.instanceControlFlow.get(n),y=e.effects.get(n),p=y?.some(T=>T.localReads.size>0||T.localDerivationReads.size>0||T.conditionLocalReads.size>0||T.conditionLocalDerivationReads.size>0)===!0;(e.selectiveDerivationComponents.has(n)||p)&&(c.reasonVar=$(e,"reasons").name);let f=$(e,"id").name,v=u?null:$(e,"parent").name,x=u&&d?$(e,"owner").name:null,I=u&&e.componentsWithHostEvents.has(n)?$(e,"eventRoot").name:null;c.delegatedEventRootVar=I;let J=s>0&&!u?$(e,"props").name:null;xt(e).registerComponentId(n,f);let F;if((a.length>0||l.length>0)&&i.bindings.length>0){let T=[...a.map(Q=>at(Q.keyExpr??null,Q.itemParam??"")),...l.map(Q=>Q.keyPath)],re=JSON.stringify(T[0]),ne=T.every(Q=>JSON.stringify(Q)===re)?T[0]:null,G=on(i,"item"),oe=Be(i);F={itemParam:G??oe??i.bindings[0],itemPath:G===null&&oe!==null?["item"]:[],rowIdVar:f,...u?{refreshVar:c.updateVar}:{},keyPath:ne,sourceKey:a[0]?.sourceKey??l[0]?.sourceKey??"",sourceLocal:d,...d?{ownerIdVar:x??v}:{}}}Wr(e,t,n,f,F);let N="jsx"in r?st(e,c,r.jsx,n,t,null,F):ea(e,c,r,n,t,f);if(u&&$t(e,c,N),g!==void 0)for(let T of g)T.declaration.kind="let";(g!==void 0||S!==void 0)&&c.updaters.unshift(()=>qr(e,n,c.reasonVar,o.body.body,g??[],S??[])),y!==void 0&&p&&c.updaters.push(()=>$o(e,n,f,c.reasonVar,y,c));let K=new Set(y?.map(T=>T.statement)??[]),_=o.body.body.filter(T=>!("jsx"in r?T===r.statement:r.statements.has(T))&&!K.has(T));s>0&&!u&&c.updaters.unshift(()=>D.blockStatement(Mn(i,i.params.map((T,re)=>D.memberExpression(D.identifier(J),D.numericLiteral(re),!0)))));let H=[Ye(c)];if(s>0&&!u){let T=Eo(i,i.params.map((re,ne)=>D.memberExpression(D.identifier(J),D.numericLiteral(ne),!0)));T!==null&&H.push(T)}if(H.push(..._,Qe(c),...u?[]:[gt(e,D.identifier(f),D.identifier(v),D.identifier(c.updateVar))]),s>0&&!u&&H.push(D.expressionStatement(D.callExpression(Z(e,"registerProps"),[D.identifier(f),D.identifier(J)]))),H.push(...c.creation,...c.mounts),y!==void 0&&H.push(...Xo(e,f,y)),u){let T=i.params.map((re,ne)=>$(e,`nextProp${ne}`));H.push(D.returnStatement(D.objectExpression([D.objectProperty(D.identifier("nodes"),D.callExpression(Z(e,"rootNodes"),[D.identifier(N)])),D.objectProperty(D.identifier("entities"),D.arrayExpression([])),D.objectProperty(D.identifier("update"),D.identifier(c.updateVar)),...s>0?[D.objectProperty(D.identifier("updateProps"),D.arrowFunctionExpression(T,D.blockStatement(Mn(i,T))))]:[],...c.disposableCallbacks.length>0?[D.objectProperty(D.identifier("dispose"),D.arrowFunctionExpression([],D.blockStatement([...c.disposableCallbacks].reverse().map(re=>D.ifStatement(D.binaryExpression("!==",D.cloneNode(re),D.nullLiteral()),D.expressionStatement(D.callExpression(D.cloneNode(re),[])))))))]:[]])))}else H.push(D.returnStatement(D.identifier(N)));o.params=u?[...i.params.map(So),D.identifier(f),...x===null?[]:[D.identifier(x)],...I===null?[]:[D.identifier(I)]]:s>0?[D.identifier(f),D.identifier(v),D.identifier(J)]:[D.identifier(f),D.identifier(v)],o.body=D.blockStatement(H)}function ea(e,t,n,o,r,i){let s=$(e,"returnRoot").name,a=$(e,"returnRegion").name,l=D.identifier(i),d=D.binaryExpression("+",D.cloneNode(l),D.stringLiteral("/$return"));return t.creation.push(D.variableDeclaration("const",[D.variableDeclarator(D.identifier(s),D.callExpression(D.memberExpression(D.identifier("document"),D.identifier("createDocumentFragment")),[]))])),t.creation.push(D.variableDeclaration("const",[D.variableDeclarator(D.identifier(a),D.callExpression(Z(e,"createCondRegion"),[D.identifier(s),D.cloneNode(d),D.cloneNode(n.pick),D.arrayExpression(n.branches.map(u=>$r(e,u,o,r,d,!1,l,!0,t.usedConds)))]))])),t.updaters.push(()=>D.expressionStatement(D.callExpression(D.memberExpression(D.identifier(a),D.identifier("update")),[]))),s}import*as de from"@babel/types";function ta(e){return!de.isIdentifier(e.id)||!/^[A-Z]/.test(e.id.name)||!de.isArrowFunctionExpression(e.init)&&!de.isFunctionExpression(e.init)||!ue(e.init.body)?null:e.init}function na(e,t,n){if(t.async||t.generator)throw n.buildCodeFrameError(`memo-dom: component '${e}' must be synchronous`);if(de.isFunctionExpression(t)&&t.id!=null&&t.id.name!==e)throw n.buildCodeFrameError(`memo-dom: named component function expression '${t.id.name}' must match binding '${e}'`);let o=de.functionDeclaration(de.identifier(e),t.params.map(r=>de.cloneNode(r,!0)),de.isBlockStatement(t.body)?de.cloneNode(t.body,!0):de.blockStatement([de.returnStatement(de.cloneNode(t.body,!0))]));return o.returnType=t.returnType==null?null:de.cloneNode(t.returnType,!0),o.typeParameters=t.typeParameters==null?null:de.cloneNode(t.typeParameters,!0),o.loc=t.loc,o}function Yr(e,t,n){if(e.kind!=="const")return[t?de.exportNamedDeclaration(de.cloneNode(e,!0)):de.cloneNode(e,!0)];let o=[];for(let r of e.declarations){let i=ta(r),s;i===null?s=de.variableDeclaration("const",[de.cloneNode(r,!0)]):s=na(r.id.name,i,n),o.push(t?de.exportNamedDeclaration(s):s)}return o.length>0&&de.inheritsComments(o[0],e),o}function Zt(e){let t=[],n=!1;for(let o of e.get("body")){let r=o.node;if(de.isVariableDeclaration(r)){let i=Yr(r,!1,o);n||=i.some(s=>de.isFunctionDeclaration(s)),t.push(...i);continue}if(de.isExportNamedDeclaration(r)&&de.isVariableDeclaration(r.declaration)){let i=Yr(r.declaration,!0,o);n||=i.some(s=>de.isExportNamedDeclaration(s)&&de.isFunctionDeclaration(s.declaration)),t.push(...i);continue}t.push(r)}n&&(e.set("body",t),e.scope.crawl())}function oa(e,t){let n=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#`;for(let o of t.get("body")){let r=o.node;if(j.isExportNamedDeclaration(r)&&(r=r.declaration),!(!j.isVariableDeclaration(r)||r.kind!=="const"))for(let i of r.declarations){if(!j.isIdentifier(i.id)||i.init==null)continue;let s=i.id.name;if(!e.computeds.has(s))continue;r.kind="let";let a=j.cloneNode(i.init),l=$(e,`${s}Next`),d=j.expressionStatement(j.callExpression(Z(e,"register"),[j.objectExpression([j.objectProperty(j.identifier("id"),j.stringLiteral(`${n}${s}`)),j.objectProperty(j.identifier("parent"),j.nullLiteral()),j.objectProperty(j.identifier("depth"),j.unaryExpression("-",j.numericLiteral(1))),j.objectProperty(j.identifier("render"),j.arrowFunctionExpression([],j.blockStatement([j.variableDeclaration("const",[j.variableDeclarator(l,a)]),j.ifStatement(j.callExpression(Z(e,"computedChanged"),[j.identifier(s),j.cloneNode(l)]),j.blockStatement([j.expressionStatement(j.assignmentExpression("=",j.identifier(s),j.cloneNode(l))),j.expressionStatement(j.callExpression(Z(e,"commitWrites"),[Ot(e,[s])]))]))])))])]));o.insertAfter(d)}}}function ra(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,$(e,`${a}Previous`)])),s=[j.variableDeclaration("const",o.bindings.map(a=>j.variableDeclarator(j.cloneNode(i.get(a)),j.identifier(a)))),j.cloneNode(o.statement,!0),...o.bindings.map(a=>j.ifStatement(j.callExpression(Z(e,"computedChanged"),[j.cloneNode(i.get(a)),j.identifier(a)]),j.blockStatement([j.expressionStatement(j.callExpression(Z(e,"commitWrites"),[Ot(e,[a])]))])))];r.insertAfter(j.expressionStatement(j.callExpression(Z(e,"register"),[j.objectExpression([j.objectProperty(j.identifier("id"),j.stringLiteral(o.entityId)),j.objectProperty(j.identifier("parent"),j.nullLiteral()),j.objectProperty(j.identifier("depth"),j.unaryExpression("-",j.numericLiteral(1))),j.objectProperty(j.identifier("render"),j.arrowFunctionExpression([],j.blockStatement(s)))])])))}}function po(e,t={}){let n=Yt(t),o=new WeakSet;return{name:"memo-dom",visitor:{Program:{enter(i){Zt(i),En(n,i),Qt(n,i),Pn(n,i),zr(n,i),Kr(n)},exit(i){Oo(n,i),Hr(i),To(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=Un(n);n.computeds.size>0&&oa(n,i),n.moduleControlFlow.length>0&&ra(n,i),s&&n.header.push(s);for(let a=n.header.length-1;a>=0;a--)i.unshiftContainer("body",n.header[a]);i.unshiftContainer("body",j.importDeclaration([j.importNamespaceSpecifier(j.identifier(xt(n).runtimeId))],j.stringLiteral(n.runtimePath)))}},FunctionDeclaration(i){let s=i.node.id?.name;!s||!n.comps.has(s)||o.has(i.node)||(o.add(i.node),Zr(n,i,s),i.skip())}}}}function fo(e,t={}){let n=ia(e,{filename:t.moduleId??"./component.tsx",plugins:[[sa,{}],[po,t],[aa,{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 Xt}from"node:path";import{transformSync as ui}from"@babel/core";import pi from"@babel/plugin-syntax-jsx";import fi from"@babel/plugin-transform-typescript";import*as V from"@babel/types";function la(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 da(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 Qr(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=la(o,a.target,d);for(let g of u)da(o,s,g,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 ca(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 ei(e,t){let n=new Map(e.map(u=>[u.key,u]));ca(n);let o=new Map,r=new Map;for(let u of n.values())for(let c of u.edges){if(!n.has(c.target))throw new Error(`memo-dom: component '${u.key}' references unknown factory '${c.target}'`);let g=o.get(c.target)??new Set;if(g.add(c.mode),o.set(c.target,g),c.mode==="row"){let S=r.get(c.target)??[];S.push({keyPath:c.keyPath===void 0||c.keyPath===null?null:[...c.keyPath],sourceKey:c.sourceKey??"",sourceLocal:c.sourceLocal??!1}),r.set(c.target,S)}}for(let[u,c]of o)if(c.size>1)throw new Error(`memo-dom: component '${u}' is used both as a keyed row and a static child`);let i=new Map,s=[...n.keys()].filter(u=>!o.has(u));for(let u of s)i.set(u,new Set([t]));let a=[...s];for(;a.length>0;){let u=a.shift(),c=i.get(u);if(c!==void 0)for(let g of n.get(u)?.edges??[]){let S=i.get(g.target)??new Set,y=S.size;for(let p of c)S.add(`${p}${g.suffix}`);i.set(g.target,S),S.size!==y&&a.push(g.target)}}let l=new Map;for(let u of n.keys())l.set(u,[...i.get(u)??[]].sort());let d=Qr(n,s);return{paths:l,rows:r,propSources:d}}import"@babel/types";import*as be from"@babel/types";function ti(e){let t=e;for(;be.isTSAsExpression(t)||be.isTSTypeAssertion(t)||be.isTSNonNullExpression(t)||be.isTSSatisfiesExpression(t);)t=t.expression;return t}function ua(e,t,n){let o=ti(n);if(be.isIdentifier(o))return!e.state.has(o.name)||t.getBinding(o.name)?.scope.path.isProgram()!==!0?null:Ue(e,o.name);if(!be.isMemberExpression(o))return null;let r=Pe(o);return r===null||!e.state.has(r)||t.getBinding(r)?.scope.path.isProgram()!==!0?null:Ue(e,ye(o)??r)}function pa(e,t){let n=ti(t);if(be.isIdentifier(n)){let a=He(e,n.name);return a===null?null:{type:"prop",name:a,path:[]}}if(!be.isMemberExpression(n))return null;let o=Pe(n),r=ye(n);if(o===null||r===null)return null;if(Be(e)===o){let[a,...l]=r.split(".").slice(1);return a===void 0?null:{type:"prop",name:a,path:l}}let s=He(e,o);return s===null?null:{type:"prop",name:s,path:r.split(".").slice(1)}}function fa(e,t){let n=!1,o=Be(e);return Xe(t,r=>{be.isIdentifier(r)&&(r.name===o||He(e,r.name)!==null)&&(n=!0)}),n}function ma(e){return be.isStringLiteral(e)||be.isNumericLiteral(e)||be.isBooleanLiteral(e)||be.isNullLiteral(e)||be.isBigIntLiteral(e)||be.isTemplateLiteral(e)}function ga(e,t,n,o){let r=ua(e,n,o);if(r!==null)return{type:"state",key:r};let i=e.componentProps.get(t),s=pa(i,o);if(s!==null)return s;let a=be.isIdentifier(o)?o.name:be.isMemberExpression(o)?Pe(o):null;return a!==null&&(e.instanceState.get(t)?.has(a)===!0||e.instanceDerivedBindings.get(t)?.has(a)===!0)||en(e,o).size>0||fa(i,o)?{type:"root"}:ma(o)?{type:"local"}:{type:"root"}}function mo(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 ba(e){return be.isJSXIdentifier(e.name)?e.name.name:null}function ni(e,t){let n=new Map;return e.compPaths.get(t).traverse({JSXOpeningElement(o){let r=o.node.name;if(!be.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)||mo(n,r.name,d,{type:"root"});continue}if(!s.isJSXAttribute())continue;let a=ba(s.node);if(a===null||a==="key"||a==="ref"||i?.refProps.includes(a)===!0)continue;let l=s.node.value;if(!be.isJSXExpressionContainer(l)||!be.isExpression(l.expression)){mo(n,r.name,a,{type:"local"});continue}mo(n,r.name,a,ga(e,t,s.scope,l.expression))}}}),n}function oi(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&&De(o)){let i=nn(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:xn(o.node.body),renderProps:[],renderCallbacks:[],refProps:[],subtreeReads:[]})}o.skip()}}),n}function ri(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:bn(e,n),delegatedEvents:e.componentsWithHostEvents.has(n),renderProps:[...o.renderProps],renderCallbacks:[...o.renderCallbacks],refProps:[...o.refProps],subtreeReads:[...Sn(e,n)].map(r=>Ue(e,r)).sort()}}function In(e,t){return e.importedComponents.get(t)?.key??`${e.moduleId}#${t}`}function ii(e,t){let n=[];for(let o of t.comps.keys()){let r=[],i=ni(t,o);for(let[s,a]of t.childRefCounts.get(o)??[]){let l=In(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:In(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:In(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:In(t,s),suffix:`/${l.suffix}/Row[*]`,mode:"row",keyPath:at(l.keyExpr??null,l.itemParam??""),sourceKey:l.sourceLocal===!0?l.sourceKey??"":Ue(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 mi(e){let t=e.replace(/\\/g,"/"),n=Xt.normalize(t);return t.startsWith("./")&&!n.startsWith("../")?`./${n}`:n}function gi(e){return{...e.runtimePath===void 0?{}:{runtimePath:e.runtimePath},...e.rootId===void 0?{}:{rootId:e.rootId}}}function ha(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(!V.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(!V.isJSXAttribute(d))continue;let u=V.isJSXIdentifier(d.name)?d.name.name:d.name.name.name,c=d.value;V.isJSXElement(c)||V.isJSXFragment(c)||V.isJSXExpressionContainer(c)&&V.isExpression(c.expression)&&(ue(c.expression)||et(e,o,c.expression))?n(l,u,"jsx"):n(l,u,"scalar")}i.node.children.some(d=>!V.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 si(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 St(e,t,n){for(;V.isTSAsExpression(e)||V.isTSTypeAssertion(e)||V.isTSNonNullExpression(e);)e=e.expression;if(V.isIdentifier(e)){t.has(e.name)&&n.add(e.name);return}if(V.isConditionalExpression(e)){St(e.consequent,t,n),St(e.alternate,t,n);return}if(V.isLogicalExpression(e)){St(e.right,t,n);return}if(V.isObjectExpression(e)){for(let o of e.properties)V.isObjectProperty(o)&&V.isExpression(o.value)&&St(o.value,t,n);return}if(V.isArrayExpression(e))for(let o of e.elements)o!=null&&!V.isSpreadElement(o)&&St(o,t,n)}function ai(e,t){let n=new Set;if(V.isExpression(e.body))return St(e.body,t,n),[...n];let o=r=>{if(!V.isFunction(r)){if(V.isReturnStatement(r)){V.isExpression(r.argument)&&St(r.argument,t,n);return}for(let i of V.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 bi(e){let t=[];for(let n of e.body)if(!(!V.isImportDeclaration(n)||n.importKind==="type"))for(let o of n.specifiers)if(V.isImportSpecifier(o)){if(o.importKind==="type")continue;let r=V.isIdentifier(o.imported)?o.imported.name:o.imported.value;t.push({local:o.local.name,imported:r,source:n.source.value})}else V.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 hi(e){let t=new Map;for(let n of e.body){if(V.isExportDefaultDeclaration(n)){(V.isFunctionDeclaration(n.declaration)||V.isClassDeclaration(n.declaration))&&n.declaration.id!=null?t.set("default",n.declaration.id.name):V.isIdentifier(n.declaration)&&t.set("default",n.declaration.name);continue}if(!V.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(V.isVariableDeclaration(o))for(let r of o.declarations)V.isIdentifier(r.id)&&t.set(r.id.name,r.id.name);else V.isFunctionDeclaration(o)&&o.id!=null&&t.set(o.id.name,o.id.name);for(let r of n.specifiers){if(!V.isExportSpecifier(r))continue;let i=r.local.name,s=V.isIdentifier(r.exported)?r.exported.name:r.exported.value;t.set(s,i)}}return t}function Ea(e,t,n){let o,r=()=>({visitor:{Program(i){Zt(i);let s=bi(i.node),a=Yt({...gi(n),moduleId:e.id,linkedImports:t});En(a,i),Qt(a,i),Pn(a,i);let l={},d=Hn(i.node);for(let[u,c]of hi(i.node)){if(a.comps.has(c)){l[u]={type:"component",...ri(a,e.id,c)};continue}let g=a.state.get(c);if(g!==void 0){l[u]={type:"state",kind:g,key:a.stateKeys.get(c)??`${e.id}#${c}`,tagCandidates:[...a.stateTagCandidates.get(c)??[]],componentCandidates:si(a,a.stateComponentCandidates.get(c)??[])};continue}let S=a.importedFunctions.get(c)??(a.helpers.has(c)?Ve(a,c):void 0);S!==void 0&&(l[u]={type:"function",tagCandidates:[...d.get(c)??a.functionTagCandidates.get(c)??[]],componentCandidates:si(a,a.functionComponentCandidates.get(c)??[]),reads:[...S.reads].map(y=>Ue(a,y)).sort(),writes:[...S.writes].map(y=>Ue(a,y)).sort(),boundedWrites:[...S.boundedWrites].map(y=>Ue(a,y)).sort(),parameterWrites:S.parameterWrites.map(y=>({index:y.index,path:[...y.path]})).sort((y,p)=>y.index-p.index||y.path.join(".").localeCompare(p.path.join("."))),unbounded:S.unbounded})}o={exports:l,imports:s,components:ii(e.id,a),componentUsages:ha(a)}}}});if(ui(e.source,{filename:e.id,plugins:[[pi,{}],r,[fi,{isTSX:!0}]],configFile:!1,babelrc:!1}),o===void 0)throw new Error(`memo-dom: failed to analyze module '${e.id}'`);return o}function ya(e){let t,n=()=>({visitor:{Program(o){Zt(o);let r=new Map,i=yn(o.node),s=Hn(o.node),a=oi(o,e.id),l=new Set(a.keys());for(let[u,c]of a)r.set(u,{type:"component",...c});for(let u of o.node.body){let c=V.isExportNamedDeclaration(u)?u.declaration:u;if(V.isVariableDeclaration(c))for(let g of c.declarations){if(!V.isIdentifier(g.id))continue;if(V.isArrowFunctionExpression(g.init)||V.isFunctionExpression(g.init)){let y=ai(g.init,l).map(p=>`${e.id}#${p}`);r.set(g.id.name,{type:"function",tagCandidates:[...s.get(g.id.name)??[]],componentCandidates:y,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0});continue}let S;if(c.kind==="let"||c.kind==="var"?S="let":Ct(g.init)?S="store":Pt(g.init)&&(S="const"),S!==void 0){let y=new Set;V.isExpression(g.init)&&St(g.init,l,y),r.set(g.id.name,{type:"state",kind:S,key:`${e.id}#${g.id.name}`,tagCandidates:[...i.get(g.id.name)??[]],componentCandidates:[...y].map(p=>`${e.id}#${p}`)})}}else if(V.isFunctionDeclaration(c)&&c.id!=null&&!a.has(c.id.name)){let g=ai(c,l).map(S=>`${e.id}#${S}`);r.set(c.id.name,{type:"function",tagCandidates:[...s.get(c.id.name)??[]],componentCandidates:g,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0})}}let d={};for(let[u,c]of hi(o.node)){let g=r.get(c);g!==void 0&&(d[u]=g)}t={exports:d,imports:bi(o.node),components:[],componentUsages:[]}}}});if(ui(e.source,{filename:e.id,plugins:[[pi,{}],n,[fi,{isTSX:!0}]],configFile:!1,babelrc:!1}),t===void 0)throw new Error(`memo-dom: failed to discover module '${e.id}'`);return t}function Ei(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=Xt.normalize(Xt.join(Xt.dirname(e),t));i=e.startsWith("./")&&!l.startsWith("../")?`./${l}`:l}else i=t;let s=mi(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 Sa(e,t){if(!t.startsWith("."))return t;let n=Xt.relative(Xt.dirname(e),t);return n.startsWith(".")?n:`./${n}`}function li(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:Sa(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 di(e,t,n,o,r,i){let s={};for(let a of t.imports){let l=Ei(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:li(e,d.componentCandidates,n)};else if(d.type==="component"){let u=i?.get(d.key),c=d.renderProps.filter(g=>u?.scalar.has(g)!==!0||u.jsx.has(g));s[a.local]={type:"component",key:d.key,props:[...d.props],objectProps:d.objectProps,acceptsUnknownProps:d.acceptsUnknownProps,hasWholeDefault:d.hasWholeDefault,listLightweight:d.listLightweight,delegatedEvents:d.delegatedEvents,renderProps:c,renderCallbacks:[...d.renderCallbacks],refProps:[...d.refProps],subtreeReads:[...d.subtreeReads]}}else s[a.local]={type:"function",tagCandidates:[...d.tagCandidates],componentCandidates:li(e,d.componentCandidates,n),reads:[...d.reads],writes:[...d.writes],boundedWrites:[...d.boundedWrites],parameterWrites:[...d.parameterWrites],unbounded:d.unbounded}}return s}function ci(e){return JSON.stringify(e)}function xa(e,t={}){let n=new Map;for(let[a,l]of Object.entries(e)){let d=mi(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 o=new Map;for(let a of n.values())o.set(a.id,ya(a));for(let a=0;a<=n.size;a++){let l=!1,d=new Map;for(let u of n.values()){let c=o.get(u.id),g=di(u,c,o,n,t),S=Ea(u,g,t);d.set(u.id,S),ci(S)!==ci(c)&&(l=!0)}if(o=d,!l)break;if(a===n.size)throw new Error("memo-dom: cross-module export summaries did not converge")}let r=new Map;for(let a of o.values())for(let l of a.componentUsages){let d=r.get(l.target);d===void 0&&(d={jsx:new Set,scalar:new Set},r.set(l.target,d)),d[l.kind].add(l.prop)}for(let[a,l]of r)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=ei([...o.values()].flatMap(a=>a.components),t.rootId??"App"),s={};for(let a of n.values()){let l=o.get(a.id),d=di(a,l,o,n,t,r);for(let y of l.imports){let p=Ei(a.id,y.source,n,t);if(p!==void 0&&o.get(p.id)?.exports[y.imported]===void 0)throw new Error(`memo-dom: '${y.imported}' is not a linkable state, function, or component export of '${y.source}'`)}let u={},c={},g={},S={};for(let y of l.components){u[y.local]=[...i.paths.get(y.key)??[]];let p=i.rows.get(y.key);p!==void 0&&(c[y.local]=p.map(x=>({keyPath:x.keyPath===null?null:[...x.keyPath],sourceKey:x.sourceKey,sourceLocal:x.sourceLocal})));let f=i.propSources.get(y.key);f!==void 0&&(g[y.local]=Object.fromEntries([...f].map(([x,I])=>[x,{keys:[...I.keys],rootFallback:I.rootFallback}])));let v=Object.values(l.exports).find(x=>x.type==="component"&&x.key===y.key);if(v?.type==="component"){let x=r.get(y.key);S[y.local]=v.renderProps.filter(I=>x?.scalar.has(I)!==!0||x.jsx.has(I))}}s[a.originalId]=fo(a.source,{...gi(t),moduleId:a.id,linkedImports:d,linkedComponentPaths:u,linkedComponentRows:c,linkedComponentPropSources:g,linkedComponentRenderProps:S})}return s}export{fo as compile,xa as compileModules};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jsx/attributes.ts - ordered JSX attribute object construction.
|
|
3
|
+
*
|
|
4
|
+
* Spread-bearing hosts and component calls must preserve source-order
|
|
5
|
+
* overrides. This module converts attributes into one object expression while
|
|
6
|
+
* delegating explicit event instrumentation to the owning emitter.
|
|
7
|
+
*/
|
|
8
|
+
import * as t from '@babel/types';
|
|
9
|
+
export interface OrderedAttributes {
|
|
10
|
+
expression: t.ObjectExpression;
|
|
11
|
+
sources: t.Expression[];
|
|
12
|
+
/** Explicit events after the last spread cannot be dynamically overridden. */
|
|
13
|
+
safeEventKeys: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface OrderedAttributeOptions {
|
|
16
|
+
skipKey?: boolean;
|
|
17
|
+
eventValue?: (name: string, value: t.Expression) => t.Expression;
|
|
18
|
+
attributeValue?: (name: string, value: t.Expression) => t.Expression;
|
|
19
|
+
fail(message: string): never;
|
|
20
|
+
}
|
|
21
|
+
/** Build one JavaScript object with normal spread override semantics. */
|
|
22
|
+
export declare function buildOrderedAttributes(attributes: readonly (t.JSXAttribute | t.JSXSpreadAttribute)[], options: OrderedAttributeOptions): OrderedAttributes;
|
|
23
|
+
export declare function jsxAttributeName(name: t.JSXIdentifier | t.JSXNamespacedName): string;
|
|
24
|
+
//# sourceMappingURL=attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/jsx/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,CAAC,CAAC,gBAAgB,CAAC;IAC/B,OAAO,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC;IACxB,8EAA8E;IAC9E,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU,CAAC;IACjE,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU,CAAC;IACrE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;CAC9B;AAED,yEAAyE;AACzE,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,kBAAkB,CAAC,EAAE,EAC9D,OAAO,EAAE,uBAAuB,GAC/B,iBAAiB,CA8CnB;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,iBAAiB,GAC1C,MAAM,CAIR"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jsx/children.ts - direct JSX child classification for host-like parents.
|
|
3
|
+
*
|
|
4
|
+
* Host elements and fragments share the same child semantics. This module
|
|
5
|
+
* classifies text, nodes, lists, conditional regions, and forwarded slots
|
|
6
|
+
* without deciding when the eventual parent node is created.
|
|
7
|
+
*/
|
|
8
|
+
import * as t from '@babel/types';
|
|
9
|
+
import { type JsxChild } from '../components/children';
|
|
10
|
+
export type JsxNode = t.JSXElement | t.JSXFragment;
|
|
11
|
+
export type DirectChildOperation = {
|
|
12
|
+
type: 'node';
|
|
13
|
+
variable: string;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'list';
|
|
16
|
+
expression: t.CallExpression;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'condition';
|
|
19
|
+
expression: t.ConditionalExpression | t.LogicalExpression;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'slot';
|
|
22
|
+
expression: t.Expression;
|
|
23
|
+
};
|
|
24
|
+
export interface DirectChildEmitters {
|
|
25
|
+
emitText(expression: t.Expression): string;
|
|
26
|
+
emitNode(node: JsxNode): string;
|
|
27
|
+
isForwarded(expression: t.Expression): boolean;
|
|
28
|
+
fail(message: string): never;
|
|
29
|
+
}
|
|
30
|
+
/** Classify and emit immediate child nodes in authored source order. */
|
|
31
|
+
export declare function collectDirectChildren(children: readonly JsxChild[], emitters: DirectChildEmitters): DirectChildOperation[];
|
|
32
|
+
//# sourceMappingURL=children.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"children.d.ts","sourceRoot":"","sources":["../../src/jsx/children.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,OAAO,EAEL,KAAK,QAAQ,EACd,MAAM,wBAAwB,CAAC;AAGhC,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,WAAW,CAAC;AAEnD,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,CAAC,CAAC,cAAc,CAAA;CAAE,GAC9C;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,UAAU,EAAE,CAAC,CAAC,qBAAqB,GAAG,CAAC,CAAC,iBAAiB,CAAC;CAC3D,GACD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,CAAC,CAAC,UAAU,CAAA;CAAE,CAAC;AAE/C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,GAAG,MAAM,CAAC;IAC3C,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IAChC,WAAW,CAAC,UAAU,EAAE,CAAC,CAAC,UAAU,GAAG,OAAO,CAAC;IAC/C,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC;CAC9B;AAED,wEAAwE;AACxE,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,SAAS,QAAQ,EAAE,EAC7B,QAAQ,EAAE,mBAAmB,GAC5B,oBAAoB,EAAE,CAqDxB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time specialization for explicit JSX host attributes.
|
|
3
|
+
*
|
|
4
|
+
* Spreads still use the generic runtime dispatcher because their keys are
|
|
5
|
+
* dynamic. Explicit HTML properties and mapped attributes can instead become
|
|
6
|
+
* direct DOM operations, avoiding unrelated runtime style/SVG machinery.
|
|
7
|
+
*/
|
|
8
|
+
import * as t from '@babel/types';
|
|
9
|
+
export declare function domPropertyName(name: string, elementIsSvg: boolean): string | null;
|
|
10
|
+
export declare function isMappedDomAttribute(name: string, elementIsSvg: boolean): boolean;
|
|
11
|
+
export declare function domPropertyWrite(varName: string, name: string, value: t.Expression): t.Statement;
|
|
12
|
+
export declare function domAttributeWrite(varName: string, name: string, value: t.Expression): t.Statement;
|
|
13
|
+
//# sourceMappingURL=dom-attributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-attributes.d.ts","sourceRoot":"","sources":["../../src/jsx/dom-attributes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AA0BlC,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,OAAO,GACpB,MAAM,GAAG,IAAI,CAEf;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,OAAO,GACpB,OAAO,CAET;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,CAAC,CAAC,UAAU,GAClB,CAAC,CAAC,SAAS,CAiDb;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,CAAC,CAAC,UAAU,GAClB,CAAC,CAAC,SAAS,CA2Cb"}
|