@memoized-dom/compiler 0.0.5 → 0.0.6
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 +106 -78
- package/dist/analysis/access-table.d.ts +1 -1
- package/dist/analysis/access-table.d.ts.map +1 -1
- package/dist/analysis/component-graph.d.ts +16 -1
- package/dist/analysis/component-graph.d.ts.map +1 -1
- package/dist/analysis/component-reads.d.ts +1 -1
- package/dist/analysis/component-reads.d.ts.map +1 -1
- package/dist/analysis/computed.d.ts +9 -5
- package/dist/analysis/computed.d.ts.map +1 -1
- package/dist/analysis/instance-control-flow.d.ts +1 -1
- package/dist/analysis/instance-control-flow.d.ts.map +1 -1
- package/dist/analysis/instance.d.ts +3 -4
- package/dist/analysis/instance.d.ts.map +1 -1
- package/dist/analysis/module-discovery.d.ts +27 -0
- package/dist/analysis/module-discovery.d.ts.map +1 -0
- package/dist/analysis/opaque-volatility.d.ts +1 -1
- package/dist/analysis/opaque-volatility.d.ts.map +1 -1
- package/dist/analysis/runtime-pattern.d.ts +3 -4
- package/dist/analysis/runtime-pattern.d.ts.map +1 -1
- package/dist/analysis/type-candidates.d.ts +15 -3
- package/dist/analysis/type-candidates.d.ts.map +1 -1
- package/dist/analysis.d.ts +7 -4
- package/dist/analysis.d.ts.map +1 -1
- package/dist/ast/builders.d.ts +108 -0
- package/dist/ast/builders.d.ts.map +1 -0
- package/dist/ast/compiler-types.d.ts +196 -0
- package/dist/ast/compiler-types.d.ts.map +1 -0
- package/dist/ast/factory.d.ts +139 -0
- package/dist/ast/factory.d.ts.map +1 -0
- package/dist/ast/index.d.ts +15 -0
- package/dist/ast/index.d.ts.map +1 -0
- package/dist/ast/mutate.d.ts +17 -0
- package/dist/ast/mutate.d.ts.map +1 -0
- package/dist/ast/normalize.d.ts +9 -0
- package/dist/ast/normalize.d.ts.map +1 -0
- package/dist/ast/parser.d.ts +72 -0
- package/dist/ast/parser.d.ts.map +1 -0
- package/dist/ast/printer.d.ts +23 -0
- package/dist/ast/printer.d.ts.map +1 -0
- package/dist/ast/scope.d.ts +44 -0
- package/dist/ast/scope.d.ts.map +1 -0
- package/dist/ast/strip-typescript.d.ts +9 -0
- package/dist/ast/strip-typescript.d.ts.map +1 -0
- package/dist/ast/transform.d.ts +21 -0
- package/dist/ast/transform.d.ts.map +1 -0
- package/dist/ast/tsrx/frontend.d.ts +8 -0
- package/dist/ast/tsrx/frontend.d.ts.map +1 -0
- package/dist/ast/tsrx/index.d.ts +5 -0
- package/dist/ast/tsrx/index.d.ts.map +1 -0
- package/dist/ast/tsrx/lower.d.ts +8 -0
- package/dist/ast/tsrx/lower.d.ts.map +1 -0
- package/dist/ast/tsrx/style.d.ts +8 -0
- package/dist/ast/tsrx/style.d.ts.map +1 -0
- package/dist/ast/tsrx/types.d.ts +50 -0
- package/dist/ast/tsrx/types.d.ts.map +1 -0
- package/dist/ast/types.d.ts +478 -0
- package/dist/ast/types.d.ts.map +1 -0
- package/dist/ast/walk.d.ts +22 -0
- package/dist/ast/walk.d.ts.map +1 -0
- package/dist/cells.d.ts +10 -0
- package/dist/cells.d.ts.map +1 -0
- package/dist/compile.d.ts +14 -20
- package/dist/compile.d.ts.map +1 -1
- package/dist/components/callback-props.d.ts +1 -1
- package/dist/components/callback-props.d.ts.map +1 -1
- package/dist/components/calls.d.ts +1 -1
- package/dist/components/calls.d.ts.map +1 -1
- package/dist/components/children.d.ts +3 -2
- package/dist/components/children.d.ts.map +1 -1
- package/dist/components/declarations.d.ts +10 -3
- package/dist/components/declarations.d.ts.map +1 -1
- package/dist/components/jsx-values.d.ts +2 -4
- package/dist/components/jsx-values.d.ts.map +1 -1
- package/dist/components/local-derived.d.ts +1 -1
- package/dist/components/local-derived.d.ts.map +1 -1
- package/dist/components/manifest.d.ts +2 -3
- package/dist/components/manifest.d.ts.map +1 -1
- package/dist/components/prop-effects.d.ts.map +1 -1
- package/dist/components/prop-linker.d.ts.map +1 -1
- package/dist/components/prop-origins.d.ts +2 -0
- package/dist/components/prop-origins.d.ts.map +1 -1
- package/dist/components/prop-projections.d.ts.map +1 -1
- package/dist/components/prop-shape.d.ts +11 -0
- package/dist/components/prop-shape.d.ts.map +1 -0
- package/dist/components/props.d.ts +9 -1
- package/dist/components/props.d.ts.map +1 -1
- package/dist/components/ref-props.d.ts.map +1 -1
- package/dist/components/render-callbacks.d.ts +7 -3
- package/dist/components/render-callbacks.d.ts.map +1 -1
- package/dist/components/render-functions.d.ts +1 -0
- package/dist/components/render-functions.d.ts.map +1 -1
- package/dist/components/render-prelude.d.ts +1 -1
- package/dist/components/render-prelude.d.ts.map +1 -1
- package/dist/components/return-plan.d.ts +13 -7
- package/dist/components/return-plan.d.ts.map +1 -1
- package/dist/conds.d.ts +6 -3
- package/dist/conds.d.ts.map +1 -1
- package/dist/context/ast.d.ts +11 -2
- package/dist/context/ast.d.ts.map +1 -1
- package/dist/context/model.d.ts +111 -7
- package/dist/context/model.d.ts.map +1 -1
- package/dist/data-sources.d.ts +78 -0
- package/dist/data-sources.d.ts.map +1 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/effects.d.ts +13 -5
- package/dist/effects.d.ts.map +1 -1
- package/dist/emission/component.d.ts +3 -3
- package/dist/emission/component.d.ts.map +1 -1
- package/dist/emission/conditional-region.d.ts +6 -5
- package/dist/emission/conditional-region.d.ts.map +1 -1
- package/dist/emission/dom-template.d.ts.map +1 -1
- package/dist/emission/list-region.d.ts +5 -4
- package/dist/emission/list-region.d.ts.map +1 -1
- package/dist/emission/node-emitter.d.ts +4 -3
- package/dist/emission/node-emitter.d.ts.map +1 -1
- package/dist/emission/render-callback.d.ts +4 -3
- package/dist/emission/render-callback.d.ts.map +1 -1
- package/dist/emission/route-region.d.ts +4 -3
- package/dist/emission/route-region.d.ts.map +1 -1
- package/dist/emission/scope.d.ts +13 -1
- package/dist/emission/scope.d.ts.map +1 -1
- package/dist/emit.d.ts +5 -4
- package/dist/emit.d.ts.map +1 -1
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/handler-commits.d.ts +6 -1
- package/dist/handler-commits.d.ts.map +1 -1
- package/dist/handler-origin.d.ts +1 -1
- package/dist/handler-origin.d.ts.map +1 -1
- package/dist/handlers/analyze.d.ts +1 -1
- package/dist/handlers/analyze.d.ts.map +1 -1
- package/dist/handlers/local-calls.d.ts +2 -2
- package/dist/handlers/local-calls.d.ts.map +1 -1
- package/dist/handlers.d.ts +6 -5
- package/dist/handlers.d.ts.map +1 -1
- package/dist/helper-summaries.d.ts +2 -3
- package/dist/helper-summaries.d.ts.map +1 -1
- package/dist/identifiers.d.ts +13 -8
- package/dist/identifiers.d.ts.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/jsx/attributes.d.ts +1 -1
- package/dist/jsx/attributes.d.ts.map +1 -1
- package/dist/jsx/children.d.ts +1 -1
- package/dist/jsx/children.d.ts.map +1 -1
- package/dist/jsx/conditional-directives.d.ts +12 -3
- package/dist/jsx/conditional-directives.d.ts.map +1 -1
- package/dist/jsx/dom-attributes.d.ts +1 -1
- package/dist/jsx/dom-attributes.d.ts.map +1 -1
- package/dist/jsx/dynamic-tags.d.ts +9 -15
- package/dist/jsx/dynamic-tags.d.ts.map +1 -1
- package/dist/jsx/events.d.ts +2 -2
- package/dist/jsx/events.d.ts.map +1 -1
- package/dist/jsx/refs.d.ts +5 -4
- package/dist/jsx/refs.d.ts.map +1 -1
- package/dist/jsx/svg.d.ts +2 -2
- package/dist/jsx/svg.d.ts.map +1 -1
- package/dist/jsx-types.d.ts +4 -1
- package/dist/jsx-types.d.ts.map +1 -1
- package/dist/lifecycle.d.ts +10 -5
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/linker.d.ts +7 -1
- package/dist/linker.d.ts.map +1 -1
- package/dist/lists/calculated-sources.d.ts +1 -1
- package/dist/lists/calculated-sources.d.ts.map +1 -1
- package/dist/lists/map-site.d.ts +11 -5
- package/dist/lists/map-site.d.ts.map +1 -1
- package/dist/lists/source-shapes.d.ts +12 -3
- package/dist/lists/source-shapes.d.ts.map +1 -1
- package/dist/lists/static-derived.d.ts +37 -0
- package/dist/lists/static-derived.d.ts.map +1 -0
- package/dist/lists/targeted-refresh.d.ts +9 -2
- package/dist/lists/targeted-refresh.d.ts.map +1 -1
- package/dist/module-control-flow.d.ts +7 -6
- package/dist/module-control-flow.d.ts.map +1 -1
- package/dist/mutation-analysis.d.ts +22 -8
- package/dist/mutation-analysis.d.ts.map +1 -1
- package/dist/plugin.d.ts +10 -6
- package/dist/plugin.d.ts.map +1 -1
- package/dist/router.d.ts +8 -4
- package/dist/router.d.ts.map +1 -1
- package/dist/server-functions.d.ts +49 -0
- package/dist/server-functions.d.ts.map +1 -0
- package/package.json +34 -36
package/dist/index.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
import{transformFromAstSync as Ll,transformSync as Al}from"@babel/core";import jl from"@babel/plugin-syntax-jsx";import Jl from"@babel/plugin-transform-typescript";import*as Ui from"@babel/types";import*as O from"@babel/types";import"@babel/types";function En(e={}){let t=e.moduleId??"./component.tsx",n=new Map,o=new Map,r=new Map,i=new Map,s=new Map,a=new Map,l=new Map,d=new Set,u=new Map,c=new Map;for(let[b,f]of Object.entries(e.linkedImports??{}))f.type==="state"?(n.set(b,f.kind),o.set(b,f.key),f.tagCandidates!==void 0&&r.set(b,[...f.tagCandidates]),f.componentCandidates!==void 0&&l.set(b,f.componentCandidates.map(g=>({...g}))),d.add(b)):f.type==="function"?(f.tagCandidates!==void 0&&i.set(b,[...f.tagCandidates]),f.componentCandidates!==void 0&&l.set(b,f.componentCandidates.map(g=>({...g}))),u.set(b,{reads:new Set(f.reads),writes:new Set(f.writes),boundedWrites:new Set(f.boundedWrites),parameterWrites:f.parameterWrites.map(g=>({index:g.index,path:[...g.path]})),unbounded:f.unbounded})):c.set(b,{...f,props:[...f.props]});let m=new Map;for(let[b,f]of c)m.set(b,{mode:f.objectProps?"object":"positional",names:[...f.props],acceptsUnknown:f.acceptsUnknownProps,bindings:[],params:[],hasWholeDefault:f.hasWholeDefault,renderProps:[...f.renderProps??[]],renderCallbacks:[...f.renderCallbacks??[]],refProps:[...f.refProps??[]]});let E=new Map(Object.entries(e.linkedComponentRenderProps??{}).map(([b,f])=>[b,[...f]]));return{runtimePath:e.runtimePath??"@memoized-dom/runtime",routerPath:e.routerPath??"@memoized-dom/router/internal",rootId:e.rootId??"App",rootComponent:e.rootComponent??null,hot:e.hot??!1,moduleId:t,linkedRoutes:e.linkedRoutes??null,emitRouteManifest:e.emitRouteManifest??e.linkedRoutes===void 0,routeElements:new WeakMap,localRoutes:[],usesRouter:!1,state:n,stateKeys:o,stateTagCandidates:r,functionTagCandidates:i,stateComponentCandidates:s,functionComponentCandidates:a,linkedDynamicComponentCandidates:l,importedState:d,importedFunctions:u,importedComponents:c,linkedComponentPaths:new Map(Object.entries(e.linkedComponentPaths??{}).map(([b,f])=>[b,[...f]])),linkedComponentRows:new Map(Object.entries(e.linkedComponentRows??{}).map(([b,f])=>[b,f.map(g=>({keyPath:g.keyPath===null?null:[...g.keyPath],sourceKey:g.sourceKey,sourceLocal:g.sourceLocal}))])),linkedComponentPropSources:new Map(Object.entries(e.linkedComponentPropSources??{}).map(([b,f])=>[b,new Map(Object.entries(f).map(([g,h])=>[g,{keys:[...h.keys],rootFallback:h.rootFallback}]))])),comps:new Map,compPaths:new Map,helpers:new Map,jsxHelpers:new Map,helperSummaries:new Map,compReads:new Map,childRefCounts:new Map,renderSlotOwners:new Set,listedSites:new Map,componentsWithHostEvents:new Set,componentHostEvents:new Map,conditionalComponentSites:new Map,rowComponentSites:new Map,componentProps:m,linkedComponentRenderProps:E,lightweightCache:new Map,rowReads:new Map,condReads:new Map,targetedListDependencies:new WeakMap,targetedListComponents:new Set,keyedListMutations:new WeakMap,keyedListMutationSources:new Map,disabledKeyedListMutationSources:new Set,instanceState:new Map,instanceDerivations:new Map,instanceControlFlow:new Map,instanceDerivedBindings:new Map,instanceReasonIds:new Map,selectiveDerivationComponents:new Set,volatileComponents:new Set,opaqueBindings:new Map,effects:new Map,moduleEffects:[],computeds:new Map,moduleControlFlow:[],header:[],readers:new Map,writeConstCounter:0,writeConsts:new Map,reasonConstCounter:0,reasonConsts:new Map,analyzedFunctions:new WeakSet,handlerHasRootCommit:new WeakMap,identifiers:null}}import*as U from"@babel/types";import*as et from"@babel/types";var Qn=class{constructor(t,n){this.scope=t;Ss(n.node,o=>this.reserved.add(o)),this.runtimeId=this.generate("MD").name,this.routerId=this.generate("MR").name}scope;runtimeId;routerId;reserved=new Set;componentIds=new Map;generate(t){let n;do n=this.scope.generateUidIdentifier(t);while(this.reserved.has(n.name));return this.reserved.add(n.name),n}registerComponentId(t,n){this.componentIds.set(t,n)}componentId(t){let n=this.componentIds.get(t);if(n===void 0)throw new Error(`memo-dom: missing generated factory id for '${t}'`);return et.identifier(n)}runtimeMember(t){return et.memberExpression(et.identifier(this.runtimeId),et.identifier(t))}};function hn(e,t){let n=new Qn(t.scope,t);return e.identifiers=n,n}function J(e,t){return Et(e).generate(t)}function Te(e,t){return Et(e).componentId(t)}function ne(e,t){return Et(e).runtimeMember(t)}function bt(e,t){let n=Et(e);return et.memberExpression(et.identifier(n.routerId),et.identifier(t))}function Et(e){if(e.identifiers===null)throw new Error("memo-dom: generated identifier allocator was not initialized");return e.identifiers}function Ss(e,t){let n=o=>{et.isIdentifier(o)&&t(o.name);for(let r of et.VISITOR_KEYS[o.type]??[]){let i=o[r];if(Array.isArray(i))for(let s of i)s&&typeof s=="object"&&"type"in s&&n(s);else i&&typeof i=="object"&&"type"in i&&n(i)}};n(e)}function $t(e){for(;U.isTSAsExpression(e)||U.isTSTypeAssertion(e)||U.isTSNonNullExpression(e)||U.isTSSatisfiesExpression(e)||U.isTSInstantiationExpression(e);)e=e.expression;return e}function wt(e,t,n){e.state.set(t,n),e.stateKeys.has(t)||e.stateKeys.set(t,`${e.moduleId}#${t}`)}function tt(e,t){if(t.includes("#"))return t;let n=t.indexOf("."),o=n===-1?t:t.slice(0,n),r=n===-1?"":t.slice(n);return`${e.stateKeys.get(o)??o}${r}`}function Qt(e,t){let n=[...new Set(t.map(s=>tt(e,s)))].sort(),o=n.join(" "),r=e.writeConsts.get(o);if(r!==void 0)return U.identifier(r);let i=J(e,`WRITES_${e.writeConstCounter++}`);return e.writeConsts.set(o,i.name),e.header.push(U.variableDeclaration("const",[U.variableDeclarator(i,U.arrayExpression(n.map(s=>U.stringLiteral(s))))])),i}function Ho(e,t){let n=[...new Set(t)].sort((s,a)=>s-a),o=n.join(" "),r=e.reasonConsts.get(o);if(r!==void 0)return U.identifier(r);let i=J(e,`REASONS_${e.reasonConstCounter++}`);return e.reasonConsts.set(o,i.name),e.header.push(U.variableDeclaration("const",[U.variableDeclarator(i,U.arrayExpression(n.map(s=>U.numericLiteral(s))))])),i}function Uo(e){return U.isMemberExpression(e)||U.isOptionalMemberExpression(e)}function Pe(e){let t=[],n=e;for(;Uo(n);){if(n.computed){if(!U.isStringLiteral(n.property))return null;t.unshift(n.property.value)}else{if(!U.isIdentifier(n.property))return null;t.unshift(n.property.name)}if(U.isSuper(n.object))return null;n=n.object}for(;U.isTSNonNullExpression(n)||U.isTSAsExpression(n)||U.isTSTypeAssertion(n)||U.isTSSatisfiesExpression(n)||U.isTSInstantiationExpression(n);)n=n.expression;return U.isIdentifier(n)?(t.unshift(n.name),t.join(".")):null}function it(e,t){if(e===null)return[];let n=[],o=e;for(;U.isMemberExpression(o)&&!o.computed;){if(!U.isIdentifier(o.property)||(n.unshift(o.property.name),U.isSuper(o.object)))return null;o=o.object}return!U.isIdentifier(o,{name:t})||n.length===0?null:n}function Xt(e,t){return t===null?!0:t.length===0||e.length>t.length?!1:e.every((n,o)=>t[o]===n)}function Re(e){let t=e;for(;;){if(Uo(t)){if(U.isSuper(t.object))return null;t=t.object;continue}if(U.isTSNonNullExpression(t)||U.isTSAsExpression(t)||U.isTSTypeAssertion(t)||U.isTSSatisfiesExpression(t)||U.isTSInstantiationExpression(t)){t=t.expression;continue}break}return U.isIdentifier(t)?t.name:null}function Dt(e){if(!e)return!1;let t=$t(e);return U.isObjectExpression(t)?t.properties.every(n=>U.isObjectProperty(n)&&!n.computed&&(U.isIdentifier(n.key)||U.isStringLiteral(n.key))):!1}function Lt(e){if(!e)return!1;let t=$t(e);return U.isArrayExpression(t)||U.isNewExpression(t)}function ze(e){return e==null?null:U.isStringLiteral(e)?e:U.isJSXExpressionContainer(e)?U.isJSXEmptyExpression(e.expression)?null:e.expression:null}function eo(e,t,n){let o=n!==void 0?e.instanceState.get(n):void 0,r=n!==void 0?e.instanceDerivedBindings.get(n):void 0,i=n!==void 0?e.componentProps.get(n)?.bindings:void 0,s=!1,a=l=>{if(!s){if(U.isIdentifier(l)&&(e.state.has(l.name)||o?.has(l.name)===!0||r?.has(l.name)===!0||i?.includes(l.name)===!0)){s=!0;return}for(let d of U.VISITOR_KEYS[l.type]??[]){let u=l[d];if(Array.isArray(u))for(let c of u)c&&typeof c=="object"&&"type"in c&&a(c);else u&&typeof u=="object"&&"type"in u&&a(u)}}};return a(t),s}function qo(e,t,n){let o=new Set([...e.instanceState.get(n)??[],...e.instanceDerivedBindings.get(n)??[],...e.componentProps.get(n)?.bindings??[]]);if(o.size===0)return!1;let r=!1;return Oe(t,i=>U.isIdentifier(i)&&o.has(i.name)?(r=!0,!1):r?!1:void 0),r}function Oe(e,t){let n=(o,r)=>{if(t(o,r)!==!1)for(let i of U.VISITOR_KEYS[o.type]??[]){let s=o[i];if(Array.isArray(s))for(let a of s)a&&typeof a=="object"&&"type"in a&&n(a,o);else s&&typeof s=="object"&&"type"in s&&n(s,o)}};n(e,null)}function fe(e){let t=!1;return Oe(e,n=>{(U.isJSXElement(n)||U.isJSXFragment(n))&&(t=!0)}),t}function yn(e,t){let n=new Set;return Oe(t,o=>{if(U.isJSXAttribute(o)&&U.isJSXIdentifier(o.name,{name:"ref"}))return!1;U.isIdentifier(o)&&e.state.has(o.name)&&n.add(o.name)}),n}import*as P from"@babel/types";import*as re from"@babel/types";import*as Ze from"@babel/types";function xn(e){let t=Ze.cloneNode(e,!0);return Ze.traverseFast(t,n=>{(Ze.isIdentifier(n)||Ze.isObjectPattern(n)||Ze.isArrayPattern(n)||Ze.isRestElement(n)||Ze.isAssignmentPattern(n))&&(n.typeAnnotation=null)}),t}import*as ve from"@babel/types";import*as Y from"@babel/types";function Sn(e){if(e.mode!=="object"||e.params.length!==1||e.hasWholeDefault)return null;let t=e.params[0];if(!Y.isObjectPattern(t))return null;let n=[];for(let o of t.properties){if(!Y.isObjectProperty(o)||o.computed||!Y.isIdentifier(o.value))return null;let r=Y.isIdentifier(o.key)?o.key.name:Y.isStringLiteral(o.key)?o.key.value:null;if(r===null)return null;n.push({name:r,local:o.value.name})}return n}function Cn(e){if(e.some(i=>Y.isTSParameterProperty(i)))throw new Error("TypeScript parameter properties are not valid component props");let t=e;if(t.length===0)return{mode:"positional",names:[],acceptsUnknown:!1,bindings:[],params:[],hasWholeDefault:!1,renderProps:[],renderCallbacks:[],refProps:[]};let n=Pt(t[0]);if(t.length===1&&(Y.isObjectPattern(n)||Y.isIdentifier(n)&&n.name==="props"))return{mode:"object",names:Y.isObjectPattern(n)?Cs(n):[],acceptsUnknown:Y.isIdentifier(n)||n.properties.some(s=>Y.isRestElement(s)),bindings:en(n),params:t.map(s=>Y.cloneNode(s)),hasWholeDefault:Y.isAssignmentPattern(t[0]),renderProps:[],renderCallbacks:[],refProps:[]};let r=[];for(let i of t){let s=Pt(i);if(!Y.isIdentifier(s))throw new Error("object-destructured props must be the component's only parameter");r.push(s.name)}return{mode:"positional",names:r,acceptsUnknown:!1,bindings:t.flatMap(i=>en(Pt(i))),params:t.map(i=>Y.cloneNode(i)),hasWholeDefault:!1,renderProps:[],renderCallbacks:[],refProps:[]}}function _o(e,t){return e.params.length===0?null:Y.variableDeclaration("let",e.params.map((n,o)=>Y.variableDeclarator(ws(Pt(n)),Yo(n,t[o]??Y.identifier("undefined")))))}function to(e,t){return e.params.map((n,o)=>Y.expressionStatement(Y.assignmentExpression("=",Qo(Pt(n)),Yo(n,t[o]??Y.identifier("undefined")))))}function Go(e){return Y.expressionStatement(Y.assignmentExpression("=",Qo(e.target),Y.cloneNode(e.source)))}function en(e){return Object.keys(Y.getBindingIdentifiers(e))}function qe(e){if(e.mode!=="object"||e.params.length!==1)return null;let t=Pt(e.params[0]);return Y.isIdentifier(t)?t.name:null}function wn(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=Pt(e.params[0]);if(!Y.isObjectPattern(n))return null;for(let o of n.properties){if(!Y.isObjectProperty(o)||o.computed||(Y.isIdentifier(o.key)?o.key.name:Y.isStringLiteral(o.key)?o.key.value:null)!==t)continue;let i=Y.isAssignmentPattern(o.value)?o.value.left:o.value;return Y.isIdentifier(i)?i.name:null}return null}function Ye(e,t){if(e.mode==="positional")return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=Pt(e.params[0]);if(!Y.isObjectPattern(n))return null;for(let o of n.properties)if(!(!Y.isObjectProperty(o)||o.computed)&&Object.keys(Y.getBindingIdentifiers(o.value)).includes(t)){if(Y.isIdentifier(o.key))return o.key.name;if(Y.isStringLiteral(o.key))return o.key.value}return null}function Pt(e){if(Y.isRestElement(e))throw new Error("rest component parameters are not supported");let t=Y.isAssignmentPattern(e)?e.left:e;if(!Y.isIdentifier(t)&&!Y.isObjectPattern(t)&&!Y.isArrayPattern(t))throw new Error("unsupported component parameter target");return t}function Zo(e){let t=Y.cloneNode(e);return tn(t),t}function Yo(e,t){return Y.isAssignmentPattern(e)?Y.conditionalExpression(Y.binaryExpression("===",Y.cloneNode(t),Y.identifier("undefined")),Y.cloneNode(e.right),Y.cloneNode(t)):Y.cloneNode(t)}function Cs(e){let t=[];for(let n of e.properties)if(!Y.isRestElement(n)){if(n.computed)throw new Error("computed keys are not supported in component prop patterns");if(Y.isIdentifier(n.key))t.push(n.key.name);else if(Y.isStringLiteral(n.key))t.push(n.key.value);else throw new Error("component prop pattern keys must be identifiers or strings")}return t}function ws(e){let t=Y.cloneNode(e);return tn(t),t}function Qo(e){let t=Y.cloneNode(e);return tn(t),t}function tn(e){let t=e;"typeAnnotation"in t&&(t.typeAnnotation=null),"optional"in t&&(t.optional=null);for(let n of Y.VISITOR_KEYS[e.type]??[]){let o=e[n];if(Array.isArray(o))for(let r of o)r&&typeof r=="object"&&"type"in r&&tn(r);else o&&typeof o=="object"&&"type"in o&&tn(o)}}function er(e,t){let n=t.findParent(d=>d.isArrowFunctionExpression()||d.isFunctionExpression());if(n===null||!n.isArrowFunctionExpression()&&!n.isFunctionExpression())return!1;let o=n.get("body");if(!(o.isJSXElement()&&o.node===t.node||o.isBlockStatement()&&o.node.body.length===1&&ve.isReturnStatement(o.node.body[0])&&o.node.body[0].argument===t.node))return!1;let i=n.parentPath,s=i?.parentPath,a=s?.parentPath;if(!i?.isJSXExpressionContainer()||!s?.isJSXAttribute()||!a?.isJSXOpeningElement()||!ve.isJSXIdentifier(a.node.name))return!1;let l=ve.isJSXIdentifier(s.node.name)?s.node.name.name:s.node.name.name.name;return e.componentProps.get(a.node.name.name)?.renderCallbacks.includes(l)===!0||/^[A-Z]/.test(a.node.name.name)}function Ps(e){return(ve.isMemberExpression(e.callee)||ve.isOptionalMemberExpression(e.callee))&&!e.callee.computed&&ve.isIdentifier(e.callee.property,{name:"map"})}function vs(e,t,n){let o=e.componentProps.get(t);if(o===void 0)return null;let r=qe(o);return r!==null&&ve.isMemberExpression(n)&&!n.computed&&ve.isIdentifier(n.object,{name:r})&&ve.isIdentifier(n.property)?n.property.name:ve.isIdentifier(n)?Ye(o,n.name)??(wn(o,n.name)!==null?n.name:null):null}function ks(e){return ve.isExpression(e.body)?e.body:e.body.body.length===1&&ve.isReturnStatement(e.body.body[0])&&ve.isExpression(e.body.body[0].argument)?e.body.body[0].argument:null}function Tt(e,t,n){if(!Ps(n)||n.arguments.length!==1)return null;let o=n.arguments[0];if(!ve.isArrowFunctionExpression(o))return null;let r=ks(o);if(r===null||!ve.isCallExpression(r)||!ve.isExpression(r.callee)||r.arguments.some(s=>!ve.isExpression(s)))return null;let i=vs(e,t,r.callee);return i===null?null:{propName:i,target:ve.cloneNode(r.callee,!0),arguments:r.arguments.map(s=>ve.cloneNode(s,!0))}}function tr(e){for(let[t,n]of e.compPaths){let o=e.componentProps.get(t),r=i=>{let s=Tt(e,t,i.node);s!==null&&!o.renderCallbacks.includes(s.propName)&&o.renderCallbacks.push(s.propName)};n.traverse({CallExpression:r,OptionalCallExpression:r})}}import*as Qe from"@babel/types";function ht(e){return $t(e)}function Pn(e){let t=ht(e);return Qe.isArrayExpression(t)&&t.elements.every(n=>n!==null&&!Qe.isSpreadElement(n)&&(Qe.isStringLiteral(n)||Qe.isNumericLiteral(n)||Qe.isBooleanLiteral(n)||Qe.isNullLiteral(n)||Qe.isBigIntLiteral(n)))}function Ke(e){if(!re.isCallExpression(e)&&!re.isOptionalCallExpression(e))return null;let t=e.callee;return(re.isMemberExpression(t)||re.isOptionalMemberExpression(t))&&!t.computed&&re.isIdentifier(t.property,{name:"map"})?e:null}function $e(e){let t=!1;return e.traverse({JSXElement(){t=!0},JSXFragment(){t=!0}}),t}function At(e,t,n,o,r,i){let s=m=>{throw n.buildCodeFrameError(m)},a=t.callee,l=Ns(e,a.object,o,i,s),d=Ms(e,t,o,s),u=Ds(e,d,s),c=js(l.suffixBase,r);return{sourceKey:l.key,sourceExpr:re.cloneNode(l.expression),optional:re.isOptionalCallExpression(t)||Fs(a.object),sourceLocal:l.local,itemPattern:d.itemPattern,itemParam:d.itemParam,indexParam:d.indexParam,keyExpr:As(d.jsx?.openingElement??null,s),jsx:d.jsx,form:u.form,rowComp:u.rowComp,renderCallback:u.renderCallback,owner:o,suffix:c,prefix:`${o}/${c}`}}function Ns(e,t,n,o,r){let i=re.isExpression(t)?ht(t):t;return re.isIdentifier(i)?Rs(e,i,n,r):re.isMemberExpression(i)||re.isOptionalMemberExpression(i)?Is(e,i,n,o,r):re.isExpression(i)&&Pn(i)?{expression:i,key:"$static-list",local:!0,suffixBase:"$static-list"}:r("memo-dom: assign an ordered collection view to reactive state or a local derivation before mapping it")}function Rs(e,t,n,o){let r=e.componentProps.get(n)?.bindings??[],i=e.opaqueBindings.get(n),s=e.instanceState.get(n)?.has(t.name)===!0||e.instanceDerivedBindings.get(n)?.has(t.name)===!0||r.includes(t.name)||i?.has(t.name)===!0,a=e.state.get(t.name);return!s&&a!=="let"&&a!=="const"&&a!=="computed"?o("memo-dom: list views must come from reactive module state, component props, component state, or a local derivation"):{expression:t,key:t.name,local:s,suffixBase:t.name}}function Is(e,t,n,o,r){let i=Re(t),s=Pe(t),a=e.componentProps.get(n)?.bindings??[],l=e.opaqueBindings.get(n),d=i!==null&&(e.instanceState.get(n)?.has(i)===!0||e.instanceDerivedBindings.get(n)?.has(i)===!0||a.includes(i)||l?.has(i)===!0),u=i!==null&&s!==null&&o!==void 0&&i===o.itemParam;return i===null||s===null||!s.includes(".")||!u&&!d&&e.state.get(i)!=="store"?r("memo-dom: list member views must be a static path on reactive module state, component props, component state, or a local derivation"):{expression:t,key:u?o.sourceKey:s,local:u?o.sourceLocal:d,suffixBase:s.slice(s.lastIndexOf(".")+1)}}function Fs(e){let t=e;for(;!re.isSuper(t);){if(re.isOptionalMemberExpression(t))return!0;if(!re.isMemberExpression(t))return!1;t=t.object}return!1}function Ms(e,t,n,o){if(t.arguments.length!==1||!re.isArrowFunctionExpression(t.arguments[0]))return o("memo-dom: list rendering expects items.map(item => <JSX />) \u2014 R7 L1");let r=t.arguments[0],i=r.params[0],s=r.params[1];if(r.params.length<1||r.params.length>2||!re.isIdentifier(i)&&!re.isObjectPattern(i)&&!re.isArrayPattern(i)||s!==void 0&&!re.isIdentifier(s))return o("memo-dom: list callback must take an item binding pattern and optional index identifier \u2014 R7 L1");let a=xn(i),l=Object.keys(re.getBindingIdentifiers(a));if(l.length===0)return o("memo-dom: list callback item pattern must bind at least one name \u2014 R7 L1");let d=re.isIdentifier(a)?a.name:l[0],u=re.isIdentifier(s)?s.name:null,c=re.isBlockStatement(r.body)&&r.body.body.length===1&&re.isReturnStatement(r.body.body[0])?r.body.body[0].argument:null,m=re.isJSXElement(r.body)?r.body:re.isJSXElement(c)?c:null,E=Tt(e,n,t);return m===null&&E===null?o("memo-dom: list callback body must be one JSX element or a block containing only return <JSX /> \u2014 R7 L1"):{itemPattern:a,itemParam:d,indexParam:u,jsx:m,renderInvocation:E}}function Ds(e,t,n){let o=t.jsx?.openingElement??null;if(o!==null&&!re.isJSXIdentifier(o.name))return n("memo-dom: namespaced JSX tags are not supported (L1)");let r=o!==null&&re.isJSXIdentifier(o.name)?o.name.name:null;return t.renderInvocation!==null?(Ls(t,n),{form:"callback",rowComp:null,renderCallback:re.cloneNode(t.renderInvocation.target,!0)}):r!==null&&/^[A-Z]/.test(r)?!e.comps.has(r)&&!e.importedComponents.has(r)?n(`memo-dom: <${r} /> is not a linked component factory`):{form:"component",rowComp:r,renderCallback:null}:{form:"inline",rowComp:null,renderCallback:null}}function Ls(e,t){let n=e.renderInvocation;(!re.isIdentifier(e.itemPattern)||n.arguments.length<1||n.arguments.length>2||!re.isIdentifier(n.arguments[0],{name:e.itemPattern.name})||n.arguments.length===2&&(e.indexParam===null||!re.isIdentifier(n.arguments[1],{name:e.indexParam})))&&t("memo-dom: render callback maps must pass their item and optional index bindings directly")}function As(e,t){let n=null;for(let o of e?.attributes??[])if(re.isJSXAttribute(o)&&re.isJSXIdentifier(o.name,{name:"key"})&&(n=ze(o.value),n===null))return t("memo-dom: key={...} needs an expression");return n}function js(e,t){let n=t.get(e)??0;return t.set(e,n+1),n===0?e:`${e}${n}`}import*as ae from"@babel/types";function vn(e){return ae.isConditionalExpression(e)||ae.isLogicalExpression(e)&&(e.operator==="&&"||e.operator==="||")?e:null}function Js(e){return ae.isNullLiteral(e)||ae.isBooleanLiteral(e,{value:!1})||ae.isIdentifier(e,{name:"undefined"})}function Os(e,t){let n=[e];for(;n.length>0;){let o=n.pop();if(ae.isJSXElement(o)){for(let r of o.openingElement.attributes)!ae.isJSXSpreadAttribute(r)&&r.name.name==="key"&&t("memo-dom: key={...} is only meaningful on list rows");n.push(...o.children)}else if(ae.isJSXFragment(o))n.push(...o.children);else if(ae.isJSXExpressionContainer(o)&&ae.isExpression(o.expression)){let r=o.expression;if(Ke(r)!==null&&fe(r))continue}}}function kn(e,t,n){let o=l=>{throw t.buildCodeFrameError(l)},r,i;if(ae.isConditionalExpression(e)){let l=[];i=[];let d=e;for(;ae.isConditionalExpression(d);)l.push(ae.cloneNode(d.test)),i.push(d.consequent),d=d.alternate;i.push(d),r=ae.numericLiteral(i.length-1);for(let u=l.length-1;u>=0;u--)r=ae.conditionalExpression(l[u],ae.numericLiteral(u),r)}else e.operator==="&&"?(r=ae.conditionalExpression(ae.cloneNode(e.left),ae.numericLiteral(0),ae.numericLiteral(1)),i=[e.right,null]):(r=ae.conditionalExpression(ae.cloneNode(e.left),ae.numericLiteral(1),ae.numericLiteral(0)),i=[e.right,null]);let s=l=>l===null||Js(l)?null:ae.isJSXElement(l)||ae.isJSXFragment(l)?l:ae.isExpression(l)?ae.jsxFragment(ae.jsxOpeningFragment(),ae.jsxClosingFragment(),[ae.jsxExpressionContainer(ae.cloneNode(l,!0))]):o("memo-dom: conditional branches must be JSX, renderable text expressions, or null/false"),a=i.map(s);for(let l of a)l!==null&&Os(l,o);return{pickExpr:r,branches:a,suffix:`when${n.count++}`}}import*as Je from"@babel/types";import*as ye from"@babel/types";var Bt=class{constructor(t){this.fallback=t}fallback;origins=new WeakMap;trackDeclarator(t,n){if(!ye.isIdentifier(n.id)||n.init===null)return;let o=this.resolveExpression(t,n.init);if(o===null)return;let r=t.getBinding(n.id.name);r!==void 0&&this.origins.set(r.identifier,o)}referencedOrigins(t,n){let o=new Map,r=i=>{if(ye.isIdentifier(i)||ye.isMemberExpression(i)){let s=this.resolveExpression(t,i);if(s!==null){let a=[s.locality,s.root,s.key??"*"].join(":");o.set(a,s);return}}for(let s of ye.VISITOR_KEYS[i.type]??[]){let a=i[s];if(Array.isArray(a))for(let l of a)l&&typeof l=="object"&&"type"in l&&r(l);else a&&typeof a=="object"&&"type"in a&&r(a)}};return r(n),[...o.values()]}resolveName(t,n){let o=t.getBinding(n);if(o!==void 0){let r=this.origins.get(o.identifier);if(r!==void 0)return r}return this.fallback(n,o)}resolveExpression(t,n){let o=nr(n);if(ye.isIdentifier(o))return this.resolveName(t,o.name);if(!ye.isMemberExpression(o))return null;let r=$s(o);if(r===null)return null;let i=this.resolveName(t,r);if(i===null)return null;let s=Pe(o);if(i.key===null||s===null)return{...i,key:null};let a=s.split(".").slice(1);return{...i,key:[i.key,...a].join(".")}}};function Nn(e,t){return{locality:"module",root:e,key:e,stateKind:t}}function vt(e,t){return e.key===null?e:{...e,key:[e.key,...t].join(".")}}function Rn(e,t){if(e.key===null)return null;let n=[];for(let o of t){if(!ye.isObjectExpression(o))return null;for(let r of o.properties){if(!ye.isObjectProperty(r)||r.computed||!ye.isIdentifier(r.key)&&!ye.isStringLiteral(r.key))return null;let i=ye.isIdentifier(r.key)?r.key.name:r.key.value;n.push(`${e.key}.${i}`)}}return n}function In(e){let t=[];for(let n of e)ye.isExpression(n)?t.push(n):ye.isSpreadElement(n)&&t.push(n.argument);return t}function Fn(e){return!e.computed&&ye.isIdentifier(e.property)?e.property.name:e.computed&&ye.isStringLiteral(e.property)?e.property.value:null}function $s(e){let t=e;for(;ye.isMemberExpression(t);){if(ye.isSuper(t.object))return null;t=nr(t.object)}return ye.isIdentifier(t)?t.name:null}function nr(e){let t=e;for(;ye.isTSAsExpression(t)||ye.isTSTypeAssertion(t)||ye.isTSNonNullExpression(t)||ye.isTypeCastExpression(t)||ye.isTSSatisfiesExpression(t);)t=t.expression;return t}function Be(e,t,n=new Set){let o=e.helperSummaries.get(t);if(o)return o;if(n.has(t))return{reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!0};let r=e.helpers.get(t),i=new Set,s=new Map(r.node.params.flatMap((f,g)=>Je.isIdentifier(f)?[[f.name,g]]:[])),a={reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!1},l=new Bt((f,g)=>{if(s.has(f)&&g?.scope.block===r.node)return{locality:"prop",root:f,key:f};let h=e.state.get(f);return h===void 0||g!==void 0&&!g.scope.path.isProgram()?null:Nn(f,h)}),d=f=>f.stateKind==="computed"||e.state.get(f.root)==="computed";n.add(t),r.traverse({VariableDeclarator(f){Je.isIdentifier(f.node.id)&&(i.add(f.node.id.name),f.parentPath.isVariableDeclaration()&&l.trackDeclarator(f.scope,f.node))},Function(f){for(let g of f.node.params)Je.isIdentifier(g)&&i.add(g.name)}});let u=(f,g)=>{a.parameterWrites.some(h=>h.index===f&&h.path.length===g.length&&h.path.every((C,N)=>C===g[N]))||a.parameterWrites.push({index:f,path:g})},c=f=>{if(!d(f)){if(f.locality==="module"){a.boundedWrites.add(f.key??f.root);return}if(f.locality==="prop"){let g=s.get(f.root);if(g!==void 0){let h=f.key===null?[]:f.key.split(".").slice(1);u(g,h);return}}a.unbounded=!0}},m=f=>{f.locality==="prop"?c(f):f.locality!=="module"?a.unbounded=!0:f.stateKind!=="store"?a.writes.add(f.root):f.key!==null&&f.key.includes(".")?a.writes.add(f.key):a.boundedWrites.add(f.root)},E=(f,g)=>{let h=l.resolveExpression(f.scope,g);h!==null&&m(h)},b=(f,g)=>{for(let h of In(g)){if(!Je.isIdentifier(h))continue;let C=l.resolveExpression(f.scope,h);C!==null&&!d(C)&&c(C)}};return r.traverse({VariableDeclarator(f){if(!Je.isIdentifier(f.node.id)&&f.node.init!==null)for(let g of l.referencedOrigins(f.scope,f.node.init))c(g)},AssignmentExpression(f){let g=f.node.left;if(Je.isIdentifier(g))if(i.has(g.name)){if(Je.isIdentifier(f.node.right)){let h=l.resolveExpression(f.scope,f.node.right);h!==null&&c(h)}}else e.state.has(g.name)&&a.writes.add(g.name);else if(Je.isMemberExpression(g))E(f,g);else for(let h of l.referencedOrigins(f.scope,f.node.right))c(h)},UpdateExpression(f){let g=f.node.argument;Je.isIdentifier(g)?!i.has(g.name)&&e.state.has(g.name)&&a.writes.add(g.name):Je.isMemberExpression(g)&&E(f,g)},UnaryExpression(f){f.node.operator==="delete"&&Je.isMemberExpression(f.node.argument)&&E(f,f.node.argument)},CallExpression(f){let g=f.node.callee;if(Je.isMemberExpression(g)){if(Fn(g)==="assign"&&Je.isIdentifier(g.object,{name:"Object"})){let N=f.node.arguments[0],v=N!==void 0&&Je.isExpression(N)?l.resolveExpression(f.scope,N):null;if(v!==null){let $=Rn(v,f.node.arguments.slice(1));if($===null)c(v);else for(let _ of $)m({...v,key:_})}return}let C=Je.isExpression(g.object)?l.resolveExpression(f.scope,g.object):null;C!==null?c(C):b(f,f.node.arguments);return}if(Je.isIdentifier(g)&&(e.helpers.has(g.name)||e.importedFunctions.has(g.name))){let h=e.importedFunctions.get(g.name)??Be(e,g.name,n);for(let C of h.reads)a.reads.add(C);for(let C of h.writes)a.writes.add(C);for(let C of h.boundedWrites)a.boundedWrites.add(C);for(let C of h.parameterWrites){let N=f.node.arguments[C.index];if(N===void 0||!Je.isExpression(N))continue;let v=l.resolveExpression(f.scope,N);v!==null&&c(vt(v,C.path))}h.unbounded&&(a.unbounded=!0);return}b(f,f.node.arguments)},Identifier(f){let g=f.node.name;if(!e.state.has(g)||i.has(g))return;let h=f.parentPath;h.isAssignmentExpression({operator:"="})&&h.node.left===f.node||a.reads.add(g)},MemberExpression(f){let g=Xs(e,f);g!==null&&a.reads.add(g)}}),n.delete(t),e.helperSummaries.set(t,a),a}function Xs(e,t){let n=Pe(t.node);if(!n||!n.includes("."))return null;let o=n.split(".")[0];if(e.state.get(o)!=="store"||t.scope.getBinding(o)?.scope.path.isProgram()!==!0)return null;let r=t.parentPath;return r.isAssignmentExpression({operator:"="})&&r.node.left===t.node||Ts(t)?null:n}function Ts(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}import*as x from"@babel/types";import*as le from"@babel/types";function st(e,t=!1){return{slots:[],tempVar:J(e,"value").name,updateVar:J(e,"update").name,reasonVar:null,delegatedEventBindings:new Map,creation:[],mounts:[],updaters:[],tagCounters:new Map,childCounts:new Map,usedPrefixes:new Map,usedConds:{count:0},textCounter:0,regionCounter:0,disposableRegions:[],disposableEntities:[],disposableCallbacks:[],forwardedSlotCounter:0,manualDisposal:t}}function at(e){return le.variableDeclaration("let",[...e.slots.map(t=>le.variableDeclarator(le.identifier(t))),le.variableDeclarator(le.identifier(e.tempVar))])}function no(e,t){let n=J(e,`slot${t.slots.length}`).name;return t.slots.push(n),n}function oo(e,t,n){let o=t.tagCounters.get(n)??0;return t.tagCounters.set(n,o+1),J(e,`${n}${o}`).name}function jt(e,t,n,o){let r=()=>le.identifier(e.tempVar),i=()=>le.identifier(t);return le.ifStatement(le.binaryExpression("!==",i(),le.assignmentExpression("=",r(),n)),le.blockStatement([le.expressionStatement(le.assignmentExpression("=",i(),r())),o(r())]))}function lt(e){return le.variableDeclaration("const",[le.variableDeclarator(le.identifier(e.updateVar),le.arrowFunctionExpression(e.reasonVar===null?[]:[le.assignmentPattern(le.identifier(e.reasonVar),le.nullLiteral())],le.blockStatement(e.updaters.map(t=>t()))))])}function ft(e,t,n,o,r=!1){return le.expressionStatement(le.callExpression(ne(e,"register"),[le.objectExpression([le.objectProperty(le.identifier("id"),t),le.objectProperty(le.identifier("parent"),n),le.objectProperty(le.identifier("render"),o),...r?[le.objectProperty(le.identifier("volatile"),le.booleanLiteral(!0))]:[]])]))}function ro(e){let t=e.replace(/\s+/g," ");return/^\s*\n/.test(e)&&(t=t.replace(/^ /,"")),/\n\s*$/.test(e)&&(t=t.replace(/ $/,"")),t}function nn(e){return e.some(t=>!x.isJSXText(t)||t.value.trim()!=="")}function yt(e,t,n){let o=e.componentProps.get(t);if(o===void 0)return null;let r=qe(o);if(r!==null&&x.isMemberExpression(n)&&!n.computed&&x.isIdentifier(n.object,{name:r})&&x.isIdentifier(n.property))return n.property.name;if(x.isIdentifier(n)){let i=Ye(o,n.name);if(i!==null)return i;if(n.name==="children"&&e.instanceDerivedBindings.get(t)?.has("children")===!0)return"children"}return null}function dt(e,t,n){let o=yt(e,t,n);return o!==null&&e.componentProps.get(t)?.renderProps.includes(o)===!0}function or(e,t,n,o){let r=st(e,!0);r.childCounts=t.childCounts,r.usedPrefixes=t.usedPrefixes,r.usedConds=t.usedConds;let i=J(e,"childrenUpdate"),s=J(e,"childrenUpdates"),a=J(e,"childrenMountSequence"),l=J(e,"children"),d=J(e,"childrenParent"),u=J(e,"childrenOwner"),c=J(e,"childrenKey"),m=J(e,"childrenSlot"),E=J(e,"childrenNextUpdate"),b=J(e,"childrenActive"),f=J(e,"childrenDispose");return o(r,d,m),t.creation.push(x.variableDeclaration("let",[x.variableDeclarator(x.cloneNode(i),x.nullLiteral()),x.variableDeclarator(x.cloneNode(s),x.nullLiteral()),x.variableDeclarator(x.cloneNode(a),x.numericLiteral(0))]),x.variableDeclaration("const",[x.variableDeclarator(x.cloneNode(l),x.arrowFunctionExpression([x.cloneNode(d),x.cloneNode(u),x.cloneNode(c)],x.blockStatement([x.variableDeclaration("const",[x.variableDeclarator(x.cloneNode(m),x.conditionalExpression(x.binaryExpression("===",x.cloneNode(a),x.numericLiteral(0)),x.cloneNode(n,!0),x.binaryExpression("+",x.binaryExpression("+",x.cloneNode(n,!0),x.stringLiteral("/$slot[")),x.binaryExpression("+",x.cloneNode(a),x.stringLiteral("]")))))]),x.expressionStatement(x.updateExpression("++",x.cloneNode(a))),x.variableDeclaration("let",[x.variableDeclarator(x.cloneNode(b),x.booleanLiteral(!0))]),at(r),lt(r),...r.creation,...r.mounts,x.ifStatement(x.binaryExpression("===",x.cloneNode(i),x.nullLiteral()),x.expressionStatement(x.assignmentExpression("=",x.cloneNode(i),x.identifier(r.updateVar))),x.blockStatement([x.ifStatement(x.binaryExpression("===",x.cloneNode(s),x.nullLiteral()),x.expressionStatement(x.assignmentExpression("=",x.cloneNode(s),x.newExpression(x.identifier("Set"),[])))),x.expressionStatement(x.callExpression(x.memberExpression(x.cloneNode(s),x.identifier("add")),[x.identifier(r.updateVar)]))])),x.variableDeclaration("const",[x.variableDeclarator(x.cloneNode(f),x.arrowFunctionExpression([],x.blockStatement([x.ifStatement(x.unaryExpression("!",x.cloneNode(b)),x.returnStatement()),x.expressionStatement(x.assignmentExpression("=",x.cloneNode(b),x.booleanLiteral(!1))),x.ifStatement(x.binaryExpression("===",x.cloneNode(i),x.identifier(r.updateVar)),x.expressionStatement(x.assignmentExpression("=",x.cloneNode(i),x.nullLiteral())),x.ifStatement(x.binaryExpression("!==",x.cloneNode(s),x.nullLiteral()),x.expressionStatement(x.callExpression(x.memberExpression(x.cloneNode(s),x.identifier("delete")),[x.identifier(r.updateVar)])))),...r.disposableRegions.map(g=>x.expressionStatement(x.callExpression(x.memberExpression(x.identifier(g),x.identifier("dispose")),[]))),...[...r.disposableCallbacks].reverse().map(g=>x.ifStatement(x.binaryExpression("!==",x.cloneNode(g),x.nullLiteral()),x.expressionStatement(x.callExpression(x.cloneNode(g),[])))),...r.disposableEntities.map(g=>x.expressionStatement(x.callExpression(ne(e,"unregisterSubtree"),[x.cloneNode(g,!0)])))])))]),x.expressionStatement(x.callExpression(ne(e,"cleanup"),[x.cloneNode(u),x.cloneNode(f)])),x.returnStatement(x.cloneNode(f))])))])),t.updaters.push(()=>x.blockStatement([x.ifStatement(x.binaryExpression("!==",x.cloneNode(i),x.nullLiteral()),x.expressionStatement(x.callExpression(x.cloneNode(i),[]))),x.ifStatement(x.binaryExpression("!==",x.cloneNode(s),x.nullLiteral()),x.forOfStatement(x.variableDeclaration("const",[x.variableDeclarator(x.cloneNode(E))]),x.cloneNode(s),x.expressionStatement(x.callExpression(x.cloneNode(E),[]))))])),l}function io(e,t,n,o,r){let i=J(e,"slotDispose"),s=t.forwardedSlotCounter++;t.creation.push(x.variableDeclaration("const",[x.variableDeclarator(x.cloneNode(i),x.conditionalExpression(x.binaryExpression("==",x.cloneNode(n,!0),x.nullLiteral()),x.nullLiteral(),x.callExpression(x.cloneNode(n,!0),[x.identifier(o),x.cloneNode(r,!0),x.stringLiteral(String(s))])))])),t.disposableCallbacks.push(i)}function rr(e,t,n,o){let r=i=>{e.creation.push(x.expressionStatement(x.callExpression(x.memberExpression(x.identifier(n),x.identifier("appendChild")),[x.identifier(i)])))};for(let i of t){if(x.isJSXText(i)){let d=ro(i.value);d!==""&&r(o.emitText(x.stringLiteral(d)));continue}if(x.isJSXElement(i)||x.isJSXFragment(i)){r(o.emitNode(i));continue}if(x.isJSXExpressionContainer(i)||o.fail("memo-dom: spread children are not supported (L1)"),x.isJSXEmptyExpression(i.expression))continue;x.isExpression(i.expression)||o.fail("memo-dom: unsupported expression in component children");let s=i.expression;if(x.isNullLiteral(s)||x.isBooleanLiteral(s)||x.isIdentifier(s,{name:"undefined"}))continue;if(o.isForwarded(s)){o.emitForwarded(s,n);continue}let a=Ke(s);if(a!==null){o.emitList(a,n);continue}let l=vn(s);if(l!==null&&fe(l)){o.emitCondition(l,n);continue}r(o.emitText(x.cloneNode(s)))}}import*as D from"@babel/types";function Ln(e){return D.isIdentifier(e.node.callee,{name:"effect"})&&e.scope.getBinding("effect")===void 0}function Dn(e,t){return D.binaryExpression("+",D.identifier(e),D.stringLiteral(`/$effects/${t}`))}function Bs(e,t){return D.binaryExpression("+",Dn(e,t),D.stringLiteral("/$active"))}function Vs(e){if(e.isFunctionDeclaration())return e;if(!e.isVariableDeclarator())return null;let t=e.get("init");return t.isArrowFunctionExpression()||t.isFunctionExpression()?t:null}function dr(e,t){let n=t.get("arguments"),o=n[0];if(n.length!==1||o===void 0)throw t.buildCodeFrameError("memo-dom: effect() requires exactly one callback");if(o.isArrowFunctionExpression()||o.isFunctionExpression()){if(o.node.async||o.node.generator)throw o.buildCodeFrameError("memo-dom: effect callback must be synchronous; start async work inside it and return a synchronous teardown");return{expression:o.node,path:o,importedReads:new Set}}if(!o.isIdentifier())throw o.buildCodeFrameError("memo-dom: effect callback must be an inline function or a resolvable function identifier");if(e.importedFunctions.get(o.node.name)!==void 0)throw o.buildCodeFrameError(`memo-dom: imported named effect callback '${o.node.name}' is not supported yet; define a local synchronous wrapper so its cleanup and writes can be instrumented`);let i=o.scope.getBinding(o.node.name),s=i===void 0?null:Vs(i.path);if(s===null)throw o.buildCodeFrameError(`memo-dom: cannot resolve effect callback '${o.node.name}' \u2014 use an inline function or a local/module-level function declaration or const`);if(s.node.async||s.node.generator)throw s.buildCodeFrameError("memo-dom: effect callback must be synchronous; start async work inside it and return a synchronous teardown");if(fe(s.node.body))throw s.buildCodeFrameError("memo-dom: a JSX component cannot be used as an effect callback");return{expression:D.cloneNode(o.node),path:s,importedReads:new Set}}function ir(e,t,n,o){let r=new Set,i=new Set,s=new Map,a=new Set([...e.componentProps.get(t)?.bindings??[],...e.instanceState.get(t)??[]]),l=new Map;for(let g of e.instanceDerivations.get(t)??[])for(let h of g.bindings)l.set(h,g.sources);for(let g of e.instanceControlFlow.get(t)??[])for(let h of g.bindings)l.set(h,g.sources);for(let g of a){let h=n.scope.getBinding(g);h!==void 0&&s.set(h,{source:g,local:!0})}for(let g of l.keys()){let h=n.scope.getBinding(g);h!==void 0&&s.set(h,{source:g,local:!0})}for(let g of e.state.keys()){let h=n.scope.getBinding(g);h?.scope.path.isProgram()===!0&&s.set(h,{source:g,local:!1})}let d=g=>{let h=g.scope.getBinding(g.node.name),C=h===void 0?void 0:s.get(h);if(C===void 0)return;let N=g.parentPath;!C.local&&e.state.get(C.source)==="store"&&N?.isMemberExpression()&&N.node.object===g.node||(C.local?i.add(C.source):r.add(C.source))},u=g=>{let h=Pe(g.node),C=Re(g.node);h===null||C===null||e.state.get(C)!=="store"||g.scope.getBinding(C)?.scope.path.isProgram()!==!0||r.add(h)},c=g=>{let h=g.node.callee;if(!D.isIdentifier(h)||g.scope.getBinding(h.name)?.scope.path.isProgram()!==!0||!e.helpers.has(h.name)&&!e.importedFunctions.has(h.name))return;let C=e.importedFunctions.get(h.name)??Be(e,h.name);for(let N of C.reads)r.add(N)};o.isIdentifier()&&o.isReferencedIdentifier()&&d(o),o.isMemberExpression()&&u(o),o.isCallExpression()&&c(o),o.traverse({Function(g){g.skip()},ReferencedIdentifier(g){g.isIdentifier()&&d(g)},MemberExpression(g){u(g)},CallExpression(g){c(g)}});let m=new Set,E=new Set,b=new Set;for(let g of i)a.has(g)&&b.add(g);let f=(g,h)=>{if(h.has(g))return;let C=l.get(g);if(C===void 0){a.has(g)?m.add(g):e.state.has(g)&&r.add(g);return}h.add(g),C.some(v=>b.has(v))||E.add(g);for(let v of C)f(v,h);h.delete(g)};for(let g of i)f(g,new Set);return{moduleReads:r,localReads:m,localDerivationReads:E}}function sr(e,t){let n=new Set,o=s=>{let a=s.node.name;if(!e.state.has(a)||s.scope.getBinding(a)?.scope.path.isProgram()!==!0)return;let l=s.parentPath;e.state.get(a)==="store"&&l?.isMemberExpression()&&l.node.object===s.node||n.add(a)},r=s=>{let a=Pe(s.node),l=Re(s.node);a!==null&&l!==null&&e.state.get(l)==="store"&&s.scope.getBinding(l)?.scope.path.isProgram()===!0&&n.add(a)},i=s=>{let a=s.node.callee;if(!D.isIdentifier(a)||s.scope.getBinding(a.name)?.scope.path.isProgram()!==!0||!e.helpers.has(a.name)&&!e.importedFunctions.has(a.name))return;let l=e.importedFunctions.get(a.name)??Be(e,a.name);for(let d of l.reads)n.add(d)};return t.isIdentifier()&&t.isReferencedIdentifier()&&o(t),t.isMemberExpression()&&r(t),t.isCallExpression()&&i(t),t.traverse({Function(s){s.skip()},ReferencedIdentifier(s){s.isIdentifier()&&o(s)},MemberExpression(s){r(s)},CallExpression(s){i(s)}}),n}function so(e){if(!e.isExpressionStatement())return null;let t=e.get("expression");return t.isCallExpression()&&Ln(t)?t:null}function cr(e){if(so(e)!==null)return!0;let t=!1;return e.traverse({Function(n){n.skip()},CallExpression(n){Ln(n)&&(t=!0,n.stop())}}),t}function Mn(e,t,n,o){let r=so(e);if(r!==null){o.push({callPath:r,rootStatement:t,conditions:[...n]});return}if(!e.isEmptyStatement()){if(e.isBlockStatement()){for(let i of e.get("body"))if(!i.isEmptyStatement()){if(!cr(i))throw i.buildCodeFrameError("memo-dom: a conditional effect branch may contain only effect() calls, nested if statements, or empty statements");Mn(i,t,n,o)}return}if(e.isIfStatement()){let i=e.get("test");Mn(e.get("consequent"),t,[...n,{path:i,negated:!1}],o);let s=e.get("alternate");s.node!==null&&Mn(s,t,[...n,{path:i,negated:!0}],o);return}throw e.buildCodeFrameError("memo-dom: conditional effect() calls must be controlled by top-level if statements")}}function ur(e){let t=[];for(let n of e){let o=so(n);if(o!==null){t.push({callPath:o,rootStatement:n.node,conditions:[]});continue}!n.isIfStatement()||!cr(n)||Mn(n,n.node,[],t)}return t}function pr(e){return e.length===0?null:e.map(({path:n,negated:o})=>o?D.unaryExpression("!",D.cloneNode(n.node,!0)):D.cloneNode(n.node,!0)).reduce((n,o)=>D.logicalExpression("&&",n,o))}function Ws(e,t){let n=[],o=ur(t.get("body"));for(let r of o){let i=dr(e,r.callPath),s=i.path===null?i.importedReads:sr(e,i.path),a=new Set;for(let d of r.conditions)for(let u of sr(e,d.path))a.add(u);let l=n.length;n.push({index:l,statement:r.rootStatement,callback:i.expression,moduleReads:s,condition:pr(r.conditions),conditionModuleReads:a,entityId:`${e.rootId}/$module-effects/${encodeURIComponent(e.moduleId)}/${l}`})}e.moduleEffects.push(...n)}function fr(e,t){Ws(e,t);for(let[n,o]of e.compPaths){let r=[],i=new Set,s=ur(o.get("body").get("body"));for(let l of s){let d=dr(e,l.callPath),u=d.path===null?{moduleReads:d.importedReads,localReads:new Set,localDerivationReads:new Set}:ir(e,n,o,d.path),c=new Set,m=new Set,E=new Set;for(let b of l.conditions){let f=ir(e,n,o,b.path);for(let g of f.moduleReads)c.add(g);for(let g of f.localReads)m.add(g);for(let g of f.localDerivationReads)E.add(g)}r.push({index:r.length,statement:l.rootStatement,callback:d.expression,...u,condition:pr(l.conditions),conditionModuleReads:c,conditionLocalReads:m,conditionLocalDerivationReads:E}),i.add(l.callPath.node)}if(o.traverse({CallExpression(l){if(!(!Ln(l)||i.has(l.node)))throw l.buildCodeFrameError("memo-dom: effect() must be a direct top-level statement in a component body")}}),r.length===0)continue;e.effects.set(n,r);let a=new Set([...e.instanceReasonIds.get(n)?.keys()??[],...e.instanceState.get(n)??[],...e.componentProps.get(n)?.bindings??[],...r.flatMap(l=>[...l.localReads]),...r.flatMap(l=>[...l.conditionLocalReads])]);a.size>0&&e.instanceReasonIds.set(n,new Map([...a].sort().map((l,d)=>[l,d])))}}function ar(e){return e.reduce((t,n)=>D.logicalExpression("||",t,n))}function zs(e,t,n,o){let r=e.instanceReasonIds.get(t);if(r===void 0)return null;let i=[...o].map(d=>r.get(d)).filter(d=>d!==void 0).sort((d,u)=>d-u);if(i.length===0||i.length!==o.size)return null;let s=()=>D.identifier(n),a=ar(i.map(d=>D.binaryExpression("===",s(),D.numericLiteral(d)))),l=ar(i.map(d=>D.callExpression(D.memberExpression(s(),D.identifier("has")),[D.numericLiteral(d)])));return D.logicalExpression("||",D.binaryExpression("===",s(),D.nullLiteral()),D.conditionalExpression(D.binaryExpression("===",D.unaryExpression("typeof",s()),D.stringLiteral("number")),a,l))}function Ks(e){let t=()=>D.identifier(e);return D.logicalExpression("||",D.binaryExpression("===",t(),D.unaryExpression("-",D.numericLiteral(1))),D.logicalExpression("&&",D.logicalExpression("&&",D.binaryExpression("!==",t(),D.nullLiteral()),D.binaryExpression("!==",D.unaryExpression("typeof",t()),D.stringLiteral("number"))),D.logicalExpression("&&",D.binaryExpression("===",D.memberExpression(t(),D.identifier("size")),D.numericLiteral(1)),D.callExpression(D.memberExpression(t(),D.identifier("has")),[D.unaryExpression("-",D.numericLiteral(1))]))))}function mr(e,t,n,o,r,i){let s=(l,d,u,c,m)=>{if(u.size===0&&c.size===0)return null;let E=D.expressionStatement(D.callExpression(ne(e,"markDirty"),[d]));if(c.size>0&&i!==void 0){let g=[],h=[];for(let N of c){let v=J(e,`eff${l.index}_${m}_${N}`).name;i.creation.push(D.variableDeclaration("let",[D.variableDeclarator(D.identifier(v),D.identifier(N))])),g.push(D.binaryExpression("!==",D.identifier(v),D.identifier(N))),h.push(D.expressionStatement(D.assignmentExpression("=",D.identifier(v),D.identifier(N))))}let C=g.length===1?g[0]:g.reduce((N,v)=>D.logicalExpression("||",N,v));E=D.ifStatement(C,D.blockStatement([...h,E]))}if(o===null)return E;let b=zs(e,t,o,u),f=b===null?E:D.ifStatement(b,E);return D.ifStatement(D.unaryExpression("!",Ks(o)),f)},a=r.flatMap(l=>{let d=l.condition===null?null:s(l,Dn(n,l.index),l.conditionLocalReads,l.conditionLocalDerivationReads,"condition"),u=s(l,l.condition===null?Dn(n,l.index):Bs(n,l.index),l.localReads,l.localDerivationReads,"callback");return[d,u].filter(c=>c!==null)});return D.blockStatement(a)}function gr(e,t,n){return n.map(o=>D.expressionStatement(D.callExpression(ne(e,o.condition===null?"registerEffect":"registerConditionalEffect"),[Dn(t,o.index),D.identifier(t),...o.condition===null?[]:[D.arrowFunctionExpression([],D.cloneNode(o.condition,!0))],D.cloneNode(o.callback,!0)])))}function lr(){return D.memberExpression(D.metaProperty(D.identifier("import"),D.identifier("meta")),D.identifier("hot"))}function br(e,t){if(e.moduleEffects.length===0)return;let n=new Map(t.get("body").map(r=>[r.node,r])),o=new Map;for(let r of e.moduleEffects){let i=o.get(r.statement)??[];i.push(r),o.set(r.statement,i)}for(let[r,i]of o){let s=n.get(r);if(s===void 0)continue;let a=[];for(let l of i)a.push(D.expressionStatement(D.callExpression(ne(e,l.condition===null?"registerEffect":"registerConditionalEffect"),[D.stringLiteral(l.entityId),D.nullLiteral(),...l.condition===null?[]:[D.arrowFunctionExpression([],D.cloneNode(l.condition,!0))],D.cloneNode(l.callback,!0)])),D.ifStatement(lr(),D.expressionStatement(D.callExpression(D.memberExpression(lr(),D.identifier("dispose")),[D.arrowFunctionExpression([],D.callExpression(ne(e,"unregisterSubtree"),[D.stringLiteral(l.entityId)]))]))));s.replaceWithMultiple(a)}}function Er(e){e.traverse({CallExpression(t){if(Ln(t))throw t.buildCodeFrameError("memo-dom: effect() must be a direct top-level statement or be controlled by a top-level effect-only if branch in a component or module")}})}import*as nt from"@babel/types";function hr(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function yr(e){let t=new Set,n=[];for(let o of e){let r=An(o);if(r===null)return null;for(let i of r.bindings){if(t.has(i))return null;t.add(i)}n.push(...r.expressions)}return t.size===0?null:{bindings:t,expressions:n}}function An(e){if(nt.isExpressionStatement(e)&&nt.isAssignmentExpression(e.expression,{operator:"="})&&nt.isIdentifier(e.expression.left))return{bindings:new Set([e.expression.left.name]),expressions:[e.expression.right]};if(nt.isBlockStatement(e))return yr(e.body);if(nt.isIfStatement(e)){let t=e.alternate;if(t==null)return null;let n=An(e.consequent),o=An(t);return n===null||o===null||!hr(n.bindings,o.bindings)?null:{bindings:n.bindings,expressions:[e.test,...n.expressions,...o.expressions]}}return null}function Hs(e){if(!e.cases.some(r=>r.test==null))return null;let t=null,n=!1,o=[e.discriminant];for(let r of e.cases){r.test!=null&&o.push(r.test);let i=[...r.consequent];if(i.length===0){n=!0;continue}if(i.at(-1)&&nt.isBreakStatement(i.at(-1))&&i.pop(),i.some(a=>nt.isBreakStatement(a)))return null;let s=yr(i);if(s===null)return null;if(n=!1,t===null)t=s.bindings;else if(!hr(t,s.bindings))return null;o.push(...s.expressions)}return t===null||n?null:{bindings:t,expressions:o}}function Us(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function qs(e,t){let n=e;for(;n?.parentPath!==t;)n=n?.parentPath??null;return n}function xr(e,t,n){let o=t.get("body"),r=new Map(o.map((i,s)=>[i.node,s]));for(let i of o){if(!i.isIfStatement()&&!i.isSwitchStatement())continue;let s=i.node,a=i.isIfStatement()?An(s):Hs(s);if(a===null)continue;let l=!0,d=[];for(let b of a.bindings){let f=t.scope.getBinding(b),g=f?.path,h=g?.parentPath,C=g===void 0?null:qs(g,t);if(f===void 0||!g?.isVariableDeclarator()||!h?.isVariableDeclaration()||h.node.kind!=="let"&&h.node.kind!=="var"||C===null||(r.get(C.node)??Number.MAX_SAFE_INTEGER)>=(r.get(s)??-1)){l=!1;break}d.push(...f.constantViolations.filter(N=>!Us(N,s)))}if(!l)continue;let u=new Set,c=null;for(let b of a.expressions){let f=n(e,b);for(let g of f.reads)u.add(g);f.impure&&c===null&&(c=f.reason??"cannot be analyzed")}if(u.size===0)continue;if(c!==null)throw i.buildCodeFrameError(`memo-dom: module control-flow derivation ${c}`);for(let b of a.bindings)if(u.has(b))throw i.buildCodeFrameError(`memo-dom: module control-flow derivation '${b}' reads its own previous value`);if(d.length>0)throw d[0].buildCodeFrameError(`memo-dom: cannot assign module control-flow computed '${[...a.bindings].sort().join(", ")}' outside its derivation`);let m=e.moduleControlFlow.length,E=[...a.bindings].sort();for(let b of E)wt(e,b,"computed");e.moduleControlFlow.push({statement:s,bindings:E,sources:[...u].sort(),entityId:`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#$flow${m}`})}}import*as ge from"@babel/types";function ao(e,t){let n=new Set,o=!1,r,i=new Set,s=l=>{o||(o=!0,r=l)},a=l=>{ge.isIdentifier(l)?i.add(l.name):Oe(l,d=>{ge.isIdentifier(d)&&i.add(d.name)})};return Oe(t,(l,d)=>{if(ge.isFunction(l)){if(!(d!==null&&(ge.isCallExpression(d)||ge.isNewExpression(d))))return!1;for(let c of l.params)ge.isLVal(c)&&a(c);return}if(ge.isVariableDeclarator(l)&&ge.isLVal(l.id)){a(l.id);return}if(ge.isAssignmentExpression(l)){let u=ge.isIdentifier(l.left)?l.left.name:ge.isMemberExpression(l.left)?Re(l.left):null;(u===null||!i.has(u))&&s("contains an assignment \u2014 writes belong in handlers, not derivations");return}if(ge.isUpdateExpression(l)){let u=l.argument,c=ge.isIdentifier(u)?u.name:ge.isMemberExpression(u)?Re(u):null;(c===null||!i.has(c))&&s("contains an update (++/--) \u2014 writes belong in handlers, not derivations");return}if(ge.isAwaitExpression(l)||ge.isYieldExpression(l)){s("uses await/yield \u2014 derivations must be synchronous");return}if(ge.isCallExpression(l)){let u=l.callee;if(ge.isIdentifier(u)&&(e.helpers.has(u.name)||e.importedFunctions.has(u.name))){let c=e.importedFunctions.get(u.name)??Be(e,u.name);for(let m of c.reads)n.add(m);if(c.writes.size>0){for(let m of c.writes)n.add(m);s(`calls helper '${u.name}' which writes state \u2014 writes belong in handlers`)}else c.unbounded&&e.helpers.has(u.name)&&s(`calls recursive helper '${u.name}' which cannot be analyzed`)}return}if(ge.isIdentifier(l)){!i.has(l.name)&&e.state.has(l.name)&&n.add(l.name);return}if(ge.isMemberExpression(l)&&!l.computed){let u=Pe(l);if(u!==null&&u.includes(".")){let c=u.split(".")[0];!i.has(c)&&e.state.get(c)==="store"&&n.add(u)}}}),{reads:n,impure:o,reason:r}}function Sr(e,t){for(let n of t.node.body){let o=ge.isExportNamedDeclaration(n)?n.declaration:n;if(!(!ge.isVariableDeclaration(o)||o.kind!=="const"))for(let r of o.declarations){if(!ge.isIdentifier(r.id)||r.init==null)continue;let i=r.id.name;if(e.state.get(i)==="let"||e.state.get(i)==="computed"||ge.isFunction(r.init)||ge.isJSX(r.init))continue;let s=ao(e,r.init);if(s.impure){if(s.reads.size>0)throw new Error(`memo-dom: const '${i}' is a state derivation but ${s.reason??"cannot be analyzed"}. Fix the derivation, or make it a 'let' you update in handlers.`);continue}s.reads.size!==0&&(wt(e,i,"computed"),e.computeds.set(i,{reads:s.reads}))}}}import*as Fe from"@babel/types";function _s(e,t,n){let o=t.scope.getBinding(n);if(o===void 0)return null;let r=null;if(o.path.isFunctionDeclaration())r=o.path;else if(o.path.isVariableDeclarator()){let i=o.path.get("init");!Array.isArray(i)&&(i.isFunctionExpression()||i.isArrowFunctionExpression())&&(r=i)}return r===null||r.findParent(i=>i.node===e.node)===null?null:r}function Cr(e,t,n,o,r,i,s){let a=_s(t,n,o);if(a===null)return null;let l=i.get(a.node);if(l!==void 0)return l;if(s.has(a.node))return{reads:new Set,reason:`calls recursive local helper '${o}'`};let d={reads:new Set,reason:null},u=b=>{d.reason??=b},c=b=>{if(!b.isIdentifier())return;let f=b.scope.getBinding(b.node.name),g=f===void 0?void 0:r.get(f);g!==void 0&&d.reads.add(g)},m=(b,f)=>{let g=Fe.isIdentifier(f)?f.name:Fe.isMemberExpression(f)?Re(f):null;if(g===null)return;let h=b.scope.getBinding(g),C=h===void 0?void 0:r.get(h);C!==void 0&&u(`calls local helper '${o}' which writes reactive state '${C}'`)},E=b=>{let f=b.node.callee;if(!Fe.isIdentifier(f))return;let g=Cr(e,t,b,f.name,r,i,s);if(g!==null){for(let C of g.reads)d.reads.add(C);g.reason!==null&&u(g.reason);return}if(!e.helpers.has(f.name)&&!e.importedFunctions.has(f.name))return;let h=e.importedFunctions.get(f.name)??Be(e,f.name);for(let C of h.reads)d.reads.add(C);h.writes.size!==0||h.boundedWrites.size!==0?u(`calls helper '${f.name}' which writes reactive state`):h.unbounded&&e.helpers.has(f.name)&&u(`calls recursive helper '${f.name}' which cannot be analyzed`)};return s.add(a.node),a.traverse({Function(b){let f=b.parentPath;(f.isCallExpression()||f.isNewExpression())&&f.node.callee===b.node||b.skip()},ReferencedIdentifier(b){c(b)},AssignmentExpression(b){m(b,b.node.left)},UpdateExpression(b){m(b,b.node.argument)},AwaitExpression(){u(`calls async local helper '${o}'`)},YieldExpression(){u(`calls yielding local helper '${o}'`)},CallExpression(b){E(b)}}),d.reads.size!==0&&a.traverse({Function(b){let f=b.parentPath;(f.isCallExpression()||f.isNewExpression())&&(f.node.callee===b.node||f.node.arguments.some(h=>h===b.node))||b.skip()},ReferencedIdentifier(b){c(b)},AssignmentExpression(b){m(b,b.node.left)},UpdateExpression(b){m(b,b.node.argument)},AwaitExpression(){u(`calls async local helper '${o}'`)},YieldExpression(){u(`calls yielding local helper '${o}'`)},CallExpression(b){E(b)}}),s.delete(a.node),i.set(a.node,d),d}function wr(e){for(let[t,n]of e.compPaths){let o=new Set;for(let r of n.node.body.body)if(Fe.isVariableDeclaration(r)&&!(r.kind!=="let"&&r.kind!=="var"&&r.kind!=="const"))for(let i of r.declarations)Fe.isIdentifier(i.id)&&(r.kind==="let"||r.kind==="var"||Dt(i.init)||Lt(i.init))&&o.add(i.id.name);o.size>0&&e.instanceState.set(t,o)}}function Pr(e){for(let[t,n]of e.compPaths){let o=new Map;for(let c of e.componentProps.get(t)?.bindings??[]){let m=n.scope.getBinding(c);m&&o.set(m,c)}for(let c of e.instanceState.get(t)??[]){let m=n.scope.getBinding(c);m&&o.set(m,c)}for(let c of e.state.keys()){let m=n.scope.getBinding(c);m?.scope.path.isProgram()&&o.set(m,c)}let r=[],i=new Set,s=new Map,a=n.get("body").get("body");for(let c of a)if(c.isVariableDeclaration({kind:"const"}))for(let m of c.get("declarations")){let E=m.node;if(!Fe.isIdentifier(E.id)&&!Fe.isObjectPattern(E.id)&&!Fe.isArrayPattern(E.id)||E.init==null||Fe.isFunction(E.init)||Fe.isIdentifier(E.id)&&e.instanceState.get(t)?.has(E.id.name)===!0&&(Dt(E.init)||Lt(E.init)))continue;let b=m.get("init");if(!b.isExpression())continue;let f=new Set,g=null,h=(k,W)=>{let T=W.scope.getBinding(k);return T!==void 0&&o.has(T)},C=k=>{if(!Fe.isIdentifier(k.node))return;let W=k.scope.getBinding(k.node.name),T=W===void 0?void 0:o.get(W);T!==void 0&&f.add(T)},N=k=>Fe.isIdentifier(k)?k.name:Fe.isMemberExpression(k)?Re(k):null,v=new Map,$=new Set,_=k=>{let W=k.node.callee;if(!Fe.isIdentifier(W))return;let T=Cr(e,n,k,W.name,o,v,$);if(T!==null){for(let oe of T.reads)f.add(oe);g??=T.reason;return}if(!e.helpers.has(W.name)&&!e.importedFunctions.has(W.name))return;let ee=e.importedFunctions.get(W.name)??Be(e,W.name);for(let oe of ee.reads)f.add(oe);ee.writes.size!==0||ee.boundedWrites.size!==0?g??=`calls helper '${W.name}' which writes reactive state`:ee.unbounded&&e.helpers.has(W.name)&&(g??=`calls recursive helper '${W.name}' which cannot be analyzed`)};if(b.isReferencedIdentifier()&&C(b),b.isAssignmentExpression()){let k=N(b.node.left);k!==null&&h(k,b)&&(g="contains an assignment to reactive state")}else if(b.isUpdateExpression()){let k=N(b.node.argument);k!==null&&h(k,b)&&(g="contains an update (++/--) to reactive state")}else b.isAwaitExpression()?g="uses await; per-instance derivations must be synchronous":b.isYieldExpression()&&(g="uses yield; per-instance derivations must be synchronous");if(b.isCallExpression()&&_(b),b.traverse({Function(k){let W=k.parentPath;(W.isCallExpression()||W.isNewExpression())&&W.node.callee===k.node||k.skip()},ReferencedIdentifier(k){C(k)},AssignmentExpression(k){let W=N(k.node.left);W!==null&&h(W,k)&&(g="contains an assignment to reactive state")},UpdateExpression(k){let W=N(k.node.argument);W!==null&&h(W,k)&&(g="contains an update (++/--) to reactive state")},AwaitExpression(){g="uses await; per-instance derivations must be synchronous"},YieldExpression(){g="uses yield; per-instance derivations must be synchronous"},CallExpression(k){_(k)}}),f.size===0)continue;if(b.traverse({Function(k){let W=k.parentPath;(W.isCallExpression()||W.isNewExpression())&&(W.node.callee===k.node||W.node.arguments.some(ee=>ee===k.node))||k.skip()},ReferencedIdentifier(k){C(k)},AssignmentExpression(k){let W=N(k.node.left);W!==null&&h(W,k)&&(g="contains an assignment to reactive state")},UpdateExpression(k){let W=N(k.node.argument);W!==null&&h(W,k)&&(g="contains an update (++/--) to reactive state")},AwaitExpression(){g="uses await; per-instance derivations must be synchronous"},YieldExpression(){g="uses yield; per-instance derivations must be synchronous"},CallExpression(k){_(k)}}),g!==null){let k=en(E.id);throw m.buildCodeFrameError(`memo-dom: local const '${k.join(", ")||"<pattern>"}' is a per-instance derivation but ${g}`)}let B=en(E.id),R=new Set;for(let k of f){let W=s.get(k);if(W===void 0)R.add(k);else for(let T of W)R.add(T)}r.push({declaration:c.node,target:Fe.cloneNode(E.id),source:Fe.cloneNode(E.init),bindings:B,sources:[...R].sort()});for(let k of B){i.add(k),s.set(k,new Set(R));let W=n.scope.getBinding(k);W&&o.set(W,k),e.instanceState.get(t)?.delete(k)}}if(r.length===0)continue;e.instanceDerivations.set(t,r),e.instanceDerivedBindings.set(t,i);let l=new Set([...e.instanceState.get(t)??[],...e.componentProps.get(t)?.bindings??[]]);if(![...l].some(c=>r.some(m=>!m.sources.includes(c))))continue;let u=new Set([...l,...r.flatMap(c=>c.sources)]);e.instanceReasonIds.set(t,new Map([...u].sort().map((c,m)=>[c,m]))),e.selectiveDerivationComponents.add(t)}}import*as _e from"@babel/types";function vr(e){return e?.path.isImportSpecifier()===!0||e?.path.isImportDefaultSpecifier()===!0||e?.path.isImportNamespaceSpecifier()===!0}function Gs(e){if(_e.isIdentifier(e))return e.name;if(!_e.isMemberExpression(e))return null;let t=e.object;for(;_e.isMemberExpression(t);)t=t.object;return _e.isIdentifier(t)?t.name:null}function jn(e,t,n,o,r=new Set){let i=Gs(t.node.callee);if(i===null)return!1;if(n.has(i))return!0;let s=e.importedFunctions.get(i);if(s!==void 0)return s.unbounded;if(vr(t.scope.getBinding(i)))return!0;if(o===void 0||!t.isCallExpression())return!1;let a=t.scope.getBinding(i),l=null;if(a?.path.isFunctionDeclaration()===!0)l=a.path;else if(a?.path.isVariableDeclarator()===!0){let E=a.path.get("init");!Array.isArray(E)&&(E.isFunctionExpression()||E.isArrowFunctionExpression())&&(l=E)}if(l===null||r.has(l.node))return!1;r.add(l.node);let d=!1,u=new Set,c=E=>{if(d||!E.isExpression())return;if(Vt(E,o,n).size>0){d=!0;return}if(E.isIdentifier()){let f=E.scope.getBinding(E.node.name);if(f?.path.isVariableDeclarator()===!0&&!u.has(f)){let g=f.path.get("init");!Array.isArray(g)&&g.node!==null&&(u.add(f),c(g),u.delete(f))}if(d)return}let b=f=>{jn(e,f,n,o,r)&&(d=!0)};(E.isCallExpression()||E.isNewExpression())&&b(E),E.traverse({Function(f){f.skip()},CallExpression:b,NewExpression:b})},m=l.get("body");return!Array.isArray(m)&&m.isExpression()?c(m):!Array.isArray(m)&&m.isBlockStatement()&&m.traverse({Function(E){E.skip()},ReturnStatement(E){let b=E.get("argument");!Array.isArray(b)&&b.node!==null&&c(b)}}),r.delete(l.node),d}function Zs(e){let t=e;for(;_e.isMemberExpression(t)||_e.isOptionalMemberExpression(t);)t=t.object;return _e.isIdentifier(t)?t.name:null}function Vt(e,t,n){let o=new Set,r=i=>{let s=i.node.name;if(!n.has(s))return;let a=i.scope.getBinding(s);a!==void 0&&a===t.scope.getBinding(s)&&o.add(s)};return e.traverse({ReferencedIdentifier(i){i.isIdentifier()&&r(i)}}),e.isReferencedIdentifier()&&r(e),o}function Ys(e,t,n){let o=t.findParent(a=>a.isProgram());if(o===null||!o.isProgram())return new Set(n);let r=new Set(Object.keys(o.scope.bindings)),i=new Set(n),s=!0;for(;s;){s=!1;for(let[a,l]of Object.entries(o.scope.bindings)){if(i.has(a))continue;let d=l.path.isVariableDeclarator()?l.path:l.path.findParent(E=>E.isVariableDeclarator());if(d===null||!d.isVariableDeclarator()||d.node.init===null)continue;let u=d.get("init"),m=[...Vt(u,o,r)].some(E=>i.has(E));m||u.traverse({CallExpression(E){jn(e,E,i,o)&&(m=!0)},NewExpression(E){jn(e,E,i,o)&&(m=!0)}}),m&&(i.add(a),s=!0)}}return i}function Qs(e,t){let n=new Set;return e.traverse({JSXExpressionContainer(o){let r=o.parentPath;if(r.isJSXAttribute()){let i=r.node.name,s=_e.isJSXIdentifier(i)?i.name:`${i.namespace.name}:${i.name.name}`;if(s==="ref"||/^on[A-Z]/.test(s))return}for(let i of Vt(o.get("expression"),e,t))n.add(i)},JSXSpreadAttribute(o){for(let r of Vt(o.get("argument"),e,t))n.add(r)}}),n}function kr(e){for(let[t,n]of e.compPaths){let o=Object.entries(n.scope.getProgramParent().bindings).filter(([d,u])=>{if(!vr(u)||e.importedState.has(d)||e.importedComponents.has(d))return!1;let c=e.importedFunctions.get(d);return c===void 0||c.unbounded}).map(([d])=>d),r=Ys(e,n,o),i=new Set([...Object.keys(n.scope.bindings),...e.state.keys(),...r,...e.instanceState.get(t)??[],...e.instanceDerivedBindings.get(t)??[],...e.componentProps.get(t)?.bindings??[]]);if(i.size===0)continue;let s=new Set(r),a=!0;for(;a;){a=!1;let d=c=>{!i.has(c)||s.has(c)||(s.add(c),a=!0)},u=c=>{if(!jn(e,c,s,n))return;for(let b of c.get("arguments"))if(!b.isSpreadElement())for(let f of Vt(b,n,i))d(f);let m=c.findParent(b=>b.isVariableDeclarator());if(m?.isVariableDeclarator()===!0)for(let b of Object.keys(_e.getBindingIdentifiers(m.node.id)))d(b);let E=c.findParent(b=>b.isAssignmentExpression({operator:"="}));if(E?.isAssignmentExpression({operator:"="})===!0){let b=Zs(E.node.left);b!==null&&d(b)}};n.traverse({CallExpression(c){u(c)},NewExpression(c){u(c)},VariableDeclarator(c){if(!(c.node.init===null||![...Vt(c.get("init"),n,i)].some(E=>s.has(E))))for(let E of Object.keys(_e.getBindingIdentifiers(c.node.id)))d(E)}})}let l=Qs(n,i);e.opaqueBindings.set(t,s),[...s].some(d=>l.has(d))&&e.volatileComponents.add(t)}}import*as be from"@babel/types";function rn(e){let t=!0;return be.traverseFast(e,n=>{if(be.isAssignmentExpression(n)||be.isUpdateExpression(n)||be.isAwaitExpression(n)||be.isYieldExpression(n)||be.isNewExpression(n)||be.isTaggedTemplateExpression(n)||be.isFunction(n)){t=!1;return}if(be.isCallExpression(n)||be.isOptionalCallExpression(n)){let o=n.callee;t=t&&be.isMemberExpression(o)&&!o.computed&&be.isIdentifier(o.object,{name:"Math"})&&be.isIdentifier(o.property)}}),t}function ea(e){return!be.isExpressionStatement(e)||!be.isAssignmentExpression(e.expression,{operator:"="})||!be.isIdentifier(e.expression.left)||!rn(e.expression.right)?null:e.expression.left.name}function Nr(e,t){return e.size===t.size&&[...e].every(n=>t.has(n))}function on(e){if(be.isExpressionStatement(e)){let t=ea(e);return t===null?null:{bindings:new Set([t]),partial:new Set}}if(be.isBlockStatement(e)){let t=new Set,n=new Set;for(let o of e.body){let r=on(o);if(r===null)return null;for(let i of r.bindings){if(t.has(i))return null;t.add(i)}for(let i of r.partial)n.add(i)}return t.size===0?null:{bindings:t,partial:n}}if(be.isIfStatement(e)){if(!rn(e.test))return null;let t=on(e.consequent);if(t===null)return null;if(e.alternate==null)return{bindings:t.bindings,partial:new Set([...t.bindings,...t.partial])};let n=on(e.alternate);return n===null||!Nr(t.bindings,n.bindings)?null:{bindings:t.bindings,partial:new Set([...t.partial,...n.partial])}}return null}function ta(e){if(!rn(e.discriminant))return null;let t=null;for(let n of e.cases){if(n.test!=null&&!rn(n.test))return null;let o=[...n.consequent];if(o.at(-1)&&be.isBreakStatement(o.at(-1))&&o.pop(),o.some(i=>be.isBreakStatement(i)))return null;let r=on(be.blockStatement(o));if(r===null)return null;if(t===null)t=r;else{if(!Nr(t.bindings,r.bindings))return null;for(let i of r.partial)t.partial.add(i)}}if(t!==null&&!e.cases.some(n=>n.test===null))for(let n of t.bindings)t.partial.add(n);return t}function na(e,t){return e.node===t||e.findParent(n=>n.node===t)!==null}function Rr(e){for(let[t,n]of e.compPaths){let o=new Map;for(let s of e.componentProps.get(t)?.bindings??[]){let a=n.scope.getBinding(s);a&&o.set(a,s)}for(let s of e.instanceState.get(t)??[]){let a=n.scope.getBinding(s);a&&o.set(a,s)}for(let s of e.instanceDerivedBindings.get(t)??[]){let a=n.scope.getBinding(s);a&&o.set(a,s)}for(let s of e.state.keys()){let a=n.scope.getBinding(s);a?.scope.path.isProgram()&&o.set(a,s)}let r=[],i=e.instanceDerivedBindings.get(t)??new Set;for(let s of n.get("body").get("body")){if(!s.isIfStatement()&&!s.isSwitchStatement())continue;let a=s,l=a.isIfStatement()?on(a.node):ta(a.node);if(l===null)continue;let d=!0,u=[],c=[];for(let f of l.bindings){let g=n.scope.getBinding(f),h=g?.path,C=h?.parentPath;if(g===void 0||!h?.isVariableDeclarator()||!C?.isVariableDeclaration()||C.node.kind!=="let"&&C.node.kind!=="var"||g.constantViolations.some(N=>!na(N,a.node))){d=!1;break}if(l.partial.has(f)){let N=h.get("init");if(!N.isExpression()||!rn(N.node)){d=!1;break}u.push({binding:f,source:N.node}),c.push(N)}}if(!d)continue;let m=new Set,E=f=>{let g=f.scope.getBinding(f.node.name),h=g===void 0?void 0:o.get(g);h!==void 0&&m.add(h)},b={Function(f){f.skip()},ReferencedIdentifier(f){f.isIdentifier()&&E(f)}};a.traverse(b);for(let f of c)f.isReferencedIdentifier()&&E(f),f.traverse(b);if(m.size!==0){for(let f of l.bindings)if(m.has(f))throw a.buildCodeFrameError(`memo-dom: reactive control-flow derivation '${f}' reads its own previous value`);r.push({statement:a.node,bindings:[...l.bindings].sort(),resets:u,sources:[...m].sort()});for(let f of l.bindings){i.add(f);let g=n.scope.getBinding(f);g&&o.set(g,f),e.instanceState.get(t)?.delete(f)}}}r.length>0&&(e.instanceControlFlow.set(t,r),e.instanceDerivedBindings.set(t,i))}}function Ir(e){for(let[t]of e.compPaths){let n=e.instanceDerivations.get(t)??[],o=e.instanceControlFlow.get(t)??[];if(n.length===0&&o.length===0)continue;let r=new Map;for(let u of n)for(let c of u.bindings)r.set(c,new Set(u.sources));for(let u of o)for(let c of u.bindings)r.set(c,new Set(u.sources));let i=(u,c=new Set)=>{let m=r.get(u);if(m===void 0)return new Set([u]);if(c.has(u))return new Set([u]);let E=new Set(c).add(u),b=new Set;for(let f of m)for(let g of i(f,E))b.add(g);return b};for(let u of n)u.sources=[...new Set(u.sources.flatMap(c=>[...i(c)]))].sort();for(let u of o)u.sources=[...new Set(u.sources.flatMap(c=>[...i(c)]))].sort();let s=new Set([...e.instanceState.get(t)??[],...e.componentProps.get(t)?.bindings??[]]),a=[...n,...o],l=[...s].some(u=>a.some(c=>!c.sources.includes(u)));if(e.selectiveDerivationComponents.delete(t),e.instanceReasonIds.delete(t),!l)continue;let d=new Set([...s,...a.flatMap(u=>u.sources)]);e.instanceReasonIds.set(t,new Map([...d].sort().map((u,c)=>[u,c]))),e.selectiveDerivationComponents.add(t)}}import*as sn from"@babel/types";function oa(e){let t=e.indexOf("[");return t<0?e:e.slice(0,t)}function kt(e,t){let n=new Set;for(let o of t){let r=o.split("/"),i=[[]];for(let s=0;s<r.length;s++){let a=r[s],l=i.map(d=>[...d,a]);if(s<r.length-1&&e.renderSlotOwners.has(oa(a)))for(let d of i)l.push([...d,a,"$slot[*]"]);i=l}for(let s of i)n.add(s.join("/"))}return[...n]}function ot(e,t,n=new Set){let o=e.linkedComponentPaths.get(t);if(o!==void 0)return[...o];if(n.has(t))throw e.compPaths.get(t).buildCodeFrameError(`memo-dom: recursive component '${t}' \u2014 components cannot render themselves (L1)`);let r=e.listedSites.get(t);if(r!==void 0&&r.length>0){n.add(t);let d=r.flatMap(u=>ot(e,u.owner,n).map(c=>`${c}/${u.suffix}/Row[*]`));return n.delete(t),[...new Set(d)]}let i=e.comps.get(t),s=e.conditionalComponentSites.get(t)??[],a=e.rowComponentSites.get(t)??[];if(i.parents.size===0&&s.length===0&&a.length===0)return[e.rootId];n.add(t);let l=[];for(let d of s)for(let u of ot(e,d.owner,n))l.push(`${u}/${d.suffix}`);for(let d of a)for(let u of ot(e,d.owner,n))l.push(`${u}/${d.suffix}`);for(let d of i.parents){let u=e.childRefCounts.get(d)?.get(t)??1;for(let c of ot(e,d,n))u>1?l.push(`${c}/${t}`,`${c}/${t}[*]`):l.push(`${c}/${t}`)}return n.delete(t),l}function lo(e,t){let n=e.linkedComponentPaths.get(t);if(n!==void 0)return kt(e,n.flatMap(i=>[i,`${i}/*`]));let o=e.listedSites.get(t),r=[];if(o&&o.length>0){if(Nt(e,t)){for(let i of o){let s=i.suffix.lastIndexOf("/"),a=s<0?"":`/${i.suffix.slice(0,s)}`;for(let l of ot(e,i.owner))r.push(`${l}${a}`,`${l}${a}/*`)}return kt(e,r)}for(let i of o)for(let s of ot(e,i.owner))r.push(`${s}/${i.suffix}/Row[*]`,`${s}/${i.suffix}/Row[*]/*`);return kt(e,r)}for(let i of ot(e,t))r.push(i,`${i}/*`);return kt(e,r)}function Nt(e,t){let n=e.importedComponents.get(t);if(n!==void 0)return n.listLightweight;let o=e.lightweightCache.get(t);if(o!==void 0)return o;let r=!1,i=e.listedSites.get(t),s=e.linkedComponentRows.get(t);return(i!==void 0&&i.length>0||s!==void 0&&s.length>0)&&e.comps.get(t).parents.size===0&&Jn(e,t)&&(r=!0),e.lightweightCache.set(t,r),r}function Jn(e,t){if((e.instanceState.get(t)?.size??0)>0)return!1;let n=!0,o=e.compPaths.get(t),r=i=>{(sn.isIdentifier(i.node.callee,{name:"cleanup"})&&i.scope.getBinding("cleanup")===void 0||sn.isIdentifier(i.node.callee,{name:"effect"})&&i.scope.getBinding("effect")===void 0)&&(n=!1),Ke(i.node)&&$e(i)&&(n=!1)};return o.traverse({JSXElement(i){let s=i.node.openingElement.name;sn.isJSXIdentifier(s)&&/^[A-Z]/.test(s.name)&&(n=!1)},CallExpression:r,OptionalCallExpression:r,ConditionalExpression(i){$e(i)&&(n=!1)},LogicalExpression(i){$e(i)&&(n=!1)}}),n}import*as Q from"@babel/types";function Fr(e,t){let n=e.findParent(o=>o.isFunctionDeclaration()||o.isFunctionExpression()||o.isArrowFunctionExpression());return n===t?!0:n?.findParent(o=>o===t)!==null}function co(e,t){let n=e;for(;n!==null;){let o=n.parentPath;if(o===null||o.isJSXAttribute()||o.isJSXSpreadAttribute())return!1;if(o.isJSXExpressionContainer()){if(o.parentPath?.isJSXAttribute()===!0){let r=o.parentPath.node,i=o.parentPath.parentPath;if(!i?.isJSXOpeningElement())return!1;let s=i.node.name;if(!Q.isJSXIdentifier(s)||!/^[A-Z]/.test(s.name))return!1;let a=Q.isJSXIdentifier(r.name)?r.name.name:r.name.name.name;return t.componentProps.get(s.name)?.renderProps.includes(a)===!0}return o.parentPath?.isJSXElement()===!0||o.parentPath?.isJSXFragment()===!0}if(o.isReturnStatement()&&o.node.argument===n.node||o.isArrowFunctionExpression()&&o.node.body===n.node||o.isVariableDeclarator()&&o.node.init===n.node)return!0;n=o}return!1}function ra(e,t){if(Q.isArrayExpression(e))return e;if(!Q.isIdentifier(e))return null;let n=t.scope.getBinding(e.name);return n?.path.isVariableDeclarator()&&Q.isArrayExpression(n.path.node.init)?n.path.node.init:null}function uo(e,t,n=new Set){if(n.has(e))throw t.buildCodeFrameError("memo-dom: cyclic JSX array spread");n.add(e);let o=[];try{for(let r of e.elements)if(!(r==null||Q.isNullLiteral(r)||Q.isBooleanLiteral(r))){if(Q.isSpreadElement(r)){if(!Q.isExpression(r.argument))throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");let i=ra(r.argument,t);if(i===null)throw t.buildCodeFrameError("memo-dom: JSX array spreads must resolve to a static JSX array");o.push(...uo(i,t,n));continue}if(Q.isArrayExpression(r)){o.push(...uo(r,t,n));continue}if(Q.isJSXElement(r)||Q.isJSXFragment(r)){o.push(Q.cloneNode(r,!0));continue}if(!Q.isExpression(r))throw t.buildCodeFrameError("memo-dom: JSX arrays require renderable expression entries");o.push(Q.jsxExpressionContainer(Q.cloneNode(r,!0)))}}finally{n.delete(e)}return o}function Mr(e,t){return Q.jsxFragment(Q.jsxOpeningFragment(),Q.jsxClosingFragment(),uo(e,t))}function ia(e,t){return Q.isArrayExpression(e)?e.elements.map((n,o)=>{if(n==null||Q.isSpreadElement(n))throw t.buildCodeFrameError("memo-dom: JSX arrays cannot contain holes or spread elements");return{key:Q.numericLiteral(o),value:n}}):e.properties.map(n=>{if(!Q.isObjectProperty(n)||n.computed||!Q.isExpression(n.value))throw t.buildCodeFrameError("memo-dom: JSX objects require static data properties without spreads");let o=Q.isIdentifier(n.key)?Q.stringLiteral(n.key.name):Q.isStringLiteral(n.key)||Q.isNumericLiteral(n.key)?Q.cloneNode(n.key):null;if(o===null)throw t.buildCodeFrameError("memo-dom: JSX objects require identifier, string, or numeric keys");return{key:o,value:n.value}})}function sa(e,t){let n=e.node,o=null;if(!n.computed&&Q.isIdentifier(n.property)?o=n.property.name:n.computed&&(Q.isStringLiteral(n.property)||Q.isNumericLiteral(n.property))&&(o=n.property.value),o!==null){let i=t.find(s=>(Q.isStringLiteral(s.key)||Q.isNumericLiteral(s.key))&&s.key.value===o);if(i===void 0)throw e.buildCodeFrameError(`memo-dom: JSX collection has no entry for '${o}'`);return Q.cloneNode(i.value,!0)}if(!n.computed||!Q.isExpression(n.property))throw e.buildCodeFrameError("memo-dom: JSX collection selection requires a static or expression key");let r=Q.nullLiteral();for(let i=t.length-1;i>=0;i--){let s=t[i];r=Q.conditionalExpression(Q.binaryExpression("===",Q.cloneNode(n.property,!0),Q.cloneNode(s.key,!0)),Q.cloneNode(s.value,!0),r)}return r}function Dr(e){for(let[,t]of e.compPaths){let n=!1;t.traverse({JSXExpressionContainer(r){if(!r.parentPath?.isJSXElement()&&!r.parentPath?.isJSXFragment())return;let i=r.get("expression");Array.isArray(i)||!i.isArrayExpression()||!fe(i.node)||(r.replaceWith(Mr(i.node,i)),n=!0)}});let o=!0;for(;o;){o=!1,t.scope.crawl();let r=t.get("body").get("body");for(let i of r)if(i.isVariableDeclaration({kind:"const"})){for(let s of i.get("declarations")){let a=s.node,l=a.init;if(!Q.isIdentifier(a.id)||l==null||!fe(l))continue;let d=s.scope.getBinding(a.id.name);if(d?.path!==s)continue;let u=[...d.referencePaths];if(Q.isObjectExpression(l)||Q.isArrayExpression(l))for(let c of u){if(!c.isIdentifier()||!Fr(c,t))throw c.buildCodeFrameError(`memo-dom: JSX collection '${a.id.name}' is used outside its component`);if(c.parentPath?.isMemberExpression()&&c.parentPath.node.object===c.node){let m=c.parentPath;if(!co(m,e))throw m.buildCodeFrameError(`memo-dom: JSX collection '${a.id.name}' is used outside a render position`);m.replaceWith(sa(m,ia(l,s)));continue}if(Q.isArrayExpression(l)&&c.parentPath?.isSpreadElement()&&c.parentPath.parentPath?.isArrayExpression()){c.replaceWith(Q.cloneNode(l,!0));continue}if(Q.isArrayExpression(l)&&co(c,e)){c.replaceWith(Mr(l,c));continue}throw c.buildCodeFrameError(Q.isArrayExpression(l)?`memo-dom: JSX collection '${a.id.name}' must be rendered directly or selected with a direct index access`:`memo-dom: JSX collection '${a.id.name}' is used outside a render position`)}else for(let c of u)if(!(!c.isIdentifier()||!Fr(c,t))){if(!co(c,e))throw c.buildCodeFrameError(`memo-dom: JSX value '${a.id.name}' is used outside a render position`);c.replaceWith(Q.cloneNode(l,!0))}i.node.declarations.length===1?i.remove():s.remove(),n=!0,o=!0;break}if(o)break}}n&&(t.traverse({JSXExpressionContainer(r){let i=r.node.expression;(r.parentPath?.isJSXElement()===!0||r.parentPath?.isJSXFragment()===!0)&&(Q.isJSXElement(i)||Q.isJSXFragment(i))&&r.replaceWith(i)}}),t.scope.crawl())}}import*as X from"@babel/types";function po(e){return X.isReturnStatement(e)&&X.isExpression(e.argument)?e.argument:X.isBlockStatement(e)&&e.body.length===1?po(e.body[0]):null}function Wt(e){let t=po(e);if(t!==null)return t;if(X.isIfStatement(e)&&e.alternate!=null){let n=Wt(e.consequent),o=Wt(e.alternate);return n===null||o===null?null:X.conditionalExpression(X.cloneNode(e.test,!0),X.cloneNode(n,!0),X.cloneNode(o,!0))}if(X.isSwitchStatement(e)){let n=e.cases.find(r=>r.test==null);if(n===void 0||n.consequent.length!==1)return null;let o=Wt(n.consequent[0]);if(o===null)return null;for(let r=e.cases.length-1;r>=0;r--){let i=e.cases[r];if(i.test==null)continue;if(i.consequent.length!==1)return null;let s=Wt(i.consequent[0]);if(s===null)return null;o=X.conditionalExpression(X.binaryExpression("===",X.cloneNode(e.discriminant,!0),X.cloneNode(i.test,!0)),X.cloneNode(s,!0),o)}return o}return null}function aa(e,t){if(X.isExpression(e.body))return{expression:X.cloneNode(e.body,!0),locals:new Map};let n=new Map,o=[];for(let s of e.body.body){if(X.isVariableDeclaration(s,{kind:"const"})){for(let a of s.declarations)(!X.isIdentifier(a.id)||a.init==null||!X.isExpression(a.init))&&t("memo-dom: JSX render functions require identifier const declarations with expression initializers"),n.set(a.id.name,X.cloneNode(a.init,!0));continue}X.isTypeScript(s)||X.isEmptyStatement(s)||o.push(s)}if(o.length===1){let s=Wt(o[0]);if(s!==null)return{expression:s,locals:n}}let r=o.at(-1),i=r===void 0?null:po(r);if(i!==null){let s=X.cloneNode(i,!0);for(let a=o.length-2;a>=0;a--){let l=o[a];if(X.isIfStatement(l)&&l.alternate==null){let d=Wt(l.consequent);if(d!==null){s=X.conditionalExpression(X.cloneNode(l.test,!0),X.cloneNode(d,!0),s);continue}}t("memo-dom: JSX render functions support pure const setup, JSX return expressions, tail early-return if statements, exhaustive return if/else, or exhaustive return switch statements")}return{expression:s,locals:n}}return t("memo-dom: JSX render function does not have supported exhaustive return control flow")}function la(e,t){return(X.isMemberExpression(e)||X.isOptionalMemberExpression(e))&&t==="property"&&!e.computed||(X.isObjectProperty(e)||X.isObjectMethod(e)||X.isClassMethod(e))&&t==="key"&&!e.computed||X.isVariableDeclarator(e)&&t==="id"||(X.isFunction(e)||X.isCatchClause(e))&&(t==="params"||t==="param"||t==="id")||X.isLabeledStatement(e)&&t==="label"}function Lr(e,t,n=new Set){let o=X.cloneNode(e,!0),r=(i,s,a,l)=>{if(X.isIdentifier(i)&&!l.has(i.name)&&t.has(i.name)&&(s===null||!la(s,a)))return X.cloneNode(t.get(i.name),!0);let d=l;if(X.isFunction(i)&&i!==o){let u=i.params.flatMap(c=>Object.keys(X.getBindingIdentifiers(c)));d=new Set([...l,...u])}for(let u of X.VISITOR_KEYS[i.type]??[]){let c=i[u];Array.isArray(c)?i[u]=c.map(m=>m!=null&&typeof m=="object"&&"type"in m?r(m,i,u,d):m):c!=null&&typeof c=="object"&&"type"in c&&(i[u]=r(c,i,u,d))}return X.isObjectProperty(i)&&i.shorthand&&!X.isIdentifier(i.value,{name:X.isIdentifier(i.key)?i.key.name:""})&&(i.shorthand=!1),i};return r(o,null,"",n)}function da(e,t){let n=a=>{throw t.buildCodeFrameError(a)},o=e.node;(o.async||o.generator)&&n("memo-dom: JSX render functions must be synchronous"),t.node.arguments.some(a=>X.isSpreadElement(a))&&n("memo-dom: JSX render function calls do not support spread arguments"),t.node.arguments.length>o.params.length&&n("memo-dom: JSX render function received more arguments than parameters");let r=new Map;for(let a=0;a<o.params.length;a++){let l=o.params[a],d=t.node.arguments[a],u=d!==void 0&&X.isExpression(d)?d:X.identifier("undefined");if(X.isIdentifier(l)){r.set(l.name,X.cloneNode(u,!0));continue}if(X.isAssignmentPattern(l)&&X.isIdentifier(l.left)){r.set(l.left.name,X.conditionalExpression(X.binaryExpression("===",X.cloneNode(u,!0),X.identifier("undefined")),X.cloneNode(l.right,!0),X.cloneNode(u,!0)));continue}n("memo-dom: JSX render functions currently require identifier parameters with optional defaults")}let i=aa(o,n);for(let[a,l]of i.locals)r.set(a,Lr(l,r));let s=Lr(i.expression,r);return fe(s)||n("memo-dom: JSX render function expansion did not produce JSX"),s}function ca(e,t){let n=t.get("callee");return Array.isArray(n)||!n.isIdentifier()?null:Ar(e,n)}function Ar(e,t){let n=t.node.name,o=e.jsxHelpers.get(n);if(o!==void 0)return{node:o.node,bindingPath:o};let r=t.scope.getBinding(n);if(r?.path.isFunctionDeclaration()&&fe(r.path.node))return{node:r.path.node,bindingPath:r.path};if(r?.path.isVariableDeclarator()){let i=r.path.node.init;if((X.isFunctionExpression(i)||X.isArrowFunctionExpression(i))&&fe(i.body))return{node:i,bindingPath:r.path}}return null}function jr(e){return X.isMemberExpression(e.callee)&&!e.callee.computed&&X.isIdentifier(e.callee.property,{name:"map"})}function ua(e){let t=e.parentPath;return t?.isCallExpression()===!0&&(t.node.callee===e.node||jr(t.node)&&t.node.arguments[0]===e.node)}function pa(e,t){let n=e.node;if(n.async||n.generator)throw t.buildCodeFrameError("memo-dom: JSX render callbacks must be synchronous");return X.arrowFunctionExpression(n.params.map(o=>X.cloneNode(o,!0)),X.cloneNode(n.body,!0))}function On(e){if(!e.removed){if(e.isFunctionDeclaration()){e.parentPath?.isExportNamedDeclaration()?e.parentPath.remove():e.remove();return}if(e.isVariableDeclarator()){let t=e.parentPath;if(!t?.isVariableDeclaration())return;t.node.declarations.length===1?t.parentPath?.isExportNamedDeclaration()?t.parentPath.remove():t.remove():e.remove();return}if(e.isArrowFunctionExpression()||e.isFunctionExpression()){let t=e.parentPath;t?.isVariableDeclarator()&&On(t)}}}function fa(e,t){let n=t.findParent(o=>o.isProgram());if(n===null||!n.isProgram()){On(t);return}for(let o of n.get("body")){let r=o.isExportNamedDeclaration()?o.get("declaration"):o;if(Array.isArray(r)||r==null)continue;if(r.isFunctionDeclaration()&&r.node.id?.name===e){o.remove();return}if(!r.isVariableDeclaration())continue;let i=r.get("declarations"),s=i.find(a=>a.isVariableDeclarator()&&X.isIdentifier(a.node.id,{name:e}));if(s!==void 0){i.length===1?o.remove():s.remove();return}}On(t)}function ma(e,t){let n=e.parentPath,o=n?.parentPath;if((X.isJSXElement(t)||X.isJSXFragment(t))&&n?.isJSXExpressionContainer()&&(o?.isJSXElement()||o?.isJSXFragment())&&o.node.children.includes(n.node)){n.replaceWith(t);return}e.replaceWith(t)}function Jr(e){let t=new Set;for(let[n,o]of e.jsxHelpers)if((o.scope.parent?.getBinding(n)??o.parentPath?.scope.getBinding(n))?.referencePaths.some(i=>i.isIdentifier()&&!ua(i)))throw o.buildCodeFrameError("memo-dom: JSX render functions may only be called in local render composition or passed directly to collection map()");for(let[,n]of e.compPaths){n.scope.crawl(),n.traverse({CallExpression(r){if(!jr(r.node)||r.node.arguments.length!==1)return;let i=r.get("arguments")[0];if(i===void 0||Array.isArray(i)||!i.isIdentifier())return;let s=Ar(e,i);s!==null&&(i.replaceWith(pa(s,i)),t.add(s.bindingPath))}});let o=!0;for(;o;){o=!1,n.scope.crawl();let r=[];n.traverse({CallExpression(i){r.push(i)}});for(let i of r.reverse()){if(i.removed)continue;let s=ca(e,i);s!==null&&(ma(i,da(s,i)),t.add(s.bindingPath),o=!0)}}}for(let[n,o]of e.jsxHelpers)fa(n,o);for(let n of t)On(n)}import*as Ve from"@babel/types";function ga(e){let t=ht(e);return Ve.isIdentifier(t)||Ve.isMemberExpression(t)||Ve.isOptionalMemberExpression(t)||Pn(t)}function ba(e,t){let n=e,o=t.get("body");for(;n!==null&&n.parentPath!==o;)n=n.parentPath;return n?.isStatement()===!0?n:null}function Ea(e,t){return e.findParent(n=>n.isFunctionDeclaration()||n.isFunctionExpression()||n.isArrowFunctionExpression())===t}function Or(e){for(let[,t]of e.compPaths){let n=[],o=a=>{let l=a.node.callee;if(Ke(a.node)===null||!Ve.isMemberExpression(l)&&!Ve.isOptionalMemberExpression(l)||!Ve.isExpression(l.object)||ga(l.object)||!Ea(a,t))return;let d=ba(a,t);d!==null&&n.push({path:a,source:Ve.cloneNode(l.object,!0),statement:d})};if(t.traverse({CallExpression:o,OptionalCallExpression:o}),n.length===0)continue;let r=t.get("body").get("body"),i=new Map(r.map((a,l)=>[a.node,l]));n.sort((a,l)=>(i.get(a.statement.node)??0)-(i.get(l.statement.node)??0));let s=[];for(let a of n){let l=J(e,"listView");s.push(Ve.variableDeclarator(Ve.cloneNode(l),a.source));let d=a.path.get("callee");if(Array.isArray(d)||!d.isMemberExpression()&&!d.isOptionalMemberExpression())continue;let u=d.get("object");Array.isArray(u)||u.replaceWith(Ve.cloneNode(l))}n[0].statement.insertBefore(Ve.variableDeclaration("const",s)),t.scope.crawl()}}import*as He from"@babel/types";var ha=new Set(["==","==="]);function $n(e,t,n){if(n(e,t),!He.isFunction(e))for(let o of He.VISITOR_KEYS[e.type]??[]){let r=e[o];if(Array.isArray(r))for(let i of r)i&&$n(i,e,n);else r&&$n(r,e,n)}}function $r(e,t,n){if(!He.isBinaryExpression(t)||!ha.has(t.operator))return!1;let o=t.left===e?t.right:t.left;return He.isExpression(o)&&He.isNodesEquivalent(o,n)}function Xr(e,t){if(e.jsx===null||e.keyExpr===null||!e.sourceLocal||!He.isIdentifier(e.sourceExpr)||!t.has(e.sourceExpr.name))return[];let n=e.sourceExpr.name,o=new Set;if($n(e.jsx,null,(i,s)=>{He.isIdentifier(i)&&t.has(i.name)&&i.name!==n&&$r(i,s,e.keyExpr)&&o.add(i.name)}),o.size===0)return[];let r=new Set;return $n(e.jsx,null,(i,s)=>{He.isIdentifier(i)&&o.has(i.name)&&He.isReferenced(i,s)&&!$r(i,s,e.keyExpr)&&r.add(i.name)}),[...o].filter(i=>!r.has(i)).sort()}import*as I from"@babel/types";function ya(e){return{mode:e.objectProps?"object":"positional",names:[...e.props],acceptsUnknown:e.acceptsUnknownProps,bindings:[],params:[],hasWholeDefault:e.hasWholeDefault,renderProps:[...e.renderProps??[]],renderCallbacks:[...e.renderCallbacks??[]],refProps:[...e.refProps??[]]}}function Xn(e,t){if(e.linkedDynamicComponentCandidates.size===0)return;t.scope.crawl();let n=new Set(Object.keys(t.scope.bindings)),o=new Map([...e.importedComponents].map(([i,s])=>[s.key,i])),r=[];for(let[i,s]of e.linkedDynamicComponentCandidates){let a=[];for(let d of s){let u=o.get(d.key);if(u===void 0){let c=`MDDynamic_${d.imported.replace(/[^A-Za-z0-9_$]/g,"_")}`;u=c;let m=1;for(;n.has(u);)u=`${c}${m++}`;n.add(u),o.set(d.key,u);let E={type:"component",key:d.key,props:[...d.props],objectProps:d.objectProps,acceptsUnknownProps:d.acceptsUnknownProps,hasWholeDefault:d.hasWholeDefault,listLightweight:d.listLightweight,delegatedEvents:d.delegatedEvents,renderProps:[...d.renderProps??[]],renderCallbacks:[...d.renderCallbacks??[]],refProps:[...d.refProps??[]],subtreeReads:[...d.subtreeReads??[]]};e.importedComponents.set(u,E),e.componentProps.set(u,ya(E)),r.push(I.importDeclaration(d.imported==="default"?[I.importDefaultSpecifier(I.identifier(u))]:[I.importSpecifier(I.identifier(u),I.isValidIdentifier(d.imported)?I.identifier(d.imported):I.stringLiteral(d.imported))],I.stringLiteral(d.source)))}a.push(u)}let l=[...new Set(a)];e.state.has(i)?e.stateComponentCandidates.set(i,l):e.functionComponentCandidates.set(i,l)}for(let i of r.reverse())t.unshiftContainer("body",i);t.scope.crawl()}function fo(e){let t=e;for(;I.isTSAsExpression(t)||I.isTSTypeAssertion(t)||I.isTSNonNullExpression(t);)t=t.expression;return t}function Tr(e){return I.isJSXIdentifier(e)?I.identifier(e.name):I.memberExpression(Tr(e.object),I.identifier(e.property.name))}function Br(e,t){let n=Pe(t);if(n===null)return null;let[o,...r]=n.split(".");if(o===void 0||r.length===0)return null;let i=e.scope.getBinding(o);if(!i?.path.isVariableDeclarator())return null;let s=i.path.node.init;if(s==null)return null;for(let a of r){if(s=fo(s),!I.isObjectExpression(s))return null;let l=s.properties.find(d=>!I.isObjectProperty(d)||d.computed?!1:(I.isIdentifier(d.key)?d.key.name:I.isStringLiteral(d.key)?d.key.value:null)===a);if(l===void 0||!I.isObjectProperty(l)||!I.isExpression(l.value))return null;s=l.value}return s}function xa(e,t){let n=e.scope.getBinding(t);if(n===void 0)return[];let o=null;return n.path.isFunctionDeclaration()?o=n.path.node:n.path.isVariableDeclarator()&&(I.isFunctionExpression(n.path.node.init)||I.isArrowFunctionExpression(n.path.node.init))&&(o=n.path.node.init),o===null?[]:Vr(o)}function Vr(e){if(I.isExpression(e.body))return[e.body];let t=[],n=o=>{if(!I.isFunction(o)){if(I.isReturnStatement(o)){I.isExpression(o.argument)&&t.push(o.argument);return}for(let r of I.VISITOR_KEYS[o.type]??[]){let i=o[r];if(Array.isArray(i))for(let s of i)s!=null&&typeof s=="object"&&"type"in s&&n(s);else i!=null&&typeof i=="object"&&"type"in i&&n(i)}}};for(let o of e.body.body)n(o);return t}function Rt(e,t,n,o=new Set){let r=fo(t);if(!o.has(r)){if(o.add(r),I.isIdentifier(r)&&(e.comps.has(r.name)||e.importedComponents.has(r.name))){n.add(r.name);return}if(I.isIdentifier(r)){for(let i of e.stateComponentCandidates.get(r.name)??e.functionComponentCandidates.get(r.name)??[])n.add(i);return}if(I.isConditionalExpression(r)){Rt(e,r.consequent,n,o),Rt(e,r.alternate,n,o);return}if(I.isLogicalExpression(r)){Rt(e,r.right,n,o);return}if(I.isObjectExpression(r)){for(let i of r.properties)I.isObjectProperty(i)&&I.isExpression(i.value)&&Rt(e,i.value,n,o);return}if(I.isArrayExpression(r)){for(let i of r.elements)i!=null&&!I.isSpreadElement(i)&&Rt(e,i,n,o);return}if(I.isCallExpression(r)&&I.isIdentifier(r.callee)){for(let i of e.functionComponentCandidates.get(r.callee.name)??[])n.add(i);return}if(I.isMemberExpression(r)){let i=Re(r);if(i!==null)for(let s of e.stateComponentCandidates.get(i)??[])n.add(s)}}}function Wr(e,t){for(let o of t.node.body){let r=I.isExportNamedDeclaration(o)?o.declaration:o;if(I.isVariableDeclaration(r))for(let i of r.declarations){if(!I.isIdentifier(i.id)||i.init==null)continue;let s=new Set;Rt(e,i.init,s),s.size>0&&e.state.has(i.id.name)&&e.stateComponentCandidates.set(i.id.name,[...s])}}let n=!0;for(;n;){n=!1;for(let[o,r]of e.helpers){let i=new Set(e.functionComponentCandidates.get(o)??[]),s=[],a=r.node;(I.isFunctionDeclaration(a)||I.isFunctionExpression(a)||I.isArrowFunctionExpression(a))&&(s=Vr(a));for(let l of s)Rt(e,l,i);i.size>0&&i.size!==(e.functionComponentCandidates.get(o)?.length??0)&&(e.functionComponentCandidates.set(o,[...i]),n=!0)}}}function rt(e,t,n,o,r=new Set){let i=fo(n);if(!r.has(i)){if(r.add(i),I.isConditionalExpression(i)){rt(e,t,i.consequent,o,r),rt(e,t,i.alternate,o,r);return}if(I.isStringLiteral(i)){if(!/^[A-Za-z][A-Za-z0-9:_-]*$/.test(i.value))throw t.buildCodeFrameError(`memo-dom: '${i.value}' is not a valid dynamic intrinsic tag name`);o.push({compare:I.cloneNode(i),tag:I.jsxIdentifier(i.value)});return}if(I.isIdentifier(i)){if(e.comps.has(i.name)||e.importedComponents.has(i.name)){o.push({compare:I.cloneNode(i),tag:I.jsxIdentifier(i.name)});return}let s=e.stateTagCandidates.get(i.name);if(s!==void 0)for(let l of s)rt(e,t,I.stringLiteral(l),o,r);let a=t.scope.getBinding(i.name);a?.path.isVariableDeclarator()&&a.path.node.init!=null&&rt(e,t,a.path.node.init,o,r);return}if(I.isCallExpression(i)&&I.isIdentifier(i.callee)){for(let s of e.functionTagCandidates.get(i.callee.name)??[])rt(e,t,I.stringLiteral(s),o,r);for(let s of xa(t,i.callee.name))rt(e,t,s,o,r);for(let s of e.functionComponentCandidates.get(i.callee.name)??[])rt(e,t,I.identifier(s),o,r);return}if(I.isMemberExpression(i)){let s=Br(t,i);if(s!==null){rt(e,t,s,o,r);return}let a=Re(i);if(a===null)return;let l=t.scope.getBinding(a);if(l?.path.isVariableDeclarator()&&l.path.node.init!=null){let d=new Set;Rt(e,l.path.node.init,d);for(let u of d)rt(e,t,I.identifier(u),o,r)}for(let d of e.stateTagCandidates.get(a)??[])rt(e,t,I.stringLiteral(d),o,r);for(let d of e.stateComponentCandidates.get(a)??[])rt(e,t,I.identifier(d),o,r)}}}function Sa(e){return I.isStringLiteral(e.compare)?`string:${e.compare.value}`:I.isIdentifier(e.compare)?`component:${e.compare.name}`:JSON.stringify(e.compare)}function Ca(e,t){if(I.isIdentifier(t)){let n=e.scope.getBinding(t.name);return n?.path.isVariableDeclarator()?[...n.path.node.init==null?[]:[n.path.node.init],...n.constantViolations.flatMap(o=>o.isAssignmentExpression()&&o.node.operator==="="&&I.isExpression(o.node.right)?[o.node.right]:[])]:[]}if(I.isMemberExpression(t)){let n=Br(e,t),o=Pe(t),r=[];return o!==null&&(e.getFunctionParent()??e.findParent(a=>a.isProgram()))?.traverse({AssignmentExpression(a){a.node.operator==="="&&I.isMemberExpression(a.node.left)&&Pe(a.node.left)===o&&I.isExpression(a.node.right)&&r.push(a.node.right)}}),[...n===null?[]:[n],...r]}return[]}function zr(e,t){let n=I.cloneNode(e,!0);n.openingElement.name=I.cloneNode(t);let o=n.closingElement;return o!=null&&(o.name=I.cloneNode(t)),n}function wa(e,t,n){let o=I.nullLiteral();for(let r=n.length-1;r>=0;r--){let i=n[r];o=I.conditionalExpression(I.binaryExpression("===",I.cloneNode(e,!0),I.cloneNode(i.compare,!0)),zr(t,i.tag),o)}return o}function Pa(e){return I.isIdentifier(e)?e.name:I.isMemberExpression(e)?Pe(e)??"<member expression>":"<expression>"}function Kr(e){let t=new Map;for(let[,n]of e.compPaths){n.scope.crawl();let o=[];n.traverse({JSXElement(r){o.push(r)}});for(let r of o.reverse()){if(r.removed)continue;let i=r.node.openingElement.name;if(I.isJSXNamespacedName(i))throw r.buildCodeFrameError("memo-dom: namespaced JSX tags are not supported");if(I.isJSXIdentifier(i)&&(!/^[A-Z]/.test(i.name)||e.comps.has(i.name)||e.importedComponents.has(i.name)))continue;let s=Tr(i),a=Ca(r,s),l=[];for(let u of a)rt(e,r,u,l);let d=[...new Map(l.map(u=>[Sa(u),u])).values()];if(d.length===0)throw r.buildCodeFrameError(`memo-dom: dynamic JSX tag '${Pa(s)}' has no finite string or linked-component candidates`);for(let u of d){if(!I.isJSXIdentifier(u.tag))continue;let c=e.componentProps.get(u.tag.name);if(c===void 0||c.renderProps.length===0)continue;let m=t.get(u.tag.name);m===void 0&&(m=new Map,t.set(u.tag.name,m));for(let E of r.node.openingElement.attributes){if(I.isJSXSpreadAttribute(E)||!I.isJSXIdentifier(E.name)||!c.renderProps.includes(E.name.name))continue;let b=ze(E.value),f=m.get(E.name.name)??{scalar:!1,jsx:!1,at:r};b!==null&&fe(b)?f.jsx=!0:f.scalar=!0,m.set(E.name.name,f)}}if(d.length===1){r.replaceWith(zr(r.node,d[0].tag));continue}r.replaceWith(I.jsxFragment(I.jsxOpeningFragment(),I.jsxClosingFragment(),[I.jsxExpressionContainer(wa(s,r.node,d))]))}n.scope.crawl()}for(let[n,o]of t){let r=e.componentProps.get(n);for(let[i,s]of o){if(s.scalar&&s.jsx)throw s.at.buildCodeFrameError(`memo-dom: dynamic component prop '${i}' is used as both scalar data and JSX content`);s.scalar&&(r.renderProps=r.renderProps.filter(a=>a!==i))}}}import*as se from"@babel/types";function mo(e){return se.isExportNamedDeclaration(e)?e.declaration??null:se.isDeclaration(e)?e:null}function Hr(e){let t=new Map;for(let n of e.body){let o=mo(n);se.isTSTypeAliasDeclaration(o)&&t.set(o.id.name,o.typeAnnotation)}return t}function xt(e,t,n=new Set){if(se.isTSLiteralType(e)&&se.isStringLiteral(e.literal))return[e.literal.value];if(se.isTSUnionType(e))return e.types.flatMap(o=>xt(o,t,n));if(se.isTSIntersectionType(e))return e.types.flatMap(o=>xt(o,t,n));if(se.isTSParenthesizedType(e))return xt(e.typeAnnotation,t,n);if(se.isTSTypeLiteral(e))return e.members.flatMap(o=>(se.isTSPropertySignature(o)||se.isTSIndexSignature(o))&&se.isTSTypeAnnotation(o.typeAnnotation)&&se.isTSType(o.typeAnnotation.typeAnnotation)?xt(o.typeAnnotation.typeAnnotation,t,n):[]);if(se.isTSMappedType(e)&&e.typeAnnotation!=null&&se.isTSType(e.typeAnnotation))return xt(e.typeAnnotation,t,n);if(se.isTSTypeReference(e)&&se.isIdentifier(e.typeName)){let o=e.typeName.name;if((o==="Record"||o==="Readonly"||o==="Partial")&&se.isTSTypeParameterInstantiation(e.typeArguments)){let s=o==="Record"?e.typeArguments.params[1]:e.typeArguments.params[0];if(s!==void 0&&se.isTSType(s))return xt(s,t,n)}if(n.has(o))return[];let r=t.get(o);if(r===void 0)return[];let i=new Set(n);return i.add(o),xt(r,t,i)}return[]}function Tn(e){let t=Hr(e),n=new Map;for(let o of e.body){let r=mo(o);if(se.isVariableDeclaration(r))for(let i of r.declarations){if(!se.isIdentifier(i.id)||!se.isTSTypeAnnotation(i.id.typeAnnotation))continue;let s=[...new Set(xt(i.id.typeAnnotation.typeAnnotation,t))];s.length>0&&n.set(i.id.name,s)}}return n}function go(e){let t=Hr(e),n=new Map,o=(r,i)=>{if(!se.isTSTypeAnnotation(i)||!se.isTSType(i.typeAnnotation))return;let s=[...new Set(xt(i.typeAnnotation,t))];s.length>0&&n.set(r,s)};for(let r of e.body){let i=mo(r);if(se.isFunctionDeclaration(i)&&i.id!=null){o(i.id.name,i.returnType);continue}if(se.isVariableDeclaration(i))for(let s of i.declarations)se.isIdentifier(s.id)&&(se.isArrowFunctionExpression(s.init)||se.isFunctionExpression(s.init))&&o(s.id.name,s.init.returnType)}return n}import*as mt from"@babel/types";import*as we from"@babel/types";function an(e,t){let n=[],o=[],r=-1;for(let s=0;s<e.length;s++)we.isJSXSpreadAttribute(e[s])&&(r=s);let i=[];for(let s=0;s<e.length;s++){let a=e[s];if(we.isJSXSpreadAttribute(a)){n.push(we.spreadElement(we.cloneNode(a.argument))),o.push(we.cloneNode(a.argument));continue}let l=De(a.name);if(l==="key"&&t.skipKey)continue;let d=va(a,t.fail),u=t.attributeValue?.(l,d)??d,c=/^on[A-Z]/.test(l)&&t.eventValue!==void 0?t.eventValue(l,u):u;n.push(we.objectProperty(we.isValidIdentifier(l)?we.identifier(l):we.stringLiteral(l),c,!1,we.isIdentifier(c)&&c.name===l)),o.push(we.cloneNode(d)),/^on[A-Z]/.test(l)&&s>r&&i.push(l)}return{expression:we.objectExpression(n),sources:o,safeEventKeys:i}}function De(e){return we.isJSXIdentifier(e)?e.name:`${e.namespace.name}:${e.name.name}`}function va(e,t){return e.value==null?we.booleanLiteral(!0):we.isStringLiteral(e.value)?we.cloneNode(e.value):we.isJSXExpressionContainer(e.value)&&we.isExpression(e.value.expression)?we.cloneNode(e.value.expression):t(`memo-dom: attribute '${De(e.name)}' must contain a JavaScript expression`)}function Bn(e,t,n=new Set){let o=e.importedComponents.get(t);if(o!==void 0)return new Set(o.subtreeReads??[]);if(n.has(t))return new Set;n.add(t);let r=new Set(e.compReads.get(t)??[]);for(let s of e.effects.get(t)??[]){for(let a of s.moduleReads)r.add(a);for(let a of s.conditionModuleReads)r.add(a)}let i=e.compPaths.get(t);return i!==void 0&&i.traverse({JSXElement(s){let a=s.node.openingElement.name;if(!(!mt.isJSXIdentifier(a)||!/^[A-Z]/.test(a.name)))for(let l of Bn(e,a.name,n))r.add(l)}}),n.delete(t),r}function Ur(e){for(let[t,n]of e.compPaths){let o=e.compReads.get(t);o!==void 0&&n.traverse({JSXAttribute(r){let i=r.parentPath;if(!i?.isJSXOpeningElement())return;let s=i.node.name;if(!mt.isJSXIdentifier(s))return;let a=De(r.node.name);if(e.componentProps.get(s.name)?.renderCallbacks.includes(a)!==!0)return;let l=r.node.value;!mt.isJSXExpressionContainer(l)||!mt.isExpression(l.expression)||Oe(l.expression,d=>{if(mt.isJSXOpeningElement(d)&&mt.isJSXIdentifier(d.name)&&/^[A-Z]/.test(d.name.name))for(let u of Bn(e,d.name.name))o.add(u)})}})}}import*as It from"@babel/types";function qr(e){for(let[t,n]of e.compPaths){let o=e.componentProps.get(t);n.traverse({JSXAttribute(r){if(De(r.node.name)!=="ref")return;let i=r.node.value;if(!(!It.isJSXExpressionContainer(i)||!It.isExpression(i.expression)))for(let s of _r(e,t,i.expression))o.refProps.includes(s)||o.refProps.push(s)}})}}function _r(e,t,n){let o=yt(e,t,n);if(o!==null)return[o];if(!It.isArrayExpression(n))return[];let r=[];for(let i of n.elements)i===null||It.isSpreadElement(i)||r.push(..._r(e,t,i));return r}import*as Jt from"@babel/types";function zt(e){let t=new Set;return Oe(e,n=>{if(!Jt.isJSXOpeningElement(n))return;let o=n.name;if(!(!Jt.isJSXIdentifier(o)||!/^[a-z]/.test(o.name)))for(let r of n.attributes)Jt.isJSXAttribute(r)&&Jt.isJSXIdentifier(r.name)&&/^on[A-Z]/.test(r.name.name)&&t.add(r.name.name)}),[...t].sort()}import*as Xe from"@babel/types";function ln(e){let t=(o,r)=>{let i=tt(e,o),s=e.readers.get(i);s||e.readers.set(i,s=new Set);for(let a of r)s.add(a)};for(let[o,r]of e.compReads){if(r.size===0)continue;let i=lo(e,o);for(let s of r)t(s,i)}for(let{owner:o,suffix:r,vars:i}of e.rowReads.values()){let s=kt(e,ot(e,o).flatMap(a=>[`${a}/${r}/Row[*]`,`${a}/${r}/Row[*]/*`]));for(let a of i)t(a,s)}for(let{owner:o,suffix:r,vars:i}of e.condReads.values()){let s=kt(e,ot(e,o).flatMap(a=>[`${a}/${r}`,`${a}/${r}/*`]));for(let a of i)t(a,s)}for(let[o,r]of e.effects){let i=lo(e,o).filter(s=>!s.endsWith("/*"));for(let s of r){let a=i.map(d=>`${d}/$effects/${s.index}`),l=s.condition===null?a:a.map(d=>`${d}/$active`);for(let d of s.moduleReads)t(d,l);for(let d of s.conditionModuleReads)t(d,a)}}for(let o of e.moduleEffects){let r=o.condition===null?o.entityId:`${o.entityId}/$active`;for(let i of o.moduleReads)t(i,[r]);for(let i of o.conditionModuleReads)t(i,[o.entityId])}for(let[o,r]of e.computeds){let i=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#${o}`;for(let s of r.reads)t(s,[i])}for(let o of e.moduleControlFlow)for(let r of o.sources)t(r,[o.entityId]);if(e.readers.size===0)return null;let n=[...e.readers.entries()].sort(([o],[r])=>o<r?-1:1).map(([o,r])=>Xe.objectProperty(Xe.stringLiteral(o),Xe.arrayExpression([...r].sort().map(i=>Xe.stringLiteral(i)))));return Xe.expressionStatement(Xe.callExpression(ne(e,"installAccessTable"),[Xe.objectExpression([Xe.objectProperty(Xe.identifier("readers"),Xe.objectExpression(n))]),Xe.stringLiteral(e.rootId),Xe.stringLiteral(e.moduleId)]))}function Zr(e,t){let n=t?.parentPath;if(!n?.isJSXAttribute())return!1;let o=n.parentPath;if(!o.isJSXOpeningElement())return!1;let r=o.node.name;if(!P.isJSXIdentifier(r)||!/^[A-Z]/.test(r.name))return!1;let i=n.node.name,s=P.isJSXIdentifier(i)?i.name:i.name.name;return e.componentProps.get(r.name)?.renderProps.includes(s)===!0}function Gr(e,t){let n=t.parentPath,o=n?.parentPath;if(!n?.isJSXExpressionContainer()||!o?.isJSXElement()&&!o?.isJSXFragment()&&!Zr(e,n))throw t.buildCodeFrameError("memo-dom: conditional rendering must be a direct JSX child: <div>{cond ? <A/> : <B/>}</div>");t.skip()}function ka(e,t){for(let n of t.get("body"))if(!(!n.isImportDeclaration()||n.node.importKind==="type"))for(let o of n.node.specifiers){if(P.isImportSpecifier(o)&&o.importKind==="type")continue;let r=o.local.name;if(!(e.importedState.has(r)||e.importedFunctions.has(r)||e.importedComponents.has(r)))throw n.buildCodeFrameError(`memo-dom: value import '${r}' requires compileModules() so its reactive identity can be linked`)}}function Na(e,t){let n=Tn(t.node);for(let o of t.node.body){let r=P.isExportNamedDeclaration(o)?o.declaration:o;if(P.isVariableDeclaration(r)){for(let i of r.declarations)if(P.isIdentifier(i.id)&&(r.kind==="let"||r.kind==="var"?wt(e,i.id.name,"let"):r.kind==="const"&&(Dt(i.init)?wt(e,i.id.name,"store"):Lt(i.init)&&wt(e,i.id.name,"const")),e.state.has(i.id.name))){let s=n.get(i.id.name);s!==void 0&&e.stateTagCandidates.set(i.id.name,[...s])}}}}function Ra(e,t){let n=o=>{if(o===null||Array.isArray(o))return null;let r=o;for(;r.isTSAsExpression()||r.isTSTypeAssertion()||r.isTSNonNullExpression()||r.isTSSatisfiesExpression()||r.isTSInstantiationExpression();){let i=r.get("expression");if(Array.isArray(i))return null;r=i}return r.isArrowFunctionExpression()||r.isFunctionExpression()?r:null};t.traverse({FunctionDeclaration(o){let r=o.node.id?.name;if(r&&!e.comps.has(r)&&!e.helpers.has(r)&&!e.jsxHelpers.has(r))if($e(o))if(/^[A-Z]/.test(r)){e.comps.set(r,{parents:new Set,jsxCount:0}),e.compPaths.set(r,o);let i=zt(o.node.body);e.componentHostEvents.set(r,i),i.length!==0&&e.componentsWithHostEvents.add(r);try{e.componentProps.set(r,Cn(o.node.params))}catch(s){throw o.buildCodeFrameError(`memo-dom: invalid props for component '${r}': ${s instanceof Error?s.message:String(s)}`)}}else e.jsxHelpers.set(r,o);else e.helpers.set(r,o);o.skip()},VariableDeclarator(o){if(!o.scope.path.isProgram()||!P.isIdentifier(o.node.id))return;let r=n(o.get("init"));r!==null&&(fe(r.node.body)?/^[A-Z]/.test(o.node.id.name)||e.jsxHelpers.set(o.node.id.name,r):e.helpers.set(o.node.id.name,r),r.skip())}});for(let o of t.get("body")){let r=o.isExportNamedDeclaration()?o.get("declaration"):o;if(!(Array.isArray(r)||!r.isVariableDeclaration()))for(let i of r.get("declarations")){if(!i.isVariableDeclarator())continue;let s=i.node.id,a=n(i.get("init"));!P.isIdentifier(s)||/^[A-Z]/.test(s.name)||a===null||!fe(a.node.body)||(e.helpers.delete(s.name),e.jsxHelpers.set(s.name,a))}}}function Vn(e,t,n=new Set){if(P.isTSStringKeyword(e)||P.isTSNumberKeyword(e)||P.isTSBooleanKeyword(e)||P.isTSBigIntKeyword(e)||P.isTSSymbolKeyword(e)||P.isTSNullKeyword(e)||P.isTSUndefinedKeyword(e)||P.isTSLiteralType(e))return!0;if(P.isTSParenthesizedType(e))return Vn(e.typeAnnotation,t,n);if(P.isTSUnionType(e))return e.types.every(o=>Vn(o,t,n));if(P.isTSTypeReference(e)&&P.isIdentifier(e.typeName)){let o=e.typeName.name;if(n.has(o))return!1;let r=new Set(n);r.add(o);for(let i of t.body){let s=P.isExportNamedDeclaration(i)?i.declaration:i;if(P.isTSTypeAliasDeclaration(s)&&s.id.name===o)return Vn(s.typeAnnotation,t,r)}}return!1}function Ia(e,t){let n=l=>P.isStringLiteral(l)||P.isNumericLiteral(l)||P.isBooleanLiteral(l)||P.isBigIntLiteral(l)||P.isUnaryExpression(l)&&(l.operator==="+"||l.operator==="-")&&P.isNumericLiteral(l.argument);for(let l of e.node.params){if(P.isTSParameterProperty(l))continue;if(P.isAssignmentPattern(l)&&P.isIdentifier(l.left,{name:t})&&n(l.right))return!0;if(P.isAssignmentPattern(l)&&P.isObjectPattern(l.left)&&P.isObjectExpression(l.right)){let u=l.right.properties.find(c=>!P.isObjectProperty(c)||c.computed?!1:(P.isIdentifier(c.key)?c.key.name:P.isStringLiteral(c.key)?c.key.value:null)===t);if(P.isObjectProperty(u)&&P.isExpression(u.value)&&n(u.value))return!0}let d=P.isAssignmentPattern(l)?l.left:l;if(P.isObjectPattern(d))for(let u of d.properties){if(!P.isObjectProperty(u)||u.computed)continue;if((P.isIdentifier(u.key)?u.key.name:P.isStringLiteral(u.key)?u.key.value:null)===t&&P.isAssignmentPattern(u.value)&&n(u.value.right))return!0}}let o=e.node.params[0];if(o==null||P.isTSParameterProperty(o))return!1;let r=P.isAssignmentPattern(o)?o.left:o;if(!P.isIdentifier(r)&&!P.isObjectPattern(r)&&!P.isArrayPattern(r))return!1;let i=r.typeAnnotation;if(!P.isTSTypeAnnotation(i))return!1;let s=e.findParent(l=>l.isProgram());if(!s?.isProgram())return!1;let a=i.typeAnnotation;if(P.isTSTypeReference(a)&&P.isIdentifier(a.typeName)){let l=a.typeName.name,d=s.node.body.map(u=>P.isExportNamedDeclaration(u)?u.declaration:u).find(u=>(P.isTSInterfaceDeclaration(u)||P.isTSTypeAliasDeclaration(u))&&u.id.name===l);P.isTSInterfaceDeclaration(d)?a=P.tsTypeLiteral(d.body.body):P.isTSTypeAliasDeclaration(d)&&(a=d.typeAnnotation)}if(!P.isTSTypeLiteral(a))return!1;for(let l of a.members){if(!P.isTSPropertySignature(l)||l.computed)continue;if((P.isIdentifier(l.key)?l.key.name:P.isStringLiteral(l.key)?l.key.value:null)===t&&P.isTSTypeAnnotation(l.typeAnnotation))return Vn(l.typeAnnotation.typeAnnotation,s.node)}return!1}function bo(e,t=new Set){if(fe(e.node))return!0;if(t.has(e.node))return!1;if(t.add(e.node),e.isIdentifier()){let n=e.scope.getBinding(e.node.name);if(n?.path.isVariableDeclarator()){let o=n.path.get("init");return!Array.isArray(o)&&o.node!=null?bo(o,t):!1}}if(e.isMemberExpression()){let n=e.get("object");return!Array.isArray(n)&&bo(n,t)}return!1}function Fa(e){let t=new Map;for(let[r,i]of e.compPaths){let s=new Set;if(t.set(r,s),i.traverse({JSXExpressionContainer(a){if(!a.parentPath?.isJSXElement()&&!a.parentPath?.isJSXFragment())return;let l=a.node.expression;if(!P.isExpression(l))return;let d=yt(e,r,l);d!==null&&(Ia(i,d)||s.add(d))}}),(i.parentPath?.isExportNamedDeclaration()||i.parentPath?.isExportDefaultDeclaration())&&!e.linkedComponentRenderProps.has(r)){let a=e.componentProps.get(r);for(let l of s)a.renderProps.includes(l)||a.renderProps.push(l)}}let n=new Map;for(let[r,i]of e.compPaths)i.traverse({JSXElement(s){let a=s.node.openingElement.name;if(!P.isJSXIdentifier(a)||!e.comps.has(a.name))return;let l=e.componentProps.get(a.name),d=t.get(a.name);if(d===void 0)return;let u=n.get(a.name);u===void 0&&(u=new Map,n.set(a.name,u)),d.has("children")&&s.node.children.some(c=>!P.isJSXText(c)||c.value.trim()!=="")&&!l.renderProps.includes("children")&&(l.renderProps.push("children"),u.set("children",{scalar:!1,jsx:!0,at:s}));for(let c of s.get("openingElement").get("attributes")){if(!c.isJSXAttribute())continue;let m=c.node.name,E=P.isJSXIdentifier(m)?m.name:m.name.name;if(!d.has(E))continue;let b=u.get(E)??{scalar:!1,jsx:!1,at:c},f=c.get("value"),g=!1;if(f.isJSXExpressionContainer()&&P.isExpression(f.node.expression)){let h=f.get("expression");!Array.isArray(h)&&(bo(h)||P.isExpression(h.node)&&yt(e,r,h.node)!==null)&&(g=!0)}g?b.jsx=!0:b.scalar=!0,u.set(E,b)}}});for(let[r,i]of n){let s=e.componentProps.get(r);for(let[a,l]of i){if(l.scalar&&l.jsx){if(a==="children"){s.renderProps.includes(a)||s.renderProps.push(a);continue}throw l.at.buildCodeFrameError(`memo-dom: prop '${a}' on <${r}> is used as both scalar data and JSX content`)}l.jsx?s.renderProps.includes(a)||s.renderProps.push(a):l.scalar&&(s.renderProps=s.renderProps.filter(d=>d!==a))}}let o=!0;for(;o;){o=!1;for(let[r,i]of e.compPaths){let s=e.componentProps.get(r);i.traverse({JSXAttribute(a){let l=a.get("value");if(!l.isJSXExpressionContainer()||!P.isExpression(l.node.expression))return;let d=yt(e,r,l.node.expression);if(d===null||s.renderProps.includes(d))return;let u=a.parentPath;if(!u.isJSXOpeningElement())return;let c=u.node.name;if(!P.isJSXIdentifier(c)||!/^[A-Z]/.test(c.name))return;let m=e.componentProps.get(c.name),E=a.node.name,b=P.isJSXIdentifier(E)?E.name:E.name.name;m?.renderProps.includes(b)===!0&&(s.renderProps.push(d),o=!0)}})}}for(let[r,i]of e.linkedComponentRenderProps){let s=e.componentProps.get(r);s!==void 0&&(s.renderProps=[...i])}}function Ma(e,t){let n=e.compPaths.get(t),o=e.comps.get(t),r=i=>{let s=Ke(i.node);if(s&&($e(i)||Tt(e,t,s)!==null)){let a=i.parentPath,l=a?.parentPath;if(!a?.isJSXExpressionContainer()||!l?.isJSXElement()&&!l?.isJSXFragment()&&!Zr(e,a))throw i.buildCodeFrameError("memo-dom: list rendering must be a direct JSX child: <ul>{items.map(item => <Row />)}</ul>");i.skip()}};n.traverse({JSXElement(i){let s=i.node.openingElement;if(!P.isJSXIdentifier(s.name))throw i.buildCodeFrameError("memo-dom: namespaced or member-expression JSX tags are not supported (L1)");for(let l of s.attributes)if(!P.isJSXSpreadAttribute(l)&&l.name.name==="key"){if(er(e,i))continue;throw i.buildCodeFrameError("memo-dom: key={...} is only meaningful on list rows: items.map(item => <Row key={item.id} />)")}let a=s.name.name;if(/^[A-Z]/.test(a)){let l=e.comps.has(a);if(!l&&!e.importedComponents.has(a))throw i.buildCodeFrameError(`memo-dom: <${a} /> is not a linked component factory`);l&&e.comps.get(a).parents.add(t);let d=e.childRefCounts.get(t);d||e.childRefCounts.set(t,d=new Map),d.set(a,(d.get(a)??0)+1),(i.node.children.some(u=>!P.isJSXText(u)||u.value.trim()!=="")||s.attributes.some(u=>{if(P.isJSXSpreadAttribute(u)||e.componentProps.get(a)?.renderProps.includes(P.isJSXIdentifier(u.name)?u.name.name:u.name.name.name)!==!0)return!1;let c=ze(u.value);return c!==null&&fe(c)}))&&e.renderSlotOwners.add(t);return}o.jsxCount++},ConditionalExpression(i){$e(i)&&Gr(e,i)},LogicalExpression(i){if($e(i)){if(i.node.operator!=="&&"&&i.node.operator!=="||")throw i.buildCodeFrameError("memo-dom: only && / || conditionals are supported (R8 L1), not ??");Gr(e,i)}},CallExpression:r,OptionalCallExpression:r})}function Da(e){let t=e.parentPath;return t.isCallExpression()&&t.node.callee===e.node}function La(e,t){let n=Pe(t.node);if(!n||!n.includes("."))return null;let o=n.split(".")[0];if(e.state.get(o)!=="store"||t.scope.getBinding(o)?.scope.path.isProgram()!==!0)return null;let r=t.parentPath;return r.isAssignmentExpression({operator:"="})&&r.node.left===t.node||Da(t)?null:n}function Yr(e,t,n){let o=new Set([...e.instanceReasonIds.get(t)?.keys()??[],...n]);e.instanceReasonIds.set(t,new Map([...o].sort().map((r,i)=>[r,i])))}function Aa(e,t){let n=[],o=e;for(;o=ht(o),!!P.isMemberExpression(o);){if(n.unshift(o),P.isSuper(o.object))return null;o=o.object}if(!P.isIdentifier(o,{name:t}))return null;let r=n[0];if(r===void 0||!r.computed||!P.isExpression(r.property)||!(P.isIdentifier(r.property)||P.isNumericLiteral(r.property)||P.isStringLiteral(r.property))||n.length<2)return null;let i=[];for(let s of n.slice(1))if(!s.computed&&P.isIdentifier(s.property))i.push(s.property.name);else if(s.computed&&P.isStringLiteral(s.property))i.push(s.property.value);else return null;return i}function ja(e,t,n){let o=!1;return Oe(e.node.body,r=>{if(o)return;let i=P.isAssignmentExpression(r)&&P.isMemberExpression(r.left)?r.left:P.isUpdateExpression(r)&&P.isMemberExpression(r.argument)||P.isUnaryExpression(r,{operator:"delete"})&&P.isMemberExpression(r.argument)?r.argument:null;if(i===null)return;let s=Aa(i,t);s!==null&&!Xt(s,n)&&(o=!0)}),o}function Ja(e,t,n,o){if(!o.sourceLocal||!P.isIdentifier(o.sourceExpr))return;let r=o.sourceExpr.name;if(e.instanceState.get(t)?.has(r)!==!0)return;let i=it(o.keyExpr,o.itemParam);if(i===null||i.length===0)return;let s=e.compPaths.get(t);if(s===void 0||!ja(s,r,i))return;let a=`${t}\0${r}`;if(e.disabledKeyedListMutationSources.has(a))return;let l=e.keyedListMutationSources.get(t);l===void 0&&(l=new Map,e.keyedListMutationSources.set(t,l));let d=l.get(r);if(d!==void 0){e.keyedListMutations.delete(d.call),l.delete(r),e.disabledKeyedListMutationSources.add(a);return}let u={source:r,keyPath:i,keysVariable:J(e,`${r}ChangedKeys`).name,targetedReason:`${a}\0content`,topologyReason:`${a}\0topology`,structuralReason:`${a}\0structure`,call:n};l.set(r,u),e.keyedListMutations.set(n,u),e.targetedListComponents.add(t),Yr(e,t,[r,u.targetedReason,u.topologyReason,u.structuralReason])}function Oa(e){for(let[l]of e.comps){let E=function(v,$,_){let B=Ke(v.node);if(B===null||!$e(v))return;let R=At(e,B,v,l,_),k=`${$}/${R.suffix}`;if(R.form==="component"){let W=e.listedSites.get(R.rowComp)??[];W.some(T=>T.owner===l&&T.suffix===k)||W.push({owner:l,suffix:k,itemParam:R.itemParam,keyExpr:R.keyExpr,sourceKey:R.sourceKey,sourceLocal:R.sourceLocal}),e.listedSites.set(R.rowComp,W)}else h(v,R,k);v.skip()},b=function(v,$,_){let B=v.node.openingElement.name;if(!P.isJSXIdentifier(B)||!/^[A-Z]/.test(B.name))return;if(!e.comps.has(B.name)&&!e.importedComponents.has(B.name))throw v.buildCodeFrameError(`memo-dom: <${B.name} /> is not a linked component factory`);let R=_.get(B.name)??0;_.set(B.name,R+1);let k=R===0?B.name:`${B.name}[${R}]`,W=`${$}/${k}`,T=e.conditionalComponentSites.get(B.name)??[];T.some(ee=>ee.owner===l&&ee.suffix===W)||T.push({owner:l,suffix:W}),e.conditionalComponentSites.set(B.name,T)},f=function(v,$,_){let B=v.node.openingElement.name;if(!P.isJSXIdentifier(B)||!/^[A-Z]/.test(B.name))return;if(!e.comps.has(B.name)&&!e.importedComponents.has(B.name))throw v.buildCodeFrameError(`memo-dom: <${B.name} /> is not a linked component factory`);let R=_.get(B.name)??0;_.set(B.name,R+1);let k=R===0?B.name:`${B.name}[${R}]`,W=`${$}/Row[*]/${k}`,T=e.rowComponentSites.get(B.name)??[];T.some(ee=>ee.owner===l&&ee.suffix===W)||T.push({owner:l,suffix:W}),e.rowComponentSites.set(B.name,T)},g=function(v,$){let _=e.listedSites.get(v.rowComp)??[];_.some(B=>B.owner===l&&B.suffix===$)||_.push({owner:l,suffix:$,itemParam:v.itemParam,keyExpr:v.keyExpr,sourceKey:v.sourceKey,sourceLocal:v.sourceLocal}),e.listedSites.set(v.rowComp,_)},h=function(v,$,_){let B=v.get("arguments")[0];if(B===void 0)return;let R=new Set,k=new Map,W=new Map,T=ee=>{let oe=Ke(ee.node);if(oe!==null&&$e(ee)){let me=At(e,oe,ee,l,W,$),de=`${_}/Row[*]/${me.suffix}`;me.form==="component"?g(me,de):h(ee,me,de),ee.skip();return}let ue=ee.node.callee;if(P.isIdentifier(ue)&&(e.helpers.has(ue.name)||e.importedFunctions.has(ue.name))){let me=e.importedFunctions.get(ue.name)??Be(e,ue.name);for(let de of me.reads)R.add(de)}};B.traverse({Identifier(ee){ee.node.name!==$.itemParam&&e.state.has(ee.node.name)&&ee.scope.getBinding(ee.node.name)?.scope.path.isProgram()===!0&&R.add(ee.node.name)},JSXElement(ee){f(ee,_,k)},CallExpression:T,OptionalCallExpression:T}),R.size>0&&e.rowReads.set(`${l}/${_}`,{owner:l,suffix:_,vars:R})},C=function(v,$=null){let _=v.node;if(!$e(v))return;let B=kn(_,v,m),R=$===null?B.suffix:`${$}/${B.suffix}`,k=[];if(v.isConditionalExpression()){let T=v;for(;T.isConditionalExpression();)k.push(T.get("consequent")),T=T.get("alternate");k.push(T)}else k.push(v.get("right"));for(let T of k){let ee=new Map,oe=new Map;if((T.isConditionalExpression()||T.isLogicalExpression())&&$e(T)){C(T,R);continue}T.isJSXElement()&&b(T,R,oe),T.traverse({ConditionalExpression(ue){$e(ue)&&(C(ue,R),ue.skip())},LogicalExpression(ue){$e(ue)&&(C(ue,R),ue.skip())},JSXElement(ue){b(ue,R,oe)},CallExpression(ue){E(ue,R,ee)},OptionalCallExpression(ue){E(ue,R,ee)}})}let W=yn(e,_);W.size>0&&$===null&&e.condReads.set(`${l}/${R}`,{owner:l,suffix:R,vars:W}),v.skip()},N=function(v){if(P.isIdentifier(v.node.callee,{name:"effect"})&&v.scope.getBinding("effect")===void 0){v.skip();return}let $=Ke(v.node);if($&&($e(v)||Tt(e,l,$)!==null)){let B=At(e,$,v,l,c);Ja(e,l,$,B);let R=Xr(B,e.instanceState.get(l)??new Set);if(R.length>0&&P.isIdentifier(B.sourceExpr)){let k=B.sourceExpr.name;e.targetedListDependencies.set($,R.map(W=>({source:k,value:W}))),e.targetedListComponents.add(l),Yr(e,l,[k,...R])}if(B.sourceLocal||u.add(B.sourceKey),B.form==="component"){for(let W of B.jsx.openingElement.attributes){if(P.isJSXSpreadAttribute(W))continue;let T=W,ee=P.isJSXIdentifier(T.name)?T.name.name:`${T.name.namespace.name}:${T.name.name.name}`;if(ee==="key"||ee==="ref"||e.componentProps.get(B.rowComp)?.refProps.includes(ee)===!0)continue;let oe=ze(T.value);oe&&Oe(oe,ue=>{if(P.isIdentifier(ue)&&e.state.has(ue.name)&&v.scope.getBinding(ue.name)?.scope.path.isProgram()===!0&&u.add(ue.name),P.isMemberExpression(ue)){let me=Pe(ue);if(me!==null&&me.includes(".")){let de=me.split(".")[0];e.state.get(de)==="store"&&v.scope.getBinding(de)?.scope.path.isProgram()===!0&&u.add(me)}}})}let k=e.listedSites.get(B.rowComp)??[];k.some(W=>W.owner===l&&W.suffix===B.suffix)||k.push({owner:l,suffix:B.suffix,itemParam:B.itemParam,keyExpr:B.keyExpr,sourceKey:B.sourceKey,sourceLocal:B.sourceLocal}),e.listedSites.set(B.rowComp,k)}else h(v,B,B.suffix);v.skip();return}let _=v.node.callee;if(P.isIdentifier(_)&&(e.helpers.has(_.name)||e.importedFunctions.has(_.name))&&v.scope.getBinding(_.name)?.scope.path.isProgram()===!0){let B=e.importedFunctions.get(_.name)??Be(e,_.name);for(let R of B.reads)u.add(R)}};var t=E,n=b,o=f,r=g,i=h,s=C,a=N;let d=e.compPaths.get(l),u=new Set,c=new Map,m={count:0};d.traverse({JSXAttribute(v){let $=v.node.name;(P.isJSXIdentifier($,{name:"ref"})||P.isJSXNamespacedName($)&&$.namespace.name==="ref")&&v.skip()},ConditionalExpression(v){C(v)},LogicalExpression(v){C(v)},CallExpression:N,OptionalCallExpression:N,Identifier(v){if(!e.state.has(v.node.name)||v.scope.getBinding(v.node.name)?.scope.path.isProgram()!==!0)return;let $=v.parentPath;$.isAssignmentExpression({operator:"="})&&$.node.left===v.node||u.add(v.node.name)},MemberExpression(v){let $=La(e,v);$!==null&&u.add($)}}),e.compReads.set(l,u)}}function Wn(e,t){ka(e,t),Na(e,t),Ra(e,t),qr(e),tr(e),Jr(e),Wr(e,t),Fa(e),Dr(e),Kr(e),Or(e),wr(e),Sr(e,t),xr(e,t,ao),Pr(e),Rr(e),Ir(e),fr(e,t),kr(e);for(let[o]of e.comps)Ma(e,o);Oa(e),Ur(e);for(let[o]of e.comps)ot(e,o);let n=new Set([...e.listedSites.keys(),...e.linkedComponentRows.keys()]);for(let o of n){if(e.importedComponents.has(o))continue;let r=e.listedSites.get(o)??[],i=e.compPaths.get(o);if((r.length>0||e.linkedComponentRows.has(o))&&(e.comps.get(o).parents.size>0||(e.conditionalComponentSites.get(o)?.length??0)>0))throw i.buildCodeFrameError(`memo-dom: <${o}> is used both as a list row and as a static child \u2014 split it into two components (R7 L1)`)}}import*as A from"@babel/types";import*as S from"@babel/types";import*as Ie from"@babel/types";import*as ce from"@babel/types";function Ot(){return{writes:new Set,rootFallback:!1,rowLocal:!1,rowOwnerLocal:!1,instanceLocal:!1,instanceWrites:new Set,eventOrigin:null}}function Kt(e,t){e.instanceLocal=!0,e.instanceWrites.add(t)}function Ht(e,t,n,o){let r=t.rowLocal&&o!==void 0?ce.expressionStatement(o.refreshVar!==void 0?ce.callExpression(ce.identifier(o.refreshVar),[]):ce.callExpression(ne(e,"markDirty"),[ce.identifier(o.rowIdVar)])):null,i=null;if(t.instanceLocal&&n!==null){let d=e.instanceReasonIds.get(n),u=[...t.instanceWrites].map(m=>d?.get(m)).filter(m=>m!==void 0).sort((m,E)=>m-E),c=t.instanceWrites.size>0&&u.length===t.instanceWrites.size;i=ce.expressionStatement(ce.callExpression(ne(e,"markDirty"),[Te(e,n),...c?[u.length===1?ce.numericLiteral(u[0]):Ho(e,u)]:[]]))}let s=t.rowOwnerLocal&&o?.ownerIdVar!==void 0?ce.expressionStatement(ce.callExpression(ne(e,"markDirty"),[ce.identifier(o.ownerIdVar)])):null,a=d=>{let u=[];return t.eventOrigin!==null&&u.push(t.eventOrigin),r!==null&&u.push(r),s!==null&&u.push(s),i!==null&&u.push(i),d!==null&&u.push(d),u.length===0?null:u.length===1?u[0]:ce.blockStatement(u)};if(t.rootFallback)return ce.expressionStatement(ce.callExpression(ne(e,"markDirtySubtree"),[ce.stringLiteral(e.rootId)]));if(t.writes.size===0)return a(null);let l=[...t.writes].sort();return a(ce.expressionStatement(ce.callExpression(ne(e,"commitWrites"),[Qt(e,l)])))}function Qr(e,t,n){if(ce.isBlockStatement(t.body)){Eo(t.body,n),t.body.body.push(n);return}let o=J(e,"returnValue");t.body=ce.blockStatement([ce.variableDeclaration("const",[ce.variableDeclarator(o,t.body)]),n,ce.returnStatement(ce.cloneNode(o))])}function Eo(e,t){if(!ce.isFunction(e))for(let n of ce.VISITOR_KEYS[e.type]??[]){let o=e[n];if(Array.isArray(o))for(let r=0;r<o.length;r++){let i=o[r];!i||typeof i!="object"||!("type"in i)||ce.isFunction(i)||(ce.isReturnStatement(i)?(o.splice(r,0,ce.cloneNode(t)),r++):Eo(i,t))}else if(o&&typeof o=="object"&&"type"in o){if(ce.isFunction(o))continue;ce.isReturnStatement(o)?e[n]=ce.blockStatement([ce.cloneNode(t),o]):Eo(o,t)}}}import*as ke from"@babel/types";function Ft(e,t,n,o){if(o===void 0&&n?.refreshVar!==void 0)return ke.expressionStatement(ke.callExpression(ke.identifier(n.refreshVar),[]));let r=o??(n!==void 0?ke.identifier(n.rowIdVar):t!==null?Te(e,t):ke.stringLiteral(e.rootId));return ke.expressionStatement(ke.callExpression(ne(e,"markDirty"),[ke.cloneNode(r)]))}function Ut(e,t,n){let o=J(e,"event"),r=J(e,"returnValue");return ke.arrowFunctionExpression([o],ke.blockStatement([ke.variableDeclaration("const",[ke.variableDeclarator(r,ke.callExpression(ke.cloneNode(t),[ke.cloneNode(o)]))]),n,ke.returnStatement(ke.cloneNode(r))]))}import ni from"@babel/traverse";import*as M from"@babel/types";function $a(e,t,n){if(n.key===null)return null;let o=e.componentProps.get(t);if(o===void 0)return null;let r=qe(o);if(n.root===r){let[s,...a]=n.key.split(".").slice(1);return s===void 0?null:{name:s,path:a}}let i=Ye(o,n.root);return i===null?null:{name:i,path:n.key.split(".").slice(1)}}function ho(e,t,n,o,r){let i=$a(e,t,o);if(i===null)return!1;n===void 0?Kt(r,o.root):r.rowLocal=!0;let s=e.linkedComponentPropSources.get(t)?.get(i.name);if(s===void 0)return r.rootFallback=!0,!0;r.rootFallback||=s.rootFallback;let a=i.path.length===0?"":`.${i.path.join(".")}`;for(let l of s.keys)r.writes.add(`${l}${a}`);return!0}import*as Se from"@babel/types";function zn(e){return Se.isIdentifier(e)||Se.isObjectPattern(e)||Se.isArrayPattern(e)||Se.isAssignmentPattern(e)||Se.isRestElement(e)}function Xa(e){let t=e;for(;Se.isTSAsExpression(t)||Se.isTSTypeAssertion(t)||Se.isTSNonNullExpression(t)||Se.isTSSatisfiesExpression(t);)t=t.expression;return t}function dn(e,t,n){if(Se.isIdentifier(t)){e.set(t.name,n);return}if(Se.isAssignmentPattern(t)){zn(t.left)&&dn(e,t.left,n);return}if(!Se.isRestElement(t)){if(Se.isArrayPattern(t)){for(let o=0;o<t.elements.length;o++){let r=t.elements[o];zn(r)&&dn(e,r,vt(n,[String(o)]))}return}if(Se.isObjectPattern(t))for(let o of t.properties){if(Se.isRestElement(o))continue;if(o.computed||!Se.isIdentifier(o.key)&&!Se.isStringLiteral(o.key)&&!Se.isNumericLiteral(o.key)){zn(o.value)&&dn(e,o.value,{...n,key:null});continue}let r=Se.isIdentifier(o.key)?o.key.name:String(o.key.value);zn(o.value)&&dn(e,o.value,vt(n,[r]))}}}function ei(e,t,n,o){let r=Xa(o),i=e.componentProps.get(t);if(i===void 0)return null;if(Se.isIdentifier(r)){let d=n.get(r.name);return d!==void 0?d:qe(i)===r.name?{locality:"prop",root:r.name,key:r.name}:Ye(i,r.name)===null?null:{locality:"prop",root:r.name,key:r.name}}if(!Se.isMemberExpression(r))return null;let s=Re(r),a=Pe(r);if(s===null)return null;let l=ei(e,t,n,Se.identifier(s));return l===null?null:a===null?{...l,key:null}:vt(l,a.split(".").slice(1))}function ti(e,t){let n=new Map;for(let o of e.instanceDerivations.get(t)??[]){let r=ei(e,t,n,o.source);r!==null&&dn(n,o.target,r)}return n}var oi=ni.default??ni,Ta=new Set(["copyWithin","fill","pop","push","reverse","shift","sort","splice","unshift"]);function Ba(e,t){let n=[],o=e;for(;o=ht(o),!!M.isMemberExpression(o);){if(n.unshift(o),M.isSuper(o.object))return null;o=o.object}if(!M.isIdentifier(o,{name:t.source}))return null;let r=n[0];if(r===void 0||!r.computed||!M.isExpression(r.property)||!(M.isIdentifier(r.property)||M.isNumericLiteral(r.property)||M.isStringLiteral(r.property))||n.length<2)return null;let i=[];for(let a of n.slice(1))if(!a.computed&&M.isIdentifier(a.property))i.push(a.property.name);else if(a.computed&&M.isStringLiteral(a.property))i.push(a.property.value);else return null;if(Xt(i,t.keyPath))return null;let s=M.cloneNode(r,!0);for(let a of t.keyPath)s=M.memberExpression(s,M.identifier(a));return s}function Va(e,t){let n=new Set;for(let[o,r]of e.compReads)r.has(t)&&n.add(o);for(let o of e.rowReads.values())o.vars.has(t)&&n.add("__rows__");for(let o of e.condReads.values())o.vars.has(t)&&n.add("__regions__");return n}function ri(e,t,n){if(n.sourceLocal)return!0;let o=n.sourceKey;if(o==="")return!0;for(let i of e.computeds.values())if(i.reads.has(o))return!0;let r=new Set((e.listedSites.get(t??"")??[]).map(i=>i.owner));r.size===0&&t!==null&&r.add(t);for(let i of Va(e,o))if(i==="__rows__"||i==="__regions__"||!r.has(i))return!0;return!1}function Wa(e,t,n,o,r,i,s,a,l,d,u){if(e.handlerHasRootCommit.set(t,r.has(o)),l&&!r.has(o)){let m=Ot();m.eventOrigin=Ft(e,s,a,d),r.set(o,m)}let c=[];if(u)for(let m of i.values()){let E=Ht(e,m.writes,s,a);E!==null&&c.push({...m,commit:E})}for(let m of c)m.flag=J(e,"didWrite");c.sort((m,E)=>ii(E.path)-ii(m.path)).forEach(m=>{m.temporaries=za(e,m.path,m.flag)});for(let[m,E]of r){let b=u&&m===o?c.length===0?null:M.blockStatement(c.map(f=>M.ifStatement(M.cloneNode(f.flag),M.cloneNode(f.commit)))):Ht(e,E,s,a);b!==null&&Qr(e,m,b)}if(c.length>0){if(!M.isBlockStatement(n.body))throw new Error("memo-dom: execution-aware callback commit did not produce a block body");n.body.body.unshift(M.variableDeclaration("let",c.flatMap(m=>[M.variableDeclarator(M.cloneNode(m.flag),M.booleanLiteral(!1)),...(m.temporaries??[]).map(E=>M.variableDeclarator(M.cloneNode(E)))])))}t.body=n.body}function cn(e,t,n,o,r=!1,i,s=!1){let a=M.cloneNode(t),l=a,d=M.file(M.program([M.isFunctionDeclaration(a)?a:M.expressionStatement(a)])),u=n!==null?e.instanceState.get(n):void 0,c=n!==null?e.instanceDerivedBindings.get(n):void 0,m=n===null?new Map:ti(e,n),E=n!==null?new Set(e.componentProps.get(n)?.bindings??[]):new Set,b=new Set([...E,...u??[],...c??[]]);if(n!==null)for(let y of e.compPaths.get(n)?.node.body.body??[])if(M.isVariableDeclaration(y))for(let w of y.declarations)for(let L of Object.keys(M.getBindingIdentifiers(w.id)))b.add(L);else M.isFunctionDeclaration(y)&&y.id&&b.add(y.id.name);let f=new Bt((y,w)=>{if(w!==void 0)return null;let L=m.get(y);if(L!==void 0)return L;if(o!==void 0&&y===o.itemParam)return{locality:"row",root:y,key:y};if(u?.has(y)===!0)return{locality:"instance",root:y,key:y};if(E.has(y))return{locality:"prop",root:y,key:y};if(b.has(y))return null;let ie=e.state.get(y);return ie===void 0?null:Nn(y,ie)}),g=y=>y.stateKind==="computed"||e.state.get(y.root)==="computed",h=n===null?void 0:e.keyedListMutationSources.get(n),C=(y,w,L="structural")=>{Kt(y,w);let ie=h?.get(w);ie!==void 0&&Kt(y,L==="targeted"?ie.targetedReason:L==="topology"?ie.topologyReason:ie.structuralReason)},N=(y,w,L)=>{y.isExpression()&&(y.replaceWith(M.sequenceExpression([M.callExpression(M.memberExpression(M.identifier(w.keysVariable),M.identifier("add")),[L]),y.node])),y.skip())},v=new Set;for(let y of a.params)M.isIdentifier(y)&&v.add(y.name);oi(d,{VariableDeclarator(y){M.isIdentifier(y.node.id)&&(v.add(y.node.id.name),y.parentPath.isVariableDeclaration()&&f.trackDeclarator(y.scope,y.node))},Function(y){for(let w of y.node.params)M.isIdentifier(w)&&v.add(w.name)}});let $=new Map,_=new Map,B=y=>{let w=y.getFunctionParent()?.node??l,L=$.get(w);return L||$.set(w,L=Ot()),L},R=(y,w)=>{if(w(B(y)),!s||y.getFunctionParent()?.node!==l)return;let L=_.get(y.node);L===void 0&&(L={path:y,writes:Ot()},_.set(y.node,L)),w(L.writes)},k=y=>{R(y,w=>{o?.sourceLocal?w.rowOwnerLocal=!0:o!==void 0&&w.writes.add(o.sourceKey)})},W=y=>{if(o===void 0)return null;let w=y.split(".").slice(1);return o.itemPath.some((L,ie)=>w[ie]!==L)?null:w.slice(o.itemPath.length)},T=(y,w)=>{R(y,L=>{w!==void 0&&n!==null&&ho(e,n,o,w,L)||(L.rowLocal=!0,L.rootFallback=!0)})},ee=(y,w)=>{R(y,L=>{(n===null||!ho(e,n,o,w,L))&&(o===void 0?(n!==null&&Kt(L,w.root),L.rootFallback=!0):(L.rowLocal=!0,L.rootFallback=!0))})},oe=(y,w)=>{if(o===void 0||Re(w)!==o.itemParam)return!1;let L=Pe(w);if(L===null)return o.itemPath.length===0?k(y):T(y),!0;let ie=L.split(".").slice(1);return o.itemPath.some((Ae,Ne)=>ie[Ne]!==Ae)?!1:(ie.splice(0,o.itemPath.length),Xt(ie,o.keyPath)?k(y):(R(y,Ae=>{Ae.rowLocal=!0}),ri(e,n,o)&&k(y)),!0)},ue=(y,w)=>{if(w.locality==="instance"){R(y,L=>{C(L,w.root)});return}if(w.locality==="row"){if(o===void 0){R(y,ie=>{ie.rootFallback=!0});return}if(w.key===null){o.itemPath.length===0?k(y):T(y);return}let L=W(w.key);if(L===null){T(y,w);return}Xt(L,o.keyPath)?k(y):(R(y,ie=>{ie.rowLocal=!0}),ri(e,n,o)&&k(y));return}if(w.locality==="prop"){ee(y,w);return}if(w.stateKind==="computed")throw y.buildCodeFrameError(`memo-dom: cannot mutate computed '${w.root}' (R13) - it is derived; write its SOURCE state instead`);if(w.stateKind!=="store"){R(y,L=>{L.writes.add(w.root)});return}w.key!==null&&w.key.includes(".")?R(y,L=>{L.writes.add(w.key)}):R(y,L=>{L.writes.add(w.root)})},me=(y,w)=>{if(w.locality==="instance"){R(y,L=>{C(L,w.root)});return}if(w.locality==="row"){if(o===void 0){R(y,Ae=>{Ae.rootFallback=!0});return}if(w.key===null){o.itemPath.length===0?k(y):T(y);return}let L=W(w.key);if(L===null){T(y,w);return}L.length===0&&(o.keyPath===null||o.keyPath.length>0)?k(y):ue(y,w);return}if(w.locality==="prop"){ee(y,w);return}if(w.stateKind==="computed"){R(y,L=>{L.writes.add(w.root)});return}R(y,L=>{L.writes.add(w.key??w.root)})},de=(y,w)=>{if(!(s&&y.getFunctionParent()?.node===l))for(let L of In(w)){if(!M.isIdentifier(L))continue;let ie=f.resolveExpression(y.scope,L);ie!==null&&(g(ie)||me(y,ie))}},G=(y,w)=>{let L=Re(w);if(L!==void 0&&u?.has(L??"")===!0){let Ne=h?.get(L),We=Ne===void 0?null:Ba(w,Ne);R(y,bn=>{C(bn,L,We===null?"structural":"targeted")}),Ne!==void 0&&We!==null&&N(y,Ne,We);return}if(L!==null&&c?.has(L)&&!m.has(L))throw y.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${L}' (R14) \u2014 write its source instead`);if(oe(y,w))return;let ie=f.resolveExpression(y.scope,w);if(ie!==null){ue(y,ie);return}if(L!==null&&E.has(L)){ee(y,{locality:"prop",root:L,key:Pe(w)});return}if(L!==null&&b.has(L)||!L||!e.state.has(L))return;let Ae=e.state.get(L);if(Ae==="computed")throw y.buildCodeFrameError(`memo-dom: cannot mutate computed '${L}' (R13) \u2014 it is derived; write its SOURCE state instead`);R(y,Ne=>{if(Ae!=="store"){Ne.writes.add(L);return}let We=Pe(w);We!==null&&We.includes(".")?Ne.writes.add(We):Ne.writes.add(L)})};oi(d,{VariableDeclarator(y){if(!M.isIdentifier(y.node.id)&&y.node.init!==null)for(let w of f.referencedOrigins(y.scope,y.node.init))me(y,w)},AssignmentExpression(y){let w=y.node.left;if(M.isIdentifier(w)){if(v.has(w.name)){if(M.isIdentifier(y.node.right)){let ie=f.resolveExpression(y.scope,y.node.right);ie!==null&&me(y,ie)}return}if(c?.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot assign per-instance derivation '${w.name}' (R14) \u2014 write its source instead`);if(u?.has(w.name)===!0){R(y,ie=>{C(ie,w.name)});return}if(E.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot assign prop '${w.name}' \u2014 copy it to component-local let state first`);if(b.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot assign component-local const '${w.name}'`);let L=e.state.get(w.name);if(!L)throw y.buildCodeFrameError(`memo-dom: handler assigns '${w.name}', which is neither module state nor a handler local \u2014 declare it at module level (let) or inside the handler`);if(e.importedState.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot reassign imported state '${w.name}' - ES module imports are read-only; export a mutator or mutate an imported store property`);if(L==="store")throw y.buildCodeFrameError(`memo-dom: cannot reassign store '${w.name}' \u2014 assign a property (${w.name}.field = \u2026) instead`);if(L==="const")throw y.buildCodeFrameError(`memo-dom: cannot reassign mutable const root '${w.name}' - mutate the object instead`);if(L==="computed")throw y.buildCodeFrameError(`memo-dom: cannot assign computed '${w.name}' (R13) \u2014 it is derived; write its SOURCE state instead and the derivation recomputes`);R(y,ie=>{ie.writes.add(w.name)})}else if(M.isMemberExpression(w))G(y,w);else for(let L of f.referencedOrigins(y.scope,y.node.right))me(y,L)},UpdateExpression(y){let w=y.node.argument;if(M.isIdentifier(w)){if(v.has(w.name))return;if(c?.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot update per-instance derivation '${w.name}' (R14) \u2014 write its source instead`);if(u?.has(w.name)===!0){R(y,ie=>{C(ie,w.name)});return}if(E.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot update prop '${w.name}' \u2014 copy it to component-local let state first`);if(b.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot update component-local const '${w.name}'`);let L=e.state.get(w.name);if(!L)throw y.buildCodeFrameError(`memo-dom: handler updates '${w.name}', which is neither module state nor a handler local`);if(e.importedState.has(w.name))throw y.buildCodeFrameError(`memo-dom: cannot update imported state '${w.name}' - ES module imports are read-only; call an exported mutator instead`);if(L!=="let")throw y.buildCodeFrameError(L==="computed"?`memo-dom: cannot update computed '${w.name}' (R13) \u2014 it is derived; write its SOURCE state instead`:`memo-dom: cannot update '${w.name}' \u2014 it is a const binding; mutate its contents instead`);R(y,ie=>{ie.writes.add(w.name)})}else M.isMemberExpression(w)&&G(y,w)},UnaryExpression(y){y.node.operator==="delete"&&M.isMemberExpression(y.node.argument)&&G(y,y.node.argument)},CallExpression(y){let w=y.node.callee;if(M.isMemberExpression(w)){let L=Fn(w);if(L==="assign"&&M.isIdentifier(w.object,{name:"Object"})){let Ne=y.node.arguments[0],We=Ne!==void 0&&M.isExpression(Ne)?f.resolveExpression(y.scope,Ne):null;if(We!==null)if(We.locality==="module"&&We.stateKind==="store"){let bn=Rn(We,y.node.arguments.slice(1));bn===null?me(y,We):R(y,ys=>{for(let xs of bn)ys.writes.add(xs)})}else ue(y,We);return}if(L!==null&&Ta.has(L)&&M.isIdentifier(w.object)&&u?.has(w.object.name)===!0&&h?.has(w.object.name)===!0){let Ne=w.object.name;R(y,We=>{C(We,Ne,"topology")});return}let ie=M.isIdentifier(w.object)?w.object.name:M.isMemberExpression(w.object)?Re(w.object):null;if(ie!==null&&c?.has(ie)&&!m.has(ie)){R(y,Ne=>{C(Ne,ie)});return}let Ae=M.isExpression(w.object)?f.resolveExpression(y.scope,w.object):null;Ae!==null?me(y,Ae):de(y,y.node.arguments);return}if(M.isIdentifier(w)&&!b.has(w.name)&&(e.helpers.has(w.name)||e.importedFunctions.has(w.name))){let L=e.importedFunctions.get(w.name)??Be(e,w.name);R(y,ie=>{for(let Ne of L.writes)ie.writes.add(Ne);for(let Ne of L.boundedWrites)ie.writes.add(Ne);let Ae=s&&y.getFunctionParent()?.node===l;L.unbounded&&!Ae&&(ie.rootFallback=!0)});for(let ie of L.parameterWrites){let Ae=y.node.arguments[ie.index];if(Ae===void 0||!M.isExpression(Ae))continue;let Ne=f.resolveExpression(y.scope,Ae);if(Ne!==null){if(g(Ne))continue;me(y,vt(Ne,ie.path))}}return}de(y,y.node.arguments)}}),Wa(e,t,a,l,$,_,n,o,r,i,s)}function ii(e){let t=0,n=e;for(;n.parentPath!==null;)t++,n=n.parentPath;return t}function za(e,t,n){if(t.isAssignmentExpression({operator:"="})&&(M.isIdentifier(t.node.left)||M.isMemberExpression(t.node.left)&&!M.isSuper(t.node.left.object)&&!M.isPrivateName(t.node.left.property))){let r=t.node,i=J(e,"previousValue"),s=J(e,"assignedValue"),a=[i,s],l,d,u;if(M.isIdentifier(r.left))l=M.identifier(r.left.name),d=M.cloneNode(r,!0),u=M.identifier(r.left.name);else if(M.isMemberExpression(r.left)){let c=J(e,"assignmentReceiver"),m=J(e,"assignmentProperty");a.push(c,m);let E=()=>M.memberExpression(M.cloneNode(c),M.cloneNode(m),!0),b=r.left.computed?M.cloneNode(r.left.property,!0):M.stringLiteral(r.left.property.name);l=M.sequenceExpression([M.assignmentExpression("=",M.cloneNode(c),M.cloneNode(r.left.object,!0)),M.assignmentExpression("=",M.cloneNode(m),b),E()]),d=M.assignmentExpression("=",E(),M.cloneNode(r.right,!0)),u=E()}else return[];return t.replaceWith(M.sequenceExpression([M.assignmentExpression("=",M.cloneNode(i),l),M.assignmentExpression("=",M.cloneNode(s),d),M.assignmentExpression("=",M.cloneNode(n),M.logicalExpression("||",M.cloneNode(n),M.callExpression(ne(e,"effectAssignmentChanged"),[M.cloneNode(i),u]))),M.cloneNode(s)])),a}let o=M.assignmentExpression("=",M.cloneNode(n),M.booleanLiteral(!0));if(t.isVariableDeclarator()){let r=t.node.init;if(r===null||!M.isExpression(r))throw new Error("memo-dom: execution-aware variable site has no expression initializer");return t.node.init=M.sequenceExpression([o,r]),[]}if(!t.isExpression())throw new Error(`memo-dom: unsupported execution-aware write site '${t.node.type}'`);return t.replaceWith(M.sequenceExpression([o,t.node])),[]}import*as gt from"@babel/types";function si(e,t){let n=!1,o=!0,r=i=>{if(o&&!(i!==e&>.isFunction(i))){if((gt.isCallExpression(i)||gt.isOptionalCallExpression(i))&&(n=!0,!gt.isIdentifier(i.callee)||!t(i.callee.name))){o=!1;return}for(let s of gt.VISITOR_KEYS[i.type]??[]){let a=i[s];if(Array.isArray(a))for(let l of a)l!==null&&typeof l=="object"&&"type"in l&&r(l);else a!==null&&typeof a=="object"&&"type"in a&&r(a)}}};return r(e),n&&o}function St(e,t){let o=e.scope.getBinding(t)?.path;if(!o||o.getFunctionParent()!==e)return null;if(o.isFunctionDeclaration())return o.node;if(!o.isVariableDeclarator())return null;let r=o.node.init;return r&&(Ie.isArrowFunctionExpression(r)||Ie.isFunctionExpression(r))?r:null}function ct(e,t,n,o,r,i=!1){e.analyzedFunctions.has(n)||(yo(e,t,n,o,r),e.analyzedFunctions.add(n),cn(e,n,o,r,!1,void 0,i))}function un(e,t,n=!1){e.analyzedFunctions.has(t)||(e.analyzedFunctions.add(t),cn(e,t,null,void 0,!1,void 0,n))}function yo(e,t,n,o,r){let i=new Set;Oe(n.body,s=>{Ie.isCallExpression(s)&&Ie.isIdentifier(s.callee)&&i.add(s.callee.name)});for(let s of i){let a=St(t,s);a===null||e.analyzedFunctions.has(a)||(e.analyzedFunctions.add(a),yo(e,t,a,o,r),cn(e,a,o,r,!1))}}function xo(e,t,n,o,r,i,s){let a=null,l=!1,d=e.componentProps.get(r),u=d===void 0?null:qe(d);if(d!==void 0&&(Ie.isIdentifier(n)&&Ye(d,n.name)!==null||Ie.isMemberExpression(n)&&u!==null&&Re(n)===u))return Ut(e,n,Ft(e,r,i,s));if(Ie.isArrowFunctionExpression(n)||Ie.isFunctionExpression(n))a=n;else if(Ie.isIdentifier(n)){let m=e.importedFunctions.get(n.name);if(m!==void 0){let f=Ot();for(let g of m.writes)f.writes.add(g);for(let g of m.boundedWrites)f.writes.add(g);return f.rootFallback=m.unbounded,Ut(e,n,Ht(e,f,null)??Ft(e,r,i,s))}let E=t.scope.getBinding(n.name),b=E?.path;if(b&&b.isVariableDeclarator()){let f=b.node.init;f&&(Ie.isArrowFunctionExpression(f)||Ie.isFunctionExpression(f))&&(a=f,l=E?.scope.path.isProgram()===!0&&e.helpers.has(n.name))}else b&&b.isFunctionDeclaration()&&(e.helpers.has(n.name)?(a=b.node,l=!0):a=St(t,n.name));if(!a)throw t.buildCodeFrameError(`memo-dom: cannot resolve handler '${n.name}' \u2014 use an inline arrow, a component-local const, or a module-level function (L1)`)}else throw t.buildCodeFrameError(`memo-dom: unsupported ${o} handler form \u2014 expected an arrow function or a function reference (L1)`);if(Ie.isBlockStatement(a.body)||(a.body=Ie.blockStatement([Ie.expressionStatement(a.body)])),!e.analyzedFunctions.has(a)){l||yo(e,t,a,r,i);let m=!l&&!Ie.isIdentifier(n)&&si(a,E=>{let b=St(t,E);return b!==null&&e.handlerHasRootCommit.get(b)===!0});e.analyzedFunctions.add(a),cn(e,a,l?null:r,l?void 0:i,!l&&!Ie.isIdentifier(n)&&!m,s)}if(l){let m=Be(e,n.name);if(a.async){let E=Ot();for(let b of m.writes)E.writes.add(b);for(let b of m.boundedWrites)E.writes.add(b);return E.rootFallback=m.unbounded,Ut(e,n,Ht(e,E,null)??Ft(e,r,i,s))}if(m.writes.size===0&&m.boundedWrites.size===0&&!m.unbounded)return Ut(e,n,Ft(e,r,i,s))}return Ie.isIdentifier(n)&&!l&&(e.handlerHasRootCommit.get(a)===!1||a.async)?Ut(e,n,Ft(e,r,i,s)):Ie.isIdentifier(n)?n:a}import*as Me from"@babel/types";function So(e,t){let n=[];for(let o of e){if(Me.isJSXText(o)){let a=ro(o.value);a!==""&&n.push({type:"node",variable:t.emitText(Me.stringLiteral(a))});continue}if(Me.isJSXElement(o)||Me.isJSXFragment(o)){n.push({type:"node",variable:t.emitNode(o)});continue}if(Me.isJSXExpressionContainer(o)||t.fail("memo-dom: spread children are not supported"),Me.isJSXEmptyExpression(o.expression))continue;Me.isExpression(o.expression)||t.fail("memo-dom: unsupported expression in JSX child position");let r=o.expression;if(t.isForwarded(r)){n.push({type:"slot",expression:Me.cloneNode(r)});continue}if(Me.isNullLiteral(r)||Me.isBooleanLiteral(r)||Me.isIdentifier(r,{name:"undefined"}))continue;let i=Ke(r);if(i!==null){n.push({type:"list",expression:i});continue}let s=vn(r);if(s!==null&&fe(s)){n.push({type:"condition",expression:s});continue}n.push({type:"node",variable:t.emitText(Me.cloneNode(r))})}return n}import*as q from"@babel/types";var Ka=new Set(["innerHTML","checked","value","selected","disabled","hidden","multiple","required","readOnly","muted","open","controls","loop","autoFocus","autoPlay","tabIndex"]),ai={htmlFor:"for",crossOrigin:"crossorigin"};function Co(e,t){return!t&&Ka.has(e)?e:null}function wo(e,t){return!t&&e in ai}function Po(e,t,n){let o=q.identifier(e);if(t==="tabIndex")return q.isStringLiteral(n)?q.expressionStatement(q.assignmentExpression("=",q.memberExpression(o,q.identifier(t)),q.cloneNode(n))):q.expressionStatement(q.conditionalExpression(q.binaryExpression("==",q.cloneNode(n),q.nullLiteral()),q.callExpression(q.memberExpression(q.cloneNode(o),q.identifier("removeAttribute")),[q.stringLiteral("tabindex")]),q.assignmentExpression("=",q.memberExpression(q.cloneNode(o),q.identifier(t)),q.cloneNode(n))));let r=t==="value"||t==="innerHTML"?q.stringLiteral(""):q.booleanLiteral(!1),i=q.isStringLiteral(n)?q.cloneNode(n):q.conditionalExpression(q.binaryExpression("==",q.cloneNode(n),q.nullLiteral()),r,q.cloneNode(n));return q.expressionStatement(q.assignmentExpression("=",q.memberExpression(o,q.identifier(t)),i))}function Kn(e,t,n){let o=q.identifier(e),r=ai[t]??t;return q.isStringLiteral(n)?q.expressionStatement(q.callExpression(q.memberExpression(o,q.identifier("setAttribute")),[q.stringLiteral(r),q.cloneNode(n)])):q.expressionStatement(q.conditionalExpression(q.logicalExpression("||",q.binaryExpression("==",q.cloneNode(n),q.nullLiteral()),q.binaryExpression("===",q.cloneNode(n),q.booleanLiteral(!1))),q.callExpression(q.memberExpression(q.cloneNode(o),q.identifier("removeAttribute")),[q.stringLiteral(r)]),q.callExpression(q.memberExpression(o,q.identifier("setAttribute")),[q.stringLiteral(r),q.conditionalExpression(q.binaryExpression("===",q.cloneNode(n),q.booleanLiteral(!0)),q.stringLiteral(""),q.callExpression(q.identifier("String"),[q.cloneNode(n)]))])))}import*as Ge from"@babel/types";var Ha="http://www.w3.org/2000/svg",Ua=new Set(["animate","animateMotion","animateTransform","circle","clipPath","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","switch","symbol","text","textPath","tspan","use","view"]);function li(e,t){return t||e==="svg"||Ua.has(e)}function di(e,t){return t?Ge.callExpression(Ge.memberExpression(Ge.identifier("document"),Ge.identifier("createElementNS")),[Ge.stringLiteral(Ha),Ge.stringLiteral(e)]):Ge.callExpression(Ge.memberExpression(Ge.identifier("document"),Ge.identifier("createElement")),[Ge.stringLiteral(e)])}import*as Ee from"@babel/types";function Hn(e,t,n){let o=e.componentProps.get(t);if(o?.mode==="object"){if(!o.acceptsUnknown){for(let s of n)if(!o.names.includes(s.name))throw new Error(`memo-dom: unknown prop '${s.name}' on <${t}> - declared props: ${o.names.length>0?o.names.join(", "):"(none)"}`)}return n.length===0&&o.hasWholeDefault?[Ee.identifier("undefined")]:[Ee.objectExpression(n.map(s=>Ee.objectProperty(Ee.identifier(s.name),s.value,!1,Ee.isIdentifier(s.value)&&s.value.name===s.name)))]}let r=o?.names;if(r===void 0)return n.map(s=>s.value);let i=new Map(n.map(s=>[s.name,s.value]));for(let s of i.keys())if(!r.includes(s))throw new Error(`memo-dom: unknown prop '${s}' on <${t}> - declared props: ${r.length>0?r.join(", "):"(none)"}`);return r.map(s=>i.get(s)??Ee.identifier("undefined"))}function qt(e,t,n){let o=e.componentProps.get(t);return o?.mode==="object"?[Ee.cloneNode(n)]:(o?.names??[]).map(r=>Ee.memberExpression(Ee.cloneNode(n),Ee.isValidIdentifier(r)?Ee.identifier(r):Ee.stringLiteral(r),!Ee.isValidIdentifier(r)))}function ci(e,t,n,o,r){let i=J(e,`${t}Props`);return Ee.blockStatement([Ee.variableDeclaration("const",[Ee.variableDeclarator(Ee.cloneNode(i),Ee.cloneNode(r))]),Ee.expressionStatement(Ee.callExpression(ne(e,"setProps"),[Ee.binaryExpression("+",Ee.cloneNode(n),Ee.stringLiteral(o)),Ee.arrayExpression(qt(e,t,i))]))])}import*as Le from"@babel/types";function _t(e){return(Le.isArrowFunctionExpression(e)||Le.isFunctionExpression(e))&&!qa(e.body)}function vo(e,t,n,o="callback"){let r=J(e,o);return t.creation.push(Le.variableDeclaration("const",[Le.variableDeclarator(Le.cloneNode(r),Le.cloneNode(n,!0))])),r}function ko(e,t,n,o="callback"){let r=J(e,o);return t.push(Le.variableDeclaration("const",[Le.variableDeclarator(Le.cloneNode(r),Le.cloneNode(n,!0))])),r}function qa(e){let t=!1;return Le.traverseFast(e,n=>{if(Le.isJSXElement(n)||Le.isJSXFragment(n))return t=!0,Le.traverseFast.stop}),t}import*as te from"@babel/types";function ui(e,t,n,o,r,i,s,a=!1,l=Te(e,r),d=!1){let u=kn(n,i,t.usedConds),c=J(e,u.suffix).name,m=te.binaryExpression("+",te.cloneNode(l),te.stringLiteral(`/${u.suffix}`)),E=te.arrowFunctionExpression([],te.cloneNode(u.pickExpr)),b=u.branches.map(f=>f!==null?pn(e,f,r,i,m,s,a,m,!1,t.usedConds):te.nullLiteral());t.creation.push(ft(e,te.cloneNode(m),te.cloneNode(l),te.arrowFunctionExpression([],te.callExpression(te.memberExpression(te.identifier(c),te.identifier("update")),[])))),t.creation.push(te.variableDeclaration("const",[te.variableDeclarator(te.identifier(c),te.callExpression(ne(e,"createCondRegion"),[te.identifier(o),te.cloneNode(m),E,te.arrayExpression(b)]))])),(d||e.volatileComponents.has(r)||qo(e,n,r))&&t.updaters.push(()=>te.expressionStatement(te.callExpression(te.memberExpression(te.identifier(c),te.identifier("update")),[]))),t.disposableRegions.push(c),t.disposableEntities.push(te.cloneNode(m))}function pn(e,t,n,o,r,i,s=!1,a=r,l=!1,d){let u=st(e,!0);d!==void 0&&(u.usedConds=d);let c=i(e,u,t,n,o,l?null:"cond",void 0,r,s,a),m=[te.objectProperty(te.identifier("nodes"),te.callExpression(ne(e,"rootNodes"),[te.identifier(c)])),te.objectProperty(te.identifier("update"),te.identifier(u.updateVar))];if(u.disposableRegions.length>0||u.disposableEntities.length>0||u.disposableCallbacks.length>0){let E=[...[...u.disposableCallbacks].reverse().map(b=>te.ifStatement(te.binaryExpression("!==",te.cloneNode(b),te.nullLiteral()),te.expressionStatement(te.callExpression(te.cloneNode(b),[])))),...u.disposableRegions.map(b=>te.expressionStatement(te.callExpression(te.memberExpression(te.identifier(b),te.identifier("dispose")),[]))),...u.disposableEntities.map(b=>te.expressionStatement(te.callExpression(ne(e,"unregisterSubtree"),[te.cloneNode(b)])))];m.push(te.objectProperty(te.identifier("dispose"),te.arrowFunctionExpression([],te.blockStatement(E))))}return te.arrowFunctionExpression([],te.blockStatement([at(u),lt(u),...u.creation,...u.mounts,te.returnStatement(te.objectExpression(m))]))}import*as p from"@babel/types";import*as H from"@babel/types";function Ct(e,t,n,o){return H.isArrayExpression(o)?H.arrayExpression(o.elements.map(r=>{if(r===null)return null;if(H.isSpreadElement(r))throw t.buildCodeFrameError("memo-dom: ref arrays must have a static shape; nested arrays are supported but array spreads are not");return Ct(e,t,n,r)})):_a(e,n,o)?H.cloneNode(o,!0):Ga(t,o)||H.isMemberExpression(o)?pi(e,o):H.cloneNode(o,!0)}function No(e,t,n,o,r){let i=J(e,"refDispose");t.mounts.push(H.variableDeclaration("const",[H.variableDeclarator(H.cloneNode(i),H.callExpression(ne(e,"mountRef"),[H.cloneNode(n,!0),H.cloneNode(r,!0)]))])),t.manualDisposal?t.disposableCallbacks.push(i):t.mounts.push(H.expressionStatement(H.callExpression(ne(e,"cleanup"),[H.cloneNode(o,!0),H.cloneNode(i)])))}function _a(e,t,n){let o=yt(e,t,n);return o!==null&&e.componentProps.get(t)?.refProps.includes(o)===!0}function Ga(e,t){if(!H.isIdentifier(t)||t.name==="undefined")return!1;let n=e.scope.getBinding(t.name);if(n===void 0||n.path.isFunctionDeclaration()||n.path.isImportSpecifier()||n.path.isImportDefaultSpecifier()||n.path.isImportNamespaceSpecifier())return!1;if(n.path.isVariableDeclarator()){if(n.path.parentPath.isVariableDeclaration({kind:"const"}))return!1;let r=n.path.node.init;if(H.isFunctionExpression(r)||H.isArrowFunctionExpression(r))return!1}return n.kind!=="param"}function pi(e,t){let n=J(e,"refNode");if(H.isMemberExpression(t)){let o=J(e,"refTarget"),r=t.computed?J(e,"refKey"):null,i=()=>H.memberExpression(H.cloneNode(o),r===null?H.cloneNode(t.property,!0):H.cloneNode(r),t.computed);return H.arrowFunctionExpression([H.cloneNode(n)],H.blockStatement([H.variableDeclaration("const",[H.variableDeclarator(H.cloneNode(o),H.cloneNode(t.object,!0)),...r===null?[]:[H.variableDeclarator(H.cloneNode(r),H.cloneNode(t.property,!0))]]),H.expressionStatement(H.assignmentExpression("=",i(),H.cloneNode(n))),H.returnStatement(H.arrowFunctionExpression([],H.blockStatement([H.ifStatement(H.binaryExpression("===",i(),H.cloneNode(n)),H.expressionStatement(H.assignmentExpression("=",i(),H.identifier("undefined"))))])))]))}return H.arrowFunctionExpression([H.cloneNode(n)],H.blockStatement([H.expressionStatement(H.assignmentExpression("=",H.cloneNode(t,!0),H.cloneNode(n))),H.returnStatement(H.arrowFunctionExpression([],H.blockStatement([H.ifStatement(H.binaryExpression("===",H.cloneNode(t,!0),H.cloneNode(n)),H.expressionStatement(H.assignmentExpression("=",H.cloneNode(t,!0),H.identifier("undefined"))))])))]))}import*as V from"@babel/types";var Za=new Set(["setClassValue","setStyleValue","setDomValue"]);function Gt(e,t,n){if(t.mounts.length!==0||t.disposableRegions.length!==0||t.disposableEntities.length!==0||t.disposableCallbacks.length!==0)return!1;let o=[],r=new Set;for(let h of t.creation){if(!V.isVariableDeclaration(h))continue;let C=Qa(h);if(C===null)return!1;o.push(C),r.add(C.name)}if(!r.has(n)||o.length<2)return!1;let i=new Map,s=new Map;for(let h of t.creation){let C=fi(h);if(C===null)continue;if(!r.has(C.parent)||!r.has(C.child))return!1;let N=s.get(C.parent)??0;s.set(C.parent,N+1),i.set(C.child,{parent:C.parent,index:N})}let a=new Map;for(let h of r){let C=el(h,n,i);if(C===null)return!1;a.set(h,C)}let l=[],d=[];for(let h of t.creation)V.isVariableDeclaration(h)||nl(h,r)?l.push(V.cloneNode(h,!0)):d.push(h);let u=J(e,`${n}Template`);e.header.push(V.variableDeclaration("let",[V.variableDeclarator(V.cloneNode(u))]));let c=V.callExpression(V.arrowFunctionExpression([],V.blockStatement([...l,V.returnStatement(V.identifier(n))])),[]),m=V.conditionalExpression(V.binaryExpression("===",V.cloneNode(u),V.unaryExpression("void",V.numericLiteral(0))),V.assignmentExpression("=",V.cloneNode(u),c),V.cloneNode(u)),E=V.callExpression(V.memberExpression(m,V.identifier("cloneNode")),[V.booleanLiteral(!0)]),b=new Set([n]);for(let h of d)Oe(h,C=>{V.isIdentifier(C)&&r.has(C.name)&&b.add(C.name)});let f=[],g=o.filter(({name:h})=>b.has(h)).sort((h,C)=>a.get(h.name).length-a.get(C.name).length).map(({name:h})=>{let C=a.get(h),N;if(h===n)N=V.cloneNode(E,!0);else{let v=f[0];for(let $ of f)$.path.length>v.path.length&&Ya($.path,C)&&(v=$);N=tl(v.name,C.slice(v.path.length))}return f.push({name:h,path:C}),V.variableDeclaration("const",[V.variableDeclarator(V.identifier(h),N)])});return t.creation=[...g,...d],!0}function Ya(e,t){return e.length<=t.length&&e.every((n,o)=>t[o]===n)}function Qa(e){if(e.declarations.length!==1)return null;let t=e.declarations[0];if(!V.isIdentifier(t.id)||!V.isCallExpression(t.init)||!V.isMemberExpression(t.init.callee)||!V.isIdentifier(t.init.callee.object,{name:"document"})||!V.isIdentifier(t.init.callee.property))return null;let n=t.init.callee.property.name;if(n!=="createElement"&&n!=="createElementNS"&&n!=="createTextNode")return null;let o=t.init.arguments.at(-1);return(n==="createElement"||n==="createElementNS")&&V.isStringLiteral(o)&&o.value.includes("-")?null:{name:t.id.name,statement:e}}function fi(e){return!V.isExpressionStatement(e)||!V.isCallExpression(e.expression)||!V.isMemberExpression(e.expression.callee)||!V.isIdentifier(e.expression.callee.object)||!V.isIdentifier(e.expression.callee.property,{name:"appendChild"})||e.expression.arguments.length!==1||!V.isIdentifier(e.expression.arguments[0])?null:{parent:e.expression.callee.object.name,child:e.expression.arguments[0].name}}function el(e,t,n){if(e===t)return[];let o=[],r=new Set,i=e;for(;i!==t;){if(r.has(i))return null;r.add(i);let s=n.get(i);if(s===void 0)return null;o.push(s.index),i=s.parent}return o.reverse(),o}function tl(e,t){let n=V.identifier(e);for(let o of t){n=V.memberExpression(n,V.identifier("firstChild"));for(let r=0;r<o;r++)n=V.memberExpression(n,V.identifier("nextSibling"))}return n}function nl(e,t){let n=fi(e);if(n!==null)return t.has(n.parent)&&t.has(n.child);if(!V.isExpressionStatement(e))return!1;let o=e.expression;return!!(V.isCallExpression(o)&&V.isMemberExpression(o.callee)&&(V.isIdentifier(o.callee.object)&&t.has(o.callee.object.name)&&V.isIdentifier(o.callee.property,{name:"setAttribute"})&&o.arguments.every(r=>V.isExpression(r)&&Un(r))||V.isIdentifier(o.callee.object)&&V.isIdentifier(o.callee.property)&&Za.has(o.callee.property.name)&&o.arguments.length>=2&&V.isIdentifier(o.arguments[0])&&t.has(o.arguments[0].name)&&o.arguments.slice(1).every(r=>V.isExpression(r)&&Un(r))))}function Un(e){return V.isStringLiteral(e)||V.isNumericLiteral(e)||V.isBooleanLiteral(e)||V.isNullLiteral(e)?!0:V.isArrayExpression(e)?e.elements.every(t=>t===null||V.isExpression(t)&&Un(t)):V.isObjectExpression(e)?e.properties.every(t=>V.isObjectProperty(t)&&!t.computed&&V.isExpression(t.value)&&Un(t.value)):!1}function fn(e,t){let n=p.cloneNode(e);return t?p.logicalExpression("??",n,p.arrayExpression([])):n}function mi(e,t,n,o,r,i,s,a,l=!1,d=Te(e,r),u){let c=At(e,n,i,r,t.usedPrefixes,u===void 0?void 0:{itemParam:u.itemParam,sourceKey:u.sourceKey,sourceLocal:u.sourceLocal??!1}),m=J(e,`region${t.regionCounter++}`).name,E=new Map,b=c.form==="inline"?zt(c.jsx):c.form==="component"&&Nt(e,c.rowComp)?e.importedComponents.get(c.rowComp)?.delegatedEvents??e.componentHostEvents.get(c.rowComp)??[]:[];for(let $ of b){let _=J(e,`${$}Binding`);E.set($,_),t.creation.push(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(_),p.callExpression(ne(e,"createDelegatedEventBinding"),[p.identifier(o),p.stringLiteral($)]))]))}let f=c.form==="callback"?rl(e,c):c.form==="component"?sl(e,c,r,i,a,l,d,E):al(e,c,r,i,s,l,d,E),g=[p.identifier(o),p.binaryExpression("+",p.cloneNode(d),p.stringLiteral(`/${c.suffix}`)),f];if(c.form==="callback"){let $=p.memberExpression(p.cloneNode(c.renderCallback,!0),p.identifier("key"));g.push(p.arrowFunctionExpression([p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]],p.conditionalExpression(p.binaryExpression("==",p.cloneNode($),p.nullLiteral()),p.cloneNode(c.itemPattern,!0),p.callExpression(p.cloneNode($),[p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]]))))}else c.keyExpr!==null&&g.push(p.arrowFunctionExpression([p.cloneNode(c.itemPattern,!0),...c.indexParam===null?[]:[p.identifier(c.indexParam)]],p.cloneNode(c.keyExpr)));c.form==="component"&&Nt(e,c.rowComp)&&(g.length===3&&g.push(p.identifier("undefined")),g.push(p.booleanLiteral(!1))),t.creation.push(p.variableDeclaration("const",[p.variableDeclarator(p.identifier(m),p.callExpression(ne(e,"createListRegion"),g))])),t.disposableRegions.push(m);let h=e.targetedListDependencies.get(n)??[],C=e.keyedListMutations.get(n);C!==void 0&&t.creation.push(p.variableDeclaration("const",[p.variableDeclarator(p.identifier(C.keysVariable),p.newExpression(p.identifier("Set"),[]))]));let N=h.map($=>({dependency:$,cache:J(e,`${$.value}ListKey`).name}));N.length>0&&t.creation.push(p.variableDeclaration("let",N.map(({dependency:$,cache:_})=>p.variableDeclarator(p.identifier(_),p.identifier($.value)))));let v=()=>p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(m),p.identifier("reconcile")),[fn(c.sourceExpr,c.optional)]));t.creation.push(v()),N.length===0&&C===void 0||t.reasonVar===null?t.updaters.push(v):t.updaters.push(()=>ol(e,r,t.reasonVar,m,c.sourceExpr,c.optional,N,C,c.indexParam===null))}function ut(e,t){let n=()=>p.identifier(e),o=()=>p.valueToNode(t);return p.logicalExpression("||",p.binaryExpression("===",n(),o()),p.logicalExpression("&&",p.binaryExpression("!==",n(),p.nullLiteral()),p.logicalExpression("&&",p.binaryExpression("!==",p.unaryExpression("typeof",n()),p.stringLiteral("number")),p.callExpression(p.memberExpression(n(),p.identifier("has")),[o()]))))}function Ro(e,t){return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(e),p.identifier("refreshKey")),[t]))}function ol(e,t,n,o,r,i,s,a,l){let d=e.instanceReasonIds.get(t);if(d===void 0)return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(o),p.identifier("reconcile")),[fn(r,i)]));let u=a?.source??s[0]?.dependency.source,c=u===void 0?void 0:d.get(u);if(c===void 0)return p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(o),p.identifier("reconcile")),[fn(r,i)]));let m=[p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(o),p.identifier("reconcile")),[fn(r,i)])),...s.map(({dependency:h,cache:C})=>p.expressionStatement(p.assignmentExpression("=",p.identifier(C),p.identifier(h.value)))),...a===void 0?[]:[p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(a.keysVariable),p.identifier("clear")),[]))]],E=null;if(a!==void 0&&l){let h=d.get(a.topologyReason);if(h!==void 0){let C=ut(n,h);for(let N of[d.get(a.targetedReason),d.get(a.structuralReason),...s.map(({dependency:v})=>d.get(v.value))])N!==void 0&&(C=p.logicalExpression("&&",C,p.unaryExpression("!",ut(n,N))));E=p.ifStatement(C,p.blockStatement([p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(o),p.identifier("reconcile")),[fn(r,i),p.booleanLiteral(!1)]))]))}}let b=[];if(a!==void 0){let h=d.get(a.targetedReason);if(h!==void 0){let C=J(e,"changedListKey");b.push(p.ifStatement(ut(n,h),p.blockStatement([p.forOfStatement(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(C))]),p.identifier(a.keysVariable),p.blockStatement([Ro(o,p.cloneNode(C))])),p.expressionStatement(p.callExpression(p.memberExpression(p.identifier(a.keysVariable),p.identifier("clear")),[]))])))}}for(let{dependency:h,cache:C}of s){let N=d.get(h.value);if(N===void 0)continue;let v=J(e,"previousListKey");b.push(p.ifStatement(ut(n,N),p.blockStatement([p.variableDeclaration("const",[p.variableDeclarator(v,p.identifier(C))]),p.expressionStatement(p.assignmentExpression("=",p.identifier(C),p.identifier(h.value))),Ro(o,p.cloneNode(v)),p.ifStatement(p.unaryExpression("!",p.callExpression(p.memberExpression(p.identifier("Object"),p.identifier("is")),[p.cloneNode(v),p.identifier(C)])),Ro(o,p.identifier(C)))])))}let f=p.binaryExpression("===",p.identifier(n),p.nullLiteral());if(f=p.logicalExpression("||",f,ut(n,-1)),a!==void 0){let h=d.get(a.structuralReason),C=d.get(a.topologyReason),N=d.get(a.targetedReason);h!==void 0&&(f=p.logicalExpression("||",f,ut(n,h))),C!==void 0&&(f=p.logicalExpression("||",f,ut(n,C))),f=p.logicalExpression("||",f,N===void 0?ut(n,c):p.logicalExpression("&&",ut(n,c),p.unaryExpression("!",ut(n,N))))}else f=p.logicalExpression("||",f,ut(n,c));let g=p.ifStatement(f,p.blockStatement(m),b.length===0?void 0:p.blockStatement(b));return E===null?g:(E.alternate=g,E)}function rl(e,t){let n=J(e,"renderRowId");return p.arrowFunctionExpression([p.cloneNode(t.itemPattern,!0),p.cloneNode(n),...t.indexParam===null?[]:[p.identifier(t.indexParam)]],p.callExpression(p.memberExpression(p.cloneNode(t.renderCallback,!0),p.identifier("create")),[p.cloneNode(t.itemPattern,!0),p.cloneNode(n),...t.indexParam===null?[]:[p.identifier(t.indexParam)]]))}function il({ctx:e,site:t,rowComponent:n,rowId:o,nextItem:r,nextIndex:i,rowRefresh:s,rowScope:a,result:l,lightweight:d,needsUpdateProps:u,reuseLightweightEntry:c,lightweightPushProps:m,ownerId:E,eventBindings:b,prefixStatements:f,callProps:g,updateStatements:h}){let C=d?[p.objectProperty(p.identifier("nodes"),p.memberExpression(p.cloneNode(l),p.identifier("nodes"))),p.objectProperty(p.identifier("entities"),p.arrayExpression([])),p.objectProperty(p.identifier("update"),p.memberExpression(p.cloneNode(l),p.identifier("update"))),p.objectProperty(p.identifier("dispose"),p.memberExpression(p.cloneNode(l),p.identifier("dispose")))]:[p.objectProperty(p.identifier("nodes"),p.callExpression(ne(e,"rootNodes"),[p.cloneNode(l)])),p.objectProperty(p.identifier("entities"),p.arrayExpression([p.cloneNode(o)]))];return u&&!c&&C.push(p.objectProperty(p.identifier("updateProps"),p.arrowFunctionExpression([p.cloneNode(r),...i===null?[]:[p.cloneNode(i)]],p.blockStatement(h)))),p.arrowFunctionExpression([p.cloneNode(t.itemPattern,!0),p.cloneNode(o),...t.indexParam===null?[]:[p.identifier(t.indexParam)]],p.blockStatement([...a.updaters.length>0?[at(a),lt(a)]:[],...a.creation,...a.mounts,...f,p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(l),d?p.callExpression(p.identifier(n),[...g.map(N=>p.cloneNode(N)),p.cloneNode(o),...t.sourceLocal?[p.cloneNode(E)]:[],...[...b.values()].map(N=>p.cloneNode(N))]):p.callExpression(p.identifier(n),[p.cloneNode(o),p.cloneNode(E),...g.length>0?[p.arrayExpression(g)]:[]]))]),...a.updaters.length>0?[p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(s),p.arrowFunctionExpression([],p.blockStatement([p.expressionStatement(d?p.callExpression(p.memberExpression(p.cloneNode(l),p.identifier("update")),[]):p.callExpression(ne(e,"markDirty"),[p.cloneNode(o)])),p.expressionStatement(p.callExpression(p.identifier(a.updateVar),[]))])))])]:[],...m===null?[]:[p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(m),p.memberExpression(p.cloneNode(l),p.identifier("updateProps")))]),p.expressionStatement(p.assignmentExpression("=",p.memberExpression(p.cloneNode(l),p.identifier("updateProps")),p.arrowFunctionExpression([p.cloneNode(r),...i===null?[]:[p.cloneNode(i)]],p.blockStatement(h))))],p.returnStatement(c?p.cloneNode(l):p.objectExpression(C))]))}function sl(e,t,n,o,r,i=!1,s=Te(e,n),a=new Map){let l=t.rowComp,d=J(e,"rowId"),u=J(e,"nextItem"),c=t.indexParam===null?null:J(e,"nextIndex"),m=J(e,"refreshRow"),E=st(e),b=Nt(e,l),f={itemParam:t.itemParam,itemPath:[],rowIdVar:d.name,refreshVar:m.name,keyPath:it(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal&&p.isIdentifier(s)?{ownerIdVar:s.name}:{}},g=t.jsx.openingElement.attributes.filter(G=>p.isJSXSpreadAttribute(G)||De(G.name)!=="key"),h=g.some(G=>p.isJSXSpreadAttribute(G)),C=[],N=[],v=null,$=e.componentProps.get(l),_=b&&(e.linkedComponentRows.get(l)?.length??0)===0&&$!==void 0?Sn($):null,B=()=>{for(let{name:y}of C)if(!_.some(w=>w.name===y))throw o.buildCodeFrameError(`memo-dom: unknown prop '${y}' on <${l}> - declared props: ${_.map(w=>w.name).join(", ")}`);let G=new Map(C.map(({name:y,value:w})=>[y,w]));return _.map(({name:y})=>p.cloneNode(G.get(y)??p.identifier("undefined")))},R=G=>_.map(({name:y})=>p.memberExpression(p.cloneNode(G),p.isValidIdentifier(y)?p.identifier(y):p.stringLiteral(y),!p.isValidIdentifier(y))),k=G=>{let y=p.isJSXElement(G)||p.isJSXFragment(G)?[G]:[p.jsxExpressionContainer(G)];return r(e,E,y,n,o,"row",f,d,i,d)};if(h){v=an(g,{attributeValue:(G,y)=>G==="ref"||$?.refProps.includes(G)===!0?Ct(e,o,n,y):y,fail:G=>{throw o.buildCodeFrameError(G)}}).expression;for(let G of v.properties){if(!p.isObjectProperty(G)||G.computed||!p.isExpression(G.value))continue;let y=p.isIdentifier(G.key)?G.key.name:p.isStringLiteral(G.key)?G.key.value:null;if(y!==null)if($?.renderProps.includes(y)===!0){if(dt(e,n,G.value))continue;if(!fe(G.value))throw o.buildCodeFrameError(`memo-dom: render prop '${y}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);G.value=k(G.value)}else{if(fe(G.value))throw o.buildCodeFrameError(`memo-dom: JSX prop '${y}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);y!=="ref"&&$?.refProps.includes(y)!==!0&&_t(G.value)&&(ct(e,o,G.value,n,f,!0),G.value=ko(e,N,G.value,`${y}Callback`))}}}else for(let G of g){let y=G,w=De(y.name),L=y.value==null?p.booleanLiteral(!0):ze(y.value);if(L===null)throw o.buildCodeFrameError(`memo-dom: prop '${De(y.name)}' on <${l}> must be an expression`);if($?.renderProps.includes(w)===!0){if(dt(e,n,L)){C.push({name:w,value:p.cloneNode(L)});continue}if(!fe(L))throw o.buildCodeFrameError(`memo-dom: render prop '${w}' on <${l}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);C.push({name:w,value:k(L)});continue}if(w==="ref"||$?.refProps.includes(w)===!0){C.push({name:w,value:Ct(e,o,n,L)});continue}if(fe(L))throw o.buildCodeFrameError(`memo-dom: JSX prop '${w}' on <${l}> is not rendered by the callee; interpolate that prop in <${l}> to declare a render slot`);let ie=_t(L);if(ie)ct(e,o,L,n,f,!0);else if(p.isIdentifier(L)){let Ae=St(o,L.name);Ae!==null&&!fe(Ae.body)&&ct(e,o,Ae,n,f,!0)}C.push({name:w,value:ie?ko(e,N,L,`${w}Callback`):p.cloneNode(L)})}if(nn(t.jsx.children)){if(g.some(y=>p.isJSXAttribute(y)&&De(y.name)==="children"))throw o.buildCodeFrameError(`memo-dom: <${l}> cannot use both a children prop and nested JSX children`);let G=r(e,E,t.jsx.children,n,o,"row",f,d,i,d);v!==null?v.properties.push(p.objectProperty(p.identifier("children"),p.cloneNode(G))):C.push({name:"children",value:p.cloneNode(G)})}let W;if(v!==null){let G=J(e,`${l}Props`);N.push(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(G),p.cloneNode(v))])),W=_===null?qt(e,l,G):R(G)}else W=_===null?Hn(e,l,C):B();let T=[p.expressionStatement(p.assignmentExpression("=",p.cloneNode(t.itemPattern,!0),p.cloneNode(u)))];c!==null&&t.indexParam!==null&&T.push(p.expressionStatement(p.assignmentExpression("=",p.identifier(t.indexParam),p.cloneNode(c))));let ee=W.map(G=>p.cloneNode(G));if(v!==null){let G=J(e,`next${l}Props`);T.push(p.variableDeclaration("const",[p.variableDeclarator(p.cloneNode(G),p.cloneNode(v))])),ee=_===null?qt(e,l,G):R(G)}let oe=J(e,b?"entry":"rowElement"),ue=W.length>0||E.updaters.length>0,me=b&&ue,de=me?J(e,"pushRowProps"):null;return b?T.push(p.expressionStatement(p.callExpression(de===null?p.memberExpression(p.cloneNode(oe),p.identifier("updateProps")):p.cloneNode(de),ee))):T.push(p.expressionStatement(p.callExpression(ne(e,"setProps"),[p.cloneNode(d),p.arrayExpression(ee)])),p.expressionStatement(p.callExpression(ne(e,"markDirty"),[p.cloneNode(d)]))),E.updaters.length>0&&T.push(p.expressionStatement(p.callExpression(p.identifier(E.updateVar),[]))),il({ctx:e,site:t,rowComponent:l,rowId:d,nextItem:u,nextIndex:c,rowRefresh:m,rowScope:E,result:oe,lightweight:b,needsUpdateProps:ue,reuseLightweightEntry:me,lightweightPushProps:de,ownerId:s,eventBindings:a,prefixStatements:N,callProps:W,updateStatements:T})}function al(e,t,n,o,r,i=!1,s=Te(e,n),a=new Map){t.jsx.openingElement.attributes=t.jsx.openingElement.attributes.filter(f=>p.isJSXSpreadAttribute(f)||f.name.name!=="key");let l=st(e);for(let[f,g]of a)l.delegatedEventBindings.set(f,g.name);let d=J(e,"rowId").name,u=J(e,"nextItem"),c=t.indexParam===null?null:J(e,"nextIndex"),m={itemParam:t.itemParam,itemPath:[],rowIdVar:d,keyPath:it(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal?{ownerIdVar:p.isIdentifier(s)?s.name:Te(e,n).name}:{}},E=r(e,l,t.jsx,n,o,"row",m,p.identifier(d),i,p.identifier(d));Gt(e,l,E);let b=[p.expressionStatement(p.assignmentExpression("=",p.cloneNode(t.itemPattern,!0),p.cloneNode(u)))];return c!==null&&t.indexParam!==null&&b.push(p.expressionStatement(p.assignmentExpression("=",p.identifier(t.indexParam),p.cloneNode(c)))),p.arrowFunctionExpression([p.cloneNode(t.itemPattern,!0),p.identifier(d),...t.indexParam===null?[]:[p.identifier(t.indexParam)]],p.blockStatement([at(l),lt(l),ft(e,p.identifier(d),p.cloneNode(s),p.identifier(l.updateVar)),...l.creation,...l.mounts,p.returnStatement(p.objectExpression([p.objectProperty(p.identifier("nodes"),p.arrayExpression([p.identifier(E)])),p.objectProperty(p.identifier("entities"),p.arrayExpression([p.identifier(d)])),p.objectProperty(p.identifier("updateProps"),p.arrowFunctionExpression([p.cloneNode(u),...c===null?[]:[p.cloneNode(c)]],p.blockStatement(b))),p.objectProperty(p.identifier("update"),p.identifier(l.updateVar))]))]))}import*as F from"@babel/types";function ll(e){return F.isJSXElement(e.body)?e.body:F.isBlockStatement(e.body)&&e.body.body.length===1&&F.isReturnStatement(e.body.body[0])&&F.isJSXElement(e.body.body[0].argument)?e.body.body[0].argument:null}function Io(e,t,n,o,r,i,s,a){if(!F.isArrowFunctionExpression(n)&&!F.isFunctionExpression(n)||n.async||n.generator)throw r.buildCodeFrameError("memo-dom: render callbacks must be synchronous inline arrows or function expressions");let l=ll(n),d=n.params[0],u=n.params[1];if(l===null||n.params.length<1||n.params.length>2||!F.isIdentifier(d)&&!F.isObjectPattern(d)&&!F.isArrayPattern(d)||u!==void 0&&!F.isIdentifier(u))throw r.buildCodeFrameError("memo-dom: render callbacks take an item binding pattern and optional index, then return one JSX element");let c=xn(d),m=Object.keys(F.getBindingIdentifiers(c));if(m.length===0)throw r.buildCodeFrameError("memo-dom: render callback item patterns must bind at least one name");let E=F.isIdentifier(c)?c.name:m[0],b=u===void 0?null:u.name,f=null;l.openingElement.attributes=l.openingElement.attributes.filter(oe=>{if(F.isJSXSpreadAttribute(oe)||!F.isJSXIdentifier(oe.name)||oe.name.name!=="key")return!0;if(f=ze(oe.value),f===null)throw r.buildCodeFrameError("memo-dom: key={...} needs an expression");return!1});let g=J(e,"renderCallback"),h=J(e,"renderRows"),C=J(e,"renderNextUpdate"),N=J(e,"renderRowId"),v=J(e,"refreshRenderRow"),$=J(e,"renderNextItem"),_=b===null?null:J(e,"renderNextIndex"),B=st(e),R={itemParam:E,itemPath:[],rowIdVar:N.name,keyPath:it(f,E),sourceKey:"$render-callback",sourceLocal:!0,...F.isIdentifier(a)?{ownerIdVar:a.name}:{}},k=i(e,B,l,o,r,"row",R,N,s,N);Gt(e,B,k),t.creation.push(F.variableDeclaration("const",[F.variableDeclarator(F.cloneNode(h),F.newExpression(F.identifier("Set"),[]))])),t.updaters.push(()=>F.forOfStatement(F.variableDeclaration("const",[F.variableDeclarator(F.cloneNode(C))]),F.cloneNode(h),F.expressionStatement(F.callExpression(F.cloneNode(C),[]))));let W=[F.expressionStatement(F.assignmentExpression("=",F.cloneNode(c,!0),F.cloneNode($)))];_!==null&&b!==null&&W.push(F.expressionStatement(F.assignmentExpression("=",F.identifier(b),F.cloneNode(_))));let T=F.arrowFunctionExpression([F.cloneNode(c,!0),F.cloneNode(N),...b===null?[]:[F.identifier(b)]],F.blockStatement([at(B),lt(B),F.variableDeclaration("const",[F.variableDeclarator(F.cloneNode(v),F.arrowFunctionExpression([],F.blockStatement([F.expressionStatement(F.callExpression(F.identifier(B.updateVar),[])),F.expressionStatement(F.callExpression(ne(e,"renderDescendants"),[F.cloneNode(N)]))])))]),ft(e,F.cloneNode(N),F.cloneNode(a,!0),F.cloneNode(v)),...B.creation,...B.mounts,F.expressionStatement(F.callExpression(F.memberExpression(F.cloneNode(h),F.identifier("add")),[F.cloneNode(v)])),F.returnStatement(F.objectExpression([F.objectProperty(F.identifier("nodes"),F.callExpression(ne(e,"rootNodes"),[F.identifier(k)])),F.objectProperty(F.identifier("entities"),F.arrayExpression([F.cloneNode(N)])),F.objectProperty(F.identifier("updateProps"),F.arrowFunctionExpression([F.cloneNode($),..._===null?[]:[F.cloneNode(_)]],F.blockStatement(W))),F.objectProperty(F.identifier("update"),F.cloneNode(v)),F.objectProperty(F.identifier("dispose"),F.arrowFunctionExpression([],F.callExpression(F.memberExpression(F.cloneNode(h),F.identifier("delete")),[F.cloneNode(v)])))]))])),ee=f===null?F.nullLiteral():F.arrowFunctionExpression([F.cloneNode(c,!0),...b===null?[]:[F.identifier(b)]],F.cloneNode(f));return t.creation.push(F.variableDeclaration("const",[F.variableDeclarator(F.cloneNode(g),F.objectExpression([F.objectProperty(F.identifier("create"),T),F.objectProperty(F.identifier("key"),ee)]))])),g}import*as K from"@babel/types";function gi(e,t,n,o,r,i,s,a,l){let d=J(e,"routeFragment"),u=J(e,"routeRegion"),c=J(e,"routeUnsubscribe"),m=J(e,"routeDispose"),E=J(e,"currentRoute"),b=J(e,"routeMatch"),f=t.regionCounter++,g=K.binaryExpression("+",K.cloneNode(l),K.stringLiteral(`/route${f}`));e.routeElements.delete(n);let h;try{h=pn(e,n,r,i,g,s,a,g,!0,t.usedConds)}finally{e.routeElements.set(n,o)}let C=K.arrowFunctionExpression([K.cloneNode(E)],K.callExpression(K.memberExpression(K.memberExpression(K.cloneNode(E),K.identifier("matches")),K.identifier("some")),[K.arrowFunctionExpression([K.cloneNode(b)],K.binaryExpression("===",K.memberExpression(K.cloneNode(b),K.identifier("id")),K.stringLiteral(o.id)))])),N=K.arrowFunctionExpression([],K.callExpression(K.memberExpression(K.cloneNode(u),K.identifier("update")),[]));return t.creation.push(K.variableDeclaration("const",[K.variableDeclarator(K.cloneNode(d),K.callExpression(K.memberExpression(K.identifier("document"),K.identifier("createDocumentFragment")),[]))]),ft(e,K.cloneNode(g),K.cloneNode(l),K.cloneNode(N)),K.variableDeclaration("const",[K.variableDeclarator(K.cloneNode(u),K.callExpression(ne(e,"createCondRegion"),[K.cloneNode(d),K.cloneNode(g),K.arrowFunctionExpression([],K.conditionalExpression(K.callExpression(C,[bt(e,"route")]),K.numericLiteral(0),K.numericLiteral(1))),K.arrayExpression([h,K.nullLiteral()])]))]),K.variableDeclaration("const",[K.variableDeclarator(K.cloneNode(c),K.callExpression(bt(e,"subscribeRouteSelected"),[K.cloneNode(C),K.cloneNode(N)]))]),K.variableDeclaration("const",[K.variableDeclarator(K.cloneNode(m),K.arrowFunctionExpression([],K.blockStatement([K.expressionStatement(K.callExpression(K.cloneNode(c),[])),K.expressionStatement(K.callExpression(K.memberExpression(K.cloneNode(u),K.identifier("dispose")),[]))])))])),t.manualDisposal?(t.disposableCallbacks.push(m),t.disposableEntities.push(K.cloneNode(g))):t.creation.push(K.expressionStatement(K.callExpression(ne(e,"cleanup"),[K.cloneNode(l),K.cloneNode(m)]))),d.name}function dl(e){return S.conditionalExpression(S.logicalExpression("||",S.binaryExpression("==",S.cloneNode(e),S.nullLiteral()),S.binaryExpression("===",S.unaryExpression("typeof",S.cloneNode(e),!0),S.stringLiteral("boolean"))),S.stringLiteral(""),S.callExpression(S.identifier("String"),[S.cloneNode(e)]))}function cl(e,t,n,o){return()=>jt(e,t,S.cloneNode(o),r=>S.expressionStatement(S.assignmentExpression("=",S.memberExpression(S.identifier(n),S.identifier("data")),dl(r))))}function Fo(e,t,n){let o=J(e,`text${t.textCounter++}`).name;if(S.isStringLiteral(n))return t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.identifier(o),S.callExpression(S.memberExpression(S.identifier("document"),S.identifier("createTextNode")),[S.stringLiteral(n.value)]))])),o;let r=no(e,t);t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.identifier(o),S.callExpression(S.memberExpression(S.identifier("document"),S.identifier("createTextNode")),[S.stringLiteral("")]))]));let i=cl(t,r,o,n);return t.creation.push(i()),t.updaters.push(i),o}function bi(e,t){let n=!1;return S.traverseFast(e,o=>{S.isIdentifier(o,{name:t})&&(n=!0)}),n}function pt(e,t,n,o,r,i=null,s,a,l=!1,d=Te(e,o)){return S.isJSXFragment(n)?ul(e,t,n,o,r,i,s,a,l,d):pl(e,t,n,o,r,i,s,a,l,d)}function ul(e,t,n,o,r,i,s,a,l=!1,d=Te(e,o)){let u=So(n.children,{emitText:m=>Fo(e,t,m),emitNode:m=>pt(e,t,m,o,r,i,s,a,l,d),isForwarded:m=>dt(e,o,m),fail:m=>{throw r.buildCodeFrameError(m)}}),c=oo(e,t,"fragment");return t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.identifier(c),S.callExpression(S.memberExpression(S.identifier("document"),S.identifier("createDocumentFragment")),[]))])),hi(e,t,u,c,o,r,i,s,l,d),c}function hi(e,t,n,o,r,i,s=null,a,l=!1,d=Te(e,r)){for(let u of n)u.type==="node"?t.creation.push(S.expressionStatement(S.callExpression(S.memberExpression(S.identifier(o),S.identifier("appendChild")),[S.identifier(u.variable)]))):u.type==="slot"?io(e,t,u.expression,o,d):u.type==="list"?yi(e,t,u.expression,o,r,i,l,d,a):xi(e,t,u.expression,o,r,i,l,d,s!==null)}function Mo(e,t,n,o,r,i,s,a,l,d){return or(e,t,d,(u,c,m)=>{rr(u,n,c.name,{emitText:E=>Fo(e,u,E),emitNode:E=>pt(e,u,E,o,r,i,s,a,l,m),emitList:(E,b)=>yi(e,u,E,b,o,r,l,m,s),emitCondition:(E,b)=>xi(e,u,E,b,o,r,l,m,i!==null),isForwarded:E=>dt(e,o,E),emitForwarded:(E,b)=>io(e,u,E,b,m),fail:E=>{throw r.buildCodeFrameError(E)}})})}function Ei(e,t,n,o,r,i,s,a,l,d){let u=S.isJSXElement(n)||S.isJSXFragment(n)?[n]:[S.jsxExpressionContainer(n)];return Mo(e,t,u,o,r,i,s,a,l,d)}function pl(e,t,n,o,r,i=null,s,a,l=!1,d=Te(e,o)){let u=e.routeElements.get(n);if(u!==void 0)return gi(e,t,n,u,o,r,pt,l,d);let c=n.openingElement,m=c.name.name;if(/^[A-Z]/.test(m)){let N=t.childCounts.get(m)??0;t.childCounts.set(m,N+1);let v=m.charAt(0).toLowerCase()+m.slice(1),$=N===0?v:`${v}${N}`,_=J(e,$).name,B=N===0?`/${m}`:`/${m}[${N}]`,R=[],k=e.componentProps.get(m);if(nn(n.children)&&c.attributes.some(me=>S.isJSXAttribute(me)&&De(me.name)==="children"))throw r.buildCodeFrameError(`memo-dom: <${m}> cannot use both a children prop and nested JSX children`);let W=c.attributes.some(me=>S.isJSXSpreadAttribute(me)),T=null,ee=!1;if(W){T=an(c.attributes,{attributeValue:(de,G)=>de==="ref"||k?.refProps.includes(de)===!0?Ct(e,r,o,G):G,fail:de=>{throw r.buildCodeFrameError(de)}}).expression;for(let de of T.properties){if(!S.isObjectProperty(de)||de.computed||!S.isExpression(de.value))continue;let G=S.isIdentifier(de.key)?de.key.name:S.isStringLiteral(de.key)?de.key.value:null;if(G!==null)if(k?.renderCallbacks.includes(G)===!0)de.value=Io(e,t,de.value,o,r,pt,l,d);else if(k?.renderProps.includes(G)===!0){if(dt(e,o,de.value))continue;if(!fe(de.value))throw r.buildCodeFrameError(`memo-dom: render prop '${G}' on <${m}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);de.value=Ei(e,t,de.value,o,r,i,s,a,l,d)}else{if(fe(de.value))throw r.buildCodeFrameError(`memo-dom: JSX prop '${G}' on <${m}> is not rendered by the callee; interpolate that prop in <${m}> to declare a render slot`);G!=="ref"&&k?.refProps.includes(G)!==!0&&_t(de.value)&&(ct(e,r,de.value,o,s,!0),de.value=vo(e,t,de.value,`${G}Callback`))}}ee=eo(e,T,o)||s!==void 0&&bi(T,s.itemParam)}else for(let me of c.attributes){let de=me,G=De(de.name),y=de.value==null?S.booleanLiteral(!0):ze(de.value);if(y==null)throw r.buildCodeFrameError(`memo-dom: prop '${De(de.name)}' on <${m}> must be an expression`);if(k?.renderCallbacks.includes(G)===!0){R.push({name:G,value:Io(e,t,y,o,r,pt,l,d)});continue}if(G==="ref"||k?.refProps.includes(G)===!0){R.push({name:G,value:Ct(e,r,o,y)});continue}if(k?.renderProps.includes(G)===!0){if(dt(e,o,y)){R.push({name:G,value:S.cloneNode(y)});continue}if(!fe(y))throw r.buildCodeFrameError(`memo-dom: render prop '${G}' on <${m}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);R.push({name:G,value:Ei(e,t,y,o,r,i,s,a,l,d)});continue}if(fe(y))throw r.buildCodeFrameError(`memo-dom: JSX prop '${G}' on <${m}> is not rendered by the callee; interpolate that prop in <${m}> to declare a render slot`);let w=_t(y);if(!w&&(eo(e,y,o)||s!==void 0&&bi(y,s.itemParam))&&(ee=!0),w)ct(e,r,y,o,s,!0);else if(S.isIdentifier(y)){let L=St(r,y.name);L!==null&&!fe(L.body)&&ct(e,r,L,o,s,!0)}R.push({name:G,value:w?vo(e,t,y,`${G}Callback`):S.cloneNode(y)})}if(nn(n.children)){if(c.attributes.some(de=>S.isJSXAttribute(de)&&De(de.name)==="children"))throw r.buildCodeFrameError(`memo-dom: <${m}> cannot use both a children prop and nested JSX children`);let me=Mo(e,t,n.children,o,r,i,s,a,l,d);T!==null?T.properties.push(S.objectProperty(S.identifier("children"),S.cloneNode(me))):R.push({name:"children",value:S.cloneNode(me)})}let oe;if(T!==null){let me=J(e,`${v}Props`);t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.cloneNode(me),S.cloneNode(T))])),oe=qt(e,m,me)}else oe=Hn(e,m,R);let ue=S.binaryExpression("+",S.cloneNode(d),S.stringLiteral(B));return t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.identifier(_),S.callExpression(S.identifier(m),[ue,S.cloneNode(d),...oe.length>0?[S.arrayExpression(oe)]:[]]))])),t.disposableEntities.push(S.cloneNode(ue)),ee&&t.updaters.push(()=>T===null?S.expressionStatement(S.callExpression(ne(e,"setProps"),[S.binaryExpression("+",S.cloneNode(d),S.stringLiteral(B)),S.arrayExpression(oe.map(me=>S.cloneNode(me)))])):ci(e,m,d,B,T)),_}let E=li(m,l),b=E&&m!=="foreignObject";if(c.attributes.find(N=>S.isJSXAttribute(N)&&De(N.name)==="innerHTML")!==void 0){if(E)throw r.buildCodeFrameError("memo-dom: innerHTML is only supported on HTML elements");if(n.children.some(v=>!S.isJSXText(v)||v.value.trim()!==""))throw r.buildCodeFrameError("memo-dom: an element using innerHTML cannot also have JSX children")}let g=So(n.children,{emitText:N=>Fo(e,t,N),emitNode:N=>pt(e,t,N,o,r,i,s,a,b,d),isForwarded:N=>dt(e,o,N),fail:N=>{throw r.buildCodeFrameError(N)}}),h=oo(e,t,m);if(t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.identifier(h),di(m,E))])),c.attributes.some(N=>S.isJSXSpreadAttribute(N))){let N=an(c.attributes,{attributeValue:(_,B)=>_==="ref"?Ct(e,r,o,B):B,eventValue:(_,B)=>{let R=xo(e,r,B,_,o,s,a),k=J(e,`${_}Handler`);return t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.cloneNode(k),R)])),k},fail:_=>{throw r.buildCodeFrameError(_)}}),v=J(e,`${m}Props`);t.creation.push(S.variableDeclaration("const",[S.variableDeclarator(S.cloneNode(v),S.cloneNode(N.expression))]));let $=_=>S.expressionStatement(S.callExpression(ne(e,"patchDomProps"),[S.identifier(h),S.cloneNode(_),S.stringLiteral(e.rootId),S.arrayExpression(N.safeEventKeys.map(B=>S.stringLiteral(B)))]));t.creation.push($(v)),No(e,t,S.identifier(h),d,S.memberExpression(S.cloneNode(v),S.identifier("ref"))),t.updaters.push(()=>$(N.expression))}else for(let N of c.attributes){let v=N,$=De(v.name);if($==="ref"){let T=ze(v.value);if(T===null)throw r.buildCodeFrameError("memo-dom: ref needs an expression");No(e,t,S.identifier(h),d,Ct(e,r,o,T));continue}if($==="key")throw r.buildCodeFrameError("memo-dom: key={...} is only meaningful on list rows: items.map(item => <Row key={item.id} />)");if(/^on[A-Z]/.test($)){let T=ze(v.value);if(T==null)throw r.buildCodeFrameError(`memo-dom: ${$} needs a handler expression (L1)`);let ee=xo(e,r,T,$,o,s,a),oe=t.delegatedEventBindings.get($);t.creation.push(oe===void 0?S.expressionStatement(S.assignmentExpression("=",S.memberExpression(S.identifier(h),S.identifier($.toLowerCase())),ee)):S.expressionStatement(S.callExpression(ne(e,"setDelegatedEvent"),[S.identifier(oe),S.identifier(h),ee])));continue}if(S.isStringLiteral(v.value)){$==="class"||$==="className"?t.creation.push(S.expressionStatement(S.callExpression(ne(e,"setClassValue"),[S.identifier(h),S.stringLiteral(v.value.value)]))):$==="style"?t.creation.push(S.expressionStatement(S.callExpression(ne(e,"setStyleValue"),[S.identifier(h),S.stringLiteral(v.value.value)]))):Co($,E)!==null?t.creation.push(Po(h,$,S.stringLiteral(v.value.value))):wo($,E)?t.creation.push(Kn(h,$,S.stringLiteral(v.value.value))):E?t.creation.push(S.expressionStatement(S.callExpression(ne(e,"setDomValue"),[S.identifier(h),S.stringLiteral($),S.stringLiteral(v.value.value)]))):t.creation.push(S.expressionStatement(S.callExpression(S.memberExpression(S.identifier(h),S.identifier("setAttribute")),[S.stringLiteral($),S.stringLiteral(v.value.value)])));continue}let _=v.value==null?S.booleanLiteral(!0):ze(v.value);if(_==null)throw r.buildCodeFrameError(`memo-dom: attribute '${$}' needs a string or an expression (L1)`);let B=S.cloneNode(_);if($==="style"){let T=()=>S.expressionStatement(S.callExpression(ne(e,"setStyleValue"),[S.identifier(h),S.cloneNode(B)]));t.creation.push(T()),t.updaters.push(T);continue}let R=no(e,t),k=Co($,E),W=()=>$==="class"||$==="className"?jt(t,R,S.callExpression(ne(e,"classValue"),[S.cloneNode(B)]),T=>S.expressionStatement(S.callExpression(ne(e,"setClassValue"),[S.identifier(h),T]))):k!==null?jt(t,R,S.cloneNode(B),T=>Po(h,k,T)):wo($,E)?jt(t,R,S.cloneNode(B),T=>Kn(h,$,T)):E?jt(t,R,S.cloneNode(B),T=>S.expressionStatement(S.callExpression(ne(e,"setDomValue"),[S.identifier(h),S.stringLiteral($),T]))):jt(t,R,S.cloneNode(B),T=>Kn(h,$,T));t.creation.push(W()),t.updaters.push(W)}return hi(e,t,g,h,o,r,i,s,b,d),h}function yi(e,t,n,o,r,i,s=!1,a=Te(e,r),l){mi(e,t,n,o,r,i,pt,Mo,s,a,l)}function xi(e,t,n,o,r,i,s=!1,a=Te(e,r),l=!1){ui(e,t,n,o,r,i,pt,s,a,l)}function Si(e,t,n,o,r,i=!1,s=r,a=!1,l){return pn(e,t,n,o,r,pt,i,s,a,l)}import*as je from"@babel/types";function Pi(e){if(e.isFunctionDeclaration())return e.node;if(!e.isVariableDeclarator())return null;let t=e.node.init;return t&&(je.isArrowFunctionExpression(t)||je.isFunctionExpression(t))?t:null}function vi(e,t,n,o,r,i=!1){let s=St(t,n);if(s!==null){ct(e,t,s,o,r,i);return}let a=t.scope.getBinding(n);if(a===void 0||a.scope.path.isProgram()!==!0||!e.helpers.has(n))return;let l=Pi(a.path);l!==null&&un(e,l,i)}function Ci(e,t,n,o,r,i=!1){if(je.isArrowFunctionExpression(n)||je.isFunctionExpression(n)){if(fe(n.body))return;ct(e,t,n,o,r,i)}else je.isIdentifier(n)&&vi(e,t,n.name,o,r,i)}function ki(e,t,n,o=!1){let r=t.scope.getBinding(n);if(r===void 0||r.scope.path.isProgram()!==!0||!e.helpers.has(n))return;let i=Pi(r.path);i!==null&&un(e,i,o)}function wi(e,t,n,o=!1){if(je.isArrowFunctionExpression(n)||je.isFunctionExpression(n)){if(fe(n.body))return;un(e,n,o)}else je.isIdentifier(n)&&ki(e,t,n.name,o)}function Ni(e,t,n,o,r){t.traverse({CallExpression(i){let s=i.getFunctionParent()===t,a=i.node.callee,l=je.isIdentifier(a,{name:"effect"})&&i.scope.getBinding("effect")===void 0;if(je.isIdentifier(a,{name:"cleanup"})&&i.scope.getBinding("cleanup")===void 0){if(!s)throw i.buildCodeFrameError("memo-dom: cleanup(disposer) must run directly during component factory initialization");let d=i.node.arguments[0];if(i.node.arguments.length!==1||d===void 0||!je.isExpression(d))throw i.buildCodeFrameError("memo-dom: cleanup(disposer) requires exactly one disposer expression");i.node.callee=ne(e,"cleanup"),i.node.arguments.unshift(je.identifier(o))}if(s){je.isIdentifier(a)&&vi(e,t,a.name,n,r);for(let d of i.node.arguments)Ci(e,t,d,n,r,l)}},NewExpression(i){if(i.getFunctionParent()===t)for(let s of i.node.arguments)Ci(e,t,s,n,r)}})}function Ri(e,t){t.traverse({CallExpression(n){if(n.getFunctionParent()!==null)return;let o=je.isIdentifier(n.node.callee,{name:"effect"})&&n.scope.getBinding("effect")===void 0;je.isIdentifier(n.node.callee)&&ki(e,t,n.node.callee.name);for(let r of n.node.arguments)wi(e,t,r,o)},NewExpression(n){if(n.getFunctionParent()===null)for(let o of n.node.arguments)wi(e,t,o)}})}function Ii(e){for(let t of e.helpers.values())t.node.async&&un(e,t.node)}function Fi(e){e.traverse({CallExpression(t){if(je.isIdentifier(t.node.callee,{name:"cleanup"})&&t.scope.getBinding("cleanup")===void 0)throw t.buildCodeFrameError("memo-dom: cleanup(disposer) is only valid directly inside a component factory")}})}import*as Ue from"@babel/types";import*as he from"@babel/types";function Mi(e){return e.reduce((t,n)=>he.logicalExpression("||",t,n))}function Di(e,t){let n=()=>he.identifier(e),o=he.logicalExpression("||",he.binaryExpression("===",n(),he.unaryExpression("-",he.numericLiteral(1))),he.logicalExpression("&&",he.binaryExpression("!==",he.unaryExpression("typeof",n()),he.stringLiteral("number")),he.callExpression(he.memberExpression(n(),he.identifier("has")),[he.unaryExpression("-",he.numericLiteral(1))]))),r=Mi(t.map(s=>he.binaryExpression("===",n(),he.numericLiteral(s)))),i=Mi(t.map(s=>he.callExpression(he.memberExpression(n(),he.identifier("has")),[he.numericLiteral(s)])));return he.logicalExpression("||",he.binaryExpression("===",n(),he.nullLiteral()),he.logicalExpression("||",o,he.conditionalExpression(he.binaryExpression("===",he.unaryExpression("typeof",n()),he.stringLiteral("number")),r,i)))}function Li(e,t,n,o,r,i){let s=new Map(o.map((c,m)=>[c,m])),a=0,l=[...r.map(c=>({order:s.get(c.declaration)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:c.sources,statement:Go(c)})),...i.map(c=>({order:s.get(c.statement)??Number.MAX_SAFE_INTEGER,sequence:a++,sources:c.sources,statement:Ue.blockStatement([...c.resets.map(m=>Ue.expressionStatement(Ue.assignmentExpression("=",Ue.identifier(m.binding),Ue.cloneNode(m.source,!0)))),Ue.cloneNode(c.statement,!0)])}))].sort((c,m)=>c.order-m.order||c.sequence-m.sequence),d=e.instanceReasonIds.get(t),u=[];for(let c of l){let m=n===null||d===void 0?null:c.sources.map(h=>d.get(h)).filter(h=>h!==void 0).sort((h,C)=>h-C),E=m===null||m.length===c.sources.length?m:null,b=E?.join(" ")??"*",f=u.at(-1),g=f?.reasons?.join(" ")??"*";f!==void 0&&g===b?f.statements.push(c.statement):u.push({reasons:E,statements:[c.statement]})}return Ue.blockStatement(u.map(c=>c.reasons===null||n===null?Ue.blockStatement(c.statements):Ue.ifStatement(Di(n,c.reasons),Ue.blockStatement(c.statements))))}import*as Z from"@babel/types";function mn(e){return!Z.isReturnStatement(e)||!Z.isJSXElement(e.argument)&&!Z.isJSXFragment(e.argument)?null:{jsx:e.argument,statement:e}}function Do(e){return Z.isBlockStatement(e)?e.body.length===1?mn(e.body[0]):null:mn(e)}function fl(e){let t=[];return e.get("body").traverse({ReturnStatement(n){t.push(n.node)},Function(n){n.skip()}}),t}function ml(e){if(Z.isFunctionDeclaration(e))return!0;if(Z.isVariableDeclaration(e))return e.declarations.every(t=>t.init==null||Z.isFunction(t.init)||gl(t.init));if(Z.isSwitchStatement(e)||Z.isIfStatement(e)){let t=!0;return Z.traverseFast(e,n=>{(Z.isCallExpression(n)||Z.isOptionalCallExpression(n)||Z.isNewExpression(n)||Z.isAwaitExpression(n)||Z.isYieldExpression(n)||Z.isThrowStatement(n)||Z.isTaggedTemplateExpression(n)||Z.isUpdateExpression(n))&&(t=!1)}),t}return Z.isTypeScript(e)}function gl(e){let t=!0;return Z.traverseFast(e,n=>{(Z.isCallExpression(n)||Z.isOptionalCallExpression(n)||Z.isNewExpression(n)||Z.isAwaitExpression(n)||Z.isYieldExpression(n)||Z.isTaggedTemplateExpression(n)||Z.isAssignmentExpression(n)||Z.isUpdateExpression(n))&&(t=!1)}),t}function bl(e){if(!e.cases.some(o=>o.test==null))return null;let t=[],n=[];for(let o of e.cases){if(o.consequent.length!==1)return null;let r=mn(o.consequent[0]);if(r===null)return null;let i=t.length;t.push(r.jsx),n.push(Z.switchCase(o.test===null?null:Z.cloneNode(o.test),[Z.returnStatement(Z.numericLiteral(i))]))}return{pick:Z.arrowFunctionExpression([],Z.blockStatement([Z.switchStatement(Z.cloneNode(e.discriminant),n)])),branches:t,statements:new Set([e])}}function Ai(e,t){let n=e.node.body.body,o=fl(e),r=n.at(-1);if(o.length===1&&r!==void 0){let s=mn(r);if(s!==null)return s}if(r&&Z.isIfStatement(r)&&r.alternate!=null){let s=r.alternate,a=Do(r.consequent),l=Do(s);if(a!==null&&l!==null&&o.length===2)return{pick:Z.arrowFunctionExpression([],Z.conditionalExpression(Z.cloneNode(r.test),Z.numericLiteral(0),Z.numericLiteral(1))),branches:[a.jsx,l.jsx],statements:new Set([r])}}if(r&&Z.isSwitchStatement(r)){let s=bl(r);if(s!==null&&s.branches.length===o.length)return s}let i=r===void 0?null:mn(r);if(i!==null){let s=[],a=[],l=new Set([r]),d=-1,u=!0;for(let c=0;c<n.length-1;c++){let m=n[c];if(Z.isIfStatement(m)&&m.alternate==null){let E=Do(m.consequent);if(E!==null){d===-1&&(d=c),s.push(Z.cloneNode(m.test)),a.push(E.jsx),l.add(m);continue}}if(d!==-1&&!ml(m)){u=!1;break}}if(a.push(i.jsx),u&&a.length===o.length&&a.length>1){let c=Z.numericLiteral(a.length-1);for(let m=s.length-1;m>=0;m--)c=Z.conditionalExpression(s[m],Z.numericLiteral(m),c);return{pick:Z.arrowFunctionExpression([],c),branches:a,statements:l}}}throw e.buildCodeFrameError(`memo-dom: component '${t}' has unsupported JSX return control flow; use a tail chain of JSX early returns, a terminal JSX if/else, or an exhaustive JSX switch`)}function El(e){return e?.some(t=>t.localReads.size>0||t.localDerivationReads.size>0||t.conditionLocalReads.size>0||t.conditionLocalDerivationReads.size>0)===!0}function hl(e,t,n,o,r,i,s,a,l){if(t.length===0&&n.length===0||e.bindings.length===0)return;let d=[...t.map(b=>it(b.keyExpr??null,b.itemParam??"")),...n.map(b=>b.keyPath)],u=JSON.stringify(d[0]),c=d.every(b=>JSON.stringify(b)===u)?d[0]:null,m=wn(e,"item"),E=qe(e);return{itemParam:m??E??e.bindings[0],itemPath:m===null&&E!==null?["item"]:[],rowIdVar:s,...r?{refreshVar:i}:{},keyPath:c,sourceKey:t[0]?.sourceKey??n[0]?.sourceKey??"",sourceLocal:o,...o?{ownerIdVar:a??l}:{}}}function yl(e,t,n,o,r,i,s){let a=Array.from({length:r},(d,u)=>J(e,`nextProp${u}`)),l=o===null?to(n,a):o.map(({local:d},u)=>A.expressionStatement(A.assignmentExpression("=",A.identifier(d),A.cloneNode(a[u]))));return A.returnStatement(A.objectExpression([A.objectProperty(A.identifier("nodes"),s?A.identifier(i):A.callExpression(ne(e,"rootNodes"),[A.identifier(i)])),A.objectProperty(A.identifier("entities"),A.arrayExpression([])),A.objectProperty(A.identifier("update"),A.identifier(t.updateVar)),...r>0?[A.objectProperty(A.identifier("updateProps"),A.arrowFunctionExpression(a,A.blockStatement(l)))]:[],...t.disposableCallbacks.length>0?[A.objectProperty(A.identifier("dispose"),A.arrowFunctionExpression([],A.blockStatement([...t.disposableCallbacks].reverse().map(d=>A.ifStatement(A.binaryExpression("!==",A.cloneNode(d),A.nullLiteral()),A.expressionStatement(A.callExpression(A.cloneNode(d),[])))))))]:[]]))}function xl(e,t,n,o,r,i,s,a,l){return n?[...t===null?e.params.map(Zo):t.map(({local:d})=>A.identifier(d)),A.identifier(r),...s===null?[]:[A.identifier(s)],...[...a.values()].map(d=>A.identifier(d))]:o>0?[A.identifier(r),A.identifier(i),A.identifier(l)]:[A.identifier(r),A.identifier(i)]}function ji(e,t,n){let o=t.node,r=Ai(t,n),i=e.componentProps.get(n),s=i.params.length,a=e.listedSites.get(n)??[],l=e.linkedComponentRows.get(n)??[],d=a.some(oe=>oe.sourceLocal===!0)||l.some(oe=>oe.sourceLocal),u=Nt(e,n),c=u&&l.length===0?Sn(i):null,m=c?.length??s,E=st(e,u),b=e.instanceDerivations.get(n),f=e.instanceControlFlow.get(n),g=e.effects.get(n),h=El(g);(e.selectiveDerivationComponents.has(n)||e.targetedListComponents.has(n)||h)&&(E.reasonVar=J(e,"reasons").name);let C=J(e,"id").name,N=u?null:J(e,"parent").name,v=u&&d?J(e,"owner").name:null,$=new Map;if(u)for(let oe of e.componentHostEvents.get(n)??[]){let ue=J(e,`${oe}Binding`).name;$.set(oe,ue),E.delegatedEventBindings.set(oe,ue)}let _=s>0&&!u?J(e,"props").name:null;Et(e).registerComponentId(n,C);let B=hl(i,a,l,d,u,E.updateVar,C,v,N);Ni(e,t,n,C,B);let R="jsx"in r?pt(e,E,r.jsx,n,t,null,B):Sl(e,E,r,n,t,C),k=u&&"jsx"in r&&A.isJSXElement(r.jsx);if(u&&Gt(e,E,R),b!==void 0)for(let oe of b)oe.declaration.kind="let";(b!==void 0||f!==void 0)&&E.updaters.unshift(()=>Li(e,n,E.reasonVar,o.body.body,b??[],f??[])),g!==void 0&&h&&E.updaters.push(()=>mr(e,n,C,E.reasonVar,g,E));let W=new Set(g?.map(oe=>oe.statement)??[]),T=o.body.body.filter(oe=>!("jsx"in r?oe===r.statement:r.statements.has(oe))&&!W.has(oe));s>0&&!u&&E.updaters.unshift(()=>A.blockStatement(to(i,i.params.map((oe,ue)=>A.memberExpression(A.identifier(_),A.numericLiteral(ue),!0)))));let ee=[at(E)];if(s>0&&!u){let oe=_o(i,i.params.map((ue,me)=>A.memberExpression(A.identifier(_),A.numericLiteral(me),!0)));oe!==null&&ee.push(oe)}ee.push(...T,lt(E),...u?[]:[ft(e,A.identifier(C),A.identifier(N),A.identifier(E.updateVar),e.volatileComponents.has(n))]),s>0&&!u&&ee.push(A.expressionStatement(A.callExpression(ne(e,"registerProps"),[A.identifier(C),A.identifier(_)]))),ee.push(...E.creation,...E.mounts),g!==void 0&&ee.push(...gr(e,C,g)),e.hot&&!u&&ee.push(A.expressionStatement(A.callExpression(ne(e,"registerHotComponent"),[A.identifier(n),A.identifier(C),A.identifier(N),A.callExpression(ne(e,"rootNodes"),[A.identifier(R)]),_===null?A.nullLiteral():A.identifier(_)]))),ee.push(u?yl(e,E,i,c,m,R,k):A.returnStatement(A.identifier(R))),o.params=xl(i,c,u,s,C,N,v,$,_),o.body=A.blockStatement(ee)}function Sl(e,t,n,o,r,i){let s=J(e,"returnRoot").name,a=J(e,"returnRegion").name,l=A.identifier(i),d=A.binaryExpression("+",A.cloneNode(l),A.stringLiteral("/$return"));return t.creation.push(A.variableDeclaration("const",[A.variableDeclarator(A.identifier(s),A.callExpression(A.memberExpression(A.identifier("document"),A.identifier("createDocumentFragment")),[]))])),t.creation.push(A.variableDeclaration("const",[A.variableDeclarator(A.identifier(a),A.callExpression(ne(e,"createCondRegion"),[A.identifier(s),A.cloneNode(d),A.cloneNode(n.pick),A.arrayExpression(n.branches.map(u=>Si(e,u,o,r,d,!1,l,!0,t.usedConds)))]))])),t.updaters.push(()=>A.expressionStatement(A.callExpression(A.memberExpression(A.identifier(a),A.identifier("update")),[]))),s}import*as pe from"@babel/types";function Cl(e){return!pe.isIdentifier(e.id)||!/^[A-Z]/.test(e.id.name)||!pe.isArrowFunctionExpression(e.init)&&!pe.isFunctionExpression(e.init)||!fe(e.init.body)?null:e.init}function wl(e,t,n){if(t.async||t.generator)throw n.buildCodeFrameError(`memo-dom: component '${e}' must be synchronous`);if(pe.isFunctionExpression(t)&&t.id!=null&&t.id.name!==e)throw n.buildCodeFrameError(`memo-dom: named component function expression '${t.id.name}' must match binding '${e}'`);let o=pe.functionDeclaration(pe.identifier(e),t.params.map(r=>pe.cloneNode(r,!0)),pe.isBlockStatement(t.body)?pe.cloneNode(t.body,!0):pe.blockStatement([pe.returnStatement(pe.cloneNode(t.body,!0))]));return o.returnType=t.returnType==null?null:pe.cloneNode(t.returnType,!0),o.typeParameters=t.typeParameters==null?null:pe.cloneNode(t.typeParameters,!0),o.loc=t.loc,o}function Ji(e,t,n){if(e.kind!=="const")return[t?pe.exportNamedDeclaration(pe.cloneNode(e,!0)):pe.cloneNode(e,!0)];let o=[];for(let r of e.declarations){let i=Cl(r),s;i===null?s=pe.variableDeclaration("const",[pe.cloneNode(r,!0)]):s=wl(r.id.name,i,n),o.push(t?pe.exportNamedDeclaration(s):s)}return o.length>0&&pe.inheritsComments(o[0],e),o}function gn(e){let t=[],n=!1;for(let o of e.get("body")){let r=o.node;if(pe.isVariableDeclaration(r)){let i=Ji(r,!1,o);n||=i.some(s=>pe.isFunctionDeclaration(s)),t.push(...i);continue}if(pe.isExportNamedDeclaration(r)&&pe.isVariableDeclaration(r.declaration)){let i=Ji(r.declaration,!0,o);n||=i.some(s=>pe.isExportNamedDeclaration(s)&&pe.isFunctionDeclaration(s.declaration)),t.push(...i);continue}t.push(r)}n&&(e.set("body",t),e.scope.crawl())}import*as j from"@babel/types";var Pl=/^:([A-Za-z_$][A-Za-z0-9_$]*)$/;function Lo(e,t){return e.openingElement.attributes.find(n=>j.isJSXAttribute(n)&&De(n.name)===t)}function Ao(e){return j.isStringLiteral(e.value)?e.value.value:j.isJSXExpressionContainer(e.value)&&j.isStringLiteral(e.value.expression)?e.value.expression.value:null}function $i(e,t,n){let o=t.openingElement.loc?.start.line,r=t.openingElement.loc?.start.column;return o===void 0||r===void 0?`${e}#route:${n}`:`${e}#route:${o}:${r}`}function jo(e){return e.split("/").filter(Boolean)}function _n(e){if(!e.startsWith("/"))throw new TypeError(`route pattern '${e}' must begin with '/'`);if(e.includes("?")||e.includes("#"))throw new TypeError(`route pattern '${e}' must not contain a query or hash`);if(e.includes("//"))throw new TypeError(`route pattern '${e}' contains an empty path segment`);let t=e.replace(/\/+$/g,""),n=t===""?"/":t,o=new Set,r=jo(n);for(let i=0;i<r.length;i++){let s=r[i];if(s==="*"){if(i!==r.length-1)throw new TypeError(`route wildcard must be terminal in '${e}'`);continue}if(!s.startsWith(":"))continue;let a=Pl.exec(s);if(a===null)throw new TypeError(`invalid route parameter segment '${s}' in '${e}'`);let l=a[1];if(o.has(l))throw new TypeError(`duplicate route parameter '${l}' in '${e}'`);o.add(l)}return n}function Zt(e){let t=[];for(let n of jo(e))n==="*"?t.push("*"):n.startsWith(":")&&t.push(n.slice(1));return t}function Xi(e,t){if(e.endsWith("/*"))throw new TypeError(`catch-all route '${e}' cannot have child routes`);return t==="/"?e:e==="/"?t:`${e}${t}`}function vl(e,t){let n=[],o=0,r=(i,s)=>{if(j.isJSXElement(i)){let a=s,l=Lo(i,"route");if(l!==void 0){let d=Ao(l);if(d!==null){let u=_n(d),c=s===null?u:Xi(s.fullPattern,u),m=new Set(s===null?[]:Zt(s.fullPattern));for(let E of Zt(u))if(m.has(E))throw new TypeError(`route '${c}' shadows active parameter '${E}'`);a={id:$i(t,i,o++),moduleId:t,pattern:u,fullPattern:c,...s===null?{}:{parentId:s.id},...i.openingElement.loc?.start.line===void 0?{}:{line:i.openingElement.loc.start.line},...i.openingElement.loc?.start.column===void 0?{}:{column:i.openingElement.loc.start.column}},n.push(a)}}for(let d of i.openingElement.attributes)r(d,a);for(let d of i.children)r(d,a);return}if(j.isJSXFragment(i)){for(let a of i.children)r(a,s);return}for(let a of j.VISITOR_KEYS[i.type]??[]){let l=i[a];if(Array.isArray(l))for(let d of l)d!==null&&typeof d=="object"&&"type"in d&&r(d,s);else l!==null&&typeof l=="object"&&"type"in l&&r(l,s)}};return r(e,null),n}function Ti(e,t){return vl(e.program,t)}function kl(e){return jo(e).map(t=>t==="*"?"*":t.startsWith(":")?":param":t).join("/")}function Oi(e,t,n){let o=t.parentId;for(;o!==void 0;){if(o===e.id)return!0;o=n.get(o)?.parentId}return!1}function Jo(e){let t=new Map(e.map(o=>[o.id,o])),n=new Map;for(let o of e){if(o.parentId!==void 0&&!t.has(o.parentId))throw new TypeError(`route '${o.fullPattern}' references a missing compiler parent`);let r=kl(o.fullPattern),i=n.get(r);if(i!==void 0&&!Oi(i,o,t)&&!Oi(o,i,t))throw new TypeError(`ambiguous routes '${i.fullPattern}' and '${o.fullPattern}' share '${r}'`);n.set(r,o)}}function qn(e){return!e.computed&&j.isIdentifier(e.key)?e.key.name:j.isStringLiteral(e.key)?e.key.value:null}function Nl(e,t){let n=e.node,o=Ao(n),r,i=null;if(o!==null)try{r=_n(o)}catch(l){throw e.buildCodeFrameError(`memo-dom: ${l.message}`)}else if(j.isJSXExpressionContainer(n.value)&&j.isObjectExpression(n.value.expression)){let l=n.value.expression;if(l.properties.some(b=>j.isSpreadElement(b)))throw e.buildCodeFrameError("memo-dom: route-to objects must have statically known keys; object spreads are not supported");let d=new Map;for(let b of l.properties){if(!j.isObjectProperty(b))continue;let f=qn(b);if(f===null)throw e.buildCodeFrameError("memo-dom: route-to object keys must be static");if(d.has(f))throw e.buildCodeFrameError(`memo-dom: route-to contains duplicate '${f}' fields`);d.set(f,b)}let u=new Set(["path","params","query","hash","replace"]);for(let b of d.keys())if(!u.has(b))throw e.buildCodeFrameError(`memo-dom: route-to does not support '${b}'`);let c=d.get("path");if(c===void 0||!j.isStringLiteral(c.value))throw e.buildCodeFrameError("memo-dom: route-to requires a static string 'path'");try{r=_n(c.value.value)}catch(b){throw e.buildCodeFrameError(`memo-dom: ${b.message}`)}i=j.objectExpression(l.properties.filter(b=>j.isObjectProperty(b)&&qn(b)!=="path").map(b=>j.cloneNode(b,!0)));let m=Zt(r),E=d.get("params");if(m.length>0&&E===void 0)throw e.buildCodeFrameError(`memo-dom: route-to '${r}' requires params { ${m.join(", ")} }`);if(E!==void 0){if(!j.isObjectExpression(E.value))throw e.buildCodeFrameError("memo-dom: route-to params must be an object literal with static keys");if(E.value.properties.some(N=>j.isSpreadElement(N)))throw e.buildCodeFrameError("memo-dom: route-to params do not support object spreads");let b=E.value.properties.map(N=>j.isObjectProperty(N)?qn(N):null);if(b.some(N=>N===null))throw e.buildCodeFrameError("memo-dom: route-to param names must be static");let f=b,g=f.find((N,v)=>f.indexOf(N)!==v);if(g!==void 0)throw e.buildCodeFrameError(`memo-dom: route-to params contain duplicate '${g}'`);let h=m.filter(N=>!f.includes(N)),C=f.filter(N=>!m.includes(N));if(h.length>0||C.length>0)throw e.buildCodeFrameError(`memo-dom: route-to '${r}' params mismatch`+(h.length===0?"":`; missing ${h.join(", ")}`)+(C.length===0?"":`; unknown ${C.join(", ")}`))}}else throw e.buildCodeFrameError("memo-dom: route-to must be a static route string or a statically shaped destination object");let s=t.get(r);if(s===void 0)throw e.buildCodeFrameError(`memo-dom: route-to references undeclared route '${r}'`);let a=Zt(s.fullPattern);if(o!==null&&a.length>0)throw e.buildCodeFrameError(`memo-dom: route-to '${r}' requires params { ${a.join(", ")} }; use the object form`);return{path:r,options:i}}function Rl(e,t){if(t.options===null)return j.stringLiteral(t.path);let n=new Map;for(let r of t.options.properties){if(!j.isObjectProperty(r)||!j.isExpression(r.value))continue;let i=qn(r);i!==null&&n.set(i,r.value)}let o=r=>j.cloneNode(n.get(r)??j.identifier("undefined"),!0);return j.callExpression(bt(e,"buildRoutePath"),[j.stringLiteral(t.path),o("params"),o("query"),o("hash")])}function Il(e,t){return j.callExpression(bt(e,"navigateRoute"),[j.stringLiteral(t.path),...t.options===null?[]:[j.cloneNode(t.options,!0)]])}function Fl(e,t,n,o){let r=t.node.openingElement;if(!j.isJSXIdentifier(r.name))throw n.buildCodeFrameError("memo-dom: route-to currently requires a statically named JSX element");let i=r.name.name;if(/^[A-Z]/.test(i))throw n.buildCodeFrameError("memo-dom: route-to currently targets intrinsic elements; put it on the interactive host rendered by this component");if(r.attributes.some(u=>j.isJSXSpreadAttribute(u)))throw n.buildCodeFrameError("memo-dom: route-to cannot be combined with JSX prop spreads because navigation ownership must be static");if(i==="a"){if(Lo(t.node,"href")!==void 0)throw n.buildCodeFrameError("memo-dom: an anchor using route-to must not also declare href");let u=Rl(e,o);r.attributes.push(j.jsxAttribute(j.jsxIdentifier("href"),j.isStringLiteral(u)?u:j.jsxExpressionContainer(u)));return}let s=Lo(t.node,"onClick"),a=J(e,"routeEvent"),l=[],d=null;if(s!==void 0){let u=null;if(j.isJSXExpressionContainer(s.value)&&j.isExpression(s.value.expression)&&(u=s.value.expression),u===null)throw n.buildCodeFrameError("memo-dom: onClick used with route-to must contain a handler expression");d=J(e,"routeClickResult"),l.push(j.variableDeclaration("const",[j.variableDeclarator(j.cloneNode(d),j.callExpression(j.cloneNode(u,!0),[j.cloneNode(a)]))])),r.attributes=r.attributes.filter(c=>c!==s)}l.push(j.ifStatement(j.unaryExpression("!",j.memberExpression(j.cloneNode(a),j.identifier("defaultPrevented"))),j.expressionStatement(Il(e,o)))),d!==null&&l.push(j.returnStatement(j.cloneNode(d))),r.attributes.push(j.jsxAttribute(j.jsxIdentifier("onClick"),j.jsxExpressionContainer(j.arrowFunctionExpression([j.cloneNode(a)],j.blockStatement(l)))))}function Bi(e,t){let n=[],o=0;t.traverse({JSXElement(s){let a=s.get("openingElement").get("attributes").find(f=>f.isJSXAttribute()&&De(f.node.name)==="route");if(a===void 0)return;let l=Ao(a.node);if(l===null)throw a.buildCodeFrameError("memo-dom: route must be a static string beginning with /");let d;try{d=_n(l)}catch(f){throw a.buildCodeFrameError(`memo-dom: ${f.message}`)}let u=s.findParent(f=>f.isJSXElement()&&e.routeElements.has(f.node)),c=u===null?null:e.routeElements.get(u.node),m;try{m=c===null?d:Xi(c.fullPattern,d)}catch(f){throw a.buildCodeFrameError(`memo-dom: ${f.message}`)}let E=new Set(c===null?[]:Zt(c.fullPattern));for(let f of Zt(d))if(E.has(f))throw a.buildCodeFrameError(`memo-dom: route '${m}' shadows active parameter '${f}'`);let b={id:$i(e.moduleId,s.node,o++),moduleId:e.moduleId,pattern:d,fullPattern:m,...c===null?{}:{parentId:c.id},...s.node.openingElement.loc?.start.line===void 0?{}:{line:s.node.openingElement.loc.start.line},...s.node.openingElement.loc?.start.column===void 0?{}:{column:s.node.openingElement.loc.start.column}};e.routeElements.set(s.node,b),n.push(b),e.localRoutes.push(b),e.usesRouter=!0,a.remove()}});let r=e.linkedRoutes??n;Jo(r);let i=new Map(r.map(s=>[s.fullPattern,s]));t.traverse({JSXElement(s){let a=s.get("openingElement").get("attributes").find(d=>d.isJSXAttribute()&&De(d.node.name)==="route-to");if(a===void 0)return;let l=Nl(a,i);e.usesRouter=!0,a.remove(),Fl(e,s,a,l)}})}function Vi(e){if(!e.emitRouteManifest)return[];let t=e.linkedRoutes??e.localRoutes;if(t.length===0)return[];e.usesRouter=!0;let n=J(e,"routeManifest");return[j.variableDeclaration("const",[j.variableDeclarator(j.cloneNode(n),j.callExpression(bt(e,"createRouteManifest"),[j.arrayExpression(t.map(o=>j.objectExpression([j.objectProperty(j.identifier("id"),j.stringLiteral(o.id)),j.objectProperty(j.identifier("pattern"),j.stringLiteral(o.pattern)),...o.parentId===void 0?[]:[j.objectProperty(j.identifier("parentId"),j.stringLiteral(o.parentId))]])))]))]),j.expressionStatement(j.callExpression(bt(e,"replaceRouteResolver"),[j.memberExpression(j.cloneNode(n),j.identifier("resolve"))])),j.expressionStatement(j.callExpression(bt(e,"ensureRouterConnected"),[]))]}import*as Ce from"@babel/types";function Ki(e){if(!Ce.isJSXIdentifier(e.name))return null;let t=e.name.name;return t==="if"||t==="else-if"||t==="else"?t:null}function Oo(e,t){let n=null;for(let o of e.openingElement.attributes){if(!Ce.isJSXAttribute(o))continue;let r=Ki(o);if(r!==null){if(n!==null)throw t.buildCodeFrameError("memo-dom: a JSX element may have only one of if, else-if, or else");if(r==="else"){if(o.value!==null)throw t.buildCodeFrameError("memo-dom: the JSX else directive does not accept a value; write <Element else>");n={kind:r,condition:null};continue}if(!Ce.isJSXExpressionContainer(o.value)||Ce.isJSXEmptyExpression(o.value.expression)||!Ce.isExpression(o.value.expression))throw t.buildCodeFrameError(`memo-dom: the JSX ${r} directive requires an expression, for example ${r}={condition}`);n={kind:r,condition:Ce.cloneNode(o.value.expression,!0)}}}return n}function Gn(e){e.openingElement.attributes=e.openingElement.attributes.filter(t=>!Ce.isJSXAttribute(t)||Ki(t)===null)}function Wi(e){return Ce.isJSXText(e)&&e.value.trim()===""||Ce.isJSXExpressionContainer(e)&&Ce.isJSXEmptyExpression(e.expression)}function zi(e){let t=e.node.children;if(t.length===0)return;let n=e.get("children"),o=new Map(n.map(a=>[a.node,a])),r=a=>o.get(a)??e,i=[],s=0;for(;s<t.length;){let a=t[s];if(!Ce.isJSXElement(a)){i.push(a),s++;continue}let l=Oo(a,r(a));if(l?.kind==="else-if"||l?.kind==="else")throw r(a).buildCodeFrameError(`memo-dom: JSX ${l.kind} must immediately follow an if or else-if sibling`);if(l?.kind!=="if"){i.push(a),s++;continue}Gn(a);let d=[{condition:l.condition,element:a}],u=null,c=s+1,m=[];for(;c<t.length;){let b=[];for(;c<t.length&&Wi(t[c]);)b.push(t[c]),c++;if(c>=t.length){m=b;break}let f=t[c];if(!Ce.isJSXElement(f)){m=b;break}let g=Oo(f,r(f));if(g?.kind==="else-if"){Gn(f),d.push({condition:g.condition,element:f}),c++;continue}if(g?.kind==="else")for(Gn(f),u=f,c++;c<t.length&&Wi(t[c]);)m.push(t[c]),c++;else m=b;break}let E=u??Ce.nullLiteral();for(let b=d.length-1;b>=0;b--){let f=d[b];E=Ce.conditionalExpression(f.condition,f.element,E)}i.push(Ce.jsxExpressionContainer(E),...m),s=c}e.node.children=i}function Hi(e){e.traverse({JSXElement:{exit(t){zi(t)}},JSXFragment:{exit(t){zi(t)}}}),e.traverse({JSXElement(t){let n=Oo(t.node,t);if(n===null)return;if(n.kind!=="if")throw t.buildCodeFrameError(`memo-dom: JSX ${n.kind} must immediately follow an if or else-if sibling`);Gn(t.node);let o=t.node;t.replaceWith(Ce.jsxFragment(Ce.jsxOpeningFragment(),Ce.jsxClosingFragment(),[Ce.jsxExpressionContainer(Ce.conditionalExpression(n.condition,o,Ce.nullLiteral()))])),t.skip()}})}function Ml(e,t){let n=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#`;for(let o of t.get("body")){let r=o.node;if(O.isExportNamedDeclaration(r)&&(r=r.declaration),!(!O.isVariableDeclaration(r)||r.kind!=="const"))for(let i of r.declarations){if(!O.isIdentifier(i.id)||i.init==null)continue;let s=i.id.name;if(!e.computeds.has(s))continue;r.kind="let";let a=O.cloneNode(i.init),l=J(e,`${s}Next`),d=O.expressionStatement(O.callExpression(ne(e,"register"),[O.objectExpression([O.objectProperty(O.identifier("id"),O.stringLiteral(`${n}${s}`)),O.objectProperty(O.identifier("parent"),O.nullLiteral()),O.objectProperty(O.identifier("depth"),O.unaryExpression("-",O.numericLiteral(1))),O.objectProperty(O.identifier("render"),O.arrowFunctionExpression([],O.blockStatement([O.variableDeclaration("const",[O.variableDeclarator(l,a)]),O.ifStatement(O.callExpression(ne(e,"computedChanged"),[O.identifier(s),O.cloneNode(l)]),O.blockStatement([O.expressionStatement(O.assignmentExpression("=",O.identifier(s),O.cloneNode(l))),O.expressionStatement(O.callExpression(ne(e,"commitWrites"),[Qt(e,[s])]))]))])))])]));o.insertAfter(d)}}}function Dl(e,t){let n=new Map(t.get("body").map(o=>[o.node,o]));for(let o of e.moduleControlFlow){let r=n.get(o.statement);if(r===void 0)continue;let i=new Map(o.bindings.map(a=>[a,J(e,`${a}Previous`)])),s=[O.variableDeclaration("const",o.bindings.map(a=>O.variableDeclarator(O.cloneNode(i.get(a)),O.identifier(a)))),O.cloneNode(o.statement,!0),...o.bindings.map(a=>O.ifStatement(O.callExpression(ne(e,"computedChanged"),[O.cloneNode(i.get(a)),O.identifier(a)]),O.blockStatement([O.expressionStatement(O.callExpression(ne(e,"commitWrites"),[Qt(e,[a])]))])))];r.insertAfter(O.expressionStatement(O.callExpression(ne(e,"register"),[O.objectExpression([O.objectProperty(O.identifier("id"),O.stringLiteral(o.entityId)),O.objectProperty(O.identifier("parent"),O.nullLiteral()),O.objectProperty(O.identifier("depth"),O.unaryExpression("-",O.numericLiteral(1))),O.objectProperty(O.identifier("render"),O.arrowFunctionExpression([],O.blockStatement(s)))])])))}}function $o(e,t={}){let n=En(t),o=new WeakSet;return{name:"memo-dom",visitor:{Program:{enter(i){gn(i),Xn(n,i),Hi(i),hn(n,i),Bi(n,i),Wn(n,i),Ri(n,i),Ii(n)},exit(i){br(n,i),Fi(i),Er(i),n.header.unshift(...Vi(n)),i.traverse({JSXElement(l){throw l.buildCodeFrameError("memo-dom: JSX outside a component or compile-time render helper; components must use a supported top-level declaration")},JSXFragment(l){throw l.buildCodeFrameError("memo-dom: JSX outside a component or compile-time render helper; components must use a supported top-level declaration")}});let s=ln(n);n.computeds.size>0&&Ml(n,i),n.moduleControlFlow.length>0&&Dl(n,i),s&&n.header.push(s);for(let l=n.header.length-1;l>=0;l--)i.unshiftContainer("body",n.header[l]);let a=[O.importDeclaration([O.importNamespaceSpecifier(O.identifier(Et(n).runtimeId))],O.stringLiteral(n.runtimePath))];n.usesRouter&&a.push(O.importDeclaration([O.importNamespaceSpecifier(O.identifier(Et(n).routerId))],O.stringLiteral(n.routerPath))),i.unshiftContainer("body",a),n.rootComponent!==null&&i.pushContainer("body",O.expressionStatement(O.callExpression(ne(n,"registerRootFactory"),[O.identifier(n.rootComponent),O.objectExpression([O.objectProperty(O.identifier("id"),O.stringLiteral(n.rootId)),O.objectProperty(O.identifier("create"),O.arrowFunctionExpression([],O.callExpression(O.identifier(n.rootComponent),[O.stringLiteral(n.rootId),O.nullLiteral(),O.arrayExpression([])])))])])))}},FunctionDeclaration(i){let s=i.node.id?.name;!s||!n.comps.has(s)||o.has(i.node)||(o.add(i.node),ji(n,i,s),i.skip())}}}}function qi(e,t,n,o){let r=t.moduleId??"./component.tsx",i={filename:r,sourceFileName:r,sourceMaps:n,plugins:[[jl,{}],[$o,t],[Jl,{isTSX:!0}]],configFile:!1,babelrc:!1};return o===void 0?Al(e,i):Ll(Ui.cloneNode(o,!0),e,i)}function Xo(e,t={}){return To(e,t)}function To(e,t,n){let o=qi(e,t,!1,n);if(!o||o.code==null)throw new Error("memo-dom: compilation produced no output");return o.code}function Ol(e,t={}){return Bo(e,t)}function Bo(e,t,n){let o=qi(e,t,!0,n);if(!o||o.code==null||o.map==null)throw new Error("memo-dom: compilation produced no output or source map");return{code:o.code,map:o.map}}import{posix as Yt}from"node:path";import{parseSync as Ul,transformFromAstSync as ss}from"@babel/core";import as from"@babel/plugin-syntax-jsx";import ls from"@babel/plugin-transform-typescript";import*as z from"@babel/types";function $l(e,t,n){let o=e.get(t);o===void 0&&(o=new Map,e.set(t,o));let r=o.get(n);return r===void 0&&(r={keys:new Set,rootFallback:!1},o.set(n,r)),r}function Xl(e,t,n,o){if(n.type==="state"){o.keys.add(n.key);return}if(n.type==="root"){o.rootFallback=!0;return}if(n.type==="local")return;let r=e.get(t)?.get(n.name);if(r===void 0){o.rootFallback=!0;return}o.rootFallback||=r.rootFallback;let i=n.path.length===0?"":`.${n.path.join(".")}`;for(let s of r.keys)o.keys.add(`${s}${i}`)}function _i(e,t){let n=new Map;for(let s of e.values())for(let a of s.edges)n.set(a.target,(n.get(a.target)??0)+1);let o=new Map,r=new Map(n),i=[...t];for(;i.length>0;){let s=i.shift();for(let a of e.get(s)?.edges??[]){for(let[d,u]of Object.entries(a.propSources??{})){let c=$l(o,a.target,d);for(let m of u)Xl(o,s,m,c)}let l=(r.get(a.target)??1)-1;r.set(a.target,l),l===0&&i.push(a.target)}}return new Map([...o].map(([s,a])=>[s,new Map([...a].map(([l,d])=>[l,{keys:[...d.keys].sort(),rootFallback:d.rootFallback}]))]))}function Tl(e){let t=new Set,n=new Set,o=r=>{if(n.has(r))throw new Error(`memo-dom: recursive cross-module component graph at '${r}'`);if(!t.has(r)){n.add(r);for(let i of e.get(r)?.edges??[])o(i.target);n.delete(r),t.add(r)}};for(let r of e.keys())o(r)}function Gi(e,t){let n=new Map(e.map(c=>[c.key,c]));Tl(n);let o=new Map,r=new Map;for(let c of n.values())for(let m of c.edges){if(!n.has(m.target))throw new Error(`memo-dom: component '${c.key}' references unknown factory '${m.target}'`);let E=o.get(m.target)??new Set;if(E.add(m.mode),o.set(m.target,E),m.mode==="row"){let b=r.get(m.target)??[];b.push({keyPath:m.keyPath===void 0||m.keyPath===null?null:[...m.keyPath],sourceKey:m.sourceKey??"",sourceLocal:m.sourceLocal??!1}),r.set(m.target,b)}}for(let[c,m]of o)if(m.size>1)throw new Error(`memo-dom: component '${c}' is used both as a keyed row and a static child`);let i=new Map,s=[...n.keys()].filter(c=>!o.has(c)),a=t===void 0?s:[t.key];if(t!==void 0&&!n.has(t.key))throw new Error(`memo-dom: mounted component '${t.key}' is missing from the linked component graph`);for(let c of a)i.set(c,new Set([t?.rootId??"App"]));let l=[...a];for(;l.length>0;){let c=l.shift(),m=i.get(c);if(m!==void 0)for(let E of n.get(c)?.edges??[]){let b=i.get(E.target)??new Set,f=b.size;for(let g of m)b.add(`${g}${E.suffix}`);i.set(E.target,b),b.size!==f&&l.push(E.target)}}let d=new Map;for(let c of n.keys())d.set(c,[...i.get(c)??[]].sort());let u=_i(n,a);return{paths:d,rows:r,propSources:u}}import"@babel/types";import*as xe from"@babel/types";function Zi(e){let t=e;for(;xe.isTSAsExpression(t)||xe.isTSTypeAssertion(t)||xe.isTSNonNullExpression(t)||xe.isTSSatisfiesExpression(t);)t=t.expression;return t}function Bl(e,t,n){let o=Zi(n);if(xe.isIdentifier(o))return!e.state.has(o.name)||t.getBinding(o.name)?.scope.path.isProgram()!==!0?null:tt(e,o.name);if(!xe.isMemberExpression(o))return null;let r=Re(o);return r===null||!e.state.has(r)||t.getBinding(r)?.scope.path.isProgram()!==!0?null:tt(e,Pe(o)??r)}function Vl(e,t){let n=Zi(t);if(xe.isIdentifier(n)){let a=Ye(e,n.name);return a===null?null:{type:"prop",name:a,path:[]}}if(!xe.isMemberExpression(n))return null;let o=Re(n),r=Pe(n);if(o===null||r===null)return null;if(qe(e)===o){let[a,...l]=r.split(".").slice(1);return a===void 0?null:{type:"prop",name:a,path:l}}let s=Ye(e,o);return s===null?null:{type:"prop",name:s,path:r.split(".").slice(1)}}function Wl(e,t){let n=!1,o=qe(e);return Oe(t,r=>{xe.isIdentifier(r)&&(r.name===o||Ye(e,r.name)!==null)&&(n=!0)}),n}function zl(e){return xe.isStringLiteral(e)||xe.isNumericLiteral(e)||xe.isBooleanLiteral(e)||xe.isNullLiteral(e)||xe.isBigIntLiteral(e)||xe.isTemplateLiteral(e)}function Kl(e,t,n,o){let r=Bl(e,n,o);if(r!==null)return{type:"state",key:r};let i=e.componentProps.get(t),s=Vl(i,o);if(s!==null)return s;let a=xe.isIdentifier(o)?o.name:xe.isMemberExpression(o)?Re(o):null;return a!==null&&(e.instanceState.get(t)?.has(a)===!0||e.instanceDerivedBindings.get(t)?.has(a)===!0)||yn(e,o).size>0||Wl(i,o)?{type:"root"}:zl(o)?{type:"local"}:{type:"root"}}function Vo(e,t,n,o){let r=e.get(t)??{},i=r[n]??[],s=JSON.stringify(o);i.some(a=>JSON.stringify(a)===s)||(i.push(o),i.sort((a,l)=>JSON.stringify(a).localeCompare(JSON.stringify(l)))),r[n]=i,e.set(t,r)}function Hl(e){return xe.isJSXIdentifier(e.name)?e.name.name:null}function Yi(e,t){let n=new Map;return e.compPaths.get(t).traverse({JSXOpeningElement(o){let r=o.node.name;if(!xe.isJSXIdentifier(r)||!/^[A-Z]/.test(r.name))return;let i=e.componentProps.get(r.name);for(let s of o.get("attributes")){if(s.isJSXSpreadAttribute()){for(let d of i?.names??[])d==="ref"||i?.refProps.includes(d)||Vo(n,r.name,d,{type:"root"});continue}if(!s.isJSXAttribute())continue;let a=Hl(s.node);if(a===null||a==="key"||a==="ref"||i?.refProps.includes(a)===!0)continue;let l=s.node.value;if(!xe.isJSXExpressionContainer(l)||!xe.isExpression(l.expression)){Vo(n,r.name,a,{type:"local"});continue}Vo(n,r.name,a,Kl(e,t,s.scope,l.expression))}}}),n}function Qi(e,t){let n=new Map;return e.traverse({FunctionDeclaration(o){let r=o.node.id?.name;if(r!==void 0&&/^[A-Z]/.test(r)&&o.scope.parent?.path.isProgram()===!0&&$e(o)){let i=Cn(o.node.params);n.set(r,{key:`${t}#${r}`,props:[...i.names],objectProps:i.mode==="object",acceptsUnknownProps:i.acceptsUnknown,hasWholeDefault:i.hasWholeDefault,listLightweight:!1,delegatedEvents:zt(o.node.body),renderProps:[],renderCallbacks:[],refProps:[],subtreeReads:[]})}o.skip()}}),n}function es(e,t,n){let o=e.componentProps.get(n);return{key:`${t}#${n}`,props:[...o.names],objectProps:o.mode==="object",acceptsUnknownProps:o.acceptsUnknown,hasWholeDefault:o.hasWholeDefault,listLightweight:Jn(e,n),delegatedEvents:[...e.componentHostEvents.get(n)??[]],renderProps:[...o.renderProps],renderCallbacks:[...o.renderCallbacks],refProps:[...o.refProps],subtreeReads:[...Bn(e,n)].map(r=>tt(e,r)).sort()}}function Zn(e,t){return e.importedComponents.get(t)?.key??`${e.moduleId}#${t}`}function ts(e,t){let n=[];for(let o of t.comps.keys()){let r=[],i=Yi(t,o);for(let[s,a]of t.childRefCounts.get(o)??[]){let l=Zn(t,s),d=i.get(s);r.push({target:l,suffix:`/${s}`,mode:"static",...d===void 0?{}:{propSources:d}}),a>1&&r.push({target:l,suffix:`/${s}[*]`,mode:"static",...d===void 0?{}:{propSources:d}})}for(let[s,a]of t.conditionalComponentSites)for(let l of a){if(l.owner!==o)continue;let d=i.get(s);r.push({target:Zn(t,s),suffix:`/${l.suffix}`,mode:"static",...d===void 0?{}:{propSources:d}})}for(let[s,a]of t.rowComponentSites)for(let l of a){if(l.owner!==o)continue;let d=i.get(s);r.push({target:Zn(t,s),suffix:`/${l.suffix}`,mode:"static",...d===void 0?{}:{propSources:d}})}for(let[s,a]of t.listedSites)for(let l of a)l.owner===o&&r.push({target:Zn(t,s),suffix:`/${l.suffix}/Row[*]`,mode:"row",keyPath:it(l.keyExpr??null,l.itemParam??""),sourceKey:l.sourceLocal===!0?l.sourceKey??"":tt(t,l.sourceKey??""),sourceLocal:l.sourceLocal??!1,...i.get(s)===void 0?{}:{propSources:i.get(s)}});n.push({key:`${e}#${o}`,moduleId:e,local:o,edges:r})}return n}function ds(e){let t=e.replace(/\\/g,"/"),n=Yt.normalize(t);return t.startsWith("./")&&!n.startsWith("../")?`./${n}`:n}function ql(e,t){let n=Ul(t,{filename:e,sourceType:"module",parserOpts:{plugins:["typescript","jsx"]},configFile:!1,babelrc:!1});if(n===null)throw new Error(`memo-dom: failed to parse module '${e}'`);return n}function cs(e,t="App"){return{...e.runtimePath===void 0?{}:{runtimePath:e.runtimePath},...e.hot===void 0?{}:{hot:e.hot},rootId:t}}function _l(e){let t=new Map,n=(o,r,i)=>{t.set(`${o}\0${r}\0${i}`,{target:o,prop:r,kind:i})};for(let[o,r]of e.compPaths)r.traverse({JSXElement(i){let s=i.node.openingElement,a=s.name;if(!z.isJSXIdentifier(a)||!/^[A-Z]/.test(a.name))return;let l=e.importedComponents.get(a.name)?.key??(e.comps.has(a.name)?`${e.moduleId}#${a.name}`:null);if(l!==null){for(let d of s.attributes){if(!z.isJSXAttribute(d))continue;let u=z.isJSXIdentifier(d.name)?d.name.name:d.name.name.name,c=d.value;z.isJSXElement(c)||z.isJSXFragment(c)||z.isJSXExpressionContainer(c)&&z.isExpression(c.expression)&&(fe(c.expression)||dt(e,o,c.expression))?n(l,u,"jsx"):n(l,u,"scalar")}i.node.children.some(d=>!z.isJSXText(d)||d.value.trim()!=="")&&n(l,"children","jsx")}}});return[...t.values()].sort((o,r)=>o.target.localeCompare(r.target)||o.prop.localeCompare(r.prop)||o.kind.localeCompare(r.kind))}function ns(e,t){return[...new Set(t.flatMap(n=>{let o=e.importedComponents.get(n);return o!==void 0?[o.key]:e.comps.has(n)?[`${e.moduleId}#${n}`]:[]}))].sort()}function Mt(e,t,n){for(;z.isTSAsExpression(e)||z.isTSTypeAssertion(e)||z.isTSNonNullExpression(e);)e=e.expression;if(z.isIdentifier(e)){t.has(e.name)&&n.add(e.name);return}if(z.isConditionalExpression(e)){Mt(e.consequent,t,n),Mt(e.alternate,t,n);return}if(z.isLogicalExpression(e)){Mt(e.right,t,n);return}if(z.isObjectExpression(e)){for(let o of e.properties)z.isObjectProperty(o)&&z.isExpression(o.value)&&Mt(o.value,t,n);return}if(z.isArrayExpression(e))for(let o of e.elements)o!=null&&!z.isSpreadElement(o)&&Mt(o,t,n)}function os(e,t){let n=new Set;if(z.isExpression(e.body))return Mt(e.body,t,n),[...n];let o=r=>{if(!z.isFunction(r)){if(z.isReturnStatement(r)){z.isExpression(r.argument)&&Mt(r.argument,t,n);return}for(let i of z.VISITOR_KEYS[r.type]??[]){let s=r[i];if(Array.isArray(s))for(let a of s)a!=null&&typeof a=="object"&&"type"in a&&o(a);else s!=null&&typeof s=="object"&&"type"in s&&o(s)}}};for(let r of e.body.body)o(r);return[...n]}function us(e){let t=[];for(let n of e.body)if(!(!z.isImportDeclaration(n)||n.importKind==="type"))for(let o of n.specifiers)if(z.isImportSpecifier(o)){if(o.importKind==="type")continue;let r=z.isIdentifier(o.imported)?o.imported.name:o.imported.value;t.push({local:o.local.name,imported:r,source:n.source.value})}else z.isImportDefaultSpecifier(o)?t.push({local:o.local.name,imported:"default",source:n.source.value}):t.push({local:o.local.name,imported:"*",source:n.source.value});return t}function ps(e,t){let n=new Set;for(let r of e.body)if(!(!z.isImportDeclaration(r)||r.source.value!==t))for(let i of r.specifiers)z.isImportSpecifier(i)&&(z.isIdentifier(i.imported,{name:"mount"})||z.isStringLiteral(i.imported,{value:"mount"}))&&n.add(i.local.name);let o=[];for(let r of e.body){if(!z.isExpressionStatement(r))continue;let i=r.expression;if(!z.isCallExpression(i)||!z.isIdentifier(i.callee)||!n.has(i.callee.name))continue;let s=i.arguments[1];if(s===void 0||!z.isIdentifier(s))throw new Error("memo-dom: mount() must receive a statically imported component identifier");o.push(s.name)}return o}function fs(e){let t=new Map;for(let n of e.body){if(z.isExportDefaultDeclaration(n)){(z.isFunctionDeclaration(n.declaration)||z.isClassDeclaration(n.declaration))&&n.declaration.id!=null?t.set("default",n.declaration.id.name):z.isIdentifier(n.declaration)&&t.set("default",n.declaration.name);continue}if(!z.isExportNamedDeclaration(n))continue;if(n.source!==null)throw new Error("memo-dom: re-export-from declarations are not supported by compileModules(); import then export the binding explicitly");let o=n.declaration;if(z.isVariableDeclaration(o))for(let r of o.declarations)z.isIdentifier(r.id)&&t.set(r.id.name,r.id.name);else z.isFunctionDeclaration(o)&&o.id!=null&&t.set(o.id.name,o.id.name);for(let r of n.specifiers){if(!z.isExportSpecifier(r))continue;let i=r.local.name,s=z.isIdentifier(r.exported)?r.exported.name:r.exported.value;t.set(s,i)}}return t}function Gl(e,t,n,o){let r,i=()=>({visitor:{Program(s){gn(s);let a=us(s.node),l=En({...cs(n,o),moduleId:e.id,linkedImports:t});Xn(l,s),hn(l,s),Wn(l,s),ln(l);let d={},u=go(s.node);for(let[c,m]of fs(s.node)){if(l.comps.has(m)){d[c]={type:"component",...es(l,e.id,m)};continue}let E=l.state.get(m);if(E!==void 0){d[c]={type:"state",kind:E,key:l.stateKeys.get(m)??`${e.id}#${m}`,tagCandidates:[...l.stateTagCandidates.get(m)??[]],componentCandidates:ns(l,l.stateComponentCandidates.get(m)??[])};continue}let b=l.importedFunctions.get(m)??(l.helpers.has(m)?Be(l,m):void 0);b!==void 0&&(d[c]={type:"function",tagCandidates:[...u.get(m)??l.functionTagCandidates.get(m)??[]],componentCandidates:ns(l,l.functionComponentCandidates.get(m)??[]),reads:[...b.reads].map(f=>tt(l,f)).sort(),writes:[...b.writes].map(f=>tt(l,f)).sort(),boundedWrites:[...b.boundedWrites].map(f=>tt(l,f)).sort(),parameterWrites:b.parameterWrites.map(f=>({index:f.index,path:[...f.path]})).sort((f,g)=>f.index-g.index||f.path.join(".").localeCompare(g.path.join("."))),unbounded:b.unbounded})}r={exports:d,imports:a,mounts:ps(s.node,n.runtimePath??"@memoized-dom/runtime"),components:ts(e.id,l),componentUsages:_l(l),readers:Object.fromEntries([...l.readers.entries()].sort(([c],[m])=>c.localeCompare(m)).map(([c,m])=>[c,[...m].sort()]))}}}});if(ss(z.cloneNode(e.ast,!0),e.source,{filename:e.id,plugins:[[as,{}],i,[ls,{isTSX:!0}]],configFile:!1,babelrc:!1}),r===void 0)throw new Error(`memo-dom: failed to analyze module '${e.id}'`);return r}function Zl(e,t){let n,o=()=>({visitor:{Program(r){gn(r);let i=new Map,s=Tn(r.node),a=go(r.node),l=Qi(r,e.id),d=new Set(l.keys());for(let[c,m]of l)i.set(c,{type:"component",...m});for(let c of r.node.body){let m=z.isExportNamedDeclaration(c)?c.declaration:c;if(z.isVariableDeclaration(m))for(let E of m.declarations){if(!z.isIdentifier(E.id))continue;let b=E.init!==null&&z.isExpression(E.init)?$t(E.init):E.init;if(z.isArrowFunctionExpression(b)||z.isFunctionExpression(b)){let g=os(b,d).map(h=>`${e.id}#${h}`);i.set(E.id.name,{type:"function",tagCandidates:[...a.get(E.id.name)??[]],componentCandidates:g,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0});continue}let f;if(m.kind==="let"||m.kind==="var"?f="let":Dt(b)?f="store":Lt(b)&&(f="const"),f!==void 0){let g=new Set;z.isExpression(b)&&Mt(b,d,g),i.set(E.id.name,{type:"state",kind:f,key:`${e.id}#${E.id.name}`,tagCandidates:[...s.get(E.id.name)??[]],componentCandidates:[...g].map(h=>`${e.id}#${h}`)})}}else if(z.isFunctionDeclaration(m)&&m.id!=null&&!l.has(m.id.name)){let E=os(m,d).map(b=>`${e.id}#${b}`);i.set(m.id.name,{type:"function",tagCandidates:[...a.get(m.id.name)??[]],componentCandidates:E,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0})}}let u={};for(let[c,m]of fs(r.node)){let E=i.get(m);E!==void 0&&(u[c]=E)}n={exports:u,imports:us(r.node),mounts:ps(r.node,t.runtimePath??"@memoized-dom/runtime"),components:[],componentUsages:[],readers:{}}}}});if(ss(z.cloneNode(e.ast,!0),e.source,{filename:e.id,plugins:[[as,{}],o,[ls,{isTSX:!0}]],configFile:!1,babelrc:!1}),n===void 0)throw new Error(`memo-dom: failed to discover module '${e.id}'`);return n}function Yn(e,t,n,o){let i=o.resolveImport?.(t,e);if(i===void 0){let l=Object.entries(o.aliases??{}).sort(([d],[u])=>u.length-d.length);for(let[d,u]of l)if(d.endsWith("/")?t.startsWith(d):t===d||t.startsWith(`${d}/`)){i=`${u}${t.slice(d.length)}`;break}}if(i===void 0)if(t.startsWith(".")){let l=Yt.normalize(Yt.join(Yt.dirname(e),t));i=e.startsWith("./")&&!l.startsWith("../")?`./${l}`:l}else i=t;let s=ds(i??t),a=[s,`${s}.ts`,`${s}.tsx`,`${s}.js`,`${s}.jsx`,`${s}/index.ts`,`${s}/index.tsx`,`${s}/index.js`,`${s}/index.jsx`];for(let l of a){let d=n.get(l);if(d!==void 0)return d}}function rs(e,t,n){let o=[];for(let r of e.values()){let i=t.get(r.id);for(let s of i.mounts){let a=i.imports.find(c=>c.local===s);if(a===void 0||a.imported==="*")throw new Error(`memo-dom: mount root '${s}' must be a statically imported component`);let l=Yn(r.id,a.source,e,n),d=l===void 0?void 0:t.get(l.id)?.exports[a.imported];if(l===void 0||d?.type!=="component")throw new Error(`memo-dom: mount root '${s}' does not resolve to a compiled component`);let u=d.key.slice(d.key.lastIndexOf("#")+1);o.push({key:d.key,moduleId:l.id,mountModuleId:r.id,local:u,rootId:u})}}if(o.length>1)throw new Error("memo-dom: one connected application graph may contain only one top-level mount() call");return o[0]}function Yl(e,t){if(!t.startsWith("."))return t;let n=Yt.relative(Yt.dirname(e),t);return n.startsWith(".")?n:`./${n}`}function Wo(e,t,n){return t.map(o=>{for(let[r,i]of n)for(let[s,a]of Object.entries(i.exports))if(!(a.type!=="component"||a.key!==o))return{key:a.key,source:Yl(e.id,r),imported:s,props:[...a.props],objectProps:a.objectProps,acceptsUnknownProps:a.acceptsUnknownProps,hasWholeDefault:a.hasWholeDefault,listLightweight:a.listLightweight,delegatedEvents:a.delegatedEvents,renderProps:[...a.renderProps],renderCallbacks:[...a.renderCallbacks],refProps:[...a.refProps],subtreeReads:[...a.subtreeReads]};throw new Error(`memo-dom: dynamic component candidate '${o}' is not exported; export the component so consuming modules can link it`)})}function ms(e,t,n,o,r,i){let s={};for(let a of t.imports){let l=Yn(e.id,a.source,o,r);if(l===void 0){s[a.local]={type:"function",tagCandidates:[],componentCandidates:[],reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}if(a.imported==="*")throw new Error(`memo-dom: namespace import '${a.local}' from '${a.source}' cannot identify a reactive export; use named imports`);let d=n.get(l.id)?.exports[a.imported];if(d===void 0){s[a.local]={type:"function",tagCandidates:[],componentCandidates:[],reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}if(d.type==="state")s[a.local]={type:"state",kind:d.kind,key:d.key,tagCandidates:[...d.tagCandidates],componentCandidates:Wo(e,d.componentCandidates,n)};else if(d.type==="component"){let u=i?.get(d.key),c=d.renderProps.filter(m=>u?.scalar.has(m)!==!0||u.jsx.has(m));s[a.local]={type:"component",key:d.key,props:[...d.props],objectProps:d.objectProps,acceptsUnknownProps:d.acceptsUnknownProps,hasWholeDefault:d.hasWholeDefault,listLightweight:d.listLightweight,delegatedEvents:d.delegatedEvents,renderProps:c,renderCallbacks:[...d.renderCallbacks],refProps:[...d.refProps],subtreeReads:[...d.subtreeReads]}}else{if(r.linkFunctionSummaries===!1){s[a.local]={type:"function",tagCandidates:[...d.tagCandidates],componentCandidates:Wo(e,d.componentCandidates,n),reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}s[a.local]={type:"function",tagCandidates:[...d.tagCandidates],componentCandidates:Wo(e,d.componentCandidates,n),reads:[...d.reads],writes:[...d.writes],boundedWrites:[...d.boundedWrites],parameterWrites:[...d.parameterWrites],unbounded:d.unbounded}}}return s}function is(e){return JSON.stringify(e)}function Ql(e,t,n){let o=new Map;for(let r of e.keys())o.set(r,new Set);for(let r of e.values()){let i=t.get(r.id);for(let s of i.imports){let a=Yn(r.id,s.source,e,n);a!==void 0&&o.get(a.id).add(r.id)}}return o}function ed(e,t,n,o){let r=new Map(t),i=Ql(e,r,n),s=[...e.keys()],a=new Set(s),l=Math.max(16,e.size*e.size*4),d=0;for(;s.length>0;){let u=s.shift();a.delete(u);let c=e.get(u),m=r.get(u),E=ms(c,m,r,e,n),b=Gl(c,E,n,o);if(d++,d>l)throw new Error("memo-dom: cross-module export summaries did not converge");if(is(b)!==is(m)){r.set(u,b);for(let f of i.get(u)??[])a.has(f)||(a.add(f),s.push(f))}}return r}function gs(e,t,n){let o=new Map;for(let[g,h]of Object.entries(e)){let C=ds(g);if(o.has(C))throw new Error(`memo-dom: duplicate module id after normalization: '${C}'`);o.set(C,{originalId:g,id:C,source:h,ast:ql(C,h)})}let r=new Map;for(let g of o.values())r.set(g.id,Zl(g,t));let s=rs(o,r,t)?.rootId??"App",a=ed(o,r,t,s),l=rs(o,a,t),d=[...o.values()].flatMap(g=>{try{return Ti(g.ast,g.id)}catch(h){throw new Error(`${g.id}: memo-dom: ${h.message}`)}});try{Jo(d)}catch(g){throw new Error(`memo-dom: ${g.message}`)}let u=l?.moduleId??o.values().next().value?.id,c=new Map;for(let g of a.values())for(let h of g.componentUsages){let C=c.get(h.target);C===void 0&&(C={jsx:new Set,scalar:new Set},c.set(h.target,C)),C[h.kind].add(h.prop)}for(let[g,h]of c)for(let C of h.jsx)if(h.scalar.has(C))throw new Error(`memo-dom: component '${g}' prop '${C}' is used as both scalar data and JSX content; split the prop or component contract`);let m=Gi([...a.values()].flatMap(g=>g.components),l),E={},b={},f={};for(let g of o.values()){let h=a.get(g.id);f[g.originalId]={componentExports:Object.entries(h.exports).filter(R=>R[1].type==="component").map(([R,k])=>({exported:R,local:h.components.find(W=>W.key===k.key)?.local??k.key.slice(k.key.lastIndexOf("#")+1),listLightweight:k.listLightweight})).sort((R,k)=>R.local.localeCompare(k.local)),stateExports:Object.entries(h.exports).filter(R=>R[1].type==="state").map(([R,k])=>({exported:R,kind:k.kind,key:k.key})).sort((R,k)=>R.exported.localeCompare(k.exported)),functionExports:Object.entries(h.exports).filter(R=>R[1].type==="function").map(([R,k])=>({exported:R,reads:[...k.reads],writes:[...k.writes],boundedWrites:[...k.boundedWrites],parameterWrites:k.parameterWrites.map(W=>({index:W.index,path:[...W.path]})),unbounded:k.unbounded})).sort((R,k)=>R.exported.localeCompare(k.exported)),readers:Object.fromEntries(Object.entries(h.readers).map(([R,k])=>[R,[...k]]))};let C=ms(g,h,a,o,t,c);for(let R of h.imports){let k=Yn(g.id,R.source,o,t);if(k!==void 0&&a.get(k.id)?.exports[R.imported]===void 0)throw new Error(`memo-dom: '${R.imported}' is not a linkable state, function, or component export of '${R.source}'`)}let N={},v={},$={},_={};for(let R of h.components){N[R.local]=[...m.paths.get(R.key)??[]];let k=m.rows.get(R.key);k!==void 0&&(v[R.local]=k.map(ee=>({keyPath:ee.keyPath===null?null:[...ee.keyPath],sourceKey:ee.sourceKey,sourceLocal:ee.sourceLocal})));let W=m.propSources.get(R.key);W!==void 0&&($[R.local]=Object.fromEntries([...W].map(([ee,oe])=>[ee,{keys:[...oe.keys],rootFallback:oe.rootFallback}])));let T=Object.values(h.exports).find(ee=>ee.type==="component"&&ee.key===R.key);if(T?.type==="component"){let ee=c.get(R.key);_[R.local]=T.renderProps.filter(oe=>ee?.scalar.has(oe)!==!0||ee.jsx.has(oe))}}let B={...cs(t,s),moduleId:g.id,linkedImports:C,linkedComponentPaths:N,linkedComponentRows:v,linkedComponentPropSources:$,linkedComponentRenderProps:_,linkedRoutes:d,emitRouteManifest:g.id===u,...l?.moduleId===g.id?{rootComponent:l.local}:{}};if(n){let R=Bo(g.source,B,g.ast);E[g.originalId]=R.code,b[g.originalId]=R.map}else E[g.originalId]=To(g.source,B,g.ast)}return{output:E,maps:b,metadata:f,...l===void 0?{}:{applicationRoot:l}}}function td(e,t={}){return gs(e,t,!0)}function zo(e,t={}){return gs(e,t,!1).output}var Es=98e3,hs="memoized-dom",nd=/\x1B\[[0-?]*[ -/]*[@-~]/g;function od(e){return e.replace(nd,"")}function bs(e){return e.replaceAll("\\","/").replace(/^\.\//,"")}function rd(e,t){let n=bs(e);return[...t].sort((o,r)=>r.length-o.length).find(o=>n.endsWith(bs(o)))}function Ko(e,t=[]){let n=e,o=od(typeof n?.message=="string"?n.message:String(e)),r=o.indexOf(": memo-dom:"),i=o.match(/\((\d+):(\d+)\)/),s=n?.loc,a=typeof s?.line=="number"?s.line:i===null?void 0:Number(i[1]),l=typeof s?.column=="number"?s.column:i===null?void 0:Number(i[2]),d=r===-1?"":o.slice(0,r),u=rd(d,t)??(t.length===1?t[0]:void 0),c=r===-1?o:o.slice(r+2);return{code:Es,source:hs,severity:"error",message:c,...u===void 0?{}:{moduleId:u},...a===void 0?{}:{line:a},...l===void 0?{}:{column:l}}}function id(e,t={}){try{return Xo(e,t),[]}catch(n){return[Ko(n,[t.moduleId??"./component.tsx"])]}}function sd(e,t={}){try{return zo(e,t),[]}catch(n){return[Ko(n,Object.keys(e))]}}export{Xo as compile,Ol as compileDetailed,zo as compileModules,td as compileModulesDetailed,Es as compilerDiagnosticCode,hs as compilerDiagnosticSource,id as diagnose,sd as diagnoseModules,Ko as toCompilerDiagnostic};
|
|
1
|
+
import{langFromPath as e,parse as t,sourceTypeFromPath as n}from"yuku-parser";import{print as r}from"esrap";import i from"esrap/languages/tsx";import{analyzeTsrx as a,annotateWithHash as o,parseModule as s,prepareStylesheetForRender as c,renderStylesheets as l}from"@tsrx/core";import{posix as u}from"node:path";function d(e){return{type:`Identifier`,name:e}}function f(e){return{type:`Literal`,value:e,raw:JSON.stringify(e)}}function p(e){return{type:`Literal`,value:e,raw:String(e)}}function m(e){return{type:`Literal`,value:e,raw:String(e)}}function h(){return{type:`Literal`,value:null,raw:`null`}}function g(e,t){return{type:`CallExpression`,callee:e,arguments:t}}function _(e,t,n=!1,r=!1){return{type:`MemberExpression`,object:e,property:t,computed:n,optional:r?!0:void 0}}function v(e,t,n=!1,r=!0){return _(e,t,n,r)}function y(e=[]){return{type:`ArrayExpression`,elements:e}}function b(e=[]){return{type:`ObjectExpression`,properties:e}}function ee(e,t,n=!1,r=!1){return{type:`Property`,key:e,value:t,kind:`init`,method:!1,shorthand:r,computed:n}}function te(e){return{type:`SpreadElement`,argument:e}}function ne(e,t=[]){return{type:`NewExpression`,callee:e,arguments:t}}function re(e,t,n){return{type:`BinaryExpression`,operator:e,left:t,right:n}}function x(e,t,n=!0){return{type:`UnaryExpression`,operator:e,argument:t,prefix:n}}function ie(e,t,n){return{type:`LogicalExpression`,operator:e,left:t,right:n}}function ae(e,t,n){return{type:`AssignmentExpression`,operator:e,left:t,right:n}}function oe(e,t,n){return{type:`ConditionalExpression`,test:e,consequent:t,alternate:n}}function se(e){return{type:`SequenceExpression`,expressions:e}}function ce(e,t){return{type:`AssignmentPattern`,left:e,right:t}}function le(e,t,n,r=!1,i=!1){return{type:`FunctionDeclaration`,id:e,params:t,body:n,generator:r,async:i}}function ue(e,t,n=!1){return{type:`ArrowFunctionExpression`,params:e,body:t,generator:!1,async:n,expression:t.type!==`BlockStatement`}}function de(e=[]){return{type:`BlockStatement`,body:e}}function fe(e){return{type:`ExpressionStatement`,expression:e}}function pe(e=null){return{type:`ReturnStatement`,argument:e}}function me(e,t,n=null){return{type:`IfStatement`,test:e,consequent:t,alternate:n}}function he(e,t,n,r=!1){return{type:`ForOfStatement`,left:e,right:t,body:n,await:r}}function ge(e,t){return{type:`VariableDeclaration`,kind:e,declarations:t}}function _e(e,t=null){return{type:`VariableDeclarator`,id:e,init:t}}function ve(e,t){return{type:`ImportDeclaration`,specifiers:e,source:t}}function ye(e,t=e){return{type:`ImportSpecifier`,local:e,imported:t}}function be(e){return{type:`ImportDefaultSpecifier`,local:e}}function xe(e){return{type:`ImportNamespaceSpecifier`,local:e}}function Se(e=null,t=[],n=null){return{type:`ExportNamedDeclaration`,declaration:e,specifiers:t,source:n}}function Ce(e){return{type:`JSXIdentifier`,name:e}}function we(e,t=null){return{type:`JSXAttribute`,name:e,value:t}}function Te(e){return{type:`JSXExpressionContainer`,expression:e}}function Ee(e,t=[],n=!1){return{type:`JSXOpeningElement`,name:e,attributes:t,selfClosing:n}}function De(e,t,n=[]){return{type:`JSXElement`,openingElement:e,closingElement:t,children:n}}function Oe(){return{type:`JSXOpeningFragment`}}function ke(){return{type:`JSXClosingFragment`}}function Ae(e=Oe(),t=ke(),n=[]){return{type:`JSXFragment`,openingFragment:e,closingFragment:t,children:n}}function je(e){if(Array.isArray(e))return e.map(je);if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(typeof e==`object`&&e){let t={};for(let[n,r]of Object.entries(e))t[n]=je(r);return t}return e}function S(e,t=!0){return t?je(e):{...e}}function Me(e,t){return e.leadingComments=t.leadingComments,e.trailingComments=t.trailingComments,e.innerComments=t.innerComments,e}function Ne(e){return!!(e&&typeof e==`object`&&e.type===`Identifier`)}function Pe(e){return!!(e&&typeof e==`object`&&e.type===`Literal`)}function Fe(e){return!!(e&&typeof e==`object`&&e.type===`Literal`&&typeof e.value==`string`)}function Ie(e){return!!(e&&typeof e==`object`&&e.type===`Literal`&&typeof e.value==`number`)}function Le(e){return!!(e&&typeof e==`object`&&e.type===`Literal`&&typeof e.value==`boolean`)}function Re(e){return!!(e&&typeof e==`object`&&e.type===`Literal`&&e.value===null)}function ze(e){return!!(e&&typeof e==`object`&&e.type===`CallExpression`)}function Be(e){return!!(e&&typeof e==`object`&&e.type===`MemberExpression`)}function Ve(e){return!!(e&&typeof e==`object`&&e.type===`ArrayExpression`)}function He(e){return!!(e&&typeof e==`object`&&e.type===`ObjectExpression`)}function Ue(e){return!!(e&&typeof e==`object`&&e.type===`FunctionDeclaration`)}function We(e){return!!(e&&typeof e==`object`&&e.type===`ArrowFunctionExpression`)}function Ge(e){return!!(e&&typeof e==`object`&&e.type===`VariableDeclaration`)}function Ke(e){return!!(e&&typeof e==`object`&&e.type===`VariableDeclarator`)}function qe(e){return!!(e&&typeof e==`object`&&e.type===`BlockStatement`)}function Je(e){return!!(e&&typeof e==`object`&&e.type===`ReturnStatement`)}function Ye(e){return!!(e&&typeof e==`object`&&e.type===`IfStatement`)}function Xe(e){return!!(e&&typeof e==`object`&&e.type===`ExpressionStatement`)}function Ze(e){return!!(e&&typeof e==`object`&&e.type===`AssignmentExpression`)}function Qe(e){return!!(e&&typeof e==`object`&&e.type===`BinaryExpression`)}function $e(e){return!!(e&&typeof e==`object`&&e.type===`UnaryExpression`)}function et(e){return!!(e&&typeof e==`object`&&e.type===`LogicalExpression`)}function tt(e){return!!(e&&typeof e==`object`&&e.type===`ConditionalExpression`)}function nt(e){if(!e||typeof e!=`object`)return!1;let t=e.type;return Ne(e)||Pe(e)||ze(e)||Be(e)||Ve(e)||He(e)||We(e)||$e(e)||Qe(e)||et(e)||Ze(e)||tt(e)||rt(e)||st(e)||t===`ThisExpression`||t===`FunctionExpression`||t===`TemplateLiteral`||t===`TaggedTemplateExpression`||t===`SequenceExpression`||t===`AwaitExpression`||t===`ChainExpression`}function rt(e){return!!(e&&typeof e==`object`&&e.type===`JSXElement`)}function it(e){return!!(e&&typeof e==`object`&&e.type===`JSXAttribute`)}function at(e){return!!(e&&typeof e==`object`&&e.type===`JSXExpressionContainer`)}function ot(e){return!!(e&&typeof e==`object`&&e.type===`JSXText`)}function st(e){return!!(e&&typeof e==`object`&&e.type===`JSXFragment`)}const ct=new Set(`await.break.case.catch.class.const.continue.debugger.default.delete.do.else.enum.export.extends.false.finally.for.function.if.implements.import.in.instanceof.interface.let.new.null.package.private.protected.public.return.static.super.switch.this.throw.true.try.typeof.var.void.while.with.yield`.split(`.`)),lt=/^(?:[$_\p{ID_Start}])(?:[$_\p{ID_Continue}]|\u{200C}|\u{200D})*$/u,ut=/^(?:[$_\p{ID_Continue}]|\u{200C}|\u{200D})$/u;function dt(e){return lt.test(e)&&!ct.has(e)}function ft(e){let t=``;for(let n of e)t+=ut.test(n)?n:`-`;return t=t.replace(/^[-0-9]+/,``),t=t.replace(/[-\s]+(.)?/g,(e,t)=>t===void 0?``:t.toUpperCase()),dt(t)||(t=`_${t}`),t||`_`}function pt(e){return!!(e&&typeof e==`object`&&e.type===`JSXSpreadAttribute`)}function mt(e){return!!(e&&typeof e==`object`&&e.type===`JSXIdentifier`)}const ht={Program:[`body`],Identifier:[],Literal:[],StringLiteral:[],NumericLiteral:[],BooleanLiteral:[],NullLiteral:[],ThisExpression:[],ArrayExpression:[`elements`],ObjectExpression:[`properties`],Property:[`key`,`value`],ObjectProperty:[`key`,`value`],SpreadElement:[`argument`],FunctionDeclaration:[`id`,`params`,`body`],FunctionExpression:[`id`,`params`,`body`],ArrowFunctionExpression:[`params`,`body`],VariableDeclaration:[`declarations`],VariableDeclarator:[`id`,`init`],BlockStatement:[`body`],ExpressionStatement:[`expression`],IfStatement:[`test`,`consequent`,`alternate`],ReturnStatement:[`argument`],MemberExpression:[`object`,`property`],OptionalMemberExpression:[`object`,`property`],CallExpression:[`callee`,`arguments`],OptionalCallExpression:[`callee`,`arguments`],UnaryExpression:[`argument`],UpdateExpression:[`argument`],BinaryExpression:[`left`,`right`],LogicalExpression:[`left`,`right`],AssignmentExpression:[`left`,`right`],ConditionalExpression:[`test`,`consequent`,`alternate`],TemplateLiteral:[`quasis`,`expressions`],TemplateElement:[],TaggedTemplateExpression:[`tag`,`quasi`],NewExpression:[`callee`,`arguments`],SequenceExpression:[`expressions`],ParenthesizedExpression:[`expression`],YieldExpression:[`argument`],AwaitExpression:[`argument`],ChainExpression:[`expression`],ImportExpression:[`source`],MetaProperty:[`meta`,`property`],ClassDeclaration:[`id`,`superClass`,`body`],ClassExpression:[`id`,`superClass`,`body`],ClassBody:[`body`],MethodDefinition:[`key`,`value`],EmptyStatement:[],DebuggerStatement:[],WithStatement:[`object`,`body`],LabeledStatement:[`label`,`body`],BreakStatement:[`label`],ContinueStatement:[`label`],SwitchStatement:[`discriminant`,`cases`],SwitchCase:[`test`,`consequent`],ThrowStatement:[`argument`],TryStatement:[`block`,`handler`,`finalizer`],CatchClause:[`param`,`body`],WhileStatement:[`test`,`body`],DoWhileStatement:[`body`,`test`],ForStatement:[`init`,`test`,`update`,`body`],ForInStatement:[`left`,`right`,`body`],ForOfStatement:[`left`,`right`,`body`],ImportDeclaration:[`specifiers`,`source`],ImportSpecifier:[`imported`,`local`],ImportDefaultSpecifier:[`local`],ImportNamespaceSpecifier:[`local`],ExportNamedDeclaration:[`declaration`,`specifiers`,`source`],ExportSpecifier:[`local`,`exported`],ExportDefaultDeclaration:[`declaration`],ExportAllDeclaration:[`source`,`exported`],RestElement:[`argument`],AssignmentPattern:[`left`,`right`],ArrayPattern:[`elements`],ObjectPattern:[`properties`],JSXElement:[`openingElement`,`children`,`closingElement`],JSXOpeningElement:[`name`,`attributes`],JSXClosingElement:[`name`],JSXIdentifier:[],JSXMemberExpression:[`object`,`property`],JSXNamespacedName:[`namespace`,`name`],JSXAttribute:[`name`,`value`],JSXSpreadAttribute:[`argument`],JSXExpressionContainer:[`expression`],JSXEmptyExpression:[],JSXText:[],JSXFragment:[`openingFragment`,`children`,`closingFragment`],JSXOpeningFragment:[],JSXClosingFragment:[],JSXSpreadChild:[`expression`],TSTypeAnnotation:[`typeAnnotation`],TSTypeAliasDeclaration:[`id`,`typeAnnotation`],TSInterfaceDeclaration:[`id`,`body`],TSTypeParameterDeclaration:[`params`],TSTypeParameterInstantiation:[`params`],TSAsExpression:[`expression`,`typeAnnotation`],TSTypeAssertion:[`expression`,`typeAnnotation`],TSNonNullExpression:[`expression`]};function C(e,t){function n(e,r,i,a){if(t.enter&&t.enter(e,r,i,a)===!1)return;let o=ht[e.type]??Object.keys(e);for(let t of o){let r=e[t];if(Array.isArray(r)){let i=r;for(let r=0;r<i.length;r++){let a=i[r];a&&typeof a==`object`&&`type`in a&&n(a,e,t,r)}}else r&&typeof r==`object`&&`type`in r&&n(r,e,t,void 0)}t.leave&&t.leave(e,r,i,a)}n(e,null,void 0,void 0)}var gt=class{parent=null;children=[];bindings=new Map;block;isFunctionScope;isProgramScope;constructor(e,t=null,n=!1){this.block=e,this.parent=t,this.isFunctionScope=n,this.isProgramScope=t===null,t&&t.children.push(this)}registerBinding(e,t,n,r){let i={name:e,kind:t,identifier:n,declarationNode:r,scope:this,references:[],constantViolations:[]};return this.bindings.set(e,i),i}getBinding(e){return this.bindings.get(e)??this.parent?.getBinding(e)}hasBinding(e){return this.getBinding(e)!==void 0}hasOwnBinding(e){return this.bindings.has(e)}getProgramScope(){return this.parent?.getProgramScope()??this}getFunctionScope(){return this.isFunctionScope?this:this.parent?.getFunctionScope()??null}};function _t(e,t){return e[t]}function vt(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function yt(e,t){let n=_t(e,t);return vt(n)?n:null}function bt(e,t){let n=_t(e,t);return Array.isArray(n)?n.filter(vt):[]}function xt(e){return e?.type===`Identifier`?e:null}function St(e){let t=[];if(e.type===`Identifier`)t.push(e);else if(e.type===`ObjectPattern`)for(let n of bt(e,`properties`))if(n.type===`Property`||n.type===`ObjectProperty`){let e=yt(n,`value`);e!==null&&t.push(...St(e))}else n.type===`RestElement`&&t.push(...St(n));else if(e.type===`ArrayPattern`)for(let n of bt(e,`elements`))t.push(...St(n));else if(e.type===`RestElement`){let n=yt(e,`argument`);n!==null&&t.push(...St(n))}else if(e.type===`AssignmentPattern`){let n=yt(e,`left`);n!==null&&t.push(...St(n))}else if(e.type===`TSParameterProperty`){let n=yt(e,`parameter`);n!==null&&t.push(...St(n))}return t}function Ct(e,t){return e===null||e.type===`MemberExpression`&&t===`property`&&_t(e,`computed`)===!1||e.type===`OptionalMemberExpression`&&t===`property`&&_t(e,`computed`)===!1||(e.type===`Property`||e.type===`ObjectProperty`)&&t===`key`&&_t(e,`computed`)===!1||e.type===`MethodDefinition`&&t===`key`&&_t(e,`computed`)===!1||e.type===`LabeledStatement`&&t===`label`||(e.type===`BreakStatement`||e.type===`ContinueStatement`)&&t===`label`||e.type===`ExportSpecifier`&&t===`exported`||e.type===`MetaProperty`||e.type.startsWith(`TS`)?!1:!e.type.startsWith(`Import`)}function wt(e,t,n){let r=e,i=t.get(r)??null;for(;i!==null;){let e=n.get(r);if(i.type===`UpdateExpression`&&e===`argument`)return i;if(i.type===`AssignmentExpression`||i.type===`ForInStatement`||i.type===`ForOfStatement`)return e===`left`?i:null;if(i.type!==`ArrayPattern`&&i.type!==`ObjectPattern`&&i.type!==`AssignmentPattern`&&i.type!==`RestElement`&&i.type!==`Property`&&i.type!==`ObjectProperty`)return null;r=i,i=t.get(r)??null}return null}function Tt(e){let t=new gt(e,null,!1),n=new Map,r=new Map,i=new Map,a=new Map,o=new Map,s=new Set,c=t;return n.set(e,t),C(e,{enter(e,t,l,u){if(r.set(e,t),i.set(e,l),a.set(e,u),e.type===`FunctionDeclaration`){let t=xt(yt(e,`id`));t!==null&&(c.registerBinding(t.name,`function`,t,e),s.add(t))}else if(e.type===`ClassDeclaration`){let t=xt(yt(e,`id`));t!==null&&(c.registerBinding(t.name,`class`,t,e),s.add(t))}if(e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`){let t=new gt(e,c,!0);o.set(e,t),c=t,n.set(e,t);let r=xt(yt(e,`id`));e.type===`FunctionExpression`&&r!==null&&(t.registerBinding(r.name,`function`,r,e),s.add(r));for(let n of bt(e,`params`))for(let r of St(n))t.registerBinding(r.name,`param`,r,e),s.add(r);return}if(e.type===`BlockStatement`){if(t&&(t.type===`FunctionDeclaration`||t.type===`FunctionExpression`||t.type===`ArrowFunctionExpression`)){n.set(e,c);return}let r=new gt(e,c,!1);o.set(e,r),n.set(e,r),c=r;return}if(e.type===`ForStatement`||e.type===`ForInStatement`||e.type===`ForOfStatement`||e.type===`SwitchStatement`||e.type===`CatchClause`){let t=new gt(e,c,!1);if(o.set(e,t),c=t,n.set(e,t),e.type===`CatchClause`){let n=yt(e,`param`);if(n!==null)for(let r of St(n))t.registerBinding(r.name,`param`,r,e),s.add(r)}return}if(n.set(e,c),e.type===`VariableDeclaration`){let t=_t(e,`kind`);if(t!==`var`&&t!==`let`&&t!==`const`)return;let n=t===`var`?c.getFunctionScope()??c.getProgramScope():c;for(let r of bt(e,`declarations`)){let i=yt(r,`id`);if(i!==null)for(let r of St(i))n.registerBinding(r.name,t,r,e),s.add(r)}}if(e.type===`ImportDeclaration`){let t=c.getProgramScope();for(let n of bt(e,`specifiers`)){let r=yt(n,`local`);r!==null&&Ne(r)&&(t.registerBinding(r.name,`import`,r,e),s.add(r))}}},leave(e){o.get(e)===c&&c.parent!==null&&(c=c.parent)}}),c=t,C(e,{enter(e,t,n){let a=o.get(e);if(a!==void 0&&(c=a),Ne(e)&&!s.has(e)&&Ct(t,n)){let t=c.getBinding(e.name);if(t!==void 0){t.references.push(e);let n=wt(e,r,i);n!==null&&!t.constantViolations.includes(n)&&t.constantViolations.push(n)}}},leave(e){o.get(e)===c&&c.parent!==null&&(c=c.parent)}}),{rootScope:t,nodeToScope:n,parentByNode:r,keyByNode:i,indexByNode:a}}function Et(e){return e}function Dt(e,t){function n(e,r,i,a){let o=e;if(t.enter){let e=t.enter(o,r,i,a);if(e!==void 0){if(e===null)return null;if(Array.isArray(e))return e;o=S(e)}}let s=ht[o.type]??Object.keys(o);for(let e of s){let t=Et(o)[e];if(Array.isArray(t)){let r=t,i=[];for(let t=0;t<r.length;t++){let a=r[t];if(a&&typeof a==`object`&&`type`in a){let r=n(a,o,e,t);if(r===null)continue;Array.isArray(r)?i.push(...r):i.push(r)}else i.push(a)}Et(o)[e]=i}else if(t&&typeof t==`object`&&`type`in t){let r=n(t,o,e,void 0);if(Array.isArray(r))throw TypeError(`Cannot splice nodes into non-array field ${o.type}.${e}`);Et(o)[e]=r}}if(t.leave){let e=t.leave(o,r,i,a);if(e!==void 0)return e}return o}let r=n(S(e),null,void 0,void 0);if(Array.isArray(r))throw TypeError(`Cannot splice nodes at the AST root`);return r}function Ot(e){return e}function kt(e,t){let n=e.parentByNode.get(t)??null,r=e.keyByNode.get(t);if(n===null||r===void 0)throw TypeError(`Cannot mutate detached AST node ${t.type}`);return{parent:n,key:r}}function At(e,t,n){let{parent:r,key:i}=kt(e,t),a=Ot(r)[i];if(Array.isArray(a)){let e=a.indexOf(t);if(e===-1)throw TypeError(`AST replacement target is stale`);a[e]=n;return}if(a!==t)throw TypeError(`AST replacement target is stale`);Ot(r)[i]=n}function jt(e,t){let n=Ot(e);for(let e of Object.keys(n))delete n[e];Object.assign(n,Ot(t))}function Mt(e,t){let{parent:n,key:r}=kt(e,t),i=Ot(n)[r];if(!Array.isArray(i))throw TypeError(`Cannot remove scalar AST field ${n.type}.${r}`);let a=i.indexOf(t);if(a===-1)throw TypeError(`AST removal target is stale`);i.splice(a,1)}function Nt(e,t,n){let r=t;for(;r!==null;){if(r===n)return!0;r=e.parentByNode.get(r)??null}return!1}function Pt(e){return e}function Ft(e,t,n){let r=Pt(e);r.type=`Literal`,r.value=t,r.raw=n}function It(e){C(e,{enter(e){let t=Pt(e);switch(e.type){case`StringLiteral`:{let n=t.value;if(typeof n!=`string`)throw TypeError(`StringLiteral requires a string value`);Ft(e,n,JSON.stringify(n));break}case`NumericLiteral`:{let n=t.value;if(typeof n!=`number`)throw TypeError(`NumericLiteral requires a number value`);Ft(e,n,String(n));break}case`BooleanLiteral`:{let n=t.value;if(typeof n!=`boolean`)throw TypeError(`BooleanLiteral requires a boolean value`);Ft(e,n,String(n));break}case`NullLiteral`:Ft(e,null,`null`);break;case`BigIntLiteral`:{let e=t.value;if(typeof e!=`string`)throw TypeError(`BigIntLiteral requires a string value`);t.type=`Literal`,t.value=BigInt(e),t.bigint=e,t.raw=`${e}n`;break}case`RegExpLiteral`:{let e=t.pattern,n=t.flags;if(typeof e!=`string`||typeof n!=`string`)throw TypeError(`RegExpLiteral requires pattern and flags`);t.type=`Literal`,t.value=null,t.regex={pattern:e,flags:n},t.raw=`/${e}/${n}`;break}case`ObjectProperty`:t.type=`Property`,t.kind??=`init`,t.method??=!1,t.shorthand??=!1}}})}function Lt(e){let t=Object.entries(e).map(([e,t])=>[e.startsWith(`.`)?e.toLowerCase():`.${e.toLowerCase()}`,t]).sort(([e],[t])=>t.length-e.length);return{name:`extensions(${t.map(([e])=>e).join(`,`)})`,parse(e,n={}){let r=n.filename??`module.tsx`,i=r.split(/[?#]/,1)[0].toLowerCase(),a=t.find(([e])=>i.endsWith(e));if(a===void 0)throw TypeError(`No ESTree frontend is registered for '${r}'; pass a frontend explicitly`);return a[1].parse(e,n)}}}var Rt=class extends SyntaxError{diagnostics;moduleId;loc;constructor(e,t,n){let r=t[0];super(r===void 0?`Could not parse ${e}`:`${e}: ${r.message}`),this.name=`EstreeParseError`,this.moduleId=e,this.diagnostics=t;let i=r?.labels[0];if(n!==void 0&&i!==void 0){let e=Vt(n),t=Bt(i.start,e),r=Bt(i.end,e);this.loc={line:t.line,column:t.column,endLine:r.line,endColumn:r.column}}}};function zt(e){if(e.type!==`Program`||!Array.isArray(e.body))throw TypeError(`ESTree parser returned a non-Program root`);return e}function Bt(e,t){let n=0,r=t.length;for(;n+1<r;){let i=Math.floor((n+r)/2);t[i]<=e?n=i:r=i}return{line:n+1,column:e-t[n]}}function Vt(e){let t=[0];for(let n=0;n<e.length;n++)e.charCodeAt(n)===10&&t.push(n+1);return t}function Ht(e,t,n,r){return{start:Bt(e,n),end:Bt(t,n),source:r}}function Ut(e,t,n){let r=new WeakSet,i=e=>{if(typeof e!=`object`||!e||r.has(e))return;if(r.add(e),Array.isArray(e)){let t=e;for(let e of t)i(e);return}let a=e;typeof a.type==`string`&&typeof a.start==`number`&&typeof a.end==`number`&&(a.loc=Ht(a.start,a.end,t,n));for(let[e,t]of Object.entries(a))e!==`parent`&&e!==`loc`&&i(t)};i(e)}function Wt(e){return e===`error`?`Error`:e===`warning`?`Warning`:`Advice`}function Gt(r,i={}){let a=i.filename??`module.tsx`,o=a.split(/[?#]/,1)[0],s=t(r,{lang:i.language??e(o),sourceType:i.sourceType===`unambiguous`?n(o):i.sourceType??n(o),preserveParens:!1,semanticErrors:i.checkSemantics??!1}),c=Vt(r),l=zt(s.program);return Ut(l,c,a),{program:l,comments:s.comments.map(e=>({type:e.type,value:e.value,start:e.start,end:e.end,loc:Ht(e.start,e.end,c,a)})),diagnostics:s.diagnostics.map(e=>({severity:Wt(e.severity),message:e.message,labels:[{message:e.message,start:e.start,end:e.end},...e.labels.map(e=>({message:e.message,start:e.start,end:e.end}))],helpMessage:e.help,codeframe:null}))}}const Kt={name:`yuku`,parse:Gt};function qt(e,t,n={}){return e.parse(t,n)}function Jt(e,t,n={}){let r=qt(e,t,n),i=r.diagnostics.filter(e=>e.severity===`Error`);if(i.length>0)throw new Rt(n.filename??`module.tsx`,i,t);return r}function Yt(e){if(typeof e!=`object`||!e)throw TypeError(`ESTree printer returned an invalid source map`);let t=e;if(t.version!==3||!Array.isArray(t.names)||!Array.isArray(t.sources)||!Array.isArray(t.sourcesContent)||typeof t.mappings!=`string`)throw TypeError(`ESTree printer returned an invalid source map`);return{version:3,names:t.names.filter(e=>typeof e==`string`),sources:t.sources.map(e=>typeof e==`string`?e:null),sourcesContent:t.sourcesContent.map(e=>typeof e==`string`?e:null),mappings:t.mappings}}function Xt(e,t={}){let n=r(e,i({quotes:t.quotes,comments:t.comments===void 0?void 0:[...t.comments]}),{...t.indent===void 0?{}:{indent:t.indent},...t.sourceMapSource===void 0?{}:{sourceMapSource:t.sourceMapSource},...t.sourceMapContent===void 0?{}:{sourceMapContent:t.sourceMapContent}});return{code:n.code,map:t.sourceMapSource===void 0?null:Yt(n.map)}}function Zt(e){return e}function Qt(e){return e.type===`TSInterfaceDeclaration`||e.type===`TSTypeAliasDeclaration`||e.type===`TSDeclareFunction`||e.type===`TSModuleDeclaration`}function $t(e){let t=Zt(e);delete t.typeAnnotation,delete t.typeParameters,delete t.returnType,delete t.typeArguments,delete t.superTypeArguments,delete t.implements,delete t.abstract,delete t.declare,delete t.definite,delete t.override,delete t.readonly,delete t.accessibility,(e.type===`Identifier`||e.type===`RestElement`||e.type===`PropertyDefinition`||e.type===`MethodDefinition`)&&delete t.optional}function en(e){let t=Dt(e,{enter(e){let t=Zt(e);if(Qt(e))return null;if(e.type===`TSEnumDeclaration`||e.type===`TSImportEqualsDeclaration`||e.type===`TSExportAssignment`)throw Error(`memo-dom: runtime TypeScript syntax '${e.type}' is not supported by the ESTree emitter`);if(e.type===`TSAsExpression`||e.type===`TSTypeAssertion`||e.type===`TSNonNullExpression`||e.type===`TSSatisfiesExpression`||e.type===`TSInstantiationExpression`)return t.expression;if(e.type===`TSParameterProperty`)return t.parameter;if(e.type===`ImportDeclaration`){if(t.importKind===`type`||t.importKind===`typeof`)return null;let e=t.specifiers;Array.isArray(e)&&(t.specifiers=e.filter(e=>{if(typeof e!=`object`||!e)return!0;let t=e.importKind;return t!==`type`&&t!==`typeof`})),delete t.importKind}if(e.type===`ExportNamedDeclaration`){if(t.exportKind===`type`)return null;let e=t.declaration;if(typeof e==`object`&&e&&`type`in e&&Qt(e))return null;let n=t.specifiers;Array.isArray(n)&&(t.specifiers=n.filter(e=>typeof e!=`object`||!e||e.exportKind!==`type`)),delete t.exportKind}if(e.type===`PropertyDefinition`&&t.declare===!0&&t.value==null||(e.type===`ClassDeclaration`||e.type===`ClassExpression`)&&t.declare===!0)return null;$t(e)}});if(t===null)throw TypeError(`Cannot erase the TypeScript program root`);return t}const tn=new Set([`JSXElement`,`JSXFragment`,`JSXText`,`JSXExpressionContainer`,`JSXCodeBlock`,`JSXIfExpression`,`JSXForExpression`,`JSXSwitchExpression`,`JSXTryExpression`,`JSXStyleElement`]),nn=new Set([`JSXCodeBlock`,`JSXIfExpression`,`JSXForExpression`,`JSXSwitchExpression`,`JSXTryExpression`]),rn=new Set([`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`,`ObjectMethod`,`ClassMethod`,`ClassPrivateMethod`]);function w(e){return e}function an(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function on(e){return e!=null&&(e.type===`JSXIfExpression`||e.type===`IfStatement`)}var sn=class extends SyntaxError{node;constructor(e,t){super(`memo-dom TSRX: ${e}`),this.node=t,this.name=`TsrxLoweringError`}};function cn(e,t){throw new sn(t,e)}function ln(e){return{type:`Literal`,value:e,raw:e===null?`null`:JSON.stringify(e)}}function un(e){return{type:`ReturnStatement`,argument:e}}function dn(e){return{type:`BlockStatement`,body:e}}function fn(e){return{type:`JSXExpressionContainer`,expression:e}}function pn(e,t){return{type:`VariableDeclaration`,kind:`const`,declarations:[{type:`VariableDeclarator`,id:{type:`Identifier`,name:e},init:t}]}}function mn(e){let t=new Set,n=new WeakSet,r=e=>{if(typeof e!=`object`||!e||n.has(e))return;if(n.add(e),Array.isArray(e)){for(let t of e)r(t);return}let i=e;i.type===`Identifier`&&typeof i.name==`string`&&t.add(i.name);for(let[e,t]of Object.entries(i))e!==`loc`&&e!==`metadata`&&r(t)};return r(e),t}function hn(e){let t=mn(e),n=0,r=()=>{let e;do e=`TsrxDynamic${n++}`;while(t.has(e));return t.add(e),e},i=new WeakSet,a=(e,t,n)=>{if(e!==n&&rn.has(e.type))return;if(e.type===`JSXElement`){let n=w(e),i=n.openingElement;if(an(i)){let e=w(i),a=e.name;if(an(a)&&a.type===`JSXExpressionContainer`){let i=w(a).expression;(!an(i)||i.type===`JSXEmptyExpression`)&&cn(a,`dynamic tag requires an expression`);let o=r();t.push(pn(o,S(i))),e.name={type:`JSXIdentifier`,name:o},delete e.isDynamic;let s=n.closingElement;an(s)&&(w(s).name={type:`JSXIdentifier`,name:o},delete w(s).isDynamic),delete n.isDynamic}}}let i=ht[e.type]??Object.keys(e);for(let r of i){if(r===`loc`||r===`metadata`)continue;let i=w(e)[r];if(Array.isArray(i))for(let e of i)an(e)&&a(e,t,n);else an(i)&&a(i,t,n)}},o=e=>{if(i.has(e))return;if(i.add(e),rn.has(e.type)){let t=w(e).body;if(an(t)&&t.type===`JSXCodeBlock`){let e=t;if(e.render!==null){let t=[];a(e.render,t,e.render),e.body.push(...t)}}}let t=ht[e.type]??Object.keys(e);for(let n of t){if(n===`loc`||n===`metadata`)continue;let t=w(e)[n];if(Array.isArray(t))for(let e of t)an(e)&&o(e);else an(t)&&o(t)}};o(e)}function gn(e){let t=new Set;return C(e,{enter(e){if(!(e.type!==`ObjectPattern`&&e.type!==`ArrayPattern`||w(e).lazy!==!0))for(let n of St(e))t.add(n)}}),t}function _n(e,t){t(e);for(let n of e.children)_n(n,t)}function vn(e){let t=gn(e);t.size>0&&_n(Tt(e).rootScope,e=>{for(let n of e.bindings.values()){if(!t.has(n.identifier))continue;let e=n.constantViolations[0];e!==void 0&&cn(e,`lazy binding '${n.name}' cannot be assigned directly; write the source property instead`)}}),C(e,{enter(e){(e.type===`ObjectPattern`||e.type===`ArrayPattern`)&&w(e).lazy===!0&&delete w(e).lazy}})}function yn(e){return{type:`JSXFragment`,openingFragment:{type:`JSXOpeningFragment`},closingFragment:{type:`JSXClosingFragment`},children:e}}function bn(e){return e.type===`JSXElement`||e.type===`JSXFragment`?e:yn([fn(e)])}function xn(e){e.type!==`BlockStatement`&&cn(e,`expected a template block, received '${e.type}'`);let t=w(e).body;Array.isArray(t)||cn(e,`template block has no body`);let n=[],r=[],i=!1;for(let e of t)an(e)&&e.type!==`JSXStyleElement`&&(tn.has(e.type)?(i=!0,r.push(e)):i?cn(e,`setup statements must appear before rendered template children`):n.push(e));return{setup:n,template:r}}function Sn(e){let t=e.map(On);if(t.length===0)return ln(null);if(t.length===1){let e=t[0];return e.type===`JSXExpressionContainer`?w(e).expression:e}return yn(t)}function Cn(e){let{setup:t,template:n}=xn(e),r=Sn(n);return t.length===0?r:Pn(dn([...t.map(e=>Ln(e)),un(r)]))}function wn(e){return{type:`ConditionalExpression`,test:Ln(e.test),consequent:Cn(e.consequent),alternate:e.alternate===null?ln(null):on(e.alternate)?wn(e.alternate):Cn(e.alternate)}}function Tn(e){(e.statementType!==`ForOfStatement`||e.right===void 0)&&cn(e,`only @for (... of ...) is supported by the experimental lowering`);let t=e.left;if(t===void 0&&cn(e,`@for is missing its iteration binding`),t.type!==`VariableDeclaration`)return Ln(t);let n=w(t).declarations;(!Array.isArray(n)||n.length!==1||!an(n[0]))&&cn(t,`@for must declare exactly one iteration binding`);let r=w(n[0]).id;return an(r)||cn(t,`@for iteration declaration has no binding`),Ln(r)}function En(e,t,n){e.type!==`JSXElement`&&cn(n,`@for key currently requires one JSX element as the loop output`);let r=w(e).openingElement;an(r)||cn(e,`loop output has no opening JSX element`);let i=w(r).attributes;Array.isArray(i)||cn(r,`loop output has no JSX attributes`),i.some(e=>{if(!an(e)||e.type!==`JSXAttribute`)return!1;let t=w(e).name;return an(t)&&t.type===`JSXIdentifier`&&w(t).name===`key`})||i.push({type:`JSXAttribute`,name:{type:`JSXIdentifier`,name:`key`},value:fn(Ln(t))})}function Dn(e){let t=Tn(e),n=Ln(e.right),{setup:r,template:i}=xn(e.body),a=Sn(i);e.key!==null&&e.key!==void 0&&En(a,e.key,e);let o=[t];e.index!==null&&e.index!==void 0&&o.push(Ln(e.index));let s=r.length===0?a:dn([...r.map(e=>Ln(e)),un(a)]),c={type:`ArrowFunctionExpression`,params:o,body:s,generator:!1,async:!1,expression:s.type!==`BlockStatement`},l={type:`CallExpression`,callee:{type:`MemberExpression`,object:S(n),property:{type:`Identifier`,name:`map`},computed:!1,optional:!1},arguments:[c],optional:!1};if(e.empty===null||e.empty===void 0)return l;let u=Cn(e.empty);return{type:`ConditionalExpression`,test:{type:`BinaryExpression`,operator:`>`,left:{type:`MemberExpression`,object:S(n),property:{type:`Identifier`,name:`length`},computed:!1,optional:!1},right:ln(0)},consequent:l,alternate:u}}function On(e){return e.type===`JSXIfExpression`?fn(wn(e)):e.type===`JSXForExpression`?fn(Dn(e)):e.type===`JSXSwitchExpression`?fn(Fn(e)):e.type===`JSXCodeBlock`?fn(In(e)):e.type===`JSXTryExpression`?An(e):Ln(e)}function kn(e){return dn([un(Cn(e))])}function An(e){let t=Cn(e.block),n=yn([t.type===`JSXElement`||t.type===`JSXFragment`?t:fn(t)]),r=e.handler,i=r===null?null:w(r),a={pending:e.pending===null||e.pending===void 0?null:Cn(e.pending),handler:r===null?null:{param:an(i?.param)?S(i.param):null,resetParam:an(i?.resetParam)?S(i.resetParam):null,output:Cn(an(i?.body)?i.body:r)}};return w(n).__memoDomTsrxTry=a,n}function jn(e){return{type:`IfStatement`,test:Ln(e.test),consequent:kn(e.consequent),alternate:e.alternate===null?dn([un(ln(null))]):on(e.alternate)?jn(e.alternate):kn(e.alternate)}}function Mn(e){return{type:`SwitchStatement`,discriminant:Ln(e.discriminant),cases:e.cases.map(e=>{e.type!==`SwitchCase`&&cn(e,`invalid @switch case`);let t=w(e).consequent;Array.isArray(t)||cn(e,`@switch case has no body`);let n=dn(t.filter(an));return{type:`SwitchCase`,test:an(w(e).test)?Ln(w(e).test):null,consequent:w(kn(n)).body}})}}function Nn(e){let t=e.body.map(e=>Ln(e));if(e.render===null&&cn(e,`statement container must finish with a render output`),e.render.type===`JSXIfExpression`)return dn([...t,jn(e.render)]);if(e.render.type===`JSXSwitchExpression`)return dn([...t,Mn(e.render)]);let n=e.render.type===`JSXForExpression`?bn(Dn(e.render)):bn(Ln(e.render));return dn([...t,un(n)])}function Pn(e){return{type:`CallExpression`,callee:{type:`ArrowFunctionExpression`,params:[],body:e,generator:!1,async:!1,expression:!1},arguments:[],optional:!1}}function Fn(e){return Pn(dn([Mn(e)]))}function In(e){return Pn(Nn(e))}function Ln(e){if(e.type===`JSXStyleElement`)return ln(null);if(e.type===`JSXTryExpression`)return An(e);if(e.type===`JSXCodeBlock`)return In(e);if(e.type===`TSModuleDeclaration`&&cn(e,`module declarations require a future client/server graph contract`),e.type===`JSXOpeningElement`){let t=w(e).name;an(t)&&t.type===`JSXExpressionContainer`&&cn(t,`dynamic tag escaped its owning function lowering`)}if(e.type===`JSXIfExpression`)return wn(e);if(e.type===`JSXForExpression`)return Dn(e);if(e.type===`JSXSwitchExpression`)return Fn(e);(e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`)&&an(w(e).body)&&w(e).body.type===`JSXCodeBlock`&&(w(e).body=Nn(w(e).body));let t=ht[e.type]??Object.keys(e);for(let n of t){let t=w(e)[n];if(n===`children`&&(e.type===`JSXElement`||e.type===`JSXFragment`)&&Array.isArray(t)){let r=[];for(let e of t){if(!an(e)){r.push(e);continue}e.type!==`JSXStyleElement`&&r.push(nn.has(e.type)?On(e):Ln(e))}w(e)[n]=r;continue}Array.isArray(t)?w(e)[n]=t.map(e=>an(e)?Ln(e):e):an(t)&&(w(e)[n]=Ln(t))}return e}function Rn(e){if(e.type!==`Program`)throw TypeError(`Expected a TSRX Program, received '${e.type}'`);let t=S(e);return vn(t),hn(t),Ln(t)}function zn(e){return e}function Bn(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function Vn(e){return e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`}function Hn(e){let t=[],n=(e,r)=>{let i=Vn(e)?e:r;if(e.type===`JSXStyleElement`){if(i===null)throw new sn(`scoped <style> blocks must belong to a function template`,e);let n=zn(e).children,r=Array.isArray(n)?n.find(e=>Bn(e)&&e.type===`StyleSheet`):void 0;if(!Bn(r))throw new sn(`scoped <style> block has no stylesheet`,e);t.push({owner:i,stylesheet:r});return}let a=ht[e.type]??Object.keys(e);for(let t of a){if(t===`loc`||t===`metadata`||t===`css`)continue;let r=zn(e)[t];if(Array.isArray(r))for(let e of r)Bn(e)&&n(e,i);else Bn(r)&&n(r,i)}};return n(e,null),t}function Un(e){let t=S(e),n=Hn(t);for(let{owner:e,stylesheet:t}of n){c(t);let n=zn(e).body;if(!Bn(n))throw new sn(`style owner has no render body`,e);o(n,String(zn(t).hash),`class`,!1)}return{program:t,css:l(n.map(({stylesheet:e})=>e))}}function Wn(e){let t=e.pos??0,n=e.end??e.raisedAt??t+1;return{severity:`Error`,message:e.message,labels:[{message:e.message,start:t,end:n}],helpMessage:null,codeframe:null}}function Gn(e){let t=e.node,n=typeof t.start==`number`?t.start:0,r=typeof t.end==`number`?t.end:n+1;return{severity:`Error`,message:e.message,labels:[{message:e.message,start:n,end:r}],helpMessage:null,codeframe:null}}function Kn(e,t={}){let n=t.filename??`module.tsrx`,r=[],i=[],o;try{o=s(e,n,{collect:!0,preserveParens:!1,errors:r,comments:i})}catch(t){throw new Rt(n,[Wn(t instanceof Error?t:Error(String(t)))],e)}let c=r.map(Wn),l=o,u=``;if(c.length===0)try{let e=a(o,n,{collect:!0,errors:[],comments:i});if(c.push(...e.errors.map(Wn)),l=e.ast,c.length===0){let e=Un(l);l=Rn(e.program),u=e.css}}catch(e){if(!(e instanceof sn))throw e;c.push(Gn(e))}return{program:l,comments:i.map(e=>({type:e.type,value:e.value,start:e.start,end:e.end,loc:{...e.loc,source:n}})),diagnostics:c,css:u}}const qn={name:`tsrx-experimental`,parse:Kn},Jn=Lt({".js":Kt,".jsx":Kt,".ts":Kt,".tsx":Kt,".d.ts":Kt,".tsrx":qn}),T=d,E=f,D=p,Yn=m,O=h,k=g,A=_,Xn=v,j=y,Zn=b,M=ee,Qn=te,$n=ne,N=re,er=x,P=ie,F=ae,I=oe,tr=se,nr=ce,rr=le,L=ue,R=de,z=fe,ir=pe,ar=me,or=he,B=ge,V=_e,sr=ve,cr=ye,lr=be,ur=xe,dr=Se,fr=Ce,pr=we,mr=Te,hr=Ee,gr=De,_r=Oe,vr=ke,yr=Ae,br=(e,t,n=!1)=>({type:`UpdateExpression`,operator:e,argument:t,prefix:n}),xr=(e,t)=>({type:`SwitchCase`,test:e,consequent:t}),Sr=(e,t)=>({type:`SwitchStatement`,discriminant:e,cases:t}),Cr=(e,t)=>({type:`MetaProperty`,meta:e,property:t}),wr=(e=[])=>({type:`TSTypeLiteral`,members:e});function Tr(e){if(!e||typeof e!=`object`)return null;let t=e.type;return typeof t==`string`?t:null}function Er(e,t){if(t==null)return!0;if(!e||typeof e!=`object`)return!1;let n=e;return Object.entries(t).every(([e,t])=>n[e]===t)}function H(e){return function(t,n){return e(t)&&Er(t,n)}}function U(...e){let t=new Set(e);return e=>{let n=Tr(e);return n!==null&&t.has(n)}}const Dr=e=>Tr(e)===`StringLiteral`||Fe(e),Or=e=>Tr(e)===`NumericLiteral`||Ie(e),kr=e=>Tr(e)===`BooleanLiteral`||Le(e),Ar=e=>Tr(e)===`NullLiteral`||Re(e),jr=U(`Property`,`ObjectProperty`),Mr=H(e=>Tr(e)!==null),W=H(Ne),G=H(Dr),Nr=H(Or),Pr=H(kr),Fr=H(Ar),Ir=H(U(`BigIntLiteral`)),Lr=H(U(`CallExpression`)),Rr=H(e=>Tr(e)===`OptionalCallExpression`||Tr(e)===`CallExpression`&&e.optional===!0),K=H(U(`MemberExpression`)),zr=H(e=>Tr(e)===`OptionalMemberExpression`||Tr(e)===`MemberExpression`&&e.optional===!0),Br=H(Ve),Vr=H(He),Hr=H(jr),Ur=H(Ue),Wr=H(U(`FunctionExpression`)),Gr=H(We),Kr=H(U(`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`,`ObjectMethod`,`ClassMethod`,`ClassPrivateMethod`)),qr=H(Ge),Jr=H(Ke),Yr=H(qe),Xr=H(Je),Zr=H(Ye),Qr=H(Xe),$r=H(Ze),ei=H(U(`UpdateExpression`)),ti=H($e),ni=H(et),ri=H(tt),q=H(e=>{let t=Tr(e);return nt(e)||t===`StringLiteral`||t===`NumericLiteral`||t===`BooleanLiteral`||t===`NullLiteral`||t===`BigIntLiteral`||t===`RegExpLiteral`||t===`OptionalMemberExpression`||t===`OptionalCallExpression`||t===`MetaProperty`||t===`Super`||t===`UpdateExpression`||t===`YieldExpression`||t===`NewExpression`||t===`ClassExpression`||t===`TSAsExpression`||t===`TSTypeAssertion`||t===`TSNonNullExpression`||t===`TSSatisfiesExpression`||t===`TSInstantiationExpression`||t===`TypeCastExpression`}),ii=H(rt),ai=H(st),oi=H(it),si=H(pt),ci=H(at),J=H(mt),li=H(ot),ui=H(U(`JSXEmptyExpression`)),di=H(U(`JSXNamespacedName`)),fi=H(U(`ObjectPattern`)),pi=H(U(`ArrayPattern`)),mi=H(U(`AssignmentPattern`)),hi=H(U(`RestElement`)),gi=H(U(`SpreadElement`)),_i=H(U(`ExportNamedDeclaration`)),vi=H(U(`ExportDefaultDeclaration`)),yi=H(U(`ExportSpecifier`)),bi=H(U(`ImportDeclaration`)),xi=H(U(`ImportSpecifier`)),Si=H(U(`ImportDefaultSpecifier`)),Ci=H(U(`SwitchStatement`)),wi=H(U(`BreakStatement`)),Ti=H(U(`EmptyStatement`)),Ei=H(U(`AwaitExpression`)),Di=H(U(`YieldExpression`)),Oi=H(U(`NewExpression`)),ki=H(U(`TemplateLiteral`)),Ai=H(U(`Super`)),ji=H(U(`PrivateName`)),Mi=H(U(`ClassDeclaration`)),Ni=H(U(`TypeCastExpression`)),Pi=H(U(`TSAsExpression`,`TSTypeAssertion`,`TSNonNullExpression`,`TSSatisfiesExpression`,`TSInstantiationExpression`,`TypeCastExpression`)),Fi=H(e=>Tr(e)?.startsWith(`TS`)===!0),Ii=H(U(`TSAsExpression`)),Li=H(U(`TSTypeAssertion`)),Ri=H(U(`TSNonNullExpression`)),zi=H(U(`TSSatisfiesExpression`)),Bi=H(U(`TSInstantiationExpression`)),Vi=H(U(`TSTypeAliasDeclaration`)),Hi=H(U(`TSInterfaceDeclaration`)),Ui=H(U(`TSParameterProperty`)),Wi=H(U(`TSTypeAnnotation`)),Gi=H(U(`TSTypeReference`)),Ki=H(U(`TSTypeLiteral`)),qi=H(U(`TSPropertySignature`)),Ji=H(U(`TSUndefinedKeyword`)),Yi=H(U(`TSNullKeyword`)),Xi=H(U(`TSSymbolKeyword`)),Zi=H(U(`TSUnionType`)),Qi=H(U(`TSParenthesizedType`)),$i=H(U(`TSLiteralType`)),ea=H(U(`TSStringKeyword`)),ta=H(U(`TSBigIntKeyword`)),na=H(U(`TSBooleanKeyword`)),ra=H(U(`TSNumberKeyword`)),ia=[{module:`@memoized-dom/data`,source:`$fetch`,track:`$track`,group:`Group`,pending:`Pending`,error:`Error`}];function aa(e={}){let t=e.moduleId??`./component.tsx`,n=new Map,r=new Map,i=new Map,a=new Map,o=new Map,s=new Map,c=new Map,l=new Map,u=new Set,d=new Set,f=new Map,p=new Map,m=new Set,h=new Map,g=new Map,_=new Set;for(let[t,o]of Object.entries(e.linkedImports??{}))o.type===`state`?(n.set(t,o.kind),r.set(t,o.key),o.tagCandidates!==void 0&&i.set(t,[...o.tagCandidates]),o.componentCandidates!==void 0&&c.set(t,o.componentCandidates.map(e=>({...e}))),o.transparentSource===!0&&l.set(t,o.key),m.add(t)):o.type===`function`?(o.transparentSourceFactory===!0&&u.add(t),o.transparentSourceMethod!==void 0&&p.set(t,o.transparentSourceMethod),o.tagCandidates!==void 0&&a.set(t,[...o.tagCandidates]),o.componentCandidates!==void 0&&c.set(t,o.componentCandidates.map(e=>({...e}))),h.set(t,{reads:new Set(o.reads),writes:new Set(o.writes),boundedWrites:new Set(o.boundedWrites),parameterWrites:o.parameterWrites.map(e=>({index:e.index,path:[...e.path]})),unbounded:o.unbounded})):o.type===`value`?_.add(t):g.set(t,o);let v=new Map;for(let[e,t]of g)v.set(e,{mode:t.objectProps?`object`:`positional`,names:[...t.props],acceptsUnknown:t.acceptsUnknownProps,bindings:[],params:[],hasWholeDefault:t.hasWholeDefault,renderProps:[...t.renderProps??[]],renderCallbacks:[...t.renderCallbacks??[]],refProps:[...t.refProps??[]]});let y=new Map(Object.entries(e.linkedComponentRenderProps??{}).map(([e,t])=>[e,[...t]])),b=e.runtimePath??`@memoized-dom/runtime`;return{runtimePath:b,hotRuntimePath:e.hotRuntimePath??`${b}/hot`,routerPath:e.routerPath??`@memoized-dom/router/internal`,dataRuntimePath:e.dataRuntimePath??`@memoized-dom/data/internal`,transparentAsyncSources:e.transparentAsyncSources??ia,rootId:e.rootId??`App`,rootComponent:e.rootComponent??null,hot:e.hot??!1,moduleStateCells:e.moduleStateCells??!1,moduleId:t,linkedRoutes:e.linkedRoutes??null,emitRouteManifest:e.emitRouteManifest??e.linkedRoutes===void 0,routeElements:new WeakMap,localRoutes:[],astAnalysis:null,usesRouter:!1,usesTransparentData:!1,transparentSourceFactories:u,transparentProviderFactories:d,eventSourceSlots:f,transparentSourceFactoryMethods:p,transparentTrackFactories:new Set,transparentSourcePassthroughs:new Set,transparentGroups:new Set,transparentPendingPolicies:new Set,transparentErrorPolicies:new Set,transparentSources:new Map,transparentTrackBindings:new Map,importedState:m,importedFunctions:h,importedComponents:g,importedValues:_,transparentModuleSources:l,transparentSourceProps:new Map,transparentPolicyParams:new Map,transparentGroupCallPolicies:new WeakMap,state:n,stateKeys:r,stateTagCandidates:i,functionTagCandidates:a,bindingTagCandidates:new Map,stateComponentCandidates:o,functionComponentCandidates:s,linkedDynamicComponentCandidates:c,linkedComponentPaths:new Map(Object.entries(e.linkedComponentPaths??{}).map(([e,t])=>[e,[...t]])),linkedComponentRows:new Map(Object.entries(e.linkedComponentRows??{}).map(([e,t])=>[e,t.map(e=>({keyPath:e.keyPath===null?null:[...e.keyPath],sourceKey:e.sourceKey,sourceLocal:e.sourceLocal}))])),linkedComponentPropSources:new Map(Object.entries(e.linkedComponentPropSources??{}).map(([e,t])=>[e,new Map(Object.entries(t).map(([e,t])=>[e,{keys:[...t.keys],rootFallback:t.rootFallback,transparent:t.transparent===!0}]))])),comps:new Map,compPaths:new Map,helpers:new Map,jsxHelpers:new Map,helperSummaries:new Map,compReads:new Map,childRefCounts:new Map,renderSlotOwners:new Set,listedSites:new Map,componentsWithHostEvents:new Set,componentHostEvents:new Map,conditionalComponentSites:new Map,rowComponentSites:new Map,componentProps:v,linkedComponentRenderProps:y,lightweightCache:new Map,rowReads:new Map,condReads:new Map,targetedListDependencies:new WeakMap,targetedListComponents:new Set,listSources:new Set,listComponents:new Set,componentListSources:new Map,keyedListMutations:new WeakMap,keyedListMutationSources:new Map,disabledKeyedListMutationSources:new Set,instanceState:new Map,instanceDerivations:new Map,instanceControlFlow:new Map,instanceDerivedBindings:new Map,instanceReasonIds:new Map,selectiveDerivationComponents:new Set,volatileComponents:new Set,opaqueBindings:new Map,effects:new Map,moduleEffects:[],computeds:new Map,moduleControlFlow:[],header:[],readers:new Map,writeConstCounter:0,writeConsts:new Map,reasonConstCounter:0,reasonConsts:new Map,analyzedFunctions:new WeakSet,compilerOwnedCallbacks:new WeakSet,handlerHasRootCommit:new WeakMap,localParamEffects:new WeakMap,identifiers:null}}var oa=class{runtimeId;hotRuntimeId;routerId;dataRuntimeId;reserved=new Set;componentIds=new Map;constructor(e){pa(e,e=>this.reserved.add(e)),this.runtimeId=this.generate(`MD`).name,this.hotRuntimeId=this.generate(`MDH`).name,this.routerId=this.generate(`MR`).name,this.dataRuntimeId=this.generate(`MDD`).name}generate(e){let t=ft(e).replace(/^_+/,``).replace(/\d+$/g,``),n=0;for(;;){let e=`_${t}`;if(n>=11?e+=n-1:n>=9?e+=n-9:n>=1&&(e+=n+1),n++,!this.reserved.has(e))return this.reserved.add(e),T(e)}}generateComponent(e){let t=ft(e).replace(/^_+/,``).replace(/\d+$/g,``),n=/^[A-Z]/.test(t)?t:`Generated${t[0]?.toUpperCase()??``}${t.slice(1)}`,r=0;for(;;){let e=r===0?n:`${n}${r+1}`;if(r++,!this.reserved.has(e))return this.reserved.add(e),T(e)}}registerComponentId(e,t){this.componentIds.set(e,t)}componentId(e){let t=this.componentIds.get(e);if(t===void 0)throw Error(`memo-dom: missing generated factory id for '${e}'`);return T(t)}runtimeMember(e){return A(T(this.runtimeId),T(e))}};function sa(e,t){let n=new oa(t);return e.identifiers=n,n}function Y(e,t){return fa(e).generate(t)}function ca(e,t){return fa(e).generateComponent(t)}function la(e,t){return fa(e).componentId(t)}function X(e,t){return fa(e).runtimeMember(t)}function ua(e,t){let n=fa(e);return A(T(n.hotRuntimeId),T(t))}function da(e,t){let n=fa(e);return A(T(n.routerId),T(t))}function Z(e,t){let n=fa(e);return A(T(n.dataRuntimeId),T(t))}function fa(e){if(e.identifiers===null)throw Error(`memo-dom: generated identifier allocator was not initialized`);return e.identifiers}function pa(e,t){C(e,{enter(e){if(e.type!==`Identifier`)return;let n=e.name;typeof n==`string`&&t(n)}})}function ma(e,t){let n=Tt(t);return e.astAnalysis=n,n}function ha(e,t){return e.astAnalysis?.nodeToScope.get(t)}function Q(e,t,n){return ha(e,t)?.getBinding(n)}function ga(e,t){if(t===void 0)return!1;if(t.constantViolations.length>0)return!0;let n=e.astAnalysis?.parentByNode;if(n===void 0)return!1;for(let e of t.references){let t=e,r=n.get(t)??null;for(;r!==null;){let e=r;if((r.type===`MemberExpression`||r.type===`OptionalMemberExpression`)&&e.object===t){t=r,r=n.get(t)??null;continue}if((r.type===`TSAsExpression`||r.type===`TSTypeAssertion`||r.type===`TSNonNullExpression`||r.type===`TSSatisfiesExpression`||r.type===`TSInstantiationExpression`||r.type===`ChainExpression`)&&e.expression===t){t=r,r=n.get(t)??null;continue}break}if(t===e)continue;let i=r;if(r?.type===`AssignmentExpression`&&i?.left===t||r?.type===`UpdateExpression`&&i?.argument===t||r?.type===`UnaryExpression`&&i?.operator===`delete`&&i.argument===t||(r?.type===`CallExpression`||r?.type===`OptionalCallExpression`)&&i?.callee===t)return!0}return!1}function _a(e){let t=e;for(;t.type===`TSAsExpression`||t.type===`TSTypeAssertion`||t.type===`TSNonNullExpression`||t.type===`TSSatisfiesExpression`||t.type===`TSInstantiationExpression`;)t=t.expression;return t}function va(e,t,n){e.state.set(t,n),e.stateKeys.has(t)||e.stateKeys.set(t,`${e.moduleId}#${t}`)}function ya(e,t){if(t.includes(`#`))return t;let n=t.indexOf(`.`),r=n===-1?t:t.slice(0,n),i=n===-1?``:t.slice(n);return`${e.stateKeys.get(r)??r}${i}`}function ba(e,t){let n=[...new Set(t.map(t=>ya(e,t)))].sort(),r=n.join(` `),i=e.writeConsts.get(r);if(i!==void 0)return T(i);let a=Y(e,`WRITES_${e.writeConstCounter++}`);return e.writeConsts.set(r,a.name),e.header.push(B(`const`,[V(a,j(n.map(e=>E(e))))])),a}function xa(e,t){let n=[...new Set(t)].sort((e,t)=>e-t),r=n.join(` `),i=e.reasonConsts.get(r);if(i!==void 0)return T(i);let a=Y(e,`REASONS_${e.reasonConstCounter++}`);return e.reasonConsts.set(r,a.name),e.header.push(B(`const`,[V(a,j(n.map(e=>D(e))))])),a}function Sa(e){return K(e)||zr(e)}function Ca(e){let t=[],n=e;for(;Sa(n);){if(n.computed){if(!G(n.property))return null;t.unshift(n.property.value)}else{if(!W(n.property))return null;t.unshift(n.property.name)}if(Ai(n.object))return null;n=n.object}for(;Ri(n)||Ii(n)||Li(n)||zi(n)||Bi(n);)n=n.expression;return W(n)?(t.unshift(n.name),t.join(`.`)):null}function wa(e,t){if(e===null)return[];let n=[],r=e;for(;K(r)&&!r.computed;){if(!W(r.property)||(n.unshift(r.property.name),Ai(r.object)))return null;r=r.object}return!W(r,{name:t})||n.length===0?null:n}function Ta(e,t){return t===null?!0:t.length===0||e.length>t.length?!1:e.every((e,n)=>t[n]===e)}function Ea(e){let t=e;for(;;){if(Sa(t)){if(Ai(t.object))return null;t=t.object;continue}if(Ri(t)||Ii(t)||Li(t)||zi(t)||Bi(t)){t=t.expression;continue}break}return W(t)?t.name:null}function Da(e){if(!e)return!1;let t=_a(e);return Vr(t)?t.properties.every(e=>Hr(e)&&!e.computed&&(W(e.key)||G(e.key))):!1}function Oa(e){if(!e)return!1;let t=_a(e);return Br(t)||Oi(t)}function ka(e){return e==null?null:G(e)?e:ci(e)?ui(e.expression)?null:e.expression:null}function Aa(e,t,n){let r=n===void 0?void 0:e.instanceState.get(n),i=n===void 0?void 0:e.instanceDerivedBindings.get(n),a=n===void 0?void 0:e.componentProps.get(n)?.bindings,o=!1;return Ma(t,t=>{if(o)return!1;if(W(t)&&(e.state.has(t.name)||r?.has(t.name)===!0||i?.has(t.name)===!0||a?.includes(t.name)===!0))return o=!0,!1}),o}function ja(e,t,n){let r=new Set([...e.instanceState.get(n)??[],...e.instanceDerivedBindings.get(n)??[],...e.componentProps.get(n)?.bindings??[]]);if(r.size===0)return!1;let i=!1;return Ma(t,e=>W(e)&&r.has(e.name)?(i=!0,!1):!i&&void 0),i}function Ma(e,t){C(e,{enter(e,n){return t(e,n)}})}function Na(e){let t=!1;return Ma(e,e=>{(ii(e)||ai(e))&&(t=!0)}),t}function Pa(e,t){let n=new Set;return Ma(t,t=>{if(oi(t)&&J(t.name,{name:`ref`}))return!1;W(t)&&e.state.has(t.name)&&n.add(t.name)}),n}const Fa=new Set([`Identifier`,`ObjectPattern`,`ArrayPattern`,`RestElement`,`AssignmentPattern`]);function Ia(e){let t=S(e);return C(t,{enter(e){Fa.has(e.type)&&(e.typeAnnotation=null)}}),t}function La(e,t){return e[t]}function Ra(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function za(e,t){let n=La(e,t);return Ra(n)?n:null}function Ba(e,t){let n=La(e,t);return Array.isArray(n)?n.filter(Ra):[]}function Va(e){if(e?.type!==`Identifier`)return null;let t=La(e,`name`);return typeof t==`string`?t:null}function Ha(e){let t=Va(e);if(t!==null)return t;if(e?.type!==`Literal`&&e?.type!==`StringLiteral`)return null;let n=La(e,`value`);return typeof n==`string`?n:null}function Ua(e){if(e.type===`RestElement`)throw Error(`rest component parameters are not supported`);let t=e.type===`AssignmentPattern`?za(e,`left`):e;if(t===null||t.type!==`Identifier`&&t.type!==`ObjectPattern`&&t.type!==`ArrayPattern`)throw Error(`unsupported component parameter target`);return t}function Wa(e){let t=Va(e);if(t!==null)return[t];if(e.type===`AssignmentPattern`){let t=za(e,`left`);return t===null?[]:Wa(t)}if(e.type===`RestElement`){let t=za(e,`argument`);return t===null?[]:Wa(t)}return e.type===`ArrayPattern`?Ba(e,`elements`).flatMap(Wa):e.type===`ObjectPattern`?Ba(e,`properties`).flatMap(e=>{if(e.type===`RestElement`)return Wa(e);if(e.type!==`Property`&&e.type!==`ObjectProperty`)return[];let t=za(e,`value`);return t===null?[]:Wa(t)}):[]}function Ga(e){let t=[];for(let n of Ba(e,`properties`)){if(n.type===`RestElement`)continue;if(n.type!==`Property`&&n.type!==`ObjectProperty`)throw Error(`unsupported component prop pattern property`);if(La(n,`computed`)===!0)throw Error(`computed keys are not supported in component prop patterns`);let e=Ha(za(n,`key`));if(e===null)throw Error(`component prop pattern keys must be identifiers or strings`);t.push(e)}return t}function Ka(e){if(e.some(e=>e.type===`TSParameterProperty`))throw Error(`TypeScript parameter properties are not valid component props`);if(e.length===0)return{mode:`positional`,names:[],acceptsUnknown:!1,bindings:[],hasWholeDefault:!1};let t=Ua(e[0]),n=Va(t);if(e.length===1&&(t.type===`ObjectPattern`||n===`props`))return{mode:`object`,names:t.type===`ObjectPattern`?Ga(t):[],acceptsUnknown:t.type===`Identifier`||Ba(t,`properties`).some(e=>e.type===`RestElement`),bindings:Wa(t),hasWholeDefault:e[0].type===`AssignmentPattern`};let r=[];for(let t of e){let e=Va(Ua(t));if(e===null)throw Error(`object-destructured props must be the component's only parameter`);r.push(e)}return{mode:`positional`,names:r,acceptsUnknown:!1,bindings:e.flatMap(e=>Wa(Ua(e))),hasWholeDefault:!1}}function qa(e){return S(e)}function Ja(e){return Hr(e)||e.type===`Property`}function Ya(e){if(W(e))return e.name;if(G(e))return e.value;if(e.type!==`Literal`)return null;let t=e.value;return typeof t==`string`?t:null}function Xa(e){if(e.mode!==`object`||e.params.length!==1||e.hasWholeDefault)return null;let t=e.params[0];if(!fi(t))return null;let n=[];for(let e of t.properties){if(!Ja(e)||e.computed||!W(e.value))return null;let t=Ya(e.key);if(t===null)return null;n.push({name:t,local:e.value.name})}return n}function Za(e){let t=e;return{...Ka(t),params:t.map(qa),renderProps:[],renderCallbacks:[],refProps:[]}}function Qa(e,t){return e.params.length===0?null:B(`let`,e.params.map((e,n)=>V(co(ao(e)),so(e,t[n]??T(`undefined`)))))}function $a(e,t){return e.params.map((e,n)=>z(F(`=`,lo(ao(e)),so(e,t[n]??T(`undefined`)))))}function eo(e){return e.replay===void 0?z(F(`=`,lo(e.target),qa(e.source))):qa(e.replay)}function to(e){return St(e).map(e=>e.name)}function no(e){if(e.mode!==`object`||e.params.length!==1)return null;let t=ao(e.params[0]);return W(t)?t.name:null}function ro(e,t){if(e.mode===`positional`)return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=ao(e.params[0]);if(!fi(n))return null;for(let e of n.properties){if(!Ja(e)||e.computed||Ya(e.key)!==t)continue;let n=mi(e.value)?e.value.left:e.value;return W(n)?n.name:null}return null}function io(e,t){if(e.mode===`positional`)return e.names.includes(t)?t:null;if(e.params.length!==1)return null;let n=ao(e.params[0]);if(!fi(n))return null;for(let e of n.properties){if(!Ja(e)||e.computed||!to(e.value).includes(t))continue;if(W(e.key))return e.key.name;let n=Ya(e.key);if(n!==null)return n}return null}function ao(e){if(hi(e))throw Error(`rest component parameters are not supported`);let t=mi(e)?e.left:e;if(!W(t)&&!fi(t)&&!pi(t))throw Error(`unsupported component parameter target`);return t}function oo(e){let t=qa(e);return uo(t),t}function so(e,t){return mi(e)?I(N(`===`,qa(t),T(`undefined`)),qa(e.right),qa(t)):qa(t)}function co(e){let t=qa(e);return uo(t),t}function lo(e){let t=qa(e);return uo(t),t}function uo(e){C(e,{enter(e){let t=e;`typeAnnotation`in t&&(t.typeAnnotation=null),`optional`in t&&(t.optional=null)}})}function fo(e,t){return e[t]}function po(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function mo(e,t){let n=fo(e,t);return po(n)?n:null}function ho(e,t){let n=fo(e,t);return Array.isArray(n)?n.filter(po):[]}function go(e,t){let n=`node`in t?t.node:t,r=e.astAnalysis?.parentByNode.get(n)??null;for(;r!==null&&r.type!==`ArrowFunctionExpression`&&r.type!==`FunctionExpression`;)r=e.astAnalysis?.parentByNode.get(r)??null;if(r===null)return!1;let i=mo(r,`body`);if(i===null||!(i.type===`JSXElement`&&i===n||i.type===`BlockStatement`&&ho(i,`body`).length===1&&ho(i,`body`)[0]?.type===`ReturnStatement`&&mo(ho(i,`body`)[0],`argument`)===n))return!1;let a=e.astAnalysis?.parentByNode.get(r)??null,o=a===null?null:e.astAnalysis?.parentByNode.get(a)??null,s=o===null?null:e.astAnalysis?.parentByNode.get(o)??null;if(a?.type!==`JSXExpressionContainer`||o?.type!==`JSXAttribute`||s?.type!==`JSXOpeningElement`)return!1;let c=mo(s,`name`),l=mo(o,`name`);if(c?.type!==`JSXIdentifier`||l===null)return!1;let u=fo(c,`name`),d=l.type===`JSXIdentifier`?fo(l,`name`):fo(mo(l,`name`)??l,`name`);return typeof u!=`string`||typeof d!=`string`?!1:e.componentProps.get(u)?.renderCallbacks.includes(d)===!0||/^[A-Z]/.test(u)}function _o(e){return(K(e.callee)||zr(e.callee))&&!e.callee.computed&&W(e.callee.property,{name:`map`})}function vo(e,t,n){let r=e.componentProps.get(t);if(r===void 0)return null;let i=no(r);return i!==null&&K(n)&&!n.computed&&W(n.object,{name:i})&&W(n.property)?n.property.name:W(n)?io(r,n.name)??(ro(r,n.name)===null?null:n.name):null}function yo(e){return q(e.body)?e.body:e.body.body.length===1&&Xr(e.body.body[0])&&q(e.body.body[0].argument)?e.body.body[0].argument:null}function bo(e,t,n){if(!_o(n)||n.arguments.length!==1)return null;let r=n.arguments[0];if(!Gr(r))return null;let i=yo(r);if(i===null||!Lr(i)||!q(i.callee)||i.arguments.some(e=>!q(e)))return null;let a=vo(e,t,i.callee);return a===null?null:{propName:a,target:S(i.callee,!0),arguments:i.arguments.map(e=>S(e,!0))}}function xo(e){for(let[t,n]of e.compPaths){let r=e.componentProps.get(t);C(n.node,{enter(n){if(n.type!==`CallExpression`&&n.type!==`OptionalCallExpression`)return;let i=bo(e,t,n);i!==null&&!r.renderCallbacks.includes(i.propName)&&r.renderCallbacks.push(i.propName)}})}}function So(e){return _a(e)}function Co(e,t){return e[t]}function wo(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function To(e){if(e.type===`StringLiteral`||e.type===`NumericLiteral`||e.type===`BooleanLiteral`||e.type===`NullLiteral`||e.type===`BigIntLiteral`)return!0;if(e.type!==`Literal`)return!1;let t=Co(e,`value`);return t===null||typeof t==`string`||typeof t==`number`||typeof t==`boolean`||typeof t==`bigint`}function Eo(e){return e.type===`ArrowFunctionExpression`||e.type===`FunctionExpression`||e.type===`StringLiteral`||e.type===`NumericLiteral`||e.type===`BooleanLiteral`||e.type===`Literal`&&[`string`,`number`,`boolean`].includes(typeof Co(e,`value`))}function Do(e){let t=So(e);if(t.type!==`ArrayExpression`)return!1;let n=Co(t,`elements`);return Array.isArray(n)&&n.every(e=>wo(e)&&e.type!==`SpreadElement`&&To(e))}function Oo(e,t=new Set){let n=So(e);if(t.has(n))return!1;if(t.add(n),Do(n))return!0;if(n.type===`CallExpression`){let e=Co(n,`callee`);if(!wo(e)||e.type!==`MemberExpression`&&e.type!==`OptionalMemberExpression`)return!1;let r=Co(e,`object`),i=Co(n,`arguments`);if(!wo(r)||!Array.isArray(i))return!1;for(let e of i)if(!wo(e)||!Eo(e))return!1;return Oo(r,t)}return!1}function ko(e,t){return e[t]}function Ao(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function jo(e,t){let n=ko(e,t);return Ao(n)?n:null}function Mo(e,t){let n=ko(e,t);return Array.isArray(n)?n.filter(Ao):[]}function No(e,t,n){let r=[],i=n==null?void 0:e.compPaths.get(n);if(i!==void 0){let t=e.astAnalysis?.rootScope.block;t?.type===`Program`&&r.push(...Mo(t,`body`)),r.push(...Mo(i.node.body,`body`))}for(let e of r)if(e.type===`VariableDeclaration`)for(let n of Mo(e,`declarations`)){let e=jo(n,`id`),r=jo(n,`init`);if(e?.type===`Identifier`&&ko(e,`name`)===t&&r!==null)return So(r)}return null}function Po(e){let t=So(e);if(t.type!==`CallExpression`)return!1;let n=jo(t,`callee`);if(n?.type!==`MemberExpression`)return!1;let r=jo(n,`object`);return r!==null&&Oo(r)}function Fo(e,t,n){let r=No(e,t,n);return r!==null&&Po(r)}function Io(e,t){let n=So(t);if(Lr(n)&&K(n.callee)&&!n.callee.computed&&W(n.callee.object,{name:e.identifiers?.dataRuntimeId})&&W(n.callee.property)){if(n.callee.property.name===`readResolvedValue`&&W(n.arguments[0]))return[n.arguments[0].name];if((n.callee.property.name===`readResolvedValuesForRender`||n.callee.property.name===`deriveResolvedValues`)&&Br(n.arguments[0]))return n.arguments[0].elements.filter(e=>W(e)).map(e=>e.name)}return Lr(n)&&(K(n.callee)||zr(n.callee))&&q(n.callee.object)?Io(e,n.callee.object):(K(n)||zr(n))&&q(n.object)?Io(e,n.object):[]}function Lo(e){let t=e;for(t.type===`ChainExpression`&&(t=t.expression);Pi(t);)t=t.expression;if(!Lr(t)&&!Rr(t))return null;let n=t.callee;return(K(n)||zr(n))&&!n.computed&&W(n.property,{name:`map`})?t:null}function Ro(e){let t=!1;return C(`node`in e?e.node:e,{enter(e){if(t)return!1;if(e.type===`JSXElement`||e.type===`JSXFragment`)return t=!0,!1}}),t}function zo(e,t,n,r,i,a){let o=e=>{throw n.buildCodeFrameError(e)},s=t.callee,c=Bo(e,s.object,r,a,o),l=Wo(e,t,r,o),u=$o(e,l,o),d=ns(c.suffixBase,i),f=s;return{sourceKey:c.key,sourceExpr:S(c.expression),optional:Rr(t)||f.type===`OptionalMemberExpression`||f.optional===!0||Uo(s.object),sourceLocal:c.local,itemPattern:l.itemPattern,itemParam:l.itemParam,indexParam:l.indexParam,keyExpr:ts(l.jsx?.openingElement??null,o),jsx:l.jsx,form:u.form,rowComp:u.rowComp,renderCallback:u.renderCallback,owner:r,suffix:d,prefix:`${r}/${d}`}}function Bo(e,t,n,r,i){let a=q(t)?So(t):t;if(W(a))return Vo(e,a,n,i);if(Lr(a)&&K(a.callee)&&!a.callee.computed&&W(a.callee.object,{name:e.identifiers?.dataRuntimeId})&&W(a.callee.property,{name:`readModuleSourceList`})){let e=a.arguments[0],t=G(e)?e.value:Lr(e)&&K(e.callee)&&W(e.callee.property,{name:`sourceRef`})&&G(e.arguments[0])?e.arguments[0].value:null;if(t!==null)return{expression:a,key:t,local:!0,suffixBase:t}}if(Lr(a)&&K(a.callee)&&!a.callee.computed&&W(a.callee.object,{name:e.identifiers?.dataRuntimeId})&&W(a.callee.property)&&(a.callee.property.name===`readResolvedValue`||a.callee.property.name===`readResolvedValueForRender`)&&W(a.arguments[0])){let e=a.arguments[0];return{expression:a.callee.property.name===`readResolvedValueForRender`?P(`||`,a,j([])):a,key:e.name,local:!0,suffixBase:e.name}}let o=q(a)?Io(e,a):[];if(q(a)&&o.length>0){let e=o.join(`$`);return{expression:a,key:e,local:!0,suffixBase:e}}return K(a)||zr(a)?Ho(e,a,n,r,i):q(a)&&(Do(a)||Oo(a))?{expression:a,key:`$static-list`,local:!0,suffixBase:`$static-list`}:i(`memo-dom: assign an ordered collection view to reactive state or a local derivation before mapping it`)}function Vo(e,t,n,r){if(Fo(e,t.name,n)){let r=No(e,t.name,n);if(r!==null)return{expression:S(r),key:`$static-list`,local:!0,suffixBase:`$static-list`}}let i=e.componentProps.get(n)?.bindings??[],a=e.opaqueBindings.get(n),o=e.instanceState.get(n)?.has(t.name)===!0||e.instanceDerivedBindings.get(n)?.has(t.name)===!0||i.includes(t.name)||a?.has(t.name)===!0,s=e.state.get(t.name);return!o&&s!==`let`&&s!==`const`&&s!==`computed`?r(`memo-dom: list views must come from reactive module state, component props, component state, or a local derivation`):{expression:t,key:t.name,local:o,suffixBase:t.name}}function Ho(e,t,n,r,i){let a=Ea(t),o=Ca(t),s=e.componentProps.get(n)?.bindings??[],c=e.opaqueBindings.get(n),l=a!==null&&(e.instanceState.get(n)?.has(a)===!0||e.instanceDerivedBindings.get(n)?.has(a)===!0||s.includes(a)||c?.has(a)===!0),u=a!==null&&o!==null&&r!==void 0&&a===r.itemParam;return a===null||o===null||!o.includes(`.`)||!u&&!l&&e.state.get(a)!==`store`?i(`memo-dom: list member views must be a static path on reactive module state, component props, component state, or a local derivation`):{expression:t,key:u?r.sourceKey:o,local:u?r.sourceLocal:l,suffixBase:o.slice(o.lastIndexOf(`.`)+1)}}function Uo(e){let t=e;for(;!Ai(t);){let e=zr(t);if(!K(t)&&!e)return!1;let n=t;if(e)return!0;t=n.object}return!1}function Wo(e,t,n,r){if(t.arguments.length!==1||!Gr(t.arguments[0]))return r(`memo-dom: list rendering expects items.map(item => <JSX />) — R7 L1`);let i=t.arguments[0],a=i.params[0],o=i.params[1];if(i.params.length<1||i.params.length>2||!W(a)&&!fi(a)&&!pi(a)||o!==void 0&&!W(o))return r(`memo-dom: list callback must take an item binding pattern and optional index identifier — R7 L1`);let s=Ia(a),c=St(s).map(e=>e.name);if(c.length===0)return r(`memo-dom: list callback item pattern must bind at least one name — R7 L1`);let l=W(s)?s.name:c[0],u=W(o)?o.name:null,d=Go(i,s,u,r),f=bo(e,n,t);return d===null&&f===null?r(`memo-dom: list callback body must be one JSX element, a block containing only return <JSX />, or const derivations followed by return <JSX /> — R7 L1`):{itemPattern:s,itemParam:l,indexParam:u,jsx:d,renderInvocation:f}}function Go(e,t,n,r){if(ii(e.body))return e.body;if(!Yr(e.body))return null;let i=e.body.body,a=i.at(-1);if(a===void 0||!Xr(a)||!ii(a.argument))return null;let o=a.argument;if(i.length>1){let a=new Set([...St(t).map(e=>e.name),...n===null?[]:[n]]),s=Yo(i.slice(0,-1),a,r);Xo(o,new Set(s.map(({name:e})=>e)),r);let c=new Map;for(let e of s)c.set(e.name,Zo(e.init,c));let l=Zo(o,c);return e.body=l,l}return o}function Ko(e,t){return I(N(`===`,S(e,!0),er(`void`,D(0))),S(t,!0),e)}function qo(e,t,n){return A(S(e,!0),S(t,!0),n||!W(t))}function Jo(e,t,n,r){if(W(e)){n.push({name:e.name,init:t});return}if(mi(e)){Jo(e.left,Ko(t,e.right),n,r);return}if(fi(e)){for(let i of e.properties)hi(i)&&r(`memo-dom: object rest in a list const destructuring declaration is not supported; destructure in the callback parameter or read the required properties explicitly — R7 L1`),Hr(i)||r(`memo-dom: unsupported list const destructuring property — R7 L1`),Jo(i.value,qo(t,i.key,i.computed),n,r);return}if(pi(e)){for(let i=0;i<e.elements.length;i++){let a=e.elements[i];if(a!==null){if(hi(a)){W(a.argument)||r(`memo-dom: nested array rest patterns are not supported in list const destructuring — R7 L1`),n.push({name:a.argument.name,init:k(A(S(t,!0),T(`slice`)),[D(i)])});continue}Jo(a,qo(t,D(i),!0),n,r)}}return}r(`memo-dom: unsupported list const destructuring target — R7 L1`)}function Yo(e,t,n){let r=[];for(let i of e){let e=qr(i)&&i.kind===`const`&&i.declarations.length===1?i.declarations[0]:null;if(e==null||!W(e.id)&&!fi(e.id)&&!pi(e.id)||e.init==null||!q(e.init))return n(`memo-dom: list callback statements before return must be one const declaration with an identifier, object pattern, or array pattern — R7 L1`);C(e.init,{enter(e){let t=e;($r(t)||ei(t)||Ei(t)||Di(t))&&n(`memo-dom: list callback derivations must be pure const expressions — R7 L1`)}});let a=[];Jo(e.id,e.init,a,n);for(let e of a){if(t.has(e.name))return n(`memo-dom: list callback derivation '${e.name}' shadows an item or index binding — R7 L1`);r.push(e)}}return r}function Xo(e,t,n){if(t.size===0)return;let r=e=>{for(let r of e)for(let{name:e}of St(r))t.has(e)&&n(`memo-dom: list callback derivation '${e}' is shadowed inside the row JSX — R7 L1`)};C(e,{enter(e){let i=e;Kr(i)&&r(i.params),Jr(i)&&W(i.id)&&t.has(i.id.name)&&n(`memo-dom: list callback derivation '${i.id.name}' is shadowed inside the row JSX — R7 L1`)}})}function Zo(e,t){return t.size===0?e:Qo(e,t,!0)}function Qo(e,t,n){if(W(e))return n&&t.has(e.name)?S(t.get(e.name),!0):e;if(K(e)||zr(e)){let n=S(e,!1);return n.object=Qo(e.object,t,!0),e.computed&&(n.property=Qo(e.property,t,!0)),n}if(Hr(e)&&e.shorthand&&W(e.key)){let n=S(e,!1);return n.value=Qo(e.value,t,!0),n.shorthand=!1,n}if(Kr(e)){let n=S(e,!1);return n.params=e.params.map(e=>S(e,!0)),n.body=Qo(e.body,t,!0),n}let r=S(e,!1),i=e,a=r;for(let n of ht[e.type]??[]){let e=i[n];Array.isArray(e)?a[n]=e.map(e=>typeof e!=`object`||!e||!(`type`in e)?e:Qo(e,t,!0)):typeof e==`object`&&e&&`type`in e&&(a[n]=Qo(e,t,!0))}return r}function $o(e,t,n){let r=t.jsx?.openingElement??null;if(r!==null&&!J(r.name))return n(`memo-dom: namespaced JSX tags are not supported (L1)`);let i=r!==null&&J(r.name)?r.name.name:null;return t.renderInvocation===null?i!==null&&/^[A-Z]/.test(i)?!e.comps.has(i)&&!e.importedComponents.has(i)?n(`memo-dom: <${i} /> is not a linked component factory`):{form:`component`,rowComp:i,renderCallback:null}:{form:`inline`,rowComp:null,renderCallback:null}:(es(t,n),{form:`callback`,rowComp:null,renderCallback:S(t.renderInvocation.target,!0)})}function es(e,t){let n=e.renderInvocation;(!W(e.itemPattern)||n.arguments.length<1||n.arguments.length>2||!W(n.arguments[0],{name:e.itemPattern.name})||n.arguments.length===2&&(e.indexParam===null||!W(n.arguments[1],{name:e.indexParam})))&&t(`memo-dom: render callback maps must pass their item and optional index bindings directly`)}function ts(e,t){let n=null;for(let r of e?.attributes??[])if(oi(r)&&J(r.name,{name:`key`})&&(n=ka(r.value),n===null))return t(`memo-dom: key={...} needs an expression`);return n}function ns(e,t){let n=t.get(e)??0;return t.set(e,n+1),n===0?e:`${e}${n}`}function rs(e){return ri(e)||ni(e)&&(e.operator===`&&`||e.operator===`||`)?e:null}function is(e){return Fr(e)||Pr(e,{value:!1})||W(e,{name:`undefined`})}function as(e,t){let n=[e];for(;n.length>0;){let e=n.pop();if(ii(e)){for(let n of e.openingElement.attributes)!si(n)&&n.name.name===`key`&&t(`memo-dom: key={...} is only meaningful on list rows`);n.push(...e.children)}else if(ai(e))n.push(...e.children);else if(ci(e)&&q(e.expression)){let t=e.expression;if(Lo(t)!==null&&Na(t))continue}}}function os(e,t,n){let r=e=>{throw t.buildCodeFrameError(e)},i,a;if(ri(e)){let t=[];a=[];let n=e;for(;ri(n);)t.push(S(n.test)),a.push(n.consequent),n=n.alternate;a.push(n),i=D(a.length-1);for(let e=t.length-1;e>=0;e--)i=I(t[e],D(e),i)}else e.operator===`&&`?(i=I(S(e.left),D(0),D(1)),a=[e.right,null]):(i=I(S(e.left),D(1),D(0)),a=[e.right,null]);let o=a.map(e=>e===null||is(e)?null:ii(e)||ai(e)?e:q(e)?yr(_r(),vr(),[mr(S(e,!0))]):r(`memo-dom: conditional branches must be JSX, renderable text expressions, or null/false`));for(let e of o)e!==null&&as(e,r);return{pickExpr:i,branches:o,suffix:`when${n.count++}`}}function ss(e){return e.scope.isProgramScope===!0||e.scope.path?.isProgram()===!0}var cs=class{fallback;origins=new WeakMap;constructor(e){this.fallback=e}trackDeclarator(e,t){if(!W(t.id)||t.init===null)return;let n=this.resolveExpression(e,t.init);if(n===null)return;let r=e.getBinding(t.id.name);r!==void 0&&this.origins.set(r.identifier,n)}referencedOrigins(e,t){let n=new Map;return C(t,{enter:t=>{if(!W(t)&&!K(t))return;let r=this.resolveExpression(e,t);if(r!==null){let e=[r.locality,r.root,r.key??`*`].join(`:`);return n.set(e,r),!1}}}),[...n.values()]}resolveName(e,t){let n=e.getBinding(t);if(n!==void 0){let e=this.origins.get(n.identifier);if(e!==void 0)return e}return this.fallback(t,n)}resolveExpression(e,t){let n=hs(t);if(Lr(n)&&K(n.callee)&&W(n.callee.property)&&(n.callee.property.name===`readResolvedValue`||n.callee.property.name===`readResolvedValueForRender`||n.callee.property.name===`readModuleSourceList`)){let t=n.arguments[1];if(G(t))return this.resolveName(e,t.value);let r=n.arguments[0];if(W(r))return this.resolveName(e,r.name)}if(W(n))return this.resolveName(e,n.name);if(!K(n))return null;let r=ms(n);if(r===null)return null;let i=this.resolveName(e,r);if(i===null)return null;let a=Ca(n);if(i.key===null||a===null)return{...i,key:null};let o=a.split(`.`).slice(1);return{...i,key:[i.key,...o].join(`.`)}}};function ls(e,t){return{locality:`module`,root:e,key:e,stateKind:t}}function us(e,t){return e.key===null?e:{...e,key:[e.key,...t].join(`.`)}}function ds(e,t){if(e.key===null)return null;let n=[];for(let r of t){if(!Vr(r))return null;for(let t of r.properties){if(!Hr(t)||t.computed||!W(t.key)&&!G(t.key))return null;let r=W(t.key)?t.key.name:t.key.value;n.push(`${e.key}.${r}`)}}return n}function fs(e){let t=[];for(let n of e)q(n)?t.push(n):gi(n)&&t.push(n.argument);return t}function ps(e){return!e.computed&&W(e.property)?e.property.name:e.computed&&G(e.property)?e.property.value:null}function ms(e){let t=e;for(;K(t);){if(Ai(t.object))return null;t=hs(t.object)}return W(t)?t.name:null}function hs(e){let t=e;for(;Ii(t)||Li(t)||Ri(t)||Ni(t)||zi(t);)t=t.expression;return t}function gs(e){return e}function _s(e){return typeof e==`object`&&e&&`type`in e?e:null}function vs(e,t){return _s(gs(e)[t])}function ys(e,t){let n=gs(e)[t];return Array.isArray(n)?n.map(_s).filter(e=>e!==null):[]}function bs(e){if(e?.type!==`Identifier`)return null;let t=gs(e).name;return typeof t==`string`?t:null}function xs(e,t){let n=ha(e,t);if(n===void 0){let r=e.astAnalysis?.rootScope.block;r?.type===`Program`&&(ma(e,r),n=ha(e,t))}if(n===void 0)throw Error(`memo-dom: missing ESTree scope during helper analysis`);return n}function Ss(e){return ys(e,`arguments`).flatMap(e=>{if(e.type===`SpreadElement`){let t=vs(e,`argument`);return t===null?[]:[t]}return e.type===`JSXNamespacedName`||e.type===`ArgumentPlaceholder`?[]:[e]})}function Cs(e,t,n){let r=e.astAnalysis?.parentByNode.get(t)??null;return r?.type===`AssignmentExpression`&&gs(r).operator===`=`&&vs(r,`left`)===n}function ws(e,t,n=new Set){let r=e.helperSummaries.get(t);if(r)return r;if(n.has(t))return{reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!0};let i=e.helpers.get(t).node,a=i,o=new Set,s=new Map(i.params.flatMap((e,t)=>W(e)?[[e.name,t]]:[])),c={reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!1},l=new cs((t,n)=>{if(s.has(t)&&n?.scope.block===a)return{locality:`prop`,root:t,key:t};let r=e.state.get(t);return r===void 0||n!==void 0&&!ss(n)?null:ls(t,r)}),u=t=>t.stateKind===`computed`||e.state.get(t.root)===`computed`;n.add(t),C(a,{enter(t){if(t.type===`VariableDeclarator`){let n=bs(vs(t,`id`));if(n===null)return;o.add(n),l.trackDeclarator(xs(e,t),t);return}if(t.type===`FunctionDeclaration`||t.type===`FunctionExpression`||t.type===`ArrowFunctionExpression`||t.type===`ObjectMethod`||t.type===`ClassMethod`||t.type===`ClassPrivateMethod`)for(let e of ys(t,`params`)){let t=bs(e);t!==null&&o.add(t)}}});let d=(e,t)=>{c.parameterWrites.some(n=>n.index===e&&n.path.length===t.length&&n.path.every((e,n)=>e===t[n]))||c.parameterWrites.push({index:e,path:t})},f=e=>{if(!u(e)){if(e.locality===`module`){c.boundedWrites.add(e.key??e.root);return}if(e.locality===`prop`){let t=s.get(e.root);if(t!==void 0){let n=e.key===null?[]:e.key.split(`.`).slice(1);d(t,n);return}}c.unbounded=!0}},p=e=>{e.locality===`prop`?f(e):e.locality===`module`?e.stateKind===`store`?e.key!==null&&e.key.includes(`.`)?c.writes.add(e.key):c.boundedWrites.add(e.root):c.writes.add(e.root):c.unbounded=!0},m=(t,n)=>{let r=l.resolveExpression(xs(e,t),n);r!==null&&p(r)},h=t=>{for(let n of Ss(t)){if(n.type!==`Identifier`)continue;let t=l.resolveExpression(xs(e,n),n);t!==null&&!u(t)&&f(t)}};return C(vs(a,`body`)??a,{enter(t){let r=xs(e,t);if(t.type===`VariableDeclarator`){let e=vs(t,`id`),n=vs(t,`init`);if(e?.type!==`Identifier`&&n!==null)for(let e of l.referencedOrigins(r,n))f(e);return}if(t.type===`AssignmentExpression`){let n=vs(t,`left`),i=vs(t,`right`),a=bs(n);if(a!==null){if(o.has(a)){if(bs(i)!==null&&i!==null){let e=l.resolveExpression(r,i);e!==null&&f(e)}}else e.state.has(a)&&c.writes.add(a)}else if(n?.type===`MemberExpression`)m(t,n);else if(i!==null)for(let e of l.referencedOrigins(r,i))f(e);return}if(t.type===`UpdateExpression`){let n=vs(t,`argument`),r=bs(n);r===null?n?.type===`MemberExpression`&&m(t,n):!o.has(r)&&e.state.has(r)&&c.writes.add(r);return}if(t.type===`UnaryExpression`&&gs(t).operator===`delete`){let e=vs(t,`argument`);e?.type===`MemberExpression`&&m(t,e);return}if(t.type===`CallExpression`){let i=vs(t,`callee`);if(i?.type===`MemberExpression`){let e=ps(i),n=vs(i,`object`);if(e===`assign`&&bs(n)===`Object`){let e=ys(t,`arguments`),n=e[0],i=n===void 0?null:l.resolveExpression(r,n);if(i!==null){let t=ds(i,e.slice(1));if(t===null)f(i);else for(let e of t)p({...i,key:e})}return}let a=n===null?null:l.resolveExpression(r,n);a===null?h(t):f(a);return}let a=bs(i);if(a!==null&&(e.helpers.has(a)||e.importedFunctions.has(a))){let i=e.importedFunctions.get(a)??ws(e,a,n);for(let e of i.reads)c.reads.add(e);for(let e of i.writes)c.writes.add(e);for(let e of i.boundedWrites)c.boundedWrites.add(e);let o=ys(t,`arguments`);for(let e of i.parameterWrites){let t=o[e.index];if(t===void 0||t.type===`SpreadElement`||t.type===`ArgumentPlaceholder`)continue;let n=l.resolveExpression(r,t);n!==null&&f(us(n,e.path))}i.unbounded&&(c.unbounded=!0);return}h(t);return}if(t.type===`Identifier`){let n=bs(t);if(!e.state.has(n)||o.has(n)||Cs(e,t,t))return;c.reads.add(n);return}if(t.type===`MemberExpression`){let n=Ts(e,t);n!==null&&c.reads.add(n)}}}),n.delete(t),e.helperSummaries.set(t,c),c}function Ts(e,t){let n=Ca(t);if(!n||!n.includes(`.`))return null;let r=n.split(`.`)[0];if(e.state.get(r)!==`store`||Q(e,t,r)?.scope.isProgramScope!==!0||Cs(e,t,t))return null;let i=e.astAnalysis?.parentByNode.get(t)??null;return i?.type===`CallExpression`&&vs(i,`callee`)===t?null:n}function Es(e,t=!1){return{slots:[],tempVar:Y(e,`value`).name,updateVar:Y(e,`update`).name,reasonVar:null,delegatedEventBindings:new Map,documentVar:null,prelude:[],creation:[],mounts:[],updaters:[],tagCounters:new Map,childCounts:new Map,usedPrefixes:new Map,usedConds:{count:0},textCounter:0,regionCounter:0,dataSiteCounter:{count:0},coveredTransparentSources:new Set,disposableRegions:[],disposableEntities:[],disposableCallbacks:[],forwardedSlotCounter:0,manualDisposal:t}}function Ds(e,t){return t.documentVar===null&&(t.documentVar=Y(e,`document`).name,t.prelude.push(B(`const`,[V(T(t.documentVar),A(k(X(e,`getActiveEnvironment`),[]),T(`document`)))]))),T(t.documentVar)}function Os(e){return B(`let`,[...e.slots.map(e=>V(T(e))),V(T(e.tempVar))])}function ks(e,t){let n=Y(e,`slot${t.slots.length}`).name;return t.slots.push(n),n}function As(e,t,n){let r=t.tagCounters.get(n)??0;return t.tagCounters.set(n,r+1),Y(e,`${n}${r}`).name}function js(e,t,n,r){let i=()=>T(e.tempVar),a=()=>T(t);return ar(N(`!==`,a(),F(`=`,i(),n)),R([z(F(`=`,a(),i())),r(i())]))}function Ms(e){return B(`const`,[V(T(e.updateVar),L(e.reasonVar===null?[]:[nr(T(e.reasonVar),O())],R(e.updaters.map(e=>e()))))])}function Ns(e,t,n,r,i=!1){return z(k(X(e,`register`),[Zn([M(T(`id`),t),M(T(`parent`),n),M(T(`render`),r),...i?[M(T(`volatile`),Yn(!0))]:[]])]))}function Ps(e){let t=e.replace(/\s+/g,` `);return/^\s*\n/.test(e)&&(t=t.replace(/^ /,``)),/\n\s*$/.test(e)&&(t=t.replace(/ $/,``)),t}function Fs(e){return e.some(e=>!li(e)||e.value.trim()!==``)}function Is(e,t,n){let r=e.componentProps.get(t);if(r===void 0)return null;let i=no(r);if(i!==null&&Be(n)&&!n.computed&&Ne(n.object)&&n.object.name===i&&Ne(n.property))return n.property.name;if(Ne(n)){let i=io(r,n.name);if(i!==null)return i;if(n.name===`children`&&e.instanceDerivedBindings.get(t)?.has(`children`)===!0)return`children`}return null}function Ls(e,t,n){let r=Is(e,t,n);return r!==null&&e.componentProps.get(t)?.renderProps.includes(r)===!0}function Rs(e,t,n,r){let i=Es(e,!0);i.childCounts=t.childCounts,i.usedPrefixes=t.usedPrefixes,i.usedConds=t.usedConds,i.dataSiteCounter=t.dataSiteCounter,i.coveredTransparentSources=new Set(t.coveredTransparentSources);let a=Y(e,`childrenUpdate`),o=Y(e,`childrenUpdates`),s=Y(e,`childrenMountSequence`),c=Y(e,`children`),l=Y(e,`childrenParent`),u=Y(e,`childrenOwner`),d=Y(e,`childrenKey`),f=Y(e,`childrenSlot`),p=Y(e,`childrenNextUpdate`),m=Y(e,`childrenActive`),h=Y(e,`childrenDispose`);return r(i,l,f),t.creation.push(B(`let`,[V(S(a),O()),V(S(o),O()),V(S(s),D(0))]),B(`const`,[V(S(c),L([S(l),S(u),S(d)],R([B(`const`,[V(S(f),I(N(`===`,S(s),D(0)),S(n,!0),N(`+`,N(`+`,S(n,!0),E(`/$slot[`)),N(`+`,S(s),E(`]`)))))]),z(br(`++`,S(s))),B(`let`,[V(S(m),Yn(!0))]),Os(i),...i.prelude,Ms(i),...i.creation,...i.mounts,ar(N(`===`,S(a),O()),z(F(`=`,S(a),T(i.updateVar))),R([ar(N(`===`,S(o),O()),z(F(`=`,S(o),$n(T(`Set`),[])))),z(k(A(S(o),T(`add`)),[T(i.updateVar)]))])),B(`const`,[V(S(h),L([],R([ar(er(`!`,S(m)),ir()),z(F(`=`,S(m),Yn(!1))),ar(N(`===`,S(a),T(i.updateVar)),z(F(`=`,S(a),O())),ar(N(`!==`,S(o),O()),z(k(A(S(o),T(`delete`)),[T(i.updateVar)])))),...i.disposableRegions.map(e=>z(k(A(T(e),T(`dispose`)),[]))),...[...i.disposableCallbacks].reverse().map(e=>ar(N(`!==`,S(e),O()),z(k(S(e),[])))),...i.disposableEntities.map(t=>z(k(X(e,`unregisterSubtree`),[S(t,!0)])))])))]),z(k(X(e,`cleanup`),[S(u),S(h)])),ir(S(h))])))])),t.updaters.push(()=>R([ar(N(`!==`,S(a),O()),z(k(S(a),[]))),ar(N(`!==`,S(o),O()),or(B(`const`,[V(S(p))]),S(o),z(k(S(p),[]))))])),c}function zs(e,t,n,r,i){let a=Y(e,`slotDispose`),o=t.forwardedSlotCounter++;t.creation.push(B(`const`,[V(S(a),I(N(`==`,S(n,!0),O()),O(),k(S(n,!0),[T(r),S(i,!0),E(String(o))])))])),t.disposableCallbacks.push(a)}function Bs(e,t,n,r){let i=t=>{e.creation.push(z(k(A(T(n),T(`appendChild`)),[T(t)])))};for(let e of t){if(li(e)){let t=Ps(e.value);t!==``&&i(r.emitText(E(t)));continue}if(ii(e)||ai(e)){i(r.emitNode(e));continue}if(ci(e)||r.fail(`memo-dom: spread children are not supported (L1)`),ui(e.expression))continue;q(e.expression)||r.fail(`memo-dom: unsupported expression in component children`);let t=e.expression;if(Fr(t)||Pr(t)||W(t,{name:`undefined`}))continue;if(r.isForwarded(t)){r.emitForwarded(t,n);continue}let a=Lo(t);if(a!==null){r.emitList(a,n);continue}let o=rs(t);if(o!==null&&Na(o)){r.emitCondition(o,n);continue}i(r.emitText(S(t)))}}function Vs(e){return e}function Hs(e,t){let n=Vs(e)[t];return typeof n==`object`&&n&&`type`in n?n:null}function Us(e,t){let n=Vs(e)[t];return Array.isArray(n)?n.filter(e=>typeof e==`object`&&!!e&&`type`in e):[]}function Ws(e){if(e?.type!==`Identifier`)return null;let t=Vs(e).name;return typeof t==`string`?t:null}function Gs(e,t){let n=Hs(t,`callee`);return t.type===`CallExpression`&&Ws(n)===`effect`&&Q(e,t,`effect`)===void 0}function Ks(e,t){return N(`+`,T(e),E(`/$effects/${t}`))}function qs(e,t){return N(`+`,Ks(e,t),E(`/$active`))}function Js(e,t){let n=t.identifier;for(;n!==null&&n!==t.declarationNode;){if(n.type===`VariableDeclarator`)return n;n=e.astAnalysis?.parentByNode.get(n)??null}return null}function Ys(e,t){if(t.kind===`function`&&t.declarationNode.type===`FunctionDeclaration`)return t.declarationNode;if(t.kind!==`const`&&t.kind!==`let`&&t.kind!==`var`)return null;let n=Js(e,t),r=n===null?null:Hs(n,`init`);return r!==null&&(r.type===`ArrowFunctionExpression`||r.type===`FunctionExpression`)?r:null}function Xs(e,t,n){let r=Us(t,`arguments`),i=r[0];if(r.length!==1||i===void 0)throw n.buildCodeFrameError(`memo-dom: effect() requires exactly one callback`);if(i.type===`ArrowFunctionExpression`||i.type===`FunctionExpression`){if(Vs(i).async===!0||Vs(i).generator===!0)throw n.buildCodeFrameError(`memo-dom: effect callback must be synchronous; start async work inside it and return a synchronous teardown`);return{expression:i,node:i,importedReads:new Set}}let a=Ws(i);if(a===null)throw n.buildCodeFrameError(`memo-dom: effect callback must be an inline function or a resolvable function identifier`);if(e.importedFunctions.get(a)!==void 0)throw n.buildCodeFrameError(`memo-dom: imported named effect callback '${a}' is not supported yet; define a local synchronous wrapper so its cleanup and writes can be instrumented`);let o=Q(e,i,a),s=o===void 0?null:Ys(e,o);if(s===null)throw n.buildCodeFrameError(`memo-dom: cannot resolve effect callback '${a}' — use an inline function or a local/module-level function declaration or const`);if(s.async||s.generator)throw n.buildCodeFrameError(`memo-dom: effect callback must be synchronous; start async work inside it and return a synchronous teardown`);if(Na(s.body))throw n.buildCodeFrameError(`memo-dom: a JSX component cannot be used as an effect callback`);return{expression:S(i),node:s,importedReads:new Set}}function Zs(e,t,n,r){let i=new Set,a=new Set,o=new Map,s=new Set([...e.componentProps.get(t)?.bindings??[],...e.instanceState.get(t)??[]]),c=new Map;for(let n of e.instanceDerivations.get(t)??[])for(let e of n.bindings)c.set(e,n.sources);for(let n of e.instanceControlFlow.get(t)??[])for(let e of n.bindings)c.set(e,n.sources);for(let t of s){let r=Q(e,n.node,t);r!==void 0&&o.set(r,{source:t,local:!0})}for(let t of c.keys()){let r=Q(e,n.node,t);r!==void 0&&o.set(r,{source:t,local:!0})}for(let t of e.state.keys()){let r=Q(e,n.node,t);r?.scope.isProgramScope===!0&&o.set(r,{source:t,local:!1})}let l=t=>{let n=Ws(t);if(n===null)return;let r=Q(e,t,n);if(r!==void 0&&!r.references.includes(t))return;let s=r===void 0?void 0:o.get(r);if(s===void 0)return;let c=e.astAnalysis?.parentByNode.get(t)??null;!s.local&&e.state.get(s.source)===`store`&&c?.type===`MemberExpression`&&Hs(c,`object`)===t||(s.local?a.add(s.source):i.add(s.source))},u=t=>{let n=Ca(t),r=Ea(t);n!==null&&r!==null&&e.state.get(r)===`store`&&Q(e,t,r)?.scope.isProgramScope===!0&&i.add(n)},d=t=>{let n=Hs(t,`callee`),r=Ws(n);if(n===null||r===null||Q(e,t,r)?.scope.isProgramScope!==!0||!e.helpers.has(r)&&!e.importedFunctions.has(r))return;let a=e.importedFunctions.get(r)??ws(e,r);for(let e of a.reads)i.add(e)};C(r,{enter(e){if(e!==r&&(e.type===`ArrowFunctionExpression`||e.type===`FunctionExpression`||e.type===`FunctionDeclaration`))return!1;e.type===`Identifier`&&l(e),e.type===`MemberExpression`&&u(e),e.type===`CallExpression`&&d(e)}});let f=new Set,p=new Set,m=new Set;for(let e of a)s.has(e)&&m.add(e);let h=(t,n)=>{if(n.has(t))return;let r=c.get(t);if(r===void 0){s.has(t)?f.add(t):e.state.has(t)&&i.add(t);return}n.add(t),r.some(e=>m.has(e))||p.add(t);for(let e of r)h(e,n);n.delete(t)};for(let e of a)h(e,new Set);return{moduleReads:i,localReads:f,localDerivationReads:p}}function Qs(e,t){let n=new Set,r=t=>{let r=Ws(t);if(r===null||!e.state.has(r)||Q(e,t,r)?.scope.isProgramScope!==!0)return;let i=Q(e,t,r);if(i!==void 0&&!i.references.includes(t))return;let a=e.astAnalysis?.parentByNode.get(t)??null;(e.state.get(r)!==`store`||a?.type!==`MemberExpression`||Hs(a,`object`)!==t)&&n.add(r)},i=t=>{let r=Ca(t),i=Ea(t);r!==null&&i!==null&&e.state.get(i)===`store`&&Q(e,t,i)?.scope.isProgramScope===!0&&n.add(r)},a=t=>{let r=Ws(Hs(t,`callee`));if(r===null||Q(e,t,r)?.scope.isProgramScope!==!0||!e.helpers.has(r)&&!e.importedFunctions.has(r))return;let i=e.importedFunctions.get(r)??ws(e,r);for(let e of i.reads)n.add(e)};return C(t,{enter(e){if(e!==t&&(e.type===`ArrowFunctionExpression`||e.type===`FunctionExpression`||e.type===`FunctionDeclaration`))return!1;e.type===`Identifier`&&r(e),e.type===`MemberExpression`&&i(e),e.type===`CallExpression`&&a(e)}}),n}function $s(e,t){if(t.type!==`ExpressionStatement`)return null;let n=Hs(t,`expression`);return n!==null&&Gs(e,n)?n:null}function ec(e,t){if($s(e,t)!==null)return!0;let n=!1;return C(t,{enter(r){if(r!==t&&(r.type===`ArrowFunctionExpression`||r.type===`FunctionExpression`||r.type===`FunctionDeclaration`))return!1;if(r.type===`CallExpression`&&Gs(e,r))return n=!0,!1}}),n}function tc(e,t,n,r,i,a){let o=$s(e,t);if(o!==null){i.push({call:o,rootStatement:n,conditions:[...r]});return}if(t.type!==`EmptyStatement`){if(t.type===`BlockStatement`){for(let o of Us(t,`body`))if(o.type!==`EmptyStatement`){if(!ec(e,o))throw a.buildCodeFrameError(`memo-dom: a conditional effect branch may contain only effect() calls, nested if statements, or empty statements`);tc(e,o,n,r,i,a)}return}if(t.type===`IfStatement`){let o=Hs(t,`test`),s=Hs(t,`consequent`);if(o===null||s===null)return;tc(e,s,n,[...r,{node:o,negated:!1}],i,a);let c=Hs(t,`alternate`);c!==null&&tc(e,c,n,[...r,{node:o,negated:!0}],i,a);return}throw a.buildCodeFrameError(`memo-dom: conditional effect() calls must be controlled by top-level if statements`)}}function nc(e,t,n){let r=[];for(let i of t){let t=$s(e,i);if(t!==null){r.push({call:t,rootStatement:i,conditions:[]});continue}i.type!==`IfStatement`||!ec(e,i)||tc(e,i,i,[],r,n)}return r}function rc(e){return e.length===0?null:e.map(({node:e,negated:t})=>t?er(`!`,S(e)):S(e)).reduce((e,t)=>P(`&&`,e,t))}function ic(e,t){let n=[],r=nc(e,Us(t.node,`body`),t);for(let i of r){let r=Xs(e,i.call,t),a=r.node===null?r.importedReads:Qs(e,r.node),o=new Set;for(let t of i.conditions)for(let n of Qs(e,t.node))o.add(n);let s=n.length;n.push({index:s,statement:i.rootStatement,callback:r.expression,moduleReads:a,condition:rc(i.conditions),conditionModuleReads:o,entityId:`${e.rootId}/$module-effects/${encodeURIComponent(e.moduleId)}/${s}`})}e.moduleEffects.push(...n)}function ac(e,t){ic(e,t);for(let[t,n]of e.compPaths){let r=[],i=new Set,a=nc(e,Us(n.node.body,`body`),n);for(let o of a){let a=Xs(e,o.call,n),s=a.node===null?{moduleReads:a.importedReads,localReads:new Set,localDerivationReads:new Set}:Zs(e,t,n,a.node),c=new Set,l=new Set,u=new Set;for(let r of o.conditions){let i=Zs(e,t,n,r.node);for(let e of i.moduleReads)c.add(e);for(let e of i.localReads)l.add(e);for(let e of i.localDerivationReads)u.add(e)}r.push({index:r.length,statement:o.rootStatement,callback:a.expression,...s,condition:rc(o.conditions),conditionModuleReads:c,conditionLocalReads:l,conditionLocalDerivationReads:u}),i.add(o.call)}if(C(n.node.body,{enter(t){if(t!==n.node.body&&(t.type===`ArrowFunctionExpression`||t.type===`FunctionExpression`||t.type===`FunctionDeclaration`))return!1;if(!(t.type!==`CallExpression`||!Gs(e,t)||i.has(t)))throw n.buildCodeFrameError(`memo-dom: effect() must be a direct top-level statement in a component body`)}}),r.length===0)continue;e.effects.set(t,r);let o=new Set([...e.instanceReasonIds.get(t)?.keys()??[],...e.instanceState.get(t)??[],...e.componentProps.get(t)?.bindings??[],...r.flatMap(e=>[...e.localReads]),...r.flatMap(e=>[...e.conditionLocalReads])]);o.size>0&&e.instanceReasonIds.set(t,new Map([...o].sort().map((e,t)=>[e,t])))}}function oc(e){return e.reduce((e,t)=>P(`||`,e,t))}function sc(e,t,n,r){let i=e.instanceReasonIds.get(t);if(i===void 0)return null;let a=[...r].map(e=>i.get(e)).filter(e=>e!==void 0).sort((e,t)=>e-t);if(a.length===0||a.length!==r.size)return null;let o=()=>T(n),s=oc(a.map(e=>N(`===`,o(),D(e)))),c=oc(a.map(e=>k(A(o(),T(`has`)),[D(e)])));return P(`||`,N(`===`,o(),O()),I(N(`===`,er(`typeof`,o()),E(`number`)),s,c))}function cc(e){let t=()=>T(e);return P(`||`,N(`===`,t(),er(`-`,D(1))),P(`&&`,P(`&&`,N(`!==`,t(),O()),N(`!==`,er(`typeof`,t()),E(`number`))),P(`&&`,N(`===`,A(t(),T(`size`)),D(1)),k(A(t(),T(`has`)),[er(`-`,D(1))]))))}function lc(e,t,n,r,i,a){let o=(n,i,o,s,c)=>{if(o.size===0&&s.size===0)return null;let l=z(k(X(e,`markDirty`),[i]));if(s.size>0&&a!==void 0){let t=[],r=[];for(let i of s){let o=Y(e,`eff${n.index}_${c}_${i}`).name;a.creation.push(B(`let`,[V(T(o),T(i))])),t.push(N(`!==`,T(o),T(i))),r.push(z(F(`=`,T(o),T(i))))}let i=t.length===1?t[0]:t.reduce((e,t)=>P(`||`,e,t));l=ar(i,R([...r,l]))}if(r===null)return l;let u=sc(e,t,r,o),d=u===null?l:ar(u,l);return ar(er(`!`,cc(r)),d)},s=i.flatMap(e=>[e.condition===null?null:o(e,Ks(n,e.index),e.conditionLocalReads,e.conditionLocalDerivationReads,`condition`),o(e,e.condition===null?Ks(n,e.index):qs(n,e.index),e.localReads,e.localDerivationReads,`callback`)].filter(e=>e!==null));return R(s)}function uc(e,t,n){return n.map(n=>z(k(X(e,n.condition===null?`registerEffect`:`registerConditionalEffect`),[Ks(t,n.index),T(t),...n.condition===null?[]:[L([],S(n.condition,!0))],S(n.callback,!0)])))}function dc(){return A(Cr(T(`import`),T(`meta`)),T(`hot`))}function fc(e,t){if(e.moduleEffects.length===0)return;let n=new Map;for(let t of e.moduleEffects){let e=n.get(t.statement)??[];e.push(t),n.set(t.statement,e)}for(let[r,i]of n){let n=Vs(t.node).body,a=n.indexOf(r);if(a===-1)continue;let o=[];for(let t of i)o.push(z(k(X(e,t.condition===null?`registerEffect`:`registerConditionalEffect`),[E(t.entityId),O(),...t.condition===null?[]:[L([],S(t.condition,!0))],S(t.callback,!0)])),ar(dc(),z(k(A(dc(),T(`dispose`)),[L([],k(X(e,`unregisterSubtree`),[E(t.entityId)]))]))));n.splice(a,1,...o)}}function pc(e,t){ma(e,t.node),C(t.node,{enter(n){if(n.type===`CallExpression`&&Gs(e,n))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`)}})}function mc(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function hc(e){let t=new Set,n=[];for(let r of e){let e=gc(r);if(e===null)return null;for(let n of e.bindings){if(t.has(n))return null;t.add(n)}n.push(...e.expressions)}return t.size===0?null:{bindings:t,expressions:n}}function gc(e){if(Qr(e)&&$r(e.expression,{operator:`=`})&&W(e.expression.left))return{bindings:new Set([e.expression.left.name]),expressions:[e.expression.right]};if(Yr(e))return hc(e.body);if(Zr(e)){let t=e.alternate;if(t==null)return null;let n=gc(e.consequent),r=gc(t);return n===null||r===null||!mc(n.bindings,r.bindings)?null:{bindings:n.bindings,expressions:[e.test,...n.expressions,...r.expressions]}}return null}function _c(e){if(!e.cases.some(e=>e.test==null))return null;let t=null,n=!1,r=[e.discriminant];for(let i of e.cases){i.test!=null&&r.push(i.test);let e=[...i.consequent];if(e.length===0){n=!0;continue}if(e.at(-1)&&wi(e.at(-1))&&e.pop(),e.some(e=>wi(e)))return null;let a=hc(e);if(a===null)return null;if(n=!1,t===null)t=a.bindings;else if(!mc(t,a.bindings))return null;r.push(...a.expressions)}return t===null||n?null:{bindings:t,expressions:r}}function vc(e,t,n){let r=t;for(;r!==null;){if(r===n)return!0;r=e.astAnalysis?.parentByNode.get(r)??null}return!1}function yc(e,t,n){let r=t;for(;r!==null&&e.astAnalysis?.parentByNode.get(r)!==n;)r=e.astAnalysis?.parentByNode.get(r)??null;return r}function bc(e,t,n){let r=t.node.body,i=new Map(r.map((e,t)=>[e,t]));for(let a of r){if(!Zr(a)&&!Ci(a))continue;let r=a,o=Zr(r)?gc(r):_c(r);if(o===null)continue;let s=!0,c=[];for(let n of o.bindings){let a=Q(e,r,n),o=a?.identifier,l=o===void 0?null:e.astAnalysis?.parentByNode.get(o)??null,u=o===void 0?null:yc(e,o,t.node);if(a===void 0||l?.type!==`VariableDeclarator`||a.kind!==`let`&&a.kind!==`var`||u===null||(i.get(u)??2**53-1)>=(i.get(r)??-1)){s=!1;break}c.push(...a.constantViolations.filter(t=>!vc(e,t,r)))}if(!s)continue;let l=new Set,u=null;for(let t of o.expressions){let r=n(e,t);for(let e of r.reads)l.add(e);r.impure&&u===null&&(u=r.reason??`cannot be analyzed`)}if(l.size===0)continue;if(u!==null)throw t.buildCodeFrameError(`memo-dom: module control-flow derivation ${u}`);for(let e of o.bindings)if(l.has(e))throw t.buildCodeFrameError(`memo-dom: module control-flow derivation '${e}' reads its own previous value`);if(c.length>0)throw t.buildCodeFrameError(`memo-dom: cannot assign module control-flow computed '${[...o.bindings].sort().join(`, `)}' outside its derivation`);let d=e.moduleControlFlow.length,f=[...o.bindings].sort();for(let t of f)va(e,t,`computed`);e.moduleControlFlow.push({statement:r,bindings:f,sources:[...l].sort(),entityId:`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#$flow${d}`})}}const xc=new Set([`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`,`ObjectMethod`,`ClassMethod`,`ClassPrivateMethod`]),Sc=new Set([`TSAsExpression`,`TSTypeAssertion`,`TSNonNullExpression`,`TSSatisfiesExpression`,`TSInstantiationExpression`]);function Cc(e,t){return e[t]}function wc(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function Tc(e,t){let n=Cc(e,t);return wc(n)?n:null}function Ec(e,t){let n=Cc(e,t);return Array.isArray(n)?n.filter(wc):[]}function Dc(e){if(e?.type!==`Identifier`)return null;let t=Cc(e,`name`);return typeof t==`string`?t:null}function Oc(e){let t=e;for(;Sc.has(t.type);){let e=Tc(t,`expression`);if(e===null)break;t=e}return t}function kc(e){return e.type===`MemberExpression`||e.type===`OptionalMemberExpression`}function Ac(e){let t=e;for(;;){if(kc(t)){let e=Tc(t,`object`);if(e===null||e.type===`Super`)return null;t=e;continue}let e=Oc(t);if(e!==t){t=e;continue}return Dc(t)}}function jc(e){if(e===null||e.type!==`StringLiteral`&&e.type!==`Literal`)return null;let t=Cc(e,`value`);return typeof t==`string`?t:null}function Mc(e){let t=[],n=e;for(;kc(n);){let e=Tc(n,`property`),r=Cc(n,`computed`)===!0?jc(e):Dc(e);if(r===null)return null;t.unshift(r);let i=Tc(n,`object`);if(i===null||i.type===`Super`)return null;n=i}n=Oc(n);let r=Dc(n);return r===null?null:(t.unshift(r),t.join(`.`))}function Nc(e,t){let n=new Set,r=!1,i,a=new Set,o=e=>{r||(r=!0,i=e)},s=e=>{C(e,{enter(e){let t=Dc(e);t!==null&&a.add(t)}})};return C(t,{enter(t,r){if(xc.has(t.type)){if(r===null||r.type!==`CallExpression`&&r.type!==`NewExpression`)return!1;for(let e of Ec(t,`params`))s(e);return}if(t.type===`VariableDeclarator`){let e=Tc(t,`id`);e!==null&&s(e);return}if(t.type===`AssignmentExpression`){let e=Tc(t,`left`),n=Dc(e)??(e!==null&&kc(e)?Ac(e):null);(n===null||!a.has(n))&&o(`contains an assignment: writes belong in handlers, not derivations`);return}if(t.type===`UpdateExpression`){let e=Tc(t,`argument`),n=Dc(e)??(e!==null&&kc(e)?Ac(e):null);(n===null||!a.has(n))&&o(`contains an update (++/--): writes belong in handlers, not derivations`);return}if(t.type===`AwaitExpression`||t.type===`YieldExpression`){o(`uses await/yield: derivations must be synchronous`);return}if(t.type===`CallExpression`){let r=Dc(Tc(t,`callee`));if(r!==null&&(e.helpers.has(r)||e.importedFunctions.has(r))){let t=e.importedFunctions.get(r)??ws(e,r);for(let e of t.reads)n.add(e);if(t.writes.size>0){for(let e of t.writes)n.add(e);o(`calls helper '${r}' which writes state: writes belong in handlers`)}else t.unbounded&&e.helpers.has(r)&&o(`calls recursive helper '${r}' which cannot be analyzed`)}return}let i=Dc(t);if(i!==null){!a.has(i)&&e.state.has(i)&&n.add(i);return}if(t.type===`MemberExpression`&&Cc(t,`computed`)!==!0){let r=Mc(t);if(r!==null&&r.includes(`.`)){let t=r.split(`.`)[0];!a.has(t)&&e.state.get(t)===`store`&&n.add(r)}}}}),{reads:n,impure:r,reason:i}}function Pc(e,t){for(let n of Ec(t.node,`body`)){let r=n.type===`ExportNamedDeclaration`?Tc(n,`declaration`):n;if(r?.type!==`VariableDeclaration`)continue;let i=Cc(r,`kind`);for(let n of Ec(r,`declarations`)){let r=Tc(n,`id`),a=Tc(n,`init`),o=Dc(r);if(o===null||a===null||e.state.get(o)===`let`||e.state.get(o)===`computed`||xc.has(a.type)||a.type===`JSXElement`||a.type===`JSXFragment`)continue;let s=Nc(e,a);if(i!==`const`){let r=e.astAnalysis?.nodeToScope.get(n)?.getBinding(o);if(s.reads.size>0&&(r?.constantViolations.length??0)===0)throw t.buildCodeFrameError(`memo-dom: ${String(i)} '${o}' is never reassigned and its initializer reads reactive state; use const for derived values`,n);continue}if(s.impure){if(s.reads.size>0)throw t.buildCodeFrameError(`memo-dom: const '${o}' is a state derivation but ${s.reason??`cannot be analyzed`}. Fix the derivation, or make it a 'let' you update in handlers.`,n);continue}s.reads.size!==0&&(va(e,o,`computed`),e.computeds.set(o,{reads:s.reads}))}}}function Fc(e,t){let n=[],r=[],i=-1;for(let t=0;t<e.length;t++)si(e[t])&&(i=t);let a=[];for(let o=0;o<e.length;o++){let s=e[o];if(si(s)){n.push(Qn(S(s.argument))),r.push(S(s.argument));continue}let c=Ic(s.name);if(c===`key`&&t.skipKey)continue;let l=Lc(s,t.fail),u=t.attributeValue?.(c,l)??l,d=/^on[A-Z]/.test(c)&&t.eventValue!==void 0?t.eventValue(c,u):u;n.push(M(dt(c)?T(c):E(c),d,!1,W(d)&&d.name===c)),r.push(S(l)),/^on[A-Z]/.test(c)&&o>i&&a.push(c)}return{expression:Zn(n),sources:r,safeEventKeys:a}}function Ic(e){return J(e)?e.name:`${e.namespace.name}:${e.name.name}`}function Lc(e,t){return e.value==null?Yn(!0):G(e.value)?S(e.value):ci(e.value)&&q(e.value.expression)?S(e.value.expression):t(`memo-dom: attribute '${Ic(e.name)}' must contain a JavaScript expression`)}const Rc=new Set([`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`,`ObjectMethod`,`ClassMethod`,`ClassPrivateMethod`]);function zc(e){return e}function Bc(e){return S(e)}function Vc(e){return typeof e==`object`&&e&&`type`in e?e:null}function Hc(e,t){return Vc(zc(e)[t])}function Uc(e,t){let n=zc(e)[t];return Array.isArray(n)?n.map(Vc).filter(e=>e!==null):[]}function Wc(e){if(e?.type!==`Identifier`)return null;let t=zc(e).name;return typeof t==`string`?t:null}function Gc(e,t){return e.astAnalysis?.parentByNode.get(t)??null}function Kc(e,t,n){let r=t;for(;r!==null;){if(r===n)return!0;r=Gc(e,r)}return!1}function qc(e,t){let n=t.identifier;for(;n!==null&&n!==t.declarationNode;){if(n.type===`VariableDeclarator`)return n;n=Gc(e,n)}return null}function Jc(e,t,n,r){let i=Q(e,n,r);if(i===void 0)return null;let a=null;if(i.declarationNode.type===`FunctionDeclaration`)a=i.declarationNode;else{let t=qc(e,i),n=t===null?null:Hc(t,`init`);n!==null&&Rc.has(n.type)&&(a=n)}return a!==null&&Kc(e,a,t)?a:null}function Yc(e,t,n){let r=Gc(e,t);return r?.type!==`CallExpression`&&r?.type!==`NewExpression`?!1:Hc(r,`callee`)===t||n&&Uc(r,`arguments`).includes(t)}function Xc(e,t,n,r){C(t,{enter(i){if(i!==t&&Rc.has(i.type)&&!Yc(e,i,n))return!1;r(i)}})}function Zc(e,t){let n=Wc(t);if(n===null)return!1;let r=Q(e,t,n);return r===void 0||r.references.includes(t)}function Qc(e){let t=Wc(e);return t===null?e?.type===`MemberExpression`?Ea(e):null:t}function $c(e,t,n,r,i,a,o){let s=Jc(e,t,n,r);if(s===null)return null;let c=a.get(s);if(c!==void 0)return c;if(o.has(s))return{reads:new Set,reason:`calls recursive local helper '${r}'`};let l={reads:new Set,reason:null},u=e=>{l.reason??=e},d=t=>{if(!Zc(e,t))return;let n=Q(e,t,t.name),r=n===void 0?void 0:i.get(n);r!==void 0&&l.reads.add(r)},f=(t,n)=>{let a=Qc(n);if(a===null)return;let o=Q(e,t,a),s=o===void 0?void 0:i.get(o);s!==void 0&&u(`calls local helper '${r}' which writes reactive state '${s}'`)},p=n=>{let r=Wc(Hc(n,`callee`));if(r===null)return;let s=$c(e,t,n,r,i,a,o);if(s!==null){for(let e of s.reads)l.reads.add(e);s.reason!==null&&u(s.reason);return}if(!e.helpers.has(r)&&!e.importedFunctions.has(r))return;let c=e.importedFunctions.get(r)??ws(e,r);for(let e of c.reads)l.reads.add(e);c.writes.size!==0||c.boundedWrites.size!==0?u(`calls helper '${r}' which writes reactive state`):c.unbounded&&e.helpers.has(r)&&u(`calls recursive helper '${r}' which cannot be analyzed`)},m=e=>{e.type===`Identifier`?d(e):e.type===`AssignmentExpression`?f(e,Hc(e,`left`)):e.type===`UpdateExpression`?f(e,Hc(e,`argument`)):e.type===`AwaitExpression`?u(`calls async local helper '${r}'`):e.type===`YieldExpression`?u(`calls yielding local helper '${r}'`):e.type===`CallExpression`&&p(e)};o.add(s);let h=Hc(s,`body`)??s;return Xc(e,h,!1,m),l.reads.size!==0&&Xc(e,h,!0,m),o.delete(s),a.set(s,l),l}function el(e){for(let[t,n]of e.compPaths){let r=new Set;for(let t of n.node.body.body)if(qr(t)&&(t.kind===`let`||t.kind===`var`||t.kind===`const`))for(let n of t.declarations){if(!W(n.id))continue;let i=Q(e,n,n.id.name);((t.kind===`let`||t.kind===`var`)&&ga(e,i)||Da(n.init)||Oa(n.init))&&r.add(n.id.name)}r.size>0&&e.instanceState.set(t,r)}}function tl(e){for(let[t,n]of e.compPaths){let r=e.instanceState.get(t);if(r===void 0||r.size===0)continue;let i=new Set;C(n.node,{enter(e){if(e.type!==`JSXAttribute`||Ic(e.name)!==`ref`)return;let t=Hc(e,`value`);if(t?.type!==`JSXExpressionContainer`)return;let n=Hc(t,`expression`),r=Wc(n);if(r!==null){i.add(r);return}if(n?.type===`ArrayExpression`)for(let e of Uc(n,`elements`)){let t=Wc(e);t!==null&&i.add(t)}}});for(let e of i)r.delete(e)}}function nl(e){for(let[t,n]of e.compPaths){let r=n.node,i=new Map,a=e.opaqueBindings.get(t),o=t=>Q(e,r,t),s=(t,n)=>{if(a?.has(t)!==!0)return!1;let r=Q(e,n,t);return r!==void 0&&r===o(t)},c=(n,r)=>{if(e.transparentSources.get(t)?.has(n)!==!0)return!1;let i=Q(e,r,n);return i!==void 0&&i===o(n)};for(let n of e.componentProps.get(t)?.bindings??[]){let e=o(n);e&&i.set(e,n)}for(let n of e.instanceState.get(t)??[]){let e=o(n);e&&i.set(e,n)}for(let t of e.state.keys()){let e=o(t);e?.scope.isProgramScope===!0&&i.set(e,t)}let l=[],u=new Set,d=new Map,f=t=>{if(t.type!==`CallExpression`)return!1;let n=Wc(Hc(t,`callee`));return n===null||!e.transparentSourceFactories.has(n)?!1:Q(e,t,n)?.kind===`import`},p=t=>{let n=t,r=!1;for(;;){let t=Gc(e,n);if((t?.type===`MemberExpression`||t?.type===`OptionalMemberExpression`)&&Hc(t,`object`)===n){n=t,r=!0;continue}break}if(!r)return!1;let i=Gc(e,n);if(i!==null){if((i.type===`CallExpression`||i.type===`NewExpression`)&&Hc(i,`callee`)===n)return c(Wc(t),t);if(i.type===`CallExpression`||i.type===`NewExpression`||i.type===`SpreadElement`||i.type===`AssignmentExpression`&&Hc(i,`left`)===n)return!1}return!0},m=t=>{let n=`none`;return Xc(e,t,!0,t=>{if(n===`bad`||!Zc(e,t))return;let r=Q(e,t,t.name);r!==void 0&&i.has(r)||s(t.name,t)&&(n=p(t)?`ok`:`bad`)}),n};for(let a of n.node.body.body)if(qr(a))for(let c of a.declarations){if(!W(c.id)&&!fi(c.id)&&!pi(c.id)||c.init==null||Kr(c.init)||W(c.id)&&e.instanceState.get(t)?.has(c.id.name)===!0&&(Da(c.init)||Oa(c.init)))continue;let p=c.init,h=f(p);if(m(p)===`bad`)continue;let g=new Set,_=null,v=(t,n)=>{let r=Q(e,n,t);return r!==void 0&&i.has(r)},y=t=>{if(!Zc(e,t))return;let n=Q(e,t,t.name),r=n===void 0?void 0:i.get(n);r===void 0?s(t.name,t)&&g.add(t.name):g.add(r)},b=new Map,ee=new Set,te=t=>{let n=Wc(Hc(t,`callee`));if(n===null)return;let a=$c(e,r,t,n,i,b,ee);if(a!==null){for(let e of a.reads)g.add(e);_??=a.reason;return}if(!e.helpers.has(n)&&!e.importedFunctions.has(n))return;let o=e.importedFunctions.get(n)??ws(e,n);for(let e of o.reads)g.add(e);o.writes.size!==0||o.boundedWrites.size!==0?_??=`calls helper '${n}' which writes reactive state`:o.unbounded&&e.helpers.has(n)&&(_??=`calls recursive helper '${n}' which cannot be analyzed`)},ne=e=>{if(e.type===`Identifier`)y(e);else if(e.type===`AssignmentExpression`){let t=Qc(Hc(e,`left`));t!==null&&v(t,e)&&(_=`contains an assignment to reactive state`)}else if(e.type===`UpdateExpression`){let t=Qc(Hc(e,`argument`));t!==null&&v(t,e)&&(_=`contains an update (++/--) to reactive state`)}else e.type===`AwaitExpression`?_=`uses await; per-instance derivations must be synchronous`:e.type===`YieldExpression`?_=`uses yield; per-instance derivations must be synchronous`:e.type===`CallExpression`&&te(e)};if(Xc(e,p,!1,ne),g.size===0)continue;if(Xc(e,p,!0,ne),a.kind!==`const`){let e=to(c.id),t=e.map(e=>o(e));if(t.length>0&&t.every(e=>e!==void 0&&e.constantViolations.length===0))throw n.buildCodeFrameError(`memo-dom: ${a.kind} '${e.join(`, `)||`<pattern>`}' is never reassigned and its initializer reads reactive state; use const for derived values`,c);continue}if(_!==null){let e=to(c.id);throw n.buildCodeFrameError(`memo-dom: local const '${e.join(`, `)||`<pattern>`}' is a per-instance derivation but ${_}`)}let re=to(c.id),x=new Set;for(let e of g){let t=d.get(e);if(t===void 0)x.add(e);else for(let e of t)x.add(e)}let ie=h&&W(c.id),ae=ie&&Lr(c.init)?z(e.transparentProviderFactories.has(c.init.callee.name)?k(Z(e,`rebindResolvedValue`),[T(c.id.name),...c.init.arguments.map(Bc)]):k(Z(e,`rebindResolvedValueFromFactory`),[T(c.id.name),L([],Bc(c.init))])):void 0;if(l.push({declaration:a,target:Bc(c.id),source:Bc(c.init),bindings:re,sources:[...x].sort(),...ie?{stableTarget:!0,replay:ae}:{}}),!ie)for(let n of re){u.add(n),d.set(n,new Set(x));let r=o(n);r&&i.set(r,n),e.instanceState.get(t)?.delete(n)}}if(l.length===0)continue;e.instanceDerivations.set(t,l),e.instanceDerivedBindings.set(t,u);let h=new Set([...e.instanceState.get(t)??[],...e.componentProps.get(t)?.bindings??[]]);if(![...h].some(e=>l.some(t=>!t.sources.includes(e))))continue;let g=new Set([...h,...l.flatMap(e=>e.sources)]);e.instanceReasonIds.set(t,new Map([...g].sort().map((e,t)=>[e,t]))),e.selectiveDerivationComponents.add(t)}}const rl=new Set([`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`,`ObjectMethod`,`ClassMethod`,`ClassPrivateMethod`]);function il(e){return e}function al(e){return typeof e==`object`&&e&&`type`in e?e:null}function ol(e,t){return al(il(e)[t])}function sl(e,t){let n=il(e)[t];return Array.isArray(n)?n.map(al).filter(e=>e!==null):[]}function cl(e){if(e?.type!==`Identifier`)return null;let t=il(e).name;return typeof t==`string`?t:null}function ll(e){return e?.kind===`import`}function ul(e){let t=e;for(;t.type===`MemberExpression`||t.type===`OptionalMemberExpression`;){let e=ol(t,`object`);if(e===null)return null;t=e}return cl(t)}function dl(e,t){let n=t.identifier;for(;n!==null&&n!==t.declarationNode;){if(n.type===`VariableDeclarator`)return n;n=e.astAnalysis?.parentByNode.get(n)??null}return null}function fl(e,t){let n=dl(e,t);return n===null?null:ol(n,`init`)}function pl(e,t){if(t.declarationNode.type===`FunctionDeclaration`)return t.declarationNode;let n=fl(e,t);return n!==null&&rl.has(n.type)?n:null}function ml(e,t,n,r){let i=new Set;return C(t,{enter(t){let a=cl(t);if(a===null||!r.has(a))return;let o=Q(e,t,a);o!==void 0&&o.references.includes(t)&&o===Q(e,n,a)&&i.add(a)}}),i}function hl(e,t,n,r,i=new Set){let a=ol(t,`callee`);if(a===null)return!1;let o=ul(a);if(o===null)return!1;if(n.has(o))return!0;let s=e.importedFunctions.get(o);if(s!==void 0)return s.unbounded;let c=Q(e,t,o);if(ll(c))return!0;if(r===void 0||t.type!==`CallExpression`)return!1;let l=c===void 0?null:pl(e,c);if(l===null||i.has(l))return!1;i.add(l);try{let t=!1,a=new Set,o=s=>{if(t)return;if(ml(e,s,r,n).size>0){t=!0;return}let c=cl(s);if(c!==null){let n=Q(e,s,c);if(n!==void 0&&!a.has(n)){let t=fl(e,n);t!==null&&(a.add(n),o(t),a.delete(n))}if(t)return}C(s,{enter(a){if(t||a!==s&&rl.has(a.type))return!1;if((a.type===`CallExpression`||a.type===`NewExpression`)&&hl(e,a,n,r,i))return t=!0,!1}})},s=ol(l,`body`);return s!==null&&(s.type===`BlockStatement`?C(s,{enter(e){if(t||e!==s&&rl.has(e.type))return!1;if(e.type!==`ReturnStatement`)return;let n=ol(e,`argument`);return n!==null&&o(n),!1}}):o(s),t)}finally{i.delete(l)}}function gl(e){let t=e;for(;t.type===`MemberExpression`||t.type===`OptionalMemberExpression`;){let e=ol(t,`object`);if(e===null)return null;t=e}return cl(t)}function _l(e,t,n){let r=e.astAnalysis?.parentByNode.get(t)??null;for(;r!==null;){if(n(r))return r;r=e.astAnalysis?.parentByNode.get(r)??null}return null}function vl(e,t){let n=e.astAnalysis?.rootScope;if(n===void 0)return new Set(t);let r=new Set(n.bindings.keys()),i=new Set(t),a=!0;for(;a;){a=!1;for(let[t,o]of n.bindings){if(i.has(t))continue;let s=fl(e,o);if(s===null)continue;let c=[...ml(e,s,n.block,r)].some(e=>i.has(e));c||C(s,{enter(t){if((t.type===`CallExpression`||t.type===`NewExpression`)&&hl(e,t,i,n.block))return c=!0,!1}}),c&&(i.add(t),a=!0)}}return i}function yl(e){let t=ol(e,`name`);if(t?.type===`JSXIdentifier`){let e=il(t).name;return typeof e==`string`?e:null}if(t?.type!==`JSXNamespacedName`)return null;let n=ol(t,`namespace`),r=ol(t,`name`),i=n?.type===`JSXIdentifier`?il(n).name:null,a=r?.type===`JSXIdentifier`?il(r).name:null;return typeof i==`string`&&typeof a==`string`?`${i}:${a}`:null}function bl(e,t,n){let r=new Set;return C(t,{enter(i,a){let o=null;if(i.type===`JSXExpressionContainer`){if(a?.type===`JSXAttribute`){let e=yl(a);if(e===`ref`||e!==null&&/^on[A-Z]/.test(e))return!1}o=ol(i,`expression`)}else i.type===`JSXSpreadAttribute`&&(o=ol(i,`argument`));if(o!==null&&o.type!==`JSXEmptyExpression`){for(let i of ml(e,o,t,n))r.add(i);return!1}}}),r}function xl(e){let t=e.astAnalysis?.rootScope.bindings;if(t===void 0)return;let n=vl(e,[...t].filter(([t,n])=>{if(!ll(n)||e.importedState.has(t)||e.importedComponents.has(t))return!1;let r=e.importedFunctions.get(t);return r===void 0||r.unbounded}).map(([e])=>e));for(let[t,r]of e.compPaths){let i=r.node,a=ha(e,i),o=new Set([...a?.bindings.keys()??[],...e.state.keys(),...n,...e.instanceState.get(t)??[],...e.instanceDerivedBindings.get(t)??[],...e.componentProps.get(t)?.bindings??[]]);if(o.size===0)continue;let s=new Set(n),c=!0;for(;c;){c=!1;let t=e=>{!o.has(e)||s.has(e)||(s.add(e),c=!0)};C(i,{enter(n){if(n.type===`CallExpression`||n.type===`NewExpression`){if(!hl(e,n,s,i))return;for(let r of sl(n,`arguments`))if(r.type!==`SpreadElement`)for(let n of ml(e,r,i,o))t(n);let r=_l(e,n,e=>e.type===`VariableDeclarator`),a=r===null?null:ol(r,`id`);if(a!==null)for(let e of St(a))t(e.name);let c=_l(e,n,e=>e.type===`AssignmentExpression`&&il(e).operator===`=`),l=c===null?null:ol(c,`left`);if(l!==null){let e=gl(l);e!==null&&t(e)}return}if(n.type!==`VariableDeclarator`)return;let r=ol(n,`init`),a=ol(n,`id`);if(r!==null&&a!==null&&[...ml(e,r,i,o)].some(e=>s.has(e)))for(let e of St(a))t(e.name)}})}let l=bl(e,i,o);e.opaqueBindings.set(t,s),[...s].some(e=>l.has(e))&&e.volatileComponents.add(t)}}function Sl(e){return e}function Cl(e,t){let n=Sl(e)[t];return typeof n==`object`&&n&&`type`in n?n:null}const wl=new Set([`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`,`ObjectMethod`,`ClassMethod`,`ClassPrivateMethod`]),Tl=new Set([...wl,`AssignmentExpression`,`AwaitExpression`,`NewExpression`,`TaggedTemplateExpression`,`UpdateExpression`,`YieldExpression`]);function El(e){let t=!0;return C(e,{enter(e){if(Tl.has(e.type))return t=!1,!1;if(e.type!==`CallExpression`&&e.type!==`OptionalCallExpression`)return;let n=Cl(e,`callee`),r=n===null?null:Cl(n,`object`),i=n===null?null:Cl(n,`property`);return t=t&&n?.type===`MemberExpression`&&Sl(n).computed===!1&&r?.type===`Identifier`&&Sl(r).name===`Math`&&i?.type===`Identifier`,t?void 0:!1}}),t}function Dl(e){return!Qr(e)||!$r(e.expression,{operator:`=`})||!W(e.expression.left)||!El(e.expression.right)?null:e.expression.left.name}function Ol(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function kl(e){if(Qr(e)){let t=Dl(e);return t===null?null:{bindings:new Set([t]),partial:new Set}}if(Yr(e)){let t=new Set,n=new Set;for(let r of e.body){let e=kl(r);if(e===null)return null;for(let n of e.bindings){if(t.has(n))return null;t.add(n)}for(let t of e.partial)n.add(t)}return t.size===0?null:{bindings:t,partial:n}}if(Zr(e)){if(!El(e.test))return null;let t=kl(e.consequent);if(t===null)return null;if(e.alternate==null)return{bindings:t.bindings,partial:new Set([...t.bindings,...t.partial])};let n=kl(e.alternate);return n===null||!Ol(t.bindings,n.bindings)?null:{bindings:t.bindings,partial:new Set([...t.partial,...n.partial])}}return null}function Al(e){if(!El(e.discriminant))return null;let t=null;for(let n of e.cases){if(n.test!=null&&!El(n.test))return null;let e=[...n.consequent];if(e.at(-1)&&wi(e.at(-1))&&e.pop(),e.some(e=>wi(e)))return null;let r=kl(R(e));if(r===null)return null;if(t===null)t=r;else{if(!Ol(t.bindings,r.bindings))return null;for(let e of r.partial)t.partial.add(e)}}if(t!==null&&!e.cases.some(e=>e.test===null))for(let e of t.bindings)t.partial.add(e);return t}function jl(e,t,n){let r=t;for(;r!==null;){if(r===n)return!0;r=e.astAnalysis?.parentByNode.get(r)??null}return!1}function Ml(e,t){let n=t.identifier;for(;n!==null&&n!==t.declarationNode;){if(n.type===`VariableDeclarator`)return n;n=e.astAnalysis?.parentByNode.get(n)??null}return null}function Nl(e,t){let n=e.astAnalysis?.parentByNode.get(t)??null,r=e.astAnalysis?.keyByNode.get(t);return n?.type===`AssignmentExpression`&&r===`left`?Sl(n).operator!==`=`:n?.type===`UpdateExpression`&&r===`argument`||(n?.type===`ForInStatement`||n?.type===`ForOfStatement`)&&r===`left`?n.type===`UpdateExpression`:!0}function Pl(e,t,n,r){C(t,{enter(i){if(i!==t&&wl.has(i.type))return!1;if(i.type!==`Identifier`||!Nl(e,i))return;let a=Sl(i).name;if(typeof a!=`string`)return;let o=Q(e,i,a),s=o===void 0?void 0:n.get(o);s!==void 0&&r.add(s)}})}function Fl(e){for(let[t,n]of e.compPaths){let r=new Map;for(let i of e.componentProps.get(t)?.bindings??[]){let t=Q(e,n.node,i);t&&r.set(t,i)}for(let i of e.instanceState.get(t)??[]){let t=Q(e,n.node,i);t&&r.set(t,i)}for(let i of e.instanceDerivedBindings.get(t)??[]){let t=Q(e,n.node,i);t&&r.set(t,i)}for(let t of e.state.keys()){let i=Q(e,n.node,t);i?.scope.isProgramScope===!0&&r.set(i,t)}let i=[],a=e.instanceDerivedBindings.get(t)??new Set;for(let o of n.node.body.body){if(!Zr(o)&&!Ci(o))continue;let s=Zr(o)?kl(o):Al(o);if(s===null)continue;let c=!0,l=[],u=[];for(let t of s.bindings){let n=Q(e,o,t),r=n===void 0?null:Ml(e,n),i=n?.declarationNode,a=i?.type===`VariableDeclaration`?Sl(i).kind:null;if(n===void 0||r===null||a!==`let`&&a!==`var`||n.constantViolations.some(t=>!jl(e,t,o))){c=!1;break}if(s.partial.has(t)){let e=Cl(r,`init`);if(e===null||!El(e)){c=!1;break}let n=e;l.push({binding:t,source:n}),u.push(n)}}if(!c)continue;let d=new Set;Pl(e,o,r,d);for(let t of u)Pl(e,t,r,d);if(d.size!==0){for(let e of s.bindings)if(d.has(e))throw n.buildCodeFrameError(`memo-dom: reactive control-flow derivation '${e}' reads its own previous value`);i.push({statement:o,bindings:[...s.bindings].sort(),resets:l,sources:[...d].sort()});for(let n of s.bindings){a.add(n);let i=Q(e,o,n);i&&r.set(i,n),e.instanceState.get(t)?.delete(n)}}}i.length>0&&(e.instanceControlFlow.set(t,i),e.instanceDerivedBindings.set(t,a))}}function Il(e){for(let[t]of e.compPaths){let n=e.instanceDerivations.get(t)??[],r=e.instanceControlFlow.get(t)??[];if(n.length===0&&r.length===0)continue;let i=new Map;for(let e of n)if(e.stableTarget!==!0)for(let t of e.bindings)i.set(t,new Set(e.sources));for(let e of r)for(let t of e.bindings)i.set(t,new Set(e.sources));let a=(e,t=new Set)=>{let n=i.get(e);if(n===void 0||t.has(e))return new Set([e]);let r=new Set(t).add(e),o=new Set;for(let e of n)for(let t of a(e,r))o.add(t);return o};for(let e of n)e.sources=[...new Set(e.sources.flatMap(e=>[...a(e)]))].sort();for(let e of r)e.sources=[...new Set(e.sources.flatMap(e=>[...a(e)]))].sort();let o=new Set([...e.instanceState.get(t)??[],...e.componentProps.get(t)?.bindings??[]]),s=[...n,...r],c=[...o].some(e=>s.some(t=>!t.sources.includes(e)));if(e.selectiveDerivationComponents.delete(t),e.instanceReasonIds.delete(t),!c)continue;let l=new Set([...o,...s.flatMap(e=>e.sources)]);e.instanceReasonIds.set(t,new Map([...l].sort().map((e,t)=>[e,t]))),e.selectiveDerivationComponents.add(t)}}function Ll(e){let t=e.indexOf(`[`);return t<0?e:e.slice(0,t)}function Rl(e,t){let n=new Set;for(let r of t){let t=r.split(`/`),i=[[]];for(let n=0;n<t.length;n++){let r=t[n],a=i.map(e=>[...e,r]);if(n<t.length-1&&e.renderSlotOwners.has(Ll(r)))for(let e of i)a.push([...e,r,`$slot[*]`]);i=a}for(let e of i)n.add(e.join(`/`))}return[...n]}function zl(e,t,n=new Set){let r=e.linkedComponentPaths.get(t);if(r!==void 0)return[...r];if(n.has(t))throw e.compPaths.get(t).buildCodeFrameError(`memo-dom: recursive component '${t}' — components cannot render themselves (L1)`);let i=e.listedSites.get(t);if(i!==void 0&&i.length>0){n.add(t);let r=i.flatMap(t=>zl(e,t.owner,n).map(e=>`${e}/${t.suffix}/Row[*]`));return n.delete(t),[...new Set(r)]}let a=e.comps.get(t),o=e.conditionalComponentSites.get(t)??[],s=e.rowComponentSites.get(t)??[];if(a.parents.size===0&&o.length===0&&s.length===0)return[e.rootId];n.add(t);let c=[];for(let t of o)for(let r of zl(e,t.owner,n))c.push(`${r}/${t.suffix}`);for(let t of s)for(let r of zl(e,t.owner,n))c.push(`${r}/${t.suffix}`);for(let r of a.parents){let i=e.childRefCounts.get(r)?.get(t)??1;for(let a of zl(e,r,n))i>1?c.push(`${a}/${t}`,`${a}/${t}[*]`):c.push(`${a}/${t}`),e.usesRouter&&c.push(`${a}/**/${t}`)}return n.delete(t),c}function Bl(e,t){let n=e.linkedComponentPaths.get(t);if(n!==void 0)return Rl(e,n.flatMap(e=>[e,`${e}/*`]));let r=e.listedSites.get(t),i=[];if(r&&r.length>0){if(Hl(e,t)){for(let t of r){let n=t.suffix.lastIndexOf(`/`),r=n<0?``:`/${t.suffix.slice(0,n)}`;for(let n of zl(e,t.owner))i.push(`${n}${r}`,`${n}${r}/*`)}return Rl(e,i)}for(let t of r)for(let n of zl(e,t.owner))i.push(`${n}/${t.suffix}/Row[*]`,`${n}/${t.suffix}/Row[*]/*`);return Rl(e,i)}for(let n of zl(e,t))i.push(n,`${n}/*`);return Rl(e,i)}function Vl(e,t){let n=e.importedComponents.get(t);if(n!==void 0)return n.listLightweight;let r=e.lightweightCache.get(t);if(r!==void 0)return r;let i=!1,a=e.listedSites.get(t),o=e.linkedComponentRows.get(t);return(a!==void 0&&a.length>0||o!==void 0&&o.length>0)&&e.comps.get(t).parents.size===0&&Ul(e,t)&&(i=!0),e.lightweightCache.set(t,i),i}function Hl(e,t){return!(!Vl(e,t)||e.transparentSources.has(t)||e.transparentPolicyParams.has(t))}function Ul(e,t){if((e.instanceState.get(t)?.size??0)>0)return!1;let n=!0;return C(e.compPaths.get(t).node,{enter(t){if(t.type===`JSXElement`){let e=t.openingElement.name;J(e)&&/^[A-Z]/.test(e.name)&&(n=!1);return}if(t.type===`CallExpression`||t.type===`OptionalCallExpression`){let r=t;(W(r.callee,{name:`cleanup`})&&Q(e,t,`cleanup`)===void 0||W(r.callee,{name:`effect`})&&Q(e,t,`effect`)===void 0)&&(n=!1),Lo(r)&&Ro(t)&&(n=!1);return}(t.type===`ConditionalExpression`||t.type===`LogicalExpression`)&&Ro(t)&&(n=!1)}}),n}function Wl(e){return e}function Gl(e){return typeof e==`object`&&e&&`type`in e?e:null}function Kl(e,t){return Gl(Wl(e)[t])}function ql(e){if(e?.type!==`Identifier`&&e?.type!==`JSXIdentifier`)return null;let t=Wl(e).name;return typeof t==`string`?t:null}function Jl(e){return S(e)}function Yl(e,t){throw e.buildCodeFrameError(`memo-dom: ${t}`)}function Xl(e,t){let n=t.identifier;for(;n!==null&&n!==t.declarationNode;){if(n.type===`VariableDeclarator`)return n;n=e.parentByNode.get(n)??null}return null}function Zl(e,t){let n=e.astAnalysis,r=t;for(;;){let t=n.parentByNode.get(r)??null;if(t===null||t.type===`JSXAttribute`||t.type===`JSXSpreadAttribute`)return!1;if(t.type===`JSXExpressionContainer`){let r=n.parentByNode.get(t)??null;if(r?.type===`JSXAttribute`){let t=n.parentByNode.get(r)??null;if(t?.type!==`JSXOpeningElement`)return!1;let i=ql(Kl(t,`name`));if(i===null||!/^[A-Z]/.test(i))return!1;let a=Kl(r,`name`),o=ql(a)??(a===null?null:ql(Kl(a,`name`)));return o!==null&&e.componentProps.get(i)?.renderProps.includes(o)===!0}return r?.type===`JSXElement`||r?.type===`JSXFragment`}if(t.type===`ReturnStatement`&&Kl(t,`argument`)===r||t.type===`ArrowFunctionExpression`&&Kl(t,`body`)===r||t.type===`VariableDeclarator`&&Kl(t,`init`)===r)return!0;r=t}}function Ql(e,t){if(t.type===`ArrayExpression`)return t;let n=ql(t);if(n===null)return null;let r=Q(e,t,n);if(r===void 0)return null;let i=Xl(e.astAnalysis,r),a=i===null?null:Kl(i,`init`);return a?.type===`ArrayExpression`?a:null}function $l(e){return e.type===`NullLiteral`||e.type===`BooleanLiteral`||e.type===`Literal`&&(Wl(e).value===null||typeof Wl(e).value==`boolean`)}function eu(e,t,n,r=new Set){let i=t;if(r.has(i))return Yl(n,`cyclic JSX array spread`);r.add(i);let a=[];try{for(let i of t.elements)if(!(i==null||$l(i))){if(gi(i)){let t=Ql(e,i.argument);if(t===null)return Yl(n,`JSX array spreads must resolve to a static JSX array`);a.push(...eu(e,t,n,r));continue}if(Br(i)){a.push(...eu(e,i,n,r));continue}if(ii(i)||ai(i)){a.push(Jl(i));continue}a.push(mr(Jl(i)))}}finally{r.delete(i)}return a}function tu(e,t,n){return yr(_r(),vr(),eu(e,t,n))}function nu(e){if(e.type!==`StringLiteral`&&e.type!==`NumericLiteral`&&e.type!==`Literal`)return null;let t=Wl(e).value;return typeof t==`string`||typeof t==`number`?t:null}function ru(e,t){return Br(e)?e.elements.map((e,n)=>e==null?Yl(t,`JSX arrays cannot contain holes`):gi(e)?Yl(t,`JSX array spreads must resolve to a static JSX array`):{key:D(n),value:e}):e.properties.map(e=>{let n=e;if(n.type!==`ObjectProperty`&&n.type!==`Property`||Wl(n).computed===!0)return Yl(t,`JSX objects require static data properties without spreads`);let r=Kl(n,`key`),i=Kl(n,`value`);if(r===null||i===null)return Yl(t,`JSX objects require static data properties without spreads`);let a=ql(r),o=nu(r),s=a===null?typeof o==`string`?E(o):typeof o==`number`?D(o):null:E(a);return s===null?Yl(t,`JSX objects require identifier, string, or numeric keys`):{key:s,value:i}})}function iu(e,t,n){let r=Kl(e,`property`),i=Wl(e).computed===!0,a=null;if(i?r!==null&&(a=nu(r)):a=ql(r),a!==null){let e=t.find(e=>nu(e.key)===a);return e===void 0?Yl(n,`JSX collection has no entry for '${a}'`):Jl(e.value)}if(!i||r===null)return Yl(n,`JSX collection selection requires a static or expression key`);let o=O();for(let e=t.length-1;e>=0;e--){let n=t[e];o=I(N(`===`,Jl(r),Jl(n.key)),Jl(n.value),o)}return o}function au(e){let t=e.astAnalysis?.rootScope.block;if(t===void 0||t.type!==`Program`)throw Error(`memo-dom: missing ESTree program during JSX normalization`);return t}function ou(e){let t=au(e);for(let[,n]of e.compPaths){let r=n.node,i=!1,a=[];C(r,{enter(e,t){if(e.type!==`JSXExpressionContainer`||t?.type!==`JSXElement`&&t?.type!==`JSXFragment`)return;let n=Kl(e,`expression`);n?.type===`ArrayExpression`&&Na(n)&&a.push(e)}});for(let t of a){let r=Kl(t,`expression`);At(e.astAnalysis,t,tu(e,r,n)),i=!0}a.length>0&&ma(e,t);let o=!0;for(;o;){o=!1;let a=n.node.body.body;for(let s of a)if(qr(s,{kind:`const`})){for(let a of s.declarations){if(!W(a.id)||a.init==null||!Na(a.init))continue;let c=a,l=Q(e,c,a.id.name);if(l===void 0||Xl(e.astAnalysis,l)!==c)continue;let u=[...l.references],d=a.init;if(Vr(d)||Br(d)){let t=ru(d,n);for(let i of u){Nt(e.astAnalysis,i,r)||Yl(n,`JSX collection '${a.id.name}' is used outside its component`);let o=e.astAnalysis.parentByNode.get(i)??null;if(o?.type===`MemberExpression`&&Kl(o,`object`)===i){Zl(e,o)||Yl(n,`JSX collection '${a.id.name}' is used outside a render position`),At(e.astAnalysis,o,iu(o,t,n));continue}if(Br(d)&&o?.type===`SpreadElement`&&e.astAnalysis.parentByNode.get(o)?.type===`ArrayExpression`){let t=e.astAnalysis.parentByNode.get(o),r=t.elements.indexOf(o);r<0&&Yl(n,`memo-dom: could not flatten JSX array spread`),t.elements.splice(r,1,...d.elements.map(e=>e===null?null:Jl(e)));continue}if(Br(d)&&Zl(e,i)){At(e.astAnalysis,i,tu(e,d,n));continue}Yl(n,Br(d)?`JSX collection '${a.id.name}' must be rendered directly or selected with a direct index access`:`JSX collection '${a.id.name}' is used outside a render position`)}}else for(let t of u)Nt(e.astAnalysis,t,r)&&(Zl(e,t)||Yl(n,`JSX value '${a.id.name}' is used outside a render position`),At(e.astAnalysis,t,Jl(d)));s.declarations.length===1?Mt(e.astAnalysis,s):Mt(e.astAnalysis,c),i=!0,o=!0,ma(e,t);break}if(o)break}}if(!i)continue;let s=[];C(r,{enter(e,t){if(e.type!==`JSXExpressionContainer`||t?.type!==`JSXElement`&&t?.type!==`JSXFragment`)return;let n=Kl(e,`expression`);(n?.type===`JSXElement`||n?.type===`JSXFragment`)&&s.push(e)}});for(let t of s)At(e.astAnalysis,t,Kl(t,`expression`));ma(e,t)}}function su(e){return e}function cu(e){return typeof e==`object`&&e&&`type`in e?e:null}function lu(e,t){return cu(su(e)[t])}function uu(e,t){let n=su(e)[t];return Array.isArray(n)?n.map(cu).filter(e=>e!==null):[]}function du(e){if(e?.type!==`Identifier`)return null;let t=su(e).name;return typeof t==`string`?t:null}function fu(e){return S(e)}function pu(e,t){throw e.buildCodeFrameError(t)}function mu(e){return Xr(e)&&e.argument!==null?e.argument:Yr(e)&&e.body.length===1?mu(e.body[0]):null}function hu(e){let t=mu(e);if(t!==null)return t;if(Zr(e)&&e.alternate!=null){let t=hu(e.consequent),n=hu(e.alternate);return t===null||n===null?null:I(fu(e.test),fu(t),fu(n))}if(Ci(e)){let t=e.cases.find(e=>e.test==null);if(t===void 0||t.consequent.length!==1)return null;let n=hu(t.consequent[0]);if(n===null)return null;for(let t=e.cases.length-1;t>=0;t--){let r=e.cases[t];if(r.test==null)continue;if(r.consequent.length!==1)return null;let i=hu(r.consequent[0]);if(i===null)return null;n=I(N(`===`,fu(e.discriminant),fu(r.test)),fu(i),n)}return n}return null}function gu(e,t){if(e.body.type!==`BlockStatement`)return{expression:fu(e.body),locals:new Map};let n=new Map,r=[];for(let i of e.body.body){if(qr(i,{kind:`const`})){for(let e of i.declarations)(!W(e.id)||e.init==null)&&t(`memo-dom: JSX render functions require identifier const declarations with expression initializers`),n.set(e.id.name,fu(e.init));continue}Fi(i)||Ti(i)||r.push(i)}if(r.length===1){let e=hu(r[0]);if(e!==null)return{expression:e,locals:n}}let i=r.at(-1),a=i===void 0?null:mu(i);if(a!==null){let e=fu(a);for(let n=r.length-2;n>=0;n--){let i=r[n];if(Zr(i)&&i.alternate==null){let t=hu(i.consequent);if(t!==null){e=I(fu(i.test),fu(t),e);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:e,locals:n}}return t(`memo-dom: JSX render function does not have supported exhaustive return control flow`)}function _u(e,t){return(e.type===`MemberExpression`||e.type===`OptionalMemberExpression`)&&t===`property`&&su(e).computed!==!0||(e.type===`ObjectProperty`||e.type===`Property`||e.type===`ObjectMethod`||e.type===`ClassMethod`)&&t===`key`&&su(e).computed!==!0||e.type===`VariableDeclarator`&&t===`id`||(e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`||e.type===`CatchClause`)&&(t===`params`||t===`param`||t===`id`)||e.type===`LabeledStatement`&&t===`label`}function vu(e,t,n=new Set){let r=fu(e),i=(e,n,a,o)=>{let s=du(e);if(s!==null&&!o.has(s)&&t.has(s)&&(n===null||!_u(n,a)))return fu(t.get(s));let c=o;if(e!==r&&(e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`)){let t=uu(e,`params`).flatMap(e=>St(e).map(e=>e.name));c=new Set([...o,...t])}for(let t of ht[e.type]??Object.keys(su(e))){let n=su(e)[t];if(Array.isArray(n))su(e)[t]=n.map(n=>{let r=cu(n);return r===null?n:i(r,e,t,c)});else{let r=cu(n);r!==null&&(su(e)[t]=i(r,e,t,c))}}return(e.type===`ObjectProperty`||e.type===`Property`)&&su(e).shorthand===!0&&du(lu(e,`key`))!==du(lu(e,`value`))&&(su(e).shorthand=!1),e};return i(r,null,``,n)}function yu(e,t,n){let r=e=>pu(n,e),i=e.node;(i.async||i.generator)&&r(`memo-dom: JSX render functions must be synchronous`);let a=uu(t,`arguments`);a.some(e=>e.type===`SpreadElement`)&&r(`memo-dom: JSX render function calls do not support spread arguments`),a.length>i.params.length&&r(`memo-dom: JSX render function received more arguments than parameters`);let o=new Map;for(let e=0;e<i.params.length;e++){let t=i.params[e],n=a[e],s=n===void 0?T(`undefined`):n;if(W(t)){o.set(t.name,fu(s));continue}if(mi(t)&&W(t.left)){o.set(t.left.name,I(N(`===`,fu(s),T(`undefined`)),fu(t.right),fu(s)));continue}r(`memo-dom: JSX render functions currently require identifier parameters with optional defaults`)}let s=gu(i,r);for(let[e,t]of s.locals)o.set(e,vu(t,o));let c=vu(s.expression,o);return Na(c)||r(`memo-dom: JSX render function expansion did not produce JSX`),c}function bu(e,t){let n=t.identifier;for(;n!==null&&n!==t.declarationNode;){if(n.type===`VariableDeclarator`)return n;n=e.parentByNode.get(n)??null}return null}function xu(e,t){let n=du(t);if(n===null)return null;let r=Q(e,t,n);if(r===void 0)return null;if(r.kind===`function`&&r.declarationNode.type===`FunctionDeclaration`&&Na(r.declarationNode))return{node:r.declarationNode,bindingNode:r.declarationNode};let i=bu(e.astAnalysis,r),a=i===null?null:lu(i,`init`);return a!==null&&(a.type===`FunctionExpression`||a.type===`ArrowFunctionExpression`)&&Na(lu(a,`body`))?{node:a,bindingNode:i}:null}function Su(e,t){let n=lu(t,`callee`);if(n===null)return null;let r=n.type===`FunctionExpression`||n.type===`ArrowFunctionExpression`?lu(n,`body`):null;return r!==null&&Na(r)?{node:n,bindingNode:null}:xu(e,n)}function Cu(e){let t=lu(e,`callee`);return t?.type===`MemberExpression`&&su(t).computed!==!0&&du(lu(t,`property`))===`map`}function wu(e,t){let n=e.parentByNode.get(t)??null;return n?.type===`CallExpression`&&(lu(n,`callee`)===t||Cu(n)&&uu(n,`arguments`)[0]===t)}function Tu(e,t){let n=e.node;return(n.async||n.generator)&&pu(t,`memo-dom: JSX render callbacks must be synchronous`),L(n.params.map(fu),fu(n.body))}function Eu(e,t){if(t.type===`FunctionDeclaration`){let n=e.parentByNode.get(t)??null;return n?.type===`ExportNamedDeclaration`?n:t}if(t.type!==`VariableDeclarator`)return t;let n=e.parentByNode.get(t)??null;if(n?.type!==`VariableDeclaration`||uu(n,`declarations`).length!==1)return t;let r=e.parentByNode.get(n)??null;return r?.type===`ExportNamedDeclaration`?r:n}function Du(e,t,n){let r=e.astAnalysis,i=r.parentByNode.get(t)??null,a=i===null?null:r.parentByNode.get(i)??null;if((ii(n)||ai(n))&&i?.type===`JSXExpressionContainer`&&(a?.type===`JSXElement`||a?.type===`JSXFragment`)){At(r,i,n);return}At(r,t,n)}function Ou(e){let t=e.astAnalysis?.rootScope.block;if(t===void 0||t.type!==`Program`)throw Error(`memo-dom: missing ESTree program during render expansion`);return t}function ku(e){let t=Ou(e),n=new Set,r=new Set;for(let[t,n]of e.jsxHelpers){let r=n.node;if(Q(e,r,t)?.references.some(t=>!wu(e.astAnalysis,t)))throw n.buildCodeFrameError(`memo-dom: JSX render functions may only be called in local render composition or passed directly to collection map()`)}for(let[,r]of e.compPaths){let i=r.node,a=[];C(i,{enter(t){if(t.type!==`CallExpression`||!Cu(t)||uu(t,`arguments`).length!==1)return;let n=uu(t,`arguments`)[0];if(n.type!==`Identifier`)return;let r=xu(e,n);r!==null&&a.push({identifier:n,resolved:r})}});for(let{identifier:t,resolved:i}of a)At(e.astAnalysis,t,Tu(i,r)),i.bindingNode!==null&&n.add(i.bindingNode);a.length>0&&ma(e,t);let o=!0;for(;o;){o=!1;let a=[];C(i,{enter(e){e.type===`CallExpression`&&a.push(e)}});for(let t of a.reverse()){let i=Su(e,t);i!==null&&(Du(e,t,yu(i,t,r)),i.bindingNode!==null&&n.add(i.bindingNode),o=!0)}o&&ma(e,t)}}for(let[t,n]of e.jsxHelpers){let i=n.node,a=Q(e,i,t),o=a===void 0?i:a.declarationNode.type===`FunctionDeclaration`?a.declarationNode:bu(e.astAnalysis,a)??i,s=Eu(e.astAnalysis,o);Mt(e.astAnalysis,s),r.add(o)}for(let t of n)r.has(t)||Mt(e.astAnalysis,Eu(e.astAnalysis,t));(e.jsxHelpers.size>0||n.size>0)&&ma(e,t)}function Au(e){let t=So(e);return W(t)||K(t)||zr(t)||Do(t)}function ju(e,t,n){let r=t;for(;r!==null&&e.astAnalysis?.parentByNode.get(r)!==n;)r=e.astAnalysis?.parentByNode.get(r)??null;return r}function Mu(e){for(let[,t]of e.compPaths){let n=[],r=t.node.body;if(C(r,{enter(t){if(t!==r&&(t.type===`FunctionDeclaration`||t.type===`FunctionExpression`||t.type===`ArrowFunctionExpression`))return!1;if(t.type!==`CallExpression`&&t.type!==`OptionalCallExpression`)return;let i=t,a=i.callee;if(Lo(i)===null||!K(a)&&!zr(a)||!q(a.object)||Au(a.object))return;let o=ju(e,t,r);o!==null&&n.push({call:i,source:S(a.object,!0),statement:o})}}),n.length===0)continue;let i=t.node.body.body,a=new Map(i.map((e,t)=>[e,t]));n.sort((e,t)=>(a.get(e.statement)??0)-(a.get(t.statement)??0));let o=[];for(let t of n){let n=Y(e,`listView`);o.push(V(S(n),t.source));let r=t.call.callee;!K(r)&&!zr(r)||!q(r.object)||(r.object=S(n))}let s=i.indexOf(n[0].statement);if(s<0)continue;i.splice(s,0,B(`const`,o));let c=e.astAnalysis?.rootScope.block;c!==void 0&&ma(e,c)}}const Nu=new Set([`==`,`===`]),Pu=new Set([`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`,`ObjectMethod`,`ClassMethod`,`ClassPrivateMethod`]),Fu=new Set([`loc`,`range`,`start`,`end`,`extra`,`leadingComments`,`trailingComments`,`innerComments`]);function Iu(e){return e}function Lu(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function Ru(e){return typeof e==`object`&&!!e}function zu(e,t){if(Object.is(e,t))return!0;if(e instanceof RegExp&&t instanceof RegExp)return e.source===t.source&&e.flags===t.flags;if(Array.isArray(e)&&Array.isArray(t)){let n=e,r=t;return n.length===r.length&&n.every((e,t)=>zu(e,r[t]))}if(!Ru(e)||!Ru(t)||(Lu(e)||Lu(t))&&(!Lu(e)||!Lu(t)||e.type!==t.type))return!1;let n=e,r=t,i=new Set([...Object.keys(n),...Object.keys(r)]);for(let e of i)if(!Fu.has(e)&&!zu(n[e],r[e]))return!1;return!0}function Bu(e,t){C(e,{enter(e,n,r){return t(e,n,r),!Pu.has(e.type)&&void 0}})}function Vu(e,t,n){if(t?.type!==`BinaryExpression`)return!1;let r=Iu(t),i=r.operator;if(typeof i!=`string`||!Nu.has(i))return!1;let a=r.left,o=r.right,s=a===e?o:a;return Lu(s)&&zu(s,n)}function Hu(e,t){if(e===null)return!1;let n=Iu(e);return!(e.type===`MemberExpression`&&t===`property`&&n.computed===!1||(e.type===`Property`||e.type===`ObjectProperty`)&&t===`key`&&n.computed===!1||(e.type===`MethodDefinition`||e.type.endsWith(`Method`))&&t===`key`&&n.computed===!1||e.type===`VariableDeclarator`&&t===`id`||(e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`)&&(t===`id`||t===`params`)||e.type.startsWith(`Import`)||e.type===`ExportSpecifier`&&t===`exported`||e.type===`LabeledStatement`&&t===`label`||(e.type===`BreakStatement`||e.type===`ContinueStatement`)&&t===`label`)}function Uu(e,t){if(e.jsx===null||e.keyExpr===null||!e.sourceLocal||!Ne(e.sourceExpr)||!t.has(e.sourceExpr.name))return[];let n=e.sourceExpr.name,r=new Set;if(Bu(e.jsx,(i,a)=>{Ne(i)&&t.has(i.name)&&i.name!==n&&Vu(i,a,e.keyExpr)&&r.add(i.name)}),r.size===0)return[];let i=new Set;return Bu(e.jsx,(t,n,a)=>{Ne(t)&&r.has(t.name)&&Hu(n,a)&&!Vu(t,n,e.keyExpr)&&i.add(t.name)}),[...r].filter(e=>!i.has(e)).sort()}function $(e){return e}function Wu(e){return typeof e==`object`&&e&&typeof e.type==`string`?e:null}function Gu(e){return Array.isArray(e)?e.flatMap(e=>{let t=Wu(e);return t===null?[]:[t]}):[]}function Ku(e){let t=Wu(e);if(t?.type!==`Identifier`)return null;let n=$(t).name;return typeof n==`string`?n:null}function qu(e){let t=Wu(e);if(t===null||t.type!==`Literal`&&t.type!==`StringLiteral`)return null;let n=$(t).value;return typeof n==`string`?n:null}function Ju(e){return e.type===`ExportNamedDeclaration`?Wu($(e).declaration):e.type.endsWith(`Declaration`)?e:null}function Yu(e){let t=new Map;for(let n of e.body){let e=Ju(n);if(e?.type!==`TSTypeAliasDeclaration`)continue;let r=Ku($(e).id),i=Wu($(e).typeAnnotation);r!==null&&i!==null&&t.set(r,i)}return t}function Xu(e){let t=Yu(e);for(let n of e.body){let e=Ju(n);if(e?.type!==`TSInterfaceDeclaration`)continue;let r=Ku($(e).id),i=Wu($(e).body);r!==null&&i!==null&&t.set(r,i)}return t}function Zu(e,t,n=new Set){let r=$(e);if(e.type===`TSLiteralType`){let e=qu(r.literal);return e===null?[]:[e]}if(e.type===`TSUnionType`){let e=Gu(r.types).map(e=>Zu(e,t,n));return e.some(e=>e.length===0)?[]:e.flat()}if(e.type===`TSIntersectionType`)return Gu(r.types).flatMap(e=>Zu(e,t,n));if(e.type===`TSParenthesizedType`){let e=Wu(r.typeAnnotation);return e===null?[]:Zu(e,t,n)}if(e.type===`TSTypeLiteral`)return Gu(r.members).flatMap(e=>{if(e.type!==`TSPropertySignature`&&e.type!==`TSIndexSignature`)return[];let r=Wu($(e).typeAnnotation),i=r?.type===`TSTypeAnnotation`?Wu($(r).typeAnnotation):null;return i===null?[]:Zu(i,t,n)});if(e.type===`TSMappedType`){let e=Wu(r.typeAnnotation);return e===null?[]:Zu(e,t,n)}if(e.type===`TSTypeReference`){let e=Ku(r.typeName);if(e===null)return[];let i=Wu(r.typeArguments);if((e===`Record`||e===`Readonly`||e===`Partial`)&&i?.type===`TSTypeParameterInstantiation`){let r=Gu($(i).params),a=e===`Record`?r[1]:r[0];return a===void 0?[]:Zu(a,t,n)}if(n.has(e))return[];let a=t.get(e);if(a===void 0)return[];let o=new Set(n);return o.add(e),Zu(a,t,o)}return[]}function Qu(e){let t=Wu(e);return t?.type===`TSTypeAnnotation`?Wu($(t).typeAnnotation):null}function $u(e){return e.type===`AssignmentPattern`?Wu($(e).left)??e:e.type===`TSParameterProperty`?Wu($(e).parameter)??e:e}function ed(e,t,n,r=new Set){if(e.type===`TSTypeAnnotation`){let i=Wu($(e).typeAnnotation);return i===null?null:ed(i,t,n,r)}if(e.type===`TSParenthesizedType`){let i=Wu($(e).typeAnnotation);return i===null?null:ed(i,t,n,r)}if(e.type===`TSTypeReference`){let i=Ku($(e).typeName);if(i===null||r.has(i))return null;let a=n.get(i);if(a===void 0)return null;let o=new Set(r);return o.add(i),ed(a,t,n,o)}if(e.type===`TSUnionType`){let i=Gu($(e).types).map(e=>ed(e,t,n,r));if(i.some(e=>e===null))return null;let a=i.filter(e=>e!==null);return a.length===1?a[0]:{type:`TSUnionType`,types:a}}if(e.type===`TSIntersectionType`){let i=Gu($(e).types).flatMap(e=>{let i=ed(e,t,n,r);return i===null?[]:[i]});return i.length===0?null:i.length===1?i[0]:{type:`TSUnionType`,types:i}}let i=e.type===`TSTypeLiteral`?Gu($(e).members):e.type===`TSInterfaceBody`?Gu($(e).body):[];for(let e of i)if(e.type===`TSPropertySignature`&&(Ku($(e).key)??qu($(e).key))===t)return Qu($(e).typeAnnotation);return null}function td(e){let t=new Map;if(e.type!==`Program`||!Array.isArray($(e).body))return t;let n=e,r=Xu(n),i=(e,n)=>{let a=$u(e),o=Qu($(a).typeAnnotation)??n;if(a.type===`Identifier`){if(o===null)return;let e=[...new Set(Zu(o,r))],n=nd(a);e.length>0&&n!==null&&t.set(n,e);return}if(a.type===`ObjectPattern`&&o!==null)for(let e of Gu($(a).properties)){if(e.type!==`Property`&&e.type!==`ObjectProperty`)continue;let t=Ku($(e).key)??qu($(e).key),n=Wu($(e).value);t!==null&&n!==null&&i(n,ed(o,t,r))}};return C(n,{enter(e){if(e.type===`VariableDeclarator`){let t=Wu($(e).id);t!==null&&i(t,null);return}if(e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`)for(let t of Gu($(e).params))i(t,null)}}),t}function nd(e){let t=Ku(e);if(t===null)return null;let n=$(e),r=typeof n.start==`number`?n.start:e.range?.[0],i=typeof n.end==`number`?n.end:e.range?.[1];if(r!==void 0&&i!==void 0)return`${t}:${r}:${i}`;let a=e.loc;return a==null?null:`${t}:${a.start.line}:${a.start.column}:${a.end.line}:${a.end.column}`}function rd(e){let t=Yu(e),n=new Map;for(let r of e.body){let e=Ju(r);if(e?.type===`VariableDeclaration`)for(let r of Gu($(e).declarations)){let e=$(r),i=Ku(e.id),a=Wu(e.id),o=a===null?null:Qu($(a).typeAnnotation);if(i===null||o===null)continue;let s=[...new Set(Zu(o,t))];s.length>0&&n.set(i,s)}}return n}function id(e){let t=Yu(e),n=new Map,r=(e,r)=>{let i=Qu(r);if(i===null)return;let a=[...new Set(Zu(i,t))];a.length>0&&n.set(e,a)};for(let t of e.body){let e=Ju(t);if(e?.type===`FunctionDeclaration`){let t=$(e),n=Ku(t.id);n!==null&&r(n,t.returnType);continue}if(e?.type===`VariableDeclaration`)for(let t of Gu($(e).declarations)){let e=$(t),n=Ku(e.id),i=Wu(e.init);n!==null&&(i?.type===`ArrowFunctionExpression`||i?.type===`FunctionExpression`)&&r(n,$(i).returnType)}}return n}function ad(e){return e}function od(e){return typeof e==`object`&&e&&`type`in e?e:null}function sd(e,t){return od(ad(e)[t])}function cd(e,t){let n=ad(e)[t];return Array.isArray(n)?n.map(od).filter(e=>e!==null):[]}function ld(e){if(e?.type!==`Identifier`&&e?.type!==`JSXIdentifier`)return null;let t=ad(e).name;return typeof t==`string`?t:null}function ud(e){if(e?.type!==`StringLiteral`&&e?.type!==`Literal`)return null;let t=ad(e).value;return typeof t==`string`?t:null}function dd(e){return S(e)}function fd(e,t){throw e.buildCodeFrameError(t)}function pd(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 md(e,t){if(e.linkedDynamicComponentCandidates.size===0)return;let n=t.node,r=new Set(Tt(n).rootScope.bindings.keys()),i=new Map([...e.importedComponents].map(([e,t])=>[t.key,e])),a=[];for(let[t,n]of e.linkedDynamicComponentCandidates){let o=[];for(let t of n){let n=i.get(t.key);if(n===void 0){let o=`MDDynamic_${t.imported.replace(/[^A-Za-z0-9_$]/g,`_`)}`;n=o;let s=1;for(;r.has(n);)n=`${o}${s++}`;r.add(n),i.set(t.key,n);let c={type:`component`,key:t.key,props:[...t.props],objectProps:t.objectProps,acceptsUnknownProps:t.acceptsUnknownProps,hasWholeDefault:t.hasWholeDefault,listLightweight:t.listLightweight,delegatedEvents:t.delegatedEvents,renderProps:[...t.renderProps??[]],renderCallbacks:[...t.renderCallbacks??[]],refProps:[...t.refProps??[]],subtreeReads:[...t.subtreeReads??[]]};e.importedComponents.set(n,c),e.componentProps.set(n,pd(c)),a.push(sr(t.imported==="default"?[lr(T(n))]:[cr(T(n),dt(t.imported)?T(t.imported):E(t.imported))],E(t.source)))}o.push(n)}let s=[...new Set(o)];e.state.has(t)?e.stateComponentCandidates.set(t,s):e.functionComponentCandidates.set(t,s)}e.header.push(...a)}function hd(e){let t=e;for(;t.type===`TSAsExpression`||t.type===`TSTypeAssertion`||t.type===`TSNonNullExpression`;){let e=sd(t,`expression`);if(e===null)break;t=e}return t}function gd(e){return J(e)?T(e.name):A(gd(e.object),T(e.property.name))}function _d(e,t){let n=t.identifier;for(;n!==null&&n!==t.declarationNode;){if(n.type===`VariableDeclarator`)return n;n=e.parentByNode.get(n)??null}return null}function vd(e,t){let n=_d(e.astAnalysis,t);return n===null?null:sd(n,`init`)}function yd(e,t,n){let r=Ca(n);if(r===null)return null;let[i,...a]=r.split(`.`);if(i===void 0||a.length===0)return null;let o=Q(e,t,i);if(o===void 0)return null;let s=vd(e,o);if(s===null)return null;for(let e of a){if(s=hd(s),s.type!==`ObjectExpression`)return null;let t=cd(s,`properties`).find(t=>t.type!==`ObjectProperty`&&t.type!==`Property`||ad(t).computed===!0?!1:(ld(sd(t,`key`))??ud(sd(t,`key`)))===e);if(t===void 0||(s=sd(t,`value`),s===null))return null}return s}function bd(e){let t=sd(e,`body`);if(t===null)return[];if(t.type!==`BlockStatement`)return[t];let n=[];return C(t,{enter(e){if(e!==t&&(e.type===`FunctionDeclaration`||e.type===`FunctionExpression`||e.type===`ArrowFunctionExpression`))return!1;if(e.type!==`ReturnStatement`)return;let r=sd(e,`argument`);return r!==null&&n.push(r),!1}}),n}function xd(e,t,n){let r=Q(e,t,n);if(r===void 0)return[];let i=r.declarationNode.type===`FunctionDeclaration`?r.declarationNode:vd(e,r);return i!==null&&(i.type===`FunctionDeclaration`||i.type===`FunctionExpression`||i.type===`ArrowFunctionExpression`)?bd(i):[]}function Sd(e,t,n,r=new Set){let i=hd(t);if(r.has(i))return;r.add(i);let a=ld(i);if(a!==null){if(e.comps.has(a)||e.importedComponents.has(a)){n.add(a);return}for(let t of e.stateComponentCandidates.get(a)??e.functionComponentCandidates.get(a)??[])n.add(t);return}if(i.type===`ConditionalExpression`){let t=sd(i,`consequent`),a=sd(i,`alternate`);t!==null&&Sd(e,t,n,r),a!==null&&Sd(e,a,n,r);return}if(i.type===`LogicalExpression`){let t=sd(i,`right`);t!==null&&Sd(e,t,n,r);return}if(i.type===`ObjectExpression`){for(let t of cd(i,`properties`)){let i=sd(t,`value`);i!==null&&Sd(e,i,n,r)}return}if(i.type===`ArrayExpression`){for(let t of cd(i,`elements`))t.type!==`SpreadElement`&&Sd(e,t,n,r);return}if(i.type===`CallExpression`){let t=ld(sd(i,`callee`));if(t!==null)for(let r of e.functionComponentCandidates.get(t)??[])n.add(r);return}if(i.type===`MemberExpression`){let t=Ea(i);if(t!==null)for(let r of e.stateComponentCandidates.get(t)??[])n.add(r)}}function Cd(e,t){for(let n of t.node.body){let t=_i(n)?n.declaration:n;if(qr(t))for(let n of t.declarations){if(!W(n.id)||n.init==null)continue;let t=new Set;Sd(e,n.init,t),t.size>0&&e.state.has(n.id.name)&&e.stateComponentCandidates.set(n.id.name,[...t])}}let n=!0;for(;n;){n=!1;for(let[t,r]of e.helpers){let i=new Set(e.functionComponentCandidates.get(t)??[]);for(let t of bd(r.node))Sd(e,t,i);i.size>0&&i.size!==(e.functionComponentCandidates.get(t)?.length??0)&&(e.functionComponentCandidates.set(t,[...i]),n=!0)}}}function wd(e,t,n,r,i,a=new Set){let o=hd(n);if(a.has(o))return;if(a.add(o),o.type===`ConditionalExpression`){let n=sd(o,`consequent`),s=sd(o,`alternate`);wd(e,t,n,r,i,a),wd(e,t,s,r,i,a);return}let s=ud(o);if(s!==null){/^[A-Za-z][A-Za-z0-9:_-]*$/.test(s)||i(`memo-dom: '${s}' is not a valid dynamic intrinsic tag name`),r.push({compare:dd(n),tag:fr(s)});return}let c=ld(o);if(c!==null){if(e.comps.has(c)||e.importedComponents.has(c)){r.push({compare:dd(n),tag:fr(c)});return}for(let n of e.stateTagCandidates.get(c)??[])wd(e,t,E(n),r,i,a);let o=Q(e,t,c),s=o===void 0?null:nd(o.identifier);for(let n of o===void 0||s===null?[]:e.bindingTagCandidates.get(s)??[])wd(e,t,E(n),r,i,a);let l=o===void 0?null:vd(e,o);l!==null&&wd(e,t,l,r,i,a);return}if(o.type===`CallExpression`){let n=ld(sd(o,`callee`));if(n===null)return;for(let o of e.functionTagCandidates.get(n)??[])wd(e,t,E(o),r,i,a);for(let o of xd(e,t,n))wd(e,t,o,r,i,a);for(let o of e.functionComponentCandidates.get(n)??[])wd(e,t,T(o),r,i,a);return}if(o.type!==`MemberExpression`)return;let l=o,u=yd(e,t,l);if(u!==null){wd(e,t,u,r,i,a);return}let d=Ea(l);if(d===null)return;let f=Q(e,t,d),p=f===void 0?null:vd(e,f);if(p!==null){let n=new Set;Sd(e,p,n);for(let o of n)wd(e,t,T(o),r,i,a)}for(let n of e.stateTagCandidates.get(d)??[])wd(e,t,E(n),r,i,a);for(let n of e.stateComponentCandidates.get(d)??[])wd(e,t,T(n),r,i,a)}function Td(e){let t=ud(e.compare);if(t!==null)return`string:${t}`;let n=ld(e.compare);return n===null?JSON.stringify(e.compare):`component:${n}`}function Ed(e,t){let n=t;for(;n!==null;){if(n.type===`FunctionDeclaration`||n.type===`FunctionExpression`||n.type===`ArrowFunctionExpression`||n.type===`Program`)return n;n=e.astAnalysis?.parentByNode.get(n)??null}return e.astAnalysis.rootScope.block}function Dd(e,t,n){if(W(n)){let r=Q(e,t,n.name);if(r===void 0)return[];let i=vd(e,r);return[...i===null?[]:[i],...r.constantViolations.flatMap(e=>{if(e.type===`AssignmentExpression`&&ad(e).operator===`=`){let t=sd(e,`right`);return t===null?[]:[t]}return[]})]}if(!K(n))return[];let r=yd(e,t,n),i=Ca(n),a=[];return i!==null&&C(Ed(e,t),{enter(e){if(e.type!==`AssignmentExpression`||ad(e).operator!==`=`)return;let t=sd(e,`left`),n=sd(e,`right`);t?.type===`MemberExpression`&&Ca(t)===i&&n!==null&&a.push(n)}}),[...r===null?[]:[r],...a]}function Od(e,t){let n=dd(e);return n.openingElement.name=dd(t),n.closingElement!=null&&(n.closingElement.name=dd(t)),n}function kd(e,t,n){let r=O();for(let i=n.length-1;i>=0;i--){let a=n[i];r=I(N(`===`,dd(e),dd(a.compare)),Od(t,a.tag),r)}return r}function Ad(e){return W(e)?e.name:K(e)?Ca(e)??`<member expression>`:`<expression>`}function jd(e){let t=new Map,n=e.astAnalysis.rootScope.block;for(let[,r]of e.compPaths){let i=r.node,a=[];C(i,{enter(e){e.type===`JSXElement`&&a.push(e)}});for(let n of a.reverse()){let i=n,a=i.openingElement.name;if(di(a)&&fd(r,`memo-dom: namespaced JSX tags are not supported`),J(a)&&(!/^[A-Z]/.test(a.name)||e.comps.has(a.name)||e.importedComponents.has(a.name)))continue;let o=gd(a),s=[];for(let t of Dd(e,n,o))wd(e,n,t,s,e=>fd(r,e));let c=[...new Map(s.map(e=>[Td(e),e])).values()];c.length===0&&fd(r,`memo-dom: dynamic JSX tag '${Ad(o)}' has no finite string or linked-component candidates`);for(let n of c){let a=e.componentProps.get(n.tag.name);if(a===void 0||a.renderProps.length===0)continue;let o=t.get(n.tag.name);o===void 0&&(o=new Map,t.set(n.tag.name,o));for(let e of i.openingElement.attributes){if(si(e)||!J(e.name)||!a.renderProps.includes(e.name.name))continue;let t=ka(e.value),n=o.get(e.name.name)??{scalar:!1,jsx:!1,at:r};t!==null&&Na(t)?n.jsx=!0:n.scalar=!0,o.set(e.name.name,n)}}let l=c.length===1?Od(i,c[0].tag):yr(_r(),vr(),[mr(kd(o,i,c))]);At(e.astAnalysis,n,l)}a.length>0&&ma(e,n)}for(let[n,r]of t){let t=e.componentProps.get(n);for(let[e,n]of r)n.scalar&&n.jsx&&fd(n.at,`memo-dom: dynamic component prop '${e}' is used as both scalar data and JSX content`),n.scalar&&(t.renderProps=t.renderProps.filter(t=>t!==e))}}function Md(e){return e}function Nd(e){return typeof e==`object`&&e&&typeof e.type==`string`?e:null}function Pd(e){let t=Nd(e);if(t?.type!==`JSXIdentifier`)return null;let n=Md(t).name;return typeof n==`string`?n:null}function Fd(e){let t=Nd(e);if(t?.type===`JSXIdentifier`)return Pd(t);if(t?.type!==`JSXNamespacedName`)return null;let n=Pd(Md(t).namespace),r=Pd(Md(t).name);return n===null||r===null?null:`${n}:${r}`}function Id(e,t,n=new Set){let r=e.importedComponents.get(t);if(r!==void 0)return new Set(r.subtreeReads??[]);if(n.has(t))return new Set;n.add(t);let i=new Set(e.compReads.get(t)??[]);for(let n of e.effects.get(t)??[]){for(let e of n.moduleReads)i.add(e);for(let e of n.conditionModuleReads)i.add(e)}let a=e.compPaths.get(t);return a!==void 0&&C(a.node,{enter(t){if(t.type!==`JSXElement`)return;let r=Nd(Md(t).openingElement),a=r===null?null:Pd(Md(r).name);if(!(a===null||!/^[A-Z]/.test(a)))for(let t of Id(e,a,n))i.add(t)}}),n.delete(t),i}function Ld(e){for(let[t,n]of e.compPaths){let r=e.compReads.get(t);r!==void 0&&C(n.node,{enter(t,n){if(t.type!==`JSXAttribute`||n?.type!==`JSXOpeningElement`)return;let i=Pd(Md(n).name);if(i===null)return;let a=Fd(Md(t).name);if(a===null||e.componentProps.get(i)?.renderCallbacks.includes(a)!==!0)return;let o=Nd(Md(t).value);if(o?.type!==`JSXExpressionContainer`)return;let s=Nd(Md(o).expression);s!==null&&s.type!==`JSXEmptyExpression`&&C(s,{enter(t){if(t.type!==`JSXOpeningElement`)return;let n=Pd(Md(t).name);if(n!==null&&/^[A-Z]/.test(n))for(let t of Id(e,n))r.add(t)}})}})}}function Rd(e){for(let[t,n]of e.compPaths){let r=e.componentProps.get(t);C(n.node,{enter(n){if(!it(n)||!mt(n.name)||n.name.name!==`ref`||!at(n.value))return;let i=n.value.expression;if(i.type!==`JSXEmptyExpression`)for(let n of zd(e,t,i))r.refProps.includes(n)||r.refProps.push(n)}})}}function zd(e,t,n){let r=Is(e,t,n);if(r!==null)return[r];if(!Ve(n))return[];let i=[];for(let r of n.elements)r!==null&&r.type!==`SpreadElement`&&i.push(...zd(e,t,r));return i}function Bd(e){return e}function Vd(e){return typeof e==`object`&&e&&typeof e.type==`string`?e:null}function Hd(e){let t=Vd(e);if(t?.type!==`JSXIdentifier`)return null;let n=Bd(t).name;return typeof n==`string`?n:null}function Ud(e){let t=new Set;return C(e,{enter(e){if(e.type!==`JSXOpeningElement`)return;let n=Bd(e),r=Hd(n.name);if(r===null||!/^[a-z]/.test(r))return;let i=Array.isArray(n.attributes)?n.attributes:[];for(let e of i){let n=Vd(e);if(n?.type!==`JSXAttribute`)continue;let r=Hd(Bd(n).name);r!==null&&/^on[A-Z]/.test(r)&&t.add(r)}}}),[...t].sort()}function Wd(e,t,n){let r=e.componentProps.get(t);if(r?.mode===`object`){if(!r.acceptsUnknown){for(let e of n)if(!r.names.includes(e.name))throw Error(`memo-dom: unknown prop '${e.name}' on <${t}> - declared props: ${r.names.length>0?r.names.join(`, `):`(none)`}`)}return n.length===0&&r.hasWholeDefault?[T(`undefined`)]:[Zn(n.map(e=>M(T(e.name),e.value,!1,W(e.value)&&e.value.name===e.name)))]}let i=r?.names;if(i===void 0)return n.map(e=>e.value);let a=new Map(n.map(e=>[e.name,e.value]));for(let e of a.keys())if(!i.includes(e))throw Error(`memo-dom: unknown prop '${e}' on <${t}> - declared props: ${i.length>0?i.join(`, `):`(none)`}`);return i.map(e=>a.get(e)??T(`undefined`))}function Gd(e,t,n){let r=e.componentProps.get(t);return r?.mode===`object`?[S(n)]:(r?.names??[]).map(e=>A(S(n),dt(e)?T(e):E(e),!dt(e)))}function Kd(e,t,n,r,i){let a=Y(e,`${t}Props`);return R([B(`const`,[V(S(a),S(i))]),z(k(X(e,`setProps`),[N(`+`,S(n),E(r)),j(Gd(e,t,a))]))])}const qd=`memo-dom: [MMD-S004] Colorless server function and $fetch sources cannot be destructured. Destructuring copies values before the source settles. Bind the source and read properties at the use site, or destructure a settled plain value.`;function Jd(e){return e}function Yd(e,t){let n=Jd(e)[t];return typeof n==`object`&&n&&`type`in n?n:null}function Xd(e){return W(e.imported)?e.imported.name:e.imported.value}function Zd(e,t){let n=new Map(e.transparentAsyncSources.map(e=>[e.module,e]));for(let r of t.node.body){if(!bi(r))continue;let t=n.get(r.source.value);if(t!==void 0)for(let n of r.specifiers){if(!xi(n))continue;let r=Xd(n);r===t.source&&(e.transparentSourceFactories.add(n.local.name),e.transparentProviderFactories.add(n.local.name),e.importedFunctions.set(n.local.name,{reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!1})),(r===t.track||r===t.operations)&&(e.transparentSourcePassthroughs.add(n.local.name),r===t.track&&e.transparentTrackFactories.add(n.local.name),e.importedFunctions.set(n.local.name,{reads:new Set,writes:new Set,boundedWrites:new Set,parameterWrites:[],unbounded:!1})),r===t.group&&e.transparentGroups.add(n.local.name),r===t.pending&&e.transparentPendingPolicies.add(n.local.name),r===t.error&&e.transparentErrorPolicies.add(n.local.name)}}}function Qd(e){return e?.type===`ObjectPattern`||e?.type===`ArrayPattern`}function $d(e,t){ma(e,t.node);let n=new Set,r=t=>{if(t===null)return!1;let r=_a(t);if(r.type===`Identifier`){let t=r,i=Q(e,t,t.name);return i!==void 0&&(n.has(i)||i.kind===`import`&&e.transparentModuleSources.has(t.name))}return r.type===`CallExpression`&&qf(e,r,r,e.transparentSourceFactories)},i=!0;for(;i;)i=!1,C(t.node,{enter(t){if(t.type!==`VariableDeclarator`)return;let a=Yd(t,`id`),o=Yd(t,`init`);if(a?.type!==`Identifier`||!r(o))return;let s=a,c=Q(e,s,s.name);c!==void 0&&!n.has(c)&&(n.add(c),i=!0)}});C(t.node,{enter(e){if(e.type===`VariableDeclarator`){let n=Yd(e,`id`);if(Qd(n)&&r(Yd(e,`init`)))throw t.buildCodeFrameError(qd,n);return}if(e.type===`AssignmentExpression`){let n=Yd(e,`left`);if(Qd(n)&&r(Yd(e,`right`)))throw t.buildCodeFrameError(qd,n);return}if(e.type!==`AssignmentPattern`)return;let n=Yd(e,`left`);if(Qd(n)&&r(Yd(e,`right`)))throw t.buildCodeFrameError(qd,n)}})}function ef(e){return J(e.openingElement.name)?e.openingElement.name.name:null}function tf(e,t){return e.children.filter(e=>{if(li(e)){if(e.value.trim()!==``)throw t.buildCodeFrameError(`memo-dom: Group requires exactly three direct children: Pending, Error, and one content child`,e);return!1}return ci(e)&&ui(e.expression)?!1:ii(e)||ai(e)||ci(e)})}function nf(e,t,n,r,i,a,o){let s=ef(t);if(s===null||!n.has(s))throw o.buildCodeFrameError(`memo-dom: Group child must be <${r} component={...} />`,t);let c=t.openingElement.attributes;if(c.length!==1||!oi(c[0]))throw o.buildCodeFrameError(`memo-dom: <${r}> requires exactly one component prop`,t.openingElement);let l=c[0],u=J(l.name)?l.name.name:null,d=l.value;if(u!==`component`||!ci(d))throw o.buildCodeFrameError(`memo-dom: <${r}> component must be a component identifier or inline render callback`,l);let f=d.expression;if(W(f))return f.name;if(!Gr(f)&&!Wr(f))throw o.buildCodeFrameError(`memo-dom: <${r}> component must be a component identifier or inline render callback`,f);if(f.async||f.generator)throw o.buildCodeFrameError(`memo-dom: <${r}> render callbacks must be synchronous`,f);if(f.params.length>1)throw o.buildCodeFrameError(`memo-dom: <${r}> render callbacks accept at most one props parameter`,f);let p=f.params[0];if(i===`pending`&&p!==void 0)throw o.buildCodeFrameError(`memo-dom: <Pending> render callbacks do not receive props`,p);if(i===`error`&&p!==void 0&&!fi(p))throw o.buildCodeFrameError(`memo-dom: <Error> render callbacks receive one destructured { error, retry } props object`,p);let m=jf(e,t,f,new Set),h=[];if(i===`error`){let t=t=>{if(fi(p)){for(let e of p.properties)if(Hr(e)&&!e.computed&&W(e.key,{name:t})&&W(e.value))return S(e.value)}return Y(e,t===`error`?`groupError`:`groupRetry`)},n=t(`error`),r=t(`retry`);h.push({prop:`error`,local:n}),h.push({prop:`retry`,local:r})}for(let e of m)h.push({prop:e.prop,local:T(e.binding.name)});let g=ca(e,i===`pending`?`GroupPending`:`GroupError`),_=[];return Yr(f.body)?_.push(...f.body.body.map(e=>S(e,!0))):_.push(ir(S(f.body,!0))),a.push(rr(S(g),h.length===0?[]:[Mf(h)],R(_))),{component:g.name,props:m.map(e=>({name:e.prop,value:T(e.binding.name)}))}}function rf(e,t){let n=e.openingElement.attributes.find(e=>oi(e)&&J(e.name,{name:`suspend`}));if(!oi(n))return null;if(n.value!==null)throw t.buildCodeFrameError(`memo-dom: suspend is a shorthand compiler directive; write 'suspend' without a value`,n);return n}function af(e,t){let n=e.openingElement.attributes.indexOf(t);n!==-1&&e.openingElement.attributes.splice(n,1)}function of(e){let t=Jd(e).__memoDomTsrxTry;if(typeof t!=`object`||!t)return null;let n=t,r=n.pending,i=n.handler;if(r!==null&&!Mr(r)||i!==null&&typeof i!=`object`)return null;if(i===null)return{pending:r,handler:null};let a=i;return Mr(a.output)?{pending:r,handler:{param:Mr(a.param)?a.param:null,resetParam:Mr(a.resetParam)?a.resetParam:null,output:a.output}}:null}function sf(e,t){let n=t.name,r=Q(e,t,n);if(r===void 0||!r.references.includes(t))return null;if(e.transparentModuleSources.has(n))return n;let i=e.astAnalysis?.parentByNode.get(r.identifier)??null;if(i?.type!==`VariableDeclarator`)return null;let a=Yd(i,`init`);return a===null||!Lr(a)||!qf(e,t,a,e.transparentSourceFactories)?null:n}function cf(e,t){let n=new Map;for(let r of t.openingElement.attributes){if(!oi(r)||!J(r.name)||!ci(r.value)||!W(r.value.expression))continue;let t=sf(e,r.value.expression);t!==null&&n.set(r.name.name,t)}return[...n].map(([e,t])=>({prop:e,source:t}))}function lf(e,t){let n=e.openingElement.attributes.find(e=>oi(e)&&J(e.name,{name:`data`}));if(n!==void 0)throw t.buildCodeFrameError(`memo-dom: Group infers colorless sources from its content; remove the data prop`,n)}function uf(e,t,n,r){lf(t,r);let i=new Set,a=e.astAnalysis?.parentByNode.get(t)??null;for(;a!==null&&a.type!==`FunctionDeclaration`;)a=e.astAnalysis?.parentByNode.get(a)??null;if(a!==null){let t=a;if(t.id!==null){let n=e.linkedComponentPropSources.get(t.id.name),r=t.params[0],o=new Set;for(let[e,t]of n??[])t.transparent&&o.add(e);let s=a;for(;e.astAnalysis?.parentByNode.get(s)!==null&&e.astAnalysis?.parentByNode.get(s)!==void 0;)s=e.astAnalysis.parentByNode.get(s);if(C(s,{enter(n){if(n.type!==`JSXElement`)return;let r=n;if(ef(r)===t.id.name)for(let t of r.openingElement.attributes)!oi(t)||!J(t.name)||!ci(t.value)||!W(t.value.expression)||sf(e,t.value.expression)!==null&&o.add(t.name.name)}}),fi(r))for(let e of o)for(let t of r.properties)Hr(t)&&!t.computed&&W(t.key,{name:e})&&W(t.value)&&i.add(t.value.name)}C(a,{enter(t){if(t!==a&&(t.type===`FunctionDeclaration`||t.type===`FunctionExpression`||t.type===`ArrowFunctionExpression`))return!1;if(t.type!==`Identifier`)return;let n=sf(e,t);n!==null&&i.add(n)}})}let o=[...xf(e,n,Sf(e,t,[...i]))].sort();if(o.length===0)throw r.buildCodeFrameError(`memo-dom: Group content must read at least one colorless source`,n);return o}function df(e,t){return gr(hr(fr(e),t,!0),null,[])}function ff(e,t){return typeof e==`string`?df(e,t):df(e.component,[...t,...e.props.map(({name:e,value:t})=>pr(fr(e),mr(S(t,!0))))])}function pf(e){return j(e.map(e=>T(e)))}function mf(e,t){let n=e.__memoDomTransparentSources??[];e.__memoDomTransparentSources=[...new Set([...n,...t])].sort()}function hf(e,t){t.length!==0&&C(e,{enter(e){if(!q(e))return;let n=e,r=n.__memoDomTransparentSubscriptionExclusions??[];n.__memoDomTransparentSubscriptionExclusions=[...new Set([...r,...t])].sort()}})}function gf(e,t){let n=new Set(t.__memoDomTransparentSources??[]),r=t=>{if(Lr(t)&&K(t.callee)&&!t.callee.computed&&W(t.callee.object,{name:e.identifiers?.dataRuntimeId})&&W(t.callee.property)){let e=t.callee.property.name;if((e===`readResolvedValue`||e===`readResolvedValueForRender`)&&W(t.arguments[0])&&n.add(t.arguments[0].name),(e===`readModuleSourceList`||e===`readResolvedValueForRender`)&&Lr(t.arguments[0])&&K(t.arguments[0].callee)&&W(t.arguments[0].callee.property,{name:`sourceRef`})&&G(t.arguments[0].arguments[0])&&n.add(t.arguments[0].arguments[0].value),(e===`readResolvedValuesForRender`||e===`deriveResolvedValues`)&&Br(t.arguments[0]))for(let e of t.arguments[0].elements){if(W(e)){n.add(e.name);continue}Lr(e)&&K(e.callee)&&W(e.callee.property,{name:`sourceRef`})&&G(e.arguments[0])&&n.add(e.arguments[0].value)}}for(let e of ht[t.type]??[]){let n=t[e];if(Array.isArray(n))for(let e of n)typeof e==`object`&&e&&`type`in e&&r(e);else typeof n==`object`&&n&&`type`in n&&r(n)}};r(t);let i=new Set(t.__memoDomTransparentSubscriptionExclusions??[]);return[...n].filter(e=>!i.has(e)).sort()}function _f(e,t){for(let[n,r]of e.transparentModuleSources)if(r===t)return n;return t}function vf(e,t,n,r){let i=n.filter(e=>!t.coveredTransparentSources.has(e));if(i.length===0)return;let a=i.map(t=>_f(e,t));t.mounts.push(z(k(X(e,`cleanup`),[S(r,!0),k(Z(e,`connectResolvedValues`),[pf(a),L([],k(X(e,`markDirty`),[S(r,!0)]))])])))}function yf(e,t,n,r,i){let a=n.filter(e=>!t.coveredTransparentSources.has(e));if(a.length===0)return!1;let o=`/$data/${t.dataSiteCounter.count++}`,s=N(`+`,S(r,!0),E(o));return t.creation.push(Ns(e,S(s,!0),S(r,!0),L([],R([i])))),vf(e,t,a,s),t.disposableEntities.push(S(s,!0)),!0}function bf(e,t,n,r){vf(e,t,gf(e,n),r)}function xf(e,t,n){let r=new Set,i=t=>{let i=Q(e,t,t.name);if(!(i===void 0||!i.references.includes(t)))for(let e of n.get(i)??[])r.add(e)};return C(t,{enter(e){e.type===`Identifier`&&i(e)}}),r}function Sf(e,t,n){let r=new Map;for(let i of n){let n=Q(e,t,i);n!==void 0&&r.set(n,new Set([i]))}let i=e.astAnalysis?.parentByNode.get(t)??null;for(;i!==null&&i.type!==`FunctionDeclaration`;)i=e.astAnalysis?.parentByNode.get(i)??null;if(i===null)return r;let a=!0;for(;a;)a=!1,C(i,{enter(t){if(t!==i&&(t.type===`ArrowFunctionExpression`||t.type===`FunctionExpression`||t.type===`FunctionDeclaration`))return!1;if(t.type!==`VariableDeclarator`)return;let n=Yd(t,`init`),o=Yd(t,`id`);if(n===null||o===null)return;let s=xf(e,n,r);if(s.size!==0)for(let t of St(o)){let n=Q(e,t,t.name);if(n===void 0)continue;let i=r.get(n)??new Set,o=i.size;for(let e of s)i.add(e);r.set(n,i),a||=i.size!==o}}});return r}function Cf(e){return e.__memoDomTransparentGroup===!0}function wf(e){return J(e.name)?e.name.name:null}function Tf(e,t,n,r,i){let a=t=>{let a=t,o=ef(a);if(o===null||!/^[A-Z]/.test(o))return;let s=e.transparentGroupCallPolicies.get(a);for(let t of a.openingElement.attributes){if(!oi(t))continue;let a=wf(t),o=t.value;if(a===null||!ci(o))continue;let c=o.expression;!W(c)||xf(e,c,n).size===0||(s??=new Map,s.has(a)||s.set(a,{pending:r,error:i}))}s!==void 0&&e.transparentGroupCallPolicies.set(a,s)};C(t,{enter(e){e.type===`JSXElement`&&a(e)}})}function Ef(e,t,n,r,i){let a=pf(n),o=()=>k(Z(e,`resolvedValuesError`),[S(a,!0)]),s=L([],k(Z(e,`retryResolvedValues`),[S(a,!0)])),c=yr(_r(),vr(),[mr(S(t,!0))]),l=I(o(),ff(i,[pr(fr(`error`),mr(o())),pr(fr(`retry`),mr(s))]),I(k(Z(e,`resolvedValuesPending`),[S(a,!0)]),ff(r,[]),c));l.__memoDomTransparentGroup=!0,mf(l,n),At(e.astAnalysis,t,l)}function Df(e,t,n,r,i){let a=pf(n),o=()=>k(Z(e,`resolvedValuesError`),[S(a,!0)]),s=L([],k(Z(e,`retryResolvedValues`),[S(a,!0)])),c=yr(_r(),vr(),[S(t,!0)]),l=I(o(),ff(i,[pr(fr(`error`),mr(o())),pr(fr(`retry`),mr(s))]),I(k(Z(e,`resolvedValuesPending`),[S(a,!0)]),ff(r,[]),c));return l.__memoDomTransparentGroup=!0,mf(l,n),yr(_r(),vr(),[mr(l)])}function Of(e){let t=S(e,!0);return yr(_r(),vr(),ii(t)||ai(t)?[t]:[mr(t)])}function kf(e,t,n,r){let i=[],a=[];if(e.param!==null){if(!W(e.param))throw r.buildCodeFrameError(`memo-dom: TSRX @catch currently requires an identifier error parameter`,e.param);i.push(S(e.param)),a.push(S(t))}if(e.resetParam!==null){if(!W(e.resetParam))throw r.buildCodeFrameError(`memo-dom: TSRX @catch currently requires an identifier reset parameter`,e.resetParam);i.push(S(e.resetParam)),a.push(S(n))}let o=S(e.output,!0);return Of(k(L(i,o),a))}function Af(e,t,n,r,i){let a=pf(n),o=()=>k(Z(e,`resolvedValuesError`),[S(a,!0)]),s=L([],k(Z(e,`retryResolvedValues`),[S(a,!0)])),c=r.handler===null?Of(k(Z(e,`throwResolvedValuesError`),[S(a,!0)])):kf(r.handler,o(),s,i),l=r.pending===null?yr(_r(),vr(),[]):Of(r.pending),u=I(o(),c,I(k(Z(e,`resolvedValuesPending`),[S(a,!0)]),l,Of(t)));return u.__memoDomTransparentGroup=!0,mf(u,n),yr(_r(),vr(),[mr(u)])}function jf(e,t,n,r){let i=Tt(n),a=new Map;return C(n,{enter(n){if(n.type!==`Identifier`)return;let o=n;if(!Ct(i.parentByNode.get(n)??null,i.keyByNode.get(n))||i.nodeToScope.get(n)?.getBinding(o.name)!==void 0||r.has(o.name))return;let s=Q(e,t,o.name);s===void 0||s.scope.isProgramScope||a.has(s)||a.set(s,{binding:s,prop:`capture${a.size}`})}}),[...a.values()]}function Mf(e){return{type:`ObjectPattern`,properties:e.map(({prop:e,local:t})=>M(T(e),S(t),!1,e===t.name))}}function Nf(e,t,n,r,i){let a=new Set;i?.param!==null&&i?.param!==void 0&&i.param.type===`Identifier`&&a.add(i.param.name),i?.resetParam!==null&&i?.resetParam!==void 0&&i.resetParam.type===`Identifier`&&a.add(i.resetParam.name);let o=jf(e,t,n,a),s=[];if(r===`error`){let t=i?.param===null||i?.param===void 0?Y(e,`tsrxError`):S(i.param),n=i?.resetParam===null||i?.resetParam===void 0?Y(e,`tsrxReset`):S(i.resetParam);s.push({prop:`error`,local:t}),s.push({prop:`retry`,local:n})}for(let e of o)s.push({prop:e.prop,local:T(e.binding.name)});let c=ca(e,r===`pending`?`TsrxPending`:`TsrxCatch`);return{declaration:rr(S(c),s.length===0?[]:[Mf(s)],R([ir(S(n,!0))])),renderer:{component:c.name,props:o.map(e=>({name:e.prop,value:T(e.binding.name)}))}}}function Pf(e,t,n,r){let i=e.transparentGroupCallPolicies.get(t)??new Map;for(let{prop:e}of n)i.set(e,r);e.transparentGroupCallPolicies.set(t,i)}function Ff(e,t,n,r,i){if(t.type!==`JSXFragment`)return t;let a=t.children.filter(e=>!li(e)||e.value.trim()!==``);if(a.length!==1||!ii(a[0]))throw i.buildCodeFrameError(`memo-dom: TSRX @try currently requires one direct component output`,t);let o=a[0],s=ef(o);if(s===null||!/^[A-Z]/.test(s))throw i.buildCodeFrameError(`memo-dom: TSRX @try currently requires one direct component output`,o);let c=rf(o,i),l=cf(e,o),u=[...new Set(l.map(({source:e})=>e))];if(l.length===0)throw i.buildCodeFrameError(`memo-dom: TSRX @try component <${s}> requires at least one direct colorless-source prop`,o);if(e.usesTransparentData=!0,c===null){if(n.handler===null)throw i.buildCodeFrameError(`memo-dom: unsuspended TSRX @try requires @catch so colorless source failures have a local policy`,t);if(!W(n.handler.param))throw i.buildCodeFrameError(`memo-dom: TSRX @catch currently requires an identifier error parameter`,n.handler.param);if(!W(n.handler.resetParam))throw i.buildCodeFrameError(`memo-dom: TSRX @catch currently requires an identifier reset parameter`,n.handler.resetParam);let a=Nf(e,t,n.pending??yr(_r(),vr(),[]),`pending`,null),s=Nf(e,t,n.handler.output,`error`,n.handler);return r.push(a.declaration,s.declaration),Pf(e,o,l,{pending:a.renderer,error:s.renderer}),o}return af(o,c),Af(e,o,u,n,i)}function If(e,t){let n=gr(hr(fr(`mmd-data-policy-render`),[],!0),null,[]);return n.__memoDomTransparentPolicyRenderer={renderer:e,args:t},n}function Lf(e){return e.__memoDomTransparentPolicyRenderer??null}function Rf(e,t,n){let r=e.transparentPolicyParams.get(t),i=e.transparentSourceProps.get(t)?.get(n);return r===void 0||i===void 0?O():Xn(S(r),dt(i)?T(i):E(i),!dt(i),!0)}function zf(e,t,n,r){let i=n.map(n=>Rf(e,t,n));return n.length===1?i[0]:A(j(i),k(Z(e,r),[pf(n)]),!0)}function Bf(e,t){return Xn(S(e),T(t),!1,!0)}function Vf(e){return yr(_r(),vr(),[mr(e)])}function Hf(e,t,n,r){let i=pf(r),a=()=>k(Z(e,`resolvedValuesError`),[S(i,!0)]),o=()=>k(Z(e,`resolvedValuesPending`),[S(i,!0)]),s=zf(e,t,r,`resolvedValuesErrorIndex`),c=zf(e,t,r,`resolvedValuesPendingIndex`),l=Bf(s,`error`),u=Bf(c,`pending`),d=L([],k(Z(e,`retryResolvedValues`),[S(i,!0)])),f=I(P(`&&`,a(),S(l)),If(S(l),[a(),d]),I(a(),Vf(k(Z(e,`throwResolvedValuesError`),[S(i,!0)])),I(P(`&&`,o(),S(u)),If(S(u),[]),I(o(),yr(_r(),vr(),[]),Vf(S(n,!0))))));f.__memoDomTransparentGroup=!0,mf(f,r),jt(n,f)}function Uf(e,t){let n=[];ma(e,t.node),C(t.node,{leave(r){let i=of(r);if(i!==null){At(e.astAnalysis,r,Ff(e,r,i,n,t));return}if(r.type!==`JSXElement`)return;let a=r,o=ef(a);if(o===null||!e.transparentGroups.has(o))return;let s=tf(a,t);if(s.length!==3)throw t.buildCodeFrameError(`memo-dom: Group requires exactly three direct children: Pending, Error, and one content child`,a);let[c,l,u]=s;if(!ii(c)||!ii(l))throw t.buildCodeFrameError(`memo-dom: Group children one and two must be Pending and Error declarations`,a);let d=nf(e,c,e.transparentPendingPolicies,`Pending`,`pending`,n,t),f=nf(e,l,e.transparentErrorPolicies,`Error`,`error`,n,t),p=ii(u)?rf(u,t):null,m=uf(e,a,u,t),h=Sf(e,r,m);if(ii(u)&&p!==null){af(u,p),At(e.astAnalysis,r,Df(e,u,m,d,f)),e.usesTransparentData=!0;return}Tf(e,u,h,d,f),C(u,{enter(t){if(t.type!==`JSXExpressionContainer`)return;if((e.astAnalysis?.parentByNode.get(t)??null)?.type===`JSXAttribute`)return!1;let n=Yd(t,`expression`);if(n===null||!q(n))return!1;let r=n;if(Cf(r))return!1;let i=xf(e,n,h);if(i.size!==0)return Ef(e,r,[...i],d,f),!1}}),e.usesTransparentData=!0,At(e.astAnalysis,r,u)}}),t.node.body.push(...n),ma(e,t.node),C(t.node,{enter(e){if(e.type!==`JSXElement`)return;let n=e,r=ef(n);if(!(r===null||!/^[A-Z]/.test(r))&&rf(n,t)!==null)throw t.buildCodeFrameError(`memo-dom: suspend requires the element to be the direct content child of Group`,n)}})}function Wf(e){for(let[t,n]of e.transparentSources){let r=e.opaqueBindings.get(t);r===void 0&&(r=new Set,e.opaqueBindings.set(t,r));for(let e of n)r.add(e)}}function Gf(e,t){ma(e,t.node);for(let n of t.node.body.slice()){let r=[],i=[],a=_i(n)?n.declaration:n;if(qr(a)){for(let t of a.declarations){if(!W(t.id)||!Lr(t.init)||!W(t.init.callee)||!e.transparentSourceFactories.has(t.init.callee.name)||Q(e,t.init,t.init.callee.name)?.kind!==`import`)continue;let n=t.id.name,a=`${e.moduleId}#${n}`;e.transparentModuleSources.set(n,a),e.usesTransparentData=!0;let o=t.init.arguments[0],s=t.init.arguments[1],c=!1,l=t=>{t!==void 0&&C(t,{enter(t){t.type===`Identifier`&&Q(e,t,t.name)?.scope.isProgramScope===!0&&(c=!0)}})};l(Mr(o)?o:void 0),l(Mr(s)?s:void 0),c&&i.push(z(k(T(`effect`),[L([],k(Z(e,`rebindModuleSource`),[k(Z(e,`sourceRef`),[E(a)]),o===void 0?O():S(o,!0),...s===void 0?[]:[S(s,!0)]]))]))),t.init=k(Z(e,`sourceRef`),[E(a)]),r.push(z(k(Z(e,`describeModuleSource`),[E(a),L([],R([ir(k(Z(e,`createSource`),[o===void 0?O():S(o),...s===void 0?[]:[S(s)]]))]))])))}if(r.length>0){let e=t.node.body.indexOf(n);e!==-1&&t.node.body.splice(e,0,...r)}if(i.length>0){let e=t.node.body.indexOf(n);e!==-1&&t.node.body.splice(e+1,0,...i)}}}}function Kf(e,t,n){let r=Q(e,t,n);return r?.kind===`import`?r:void 0}function qf(e,t,n,r){return!Lr(n)||!W(n.callee)||!r.has(n.callee.name)?!1:Kf(e,t,n.callee.name)!==void 0}function Jf(e,t){if(e.transparentSourceFactoryMethods.size===0)return;let n=new Set([...e.compPaths.values()].map(e=>e.node)),r=[],i=new Set([`FunctionDeclaration`,`FunctionExpression`,`ArrowFunctionExpression`]);C(t.node,{enter(a){if(i.has(a.type)){r.push(a);return}if(a.type!==`CallExpression`)return;let o=a;if(!W(o.callee))return;let s=e.transparentSourceFactoryMethods.get(o.callee.name);if(s===void 0||s===`GET`||!qf(e,a,o,e.transparentSourceFactories))return;let c=r.at(-1);if(!(c!==void 0&&!n.has(c)))throw t.buildCodeFrameError(`memo-dom: [MMD-S010] '${o.callee.name}' is an HTTP ${s} server function and cannot be invoked during ${c===void 0?`module evaluation`:`component rendering`}. Move the call into an event handler, effect, or another deferred callback.`,o)},leave(e){i.has(e.type)&&r.pop()}})}function Yf(e){for(let[t,n]of e.compPaths){let r=n.node,i=new Set;if(C(r,{enter(n){if(n.type!==`AssignmentExpression`||n.operator!==`=`)return;let a=Yd(n,`left`),o=Yd(n,`right`);if(a?.type!==`Identifier`||o===null||!Lr(o)||!qf(e,r,o,e.transparentSourceFactories))return;let s=Q(e,a,a.name),c=a.name,l=Q(e,r,c);s!==void 0&&s.kind!==`import`&&s===l&&e.instanceState.get(t)?.has(c)===!0&&i.add(c)}}),i.size===0)continue;e.eventSourceSlots.set(t,i);let a=e.transparentSources.get(t);a===void 0&&(a=new Set,e.transparentSources.set(t,a));let o=e.opaqueBindings.get(t);o===void 0&&(o=new Set,e.opaqueBindings.set(t,o));for(let e of i)a.add(e),o.add(e);e.usesTransparentData=!0}}function Xf(e){for(let[t,n]of e.compPaths){let r=n.node,i=new Set,a=[];for(let t of n.node.body.body)if(qr(t))for(let n of t.declarations){if(!W(n.id))continue;let t=n.init;if(Lr(t)){if(qf(e,r,t,e.transparentSourceFactories)){i.add(n.id.name);continue}qf(e,r,t,e.transparentTrackFactories)&&a.push({name:n.id.name,argument:t.arguments[0]})}}e.transparentModuleSources.size>0&&C(r,{enter(t){if(t.type!==`Identifier`)return;let n=t,r=n.name;if(!e.transparentModuleSources.has(r))return;let a=Q(e,t,r);a===void 0||!a.references.includes(n)||a.kind!==`import`&&!a.scope.isProgramScope||i.add(r)}});let o=e.componentProps.get(t),s=new Map;for(let[n,r]of e.linkedComponentPropSources.get(t)??[]){if(r.transparent!==!0||o===void 0)continue;let e=ro(o,n);e!==null&&(i.add(e),s.set(e,n))}if(s.size>0&&(e.transparentSourceProps.set(t,s),e.transparentPolicyParams.set(t,Y(e,`dataPolicies`))),i.size===0)continue;e.usesTransparentData=!0,e.transparentSources.set(t,i);let c=new Map;for(let e of a){let t=new Set;if(W(e.argument)&&i.has(e.argument.name))t.add(e.argument.name);else if(Vr(e.argument))for(let n of e.argument.properties)Hr(n)&&W(n.value)&&i.has(n.value.name)&&t.add(n.value.name);t.size>0&&c.set(e.name,[...t].sort())}c.size>0&&e.transparentTrackBindings.set(t,c)}}function Zf(e,t,n){if(t.type!==`Identifier`)return!1;let r=t,i=Q(e,t,r.name);return i?.identifier===n.identifier&&i.references.includes(r)}function Qf(e){let t=e.name;return J(t)?t.name:`${t.namespace.name}:${t.name.name}`}function $f(e,t){let n=e.astAnalysis?.parentByNode.get(t)??null;if(n?.type!==`JSXAttribute`)return!1;let r=Qf(n);return r===`ref`||/^on[A-Z]/.test(r)}function ep(e,t){let n=e.astAnalysis?.parentByNode.get(t)??null;if(n?.type!==`JSXAttribute`)return!1;let r=e.astAnalysis?.parentByNode.get(n)??null;if(r?.type!==`JSXOpeningElement`)return!1;let i=r.name;return J(i)&&/^[A-Z]/.test(i.name)}function tp(e,t,n){if(!ep(e,t))return!1;let r=Yd(t,`expression`);if(r?.type!==`Identifier`)return!1;let i=r.name,a=n.get(i);return a!==void 0&&Zf(e,r,a)}function np(e,t,n){let r=e.astAnalysis?.parentByNode.get(t)??null;return r?.type!==`JSXExpressionContainer`||Yd(r,`expression`)!==t?!1:tp(e,r,n)}function rp(e,t){let n=e.astAnalysis?.parentByNode.get(t)??null;if(n?.type!==`JSXAttribute`||Qf(n)!==`data`)return!1;let r=e.astAnalysis?.parentByNode.get(n)??null;return r?.type===`JSXOpeningElement`&&J(r.name,{name:`Group`})}function ip(e,t){let n=e.astAnalysis?.parentByNode.get(t)??null;for(;n!==null&&n.type!==`JSXExpressionContainer`;)n=e.astAnalysis?.parentByNode.get(n)??null;return n!==null&&rp(e,n)}function ap(e,t){let n=e.astAnalysis?.parentByNode.get(t)??null;if(n?.type!==`CallExpression`)return!1;let r=n;if(!r.arguments.includes(t))return!1;let i=W(r.callee)?r.callee.name:null;return i!==null&&e.transparentSourcePassthroughs.has(i)}function op(e,t){let n=e.astAnalysis?.parentByNode.get(t)??null;for(;n!==null&&n.type!==`ArrayExpression`;)n=e.astAnalysis?.parentByNode.get(n)??null;if(n===null)return!1;let r=e.astAnalysis?.parentByNode.get(n)??null;if(r?.type!==`ObjectProperty`&&r?.type!==`Property`||Yd(r,`value`)!==n)return!1;let i=r,a=i.key;return!i.computed&&W(a,{name:`refresh`})||G(a,{value:`refresh`})}function sp(e,t){let n=e.astAnalysis?.parentByNode.get(t)??null;for(;n!==null&&n.type!==`CallExpression`;)n=e.astAnalysis?.parentByNode.get(n)??null;if(n===null)return!1;let r=n.callee;return K(r)&&W(r.object,{name:e.identifiers?.dataRuntimeId})}function cp(e,t,n){let r=new Map;for(let i of n){let n=Q(e,t,i);n!==void 0&&r.set(i,n)}return r}function lp(e,t,n){if(t.type!==`Identifier`||!n.has(t.name))return!1;let r=e.astAnalysis?.parentByNode.get(t)??null;if(r===null)return!1;if(r.type===`AssignmentExpression`&&Yd(r,`left`)===t)return!0;if(r.type===`BinaryExpression`||r.type===`LogicalExpression`){let e=Yd(r,`left`),n=Yd(r,`right`);if(r.type===`BinaryExpression`&&[`==`,`!=`,`===`,`!==`].includes(r.operator)){let r=e===t?n:e;if(r!==null&&Fr(r))return!0}if(r.type===`LogicalExpression`&&e===t)return!0}return r.type===`UnaryExpression`&&r.operator===`!`&&Yd(r,`argument`)===t||(r.type===`ConditionalExpression`||r.type===`IfStatement`)&&Yd(r,`test`)===t}function up(e,t,n,r,i){let a=new Set,o=t=>{let o=t.name,s=n.get(o);if(s!==void 0&&Zf(e,t,s)){!ap(e,t)&&!lp(e,t,i)&&a.add(o);return}let c=r.get(o);if(c!==void 0&&Zf(e,t,c.binding))for(let e of c.sources)a.add(e)};return C(t,{enter(e){e.type===`Identifier`&&o(e)}}),[...a].sort()}function dp(e,t,n){let r=[];C(t,{enter(t){if(t.type!==`Identifier`)return;let i=t.name,a=n.get(i);if(!(a===void 0||!Zf(e,t,a.binding)))return r.push({identifier:t,expression:a.expression}),!1}});for(let{identifier:e,expression:t}of r)jt(e,S(t,!0))}function fp(e,t,n,r){let i=new Set,a=r=>{let a=r.name,o=n.get(a);if(o===void 0)return;let s=Q(e,t,a);if(!(s===void 0||!Zf(e,r,s)))for(let e of o)i.add(e)};return C(t,{enter(t){if(t.type===`Identifier`){a(t);return}if(t.type!==`CallExpression`)return;let n=t;if(!W(n.callee)||!e.transparentTrackFactories.has(n.callee.name)||Q(e,t,n.callee.name)?.kind!==`import`)return;let o=n.arguments[0];if(!W(o))return;let s=r.get(o.name);s!==void 0&&Zf(e,o,s)&&i.add(o.name)}}),[...i].sort()}function pp(e,t,n,r,i){let a=[];C(t,{enter(t){if(t.type!==`Identifier`)return;let o=t.name,s=n.get(o),c=r.get(o);if(!(s===void 0||c===void 0||!Zf(e,t,s)||ap(e,t)||lp(e,t,i)))return a.push({identifier:t,replacement:c}),!1}});for(let{identifier:e,replacement:t}of a)jt(e,S(t))}function mp(e,t,n,r){let i=[],a=t=>{let a=t.name,o=n.get(a);o===void 0||!Zf(e,t,o)||ap(e,t)||lp(e,t,r)||i.push(t)};C(t,{enter(e){e.type===`Identifier`&&a(e)}});for(let t of i){let n=t.name;jt(t,k(Z(e,`readResolvedValueForRender`),[T(n)]))}}function hp(e,t){let n=e.astAnalysis?.parentByNode.get(t)??null;for(;n!==null;){if(n.__memoDomRenderGated===!0)return!0;if(n.type===`ArrowFunctionExpression`||n.type===`FunctionExpression`||n.type===`FunctionDeclaration`)return!1;n=e.astAnalysis?.parentByNode.get(n)??null}return!1}function gp(e,t,n,r,i,a=`readResolvedValuesForRender`){let o=new Map,s=n.map(t=>{let n=Y(e,`${t}Value`);return o.set(t,n),S(n)});pp(e,t,r,o,i);let c=L(s,S(t,!0));return e.compilerOwnedCallbacks.add(c),k(Z(e,a),[j(n.map(e=>T(e))),c])}function _p(e,t,n,r){if(r.size===0)return;let i=new Map;for(let a of e.effects.get(t)??[]){let t=a.callback;if(!Gr(t)&&!Wr(t))continue;let o=up(e,t,n,i,r);if(!o.some(e=>r.has(e)))continue;let s=new Map,c=o.map(t=>{let n=Y(e,`${t}EffectValue`);return s.set(t,n),S(n)});pp(e,t.body,n,s,r);let l=L(c,S(t.body,!0));e.compilerOwnedCallbacks.add(l);let u=L([],k(Z(e,`runResolvedValuesEffect`),[pf(o),l]));e.compilerOwnedCallbacks.add(u),a.callback=u}}function vp(e){let t=!1;return C(e,{enter(e){if(e.type===`JSXElement`||e.type===`JSXFragment`)return t=!0,!1}}),t}function yp(e,t,n,r){let i=[];for(let[t,r]of e.transparentModuleSources){let a=Q(e,n,t);a!==void 0&&i.push({name:t,key:r,binding:a})}if(i.length===0)return;e.usesTransparentData=!0;let a=t=>{if(t.type!==`Identifier`)return null;let n=t.name,r=i.find(e=>e.name===n);return r!==void 0&&Zf(e,t,r.binding)?r:null},o=t=>k(Z(e,`sourceRef`),[E(t)]),s=t=>{let n=e.astAnalysis?.parentByNode.get(t)??null;if(n?.type!==`MemberExpression`)return!1;let r=n;return r.object!==t||r.computed||!W(r.property,{name:`map`})?!1:e.astAnalysis?.parentByNode.get(n)?.type===`CallExpression`},c=t=>{let n=[];return C(t,{enter(t){if(t.type!==`Identifier`)return;let r=a(t);r===null||ap(e,t)||n.push({identifier:t,entry:r})}}),n},l=(t,n,r)=>{jt(t,k(Z(e,r),[o(n.key)]))};C(n,{enter(t){if(t.type!==`JSXExpressionContainer`)return;if($f(e,t))return!1;let n=Yd(t,`expression`);if(n===null||!q(n))return!1;let i=n;if(i.__memoDomTransparentGroup===!0){let i=[];C(n,{enter(r){let a=e.astAnalysis?.parentByNode.get(r)??null,o=!1;for(;a!==null&&a!==n;){if(a.type===`JSXFragment`){o=!0;break}a=e.astAnalysis?.parentByNode.get(a)??null}r!==t&&r.type===`JSXExpressionContainer`&&o&&!$f(e,r)&&i.push(r)}});for(let e of i){let t=Yd(e,`expression`);if(t!==null)for(let{identifier:e,entry:n}of c(t))l(e,n,s(e)?`readModuleSourceList`:`readResolvedValueForRender`)}return r(),!1}let u=c(n);if(u.length===0)return;for(let{identifier:e,entry:t}of u)s(e)&&l(e,t,`readModuleSourceList`);r();let d=c(n);if(d.length>0){let t=a(n);if(t!==null)l(n,t,`readResolvedValueForRender`);else{let t=[...new Map(d.map(({entry:e})=>[e.name,e])).values()],r=new Map,a=t.map(t=>{let n=Y(e,`${t.name}Value`);return r.set(t.name,n),S(n)});for(let{identifier:e,entry:t}of d)jt(e,S(r.get(t.name)));let s=S(i,!0),c=L(a,s);e.compilerOwnedCallbacks.add(c),jt(n,k(Z(e,`readResolvedValuesForRender`),[j(t.map(e=>o(e.key))),c]))}}return mf(n,gf(e,n)),r(),!1}});let u=new Set((e.instanceDerivations.get(t)??[]).map(e=>e.declaration)),d=t=>{let n=e.astAnalysis?.parentByNode.get(t)??null;for(;n!==null&&!n.type.endsWith(`Statement`);){if(n.type===`VariableDeclarator`){let t=e.astAnalysis?.parentByNode.get(n)??null;return t!==null&&u.has(t)}n=e.astAnalysis?.parentByNode.get(n)??null}return!1},f=c(n).filter(({identifier:t})=>!d(t)&&!op(e,t)&&!sp(e,t));for(let{identifier:t,entry:n}of f){let r=t.loc===null||t.loc===void 0?e.moduleId:`${e.moduleId}:${t.loc.start.line}:${t.loc.start.column+1}`;jt(t,k(Z(e,`readResolvedValue`),[o(n.key),E(n.name),E(r)]))}r()}function bp(e){let t=()=>{let t=e.astAnalysis?.rootScope.block;t!==void 0&&ma(e,t)};for(let[n,r]of e.compPaths)yp(e,n,r.node,t);t();let n=(t,n)=>{if(!e.transparentModuleSources.has(n))return;let r=Q(e,t,n);return r?.kind===`import`?r:void 0};for(let[r,i]of e.compPaths){let a=i.node,o=e.transparentSources.get(r)??new Set,s=cp(e,a,o),c=!1;for(let t of e.transparentModuleSources.keys()){let e=n(a,t);e!==void 0&&(s.set(t,e),c=!0)}if(o.size===0&&!c)continue;let l=o,u=e.eventSourceSlots.get(r)??new Set,d=e.transparentTrackBindings.get(r)??new Map,f=new Map;for(let n of e.instanceDerivations.get(r)??[]){let r=n.sources.filter(e=>l.has(e)),i=[];for(let t of e.transparentModuleSources.keys())s.has(t)&&n.sources.includes(t)&&i.push(t);if(r=[...new Set([...r,...i])],r.length===0)continue;let o=n.declaration.declarations.find(e=>e.init!==null&&St(e.id).some(e=>n.bindings.includes(e.name)))?.init;if(o==null||!q(o))continue;dp(e,o,f),t();let c=S(o,!0),d=gp(e,o,r,s,u,`deriveResolvedValues`);jt(o,d),n.source=S(d,!0);for(let t of n.bindings){let n=Q(e,a,t);n!==void 0&&f.set(t,{binding:n,sources:r,expression:S(c,!0)})}}t(),_p(e,r,s,u),t(),C(a,{enter(n){if(n.type!==`JSXExpressionContainer`)return;if($f(e,n)||rp(e,n)||tp(e,n,s))return!1;let i=Yd(n,`expression`);if(i===null||!q(i))return!1;let a=i;if(a.__memoDomTransparentGroup===!0)return dp(e,i,f),!1;let o=up(e,i,s,f,u),c=fp(e,i,d,s);if(o.length===0){c.length>0&&(mf(a,c),hf(a,c.filter(e=>u.has(e))));return}let l=[...new Set([...o,...c])].sort();dp(e,i,f),t();let p=l.filter(e=>u.has(e));if(vp(i)||o.some(t=>e.transparentSourceProps.get(r)?.has(t)===!0))return c.length>0||p.length>0?(mp(e,i,s,u),a.__memoDomRenderGated=!0,mf(a,l),hf(a,p),!1):(Hf(e,r,a,o),!1);let m=gp(e,a,o,s,u);return mf(m,l),hf(m,p),jt(i,m),!1}}),t();let p=[];C(a,{enter(t){if(t.type!==`Identifier`)return;let n=t.name,r=s.get(n);r===void 0||!Zf(e,t,r)||ap(e,t)||lp(e,t,u)||op(e,t)||ip(e,t)||np(e,t,s)||hp(e,t)||sp(e,t)||p.push({identifier:t,name:n})}});for(let{identifier:t,name:n}of p){let r=t.loc===null||t.loc===void 0?e.moduleId:`${e.moduleId}:${t.loc.start.line}:${t.loc.start.column+1}`;jt(t,k(Z(e,`readResolvedValue`),[T(n),E(n),E(r)]))}t()}}function xp(e,t,n){let r=typeof t==`string`?t:t.component,i=Y(e,`dataPolicyId`),a=Y(e,`dataPolicyParent`),o=Y(e,`dataPolicyError`),s=Y(e,`dataPolicyRetry`),c=n===`error`?[{name:`error`,value:S(o)},{name:`retry`,value:S(s)}]:[];typeof t!=`string`&&c.push(...t.props.map(({name:e,value:t})=>({name:e,value:S(t,!0)})));let l=Wd(e,r,c);return L([S(i),S(a),...n===`error`?[S(o),S(s)]:[]],k(T(r),[S(i),S(a),...l.length>0?[j(l)]:[]]))}function Sp(e,t){return Zn([M(T(`pending`),xp(e,t.pending,`pending`)),M(T(`error`),xp(e,t.error,`error`))])}function Cp(e,t,n){let r=new Map;for(let[t,i]of e.transparentGroupCallPolicies.get(n)??[])r.set(t,Sp(e,i));let i=e.transparentPolicyParams.get(t),a=e.transparentSourceProps.get(t);if(i!==void 0&&a!==void 0)for(let e of n.openingElement.attributes){if(!oi(e)||!J(e.name)||!ci(e.value)||!W(e.value.expression)||r.has(e.name.name))continue;let t=a.get(e.value.expression.name);t!==void 0&&r.set(e.name.name,Xn(S(i),dt(t)?T(t):E(t),!dt(t),!0))}return r.size===0?null:Zn([...r].map(([e,t])=>M(dt(e)?T(e):E(e),t,!dt(e))))}function wp(e,t,n){let r=e.transparentSourceProps.get(t),i=e.eventSourceSlots.get(t);return[...e.transparentSources.get(t)??[]].filter(e=>r?.has(e)!==!0&&i?.has(e)!==!0).map(t=>z(k(X(e,`cleanup`),[S(n),k(Z(e,`ownResolvedValue`),[T(t)])])))}function Tp(e){return e}function Ep(e){return typeof e==`object`&&e&&typeof e.type==`string`?e:null}function Dp(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.type==`string`):[]}function Op(e){if(e?.type!==`Identifier`)return null;let t=Tp(e).name;return typeof t==`string`?t:null}function kp(e){return e.type===`ExportNamedDeclaration`||e.type===`ExportDefaultDeclaration`?Ep(Tp(e).declaration):e}function Ap(e){let t=e;for(;t!==null&&(t.type===`TSAsExpression`||t.type===`TSTypeAssertion`||t.type===`TSNonNullExpression`||t.type===`TSSatisfiesExpression`||t.type===`TSInstantiationExpression`);)t=Ep(Tp(t).expression);return t?.type===`ArrowFunctionExpression`||t?.type===`FunctionExpression`?t:null}function jp(e){let t=!1;return C(e,{enter(e){return e.type===`JSXElement`||e.type===`JSXFragment`?(t=!0,!1):!t&&void 0}}),t}function Mp(e){if(e.type!==`Program`)return[];let t=[];for(let n of Dp(Tp(e).body)){let e=kp(n);if(e!==null){if(e.type===`FunctionDeclaration`){let n=Op(Ep(Tp(e).id));if(n===null)continue;let r=jp(e);t.push({name:n,kind:r?/^[A-Z]/.test(n)?`component`:`jsx-helper`:`helper`,node:e});continue}if(e.type===`VariableDeclaration`)for(let n of Dp(Tp(e).declarations)){if(n.type!==`VariableDeclarator`)continue;let e=Op(Ep(Tp(n).id)),r=Ap(Ep(Tp(n).init));if(e===null||r===null)continue;let i=jp(Ep(Tp(r).body)??r);i&&/^[A-Z]/.test(e)||t.push({name:e,kind:i?`jsx-helper`:`helper`,node:r})}}}return t}function Np(e,t){if(e.type!==`Program`)return[];let n=[];for(let r of Dp(Tp(e).body))if(r.type===`ImportDeclaration`&&Tp(r).importKind!==`type`)for(let e of Dp(Tp(r).specifiers)){if(e.type===`ImportSpecifier`&&Tp(e).importKind===`type`)continue;let i=Op(Ep(Tp(e).local));i!==null&&!t.has(i)&&n.push({local:i,declaration:r})}return n}function Pp(e){let t=new Set([...e.listSources].map(t=>ya(e,t))),n=(t,n)=>{let r=ya(e,n);for(let n of e.componentListSources.get(t)??[])if(ya(e,n)===r)return!0;return!1},r=(n,r,i=r)=>{let a=ya(e,n),o=e.readers.get(a);o||e.readers.set(a,o=new Set);for(let e of r)o.add(e);if(!t.has(a))return;let s=`${a}memo-dom:list-structure-reader`,c=e.readers.get(s);c||e.readers.set(s,c=new Set);for(let e of i)c.add(e)};for(let[t,i]of e.compReads){if(i.size===0)continue;let a=Bl(e,t),o=Rl(e,zl(e,t));for(let e of i)r(e,a,n(t,e)?o:a)}for(let{owner:t,suffix:n,vars:i}of e.rowReads.values()){let a=Rl(e,zl(e,t).flatMap(e=>[`${e}/${n}/Row[*]`,`${e}/${n}/Row[*]/*`]));for(let e of i)r(e,a)}for(let{owner:t,suffix:n,vars:i}of e.condReads.values()){let a=Rl(e,zl(e,t).flatMap(e=>[`${e}/${n}`,`${e}/${n}/*`]));for(let e of i)r(e,a)}for(let[t,n]of e.effects){let i=Bl(e,t).filter(e=>!e.endsWith(`/*`));for(let e of n){let t=i.map(t=>`${t}/$effects/${e.index}`),n=e.condition===null?t:t.map(e=>`${e}/$active`);for(let t of e.moduleReads)r(t,n);for(let n of e.conditionModuleReads)r(n,t)}}for(let t of e.moduleEffects){let e=t.condition===null?t.entityId:`${t.entityId}/$active`;for(let n of t.moduleReads)r(n,[e]);for(let e of t.conditionModuleReads)r(e,[t.entityId])}for(let[t,n]of e.computeds){let i=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#${t}`;for(let e of n.reads)r(e,[i])}for(let t of e.moduleControlFlow)for(let e of t.sources)r(e,[t.entityId]);if(e.readers.size===0)return null;let i=[...e.readers.entries()].sort(([e],[t])=>e<t?-1:1).map(([e,t])=>M(E(e),j([...t].sort().map(e=>E(e)))));return z(k(X(e,`installAccessTable`),[Zn([M(T(`readers`),Zn(i))]),E(e.rootId),E(e.moduleId)]))}function Fp(e,t){if(t.type!==`JSXExpressionContainer`)return!1;let n=e.astAnalysis?.parentByNode.get(t)??null;if(n?.type!==`JSXAttribute`)return!1;let r=e.astAnalysis?.parentByNode.get(n)??null;if(r?.type!==`JSXOpeningElement`)return!1;let i=r.name;if(!J(i)||!/^[A-Z]/.test(i.name))return!1;let a=n.name,o=J(a)?a.name:a.name.name;return e.componentProps.get(i.name)?.renderProps.includes(o)===!0}function Ip(e,t){let n=new Set([...e.importedState,...e.importedFunctions.keys(),...e.importedComponents.keys(),...e.importedValues]);for(let e of Np(t.node,n))throw t.buildCodeFrameError(`memo-dom: value import '${e.local}' requires compileModules() so its reactive identity can be linked`)}function Lp(e,t){let n=rd(t.node);for(let r of t.node.body){let t=_i(r)?r.declaration:r;if(qr(t)){for(let r of t.declarations)if(W(r.id)&&(t.kind===`let`||t.kind===`var`?ga(e,Q(e,r,r.id.name))?va(e,r.id.name,`let`):Da(r.init)?va(e,r.id.name,`store`):Oa(r.init)&&va(e,r.id.name,`const`):t.kind===`const`&&(Da(r.init)?va(e,r.id.name,`store`):Oa(r.init)&&va(e,r.id.name,`const`)),e.state.has(r.id.name))){let t=n.get(r.id.name);t!==void 0&&e.stateTagCandidates.set(r.id.name,[...t])}}}}function Rp(e,t){let n=e=>{if(e==null)return null;let t=e;for(;Pi(t);)t=t.expression;return Gr(t)||Wr(t)?t:null},r=new Map,i=e=>({node:e,buildCodeFrameError(n,r=e){return t.buildCodeFrameError(n,r)}});for(let e of t.node.body){let t=_i(e)||vi(e)?e.declaration:e;if(Ur(t)){r.set(t,i(t));continue}if(qr(t))for(let e of t.declarations){let t=n(e.init);t!==null&&r.set(t,i(t))}}for(let n of Mp(t.node)){if(e.comps.has(n.name)||e.helpers.has(n.name)||e.jsxHelpers.has(n.name))continue;let t=r.get(n.node);if(t===void 0)continue;if(n.kind===`helper`){e.helpers.set(n.name,t);continue}if(n.kind===`jsx-helper`){e.jsxHelpers.set(n.name,t);continue}if(t.node.type!==`FunctionDeclaration`)continue;let i=t;e.comps.set(n.name,{parents:new Set,jsxCount:0}),e.compPaths.set(n.name,i);let a=Ud(i.node.body);e.componentHostEvents.set(n.name,a),a.length!==0&&e.componentsWithHostEvents.add(n.name);try{e.componentProps.set(n.name,Za(i.node.params))}catch(e){throw t.buildCodeFrameError(`memo-dom: invalid props for component '${n.name}': ${e instanceof Error?e.message:String(e)}`)}}}function zp(e,t,n=new Set){if(ea(e)||ra(e)||na(e)||ta(e)||Xi(e)||Yi(e)||Ji(e)||$i(e))return!0;if(Qi(e))return zp(e.typeAnnotation,t,n);if(Zi(e))return e.types.every(e=>zp(e,t,n));if(Gi(e)&&W(e.typeName)){let r=e.typeName.name;if(n.has(r))return!1;let i=new Set(n);i.add(r);for(let e of t.body){let n=_i(e)?e.declaration:e;if(Vi(n)&&n.id.name===r)return zp(n.typeAnnotation,t,i)}}return!1}function Bp(e,t,n){let r=(e,t)=>e.type===t,i=e=>G(e)||Nr(e)||Pr(e)||Ir(e)||r(e,`Literal`)&&(typeof e.value==`string`||typeof e.value==`number`||typeof e.value==`boolean`||typeof e.value==`bigint`)||ti(e)&&(e.operator===`+`||e.operator===`-`)&&(Nr(e.argument)||r(e.argument,`Literal`)&&typeof e.argument.value==`number`),a=e=>{if(W(e))return e.name;if(G(e))return e.value;if(r(e,`Literal`)){let t=e.value;return typeof t==`string`?t:null}return null};for(let t of e.params){if(Ui(t))continue;if(mi(t)&&W(t.left,{name:n})&&i(t.right))return!0;if(mi(t)&&fi(t.left)&&Vr(t.right)){let e=t.right.properties.find(e=>!Hr(e)||e.computed?!1:a(e.key)===n);if(Hr(e)&&q(e.value)&&i(e.value))return!0}let e=mi(t)?t.left:t;if(fi(e)){for(let t of e.properties)if(!(!Hr(t)||t.computed)&&a(t.key)===n&&mi(t.value)&&i(t.value.right))return!0}}let o=e.params[0];if(o==null||Ui(o))return!1;let s=mi(o)?o.left:o;if(!W(s)&&!fi(s)&&!pi(s))return!1;let c=s.typeAnnotation;if(!Wi(c))return!1;let l=c.typeAnnotation;if(Gi(l)&&W(l.typeName)){let e=l.typeName.name,n=null;for(let r of t.body){let t=_i(r)?r.declaration:r;if(Hi(t)&&t.id.name===e){n=t;break}if(Vi(t)&&t.id.name===e){n=t;break}}Hi(n)?l=wr(n.body.body):Vi(n)&&(l=n.typeAnnotation)}if(!Ki(l))return!1;for(let e of l.members)if(!(!qi(e)||e.computed)&&a(e.key)===n&&Wi(e.typeAnnotation))return zp(e.typeAnnotation.typeAnnotation,t);return!1}function Vp(e,t,n=new Set){if(jp(t))return!0;if(n.has(t))return!1;if(n.add(t),t.type===`Identifier`){let r=t.name,i=e.astAnalysis?.nodeToScope.get(t)?.getBinding(r),a=i?.identifier??null;for(;a!==null&&a!==i?.declarationNode&&a.type!==`VariableDeclarator`;)a=e.astAnalysis?.parentByNode.get(a)??null;if(a?.type===`VariableDeclarator`){let t=a.init;return nt(t)?Vp(e,t,n):!1}}if(t.type===`MemberExpression`){let r=t.object;return nt(r)?Vp(e,r,n):!1}return!1}function Hp(e){let t=e.astAnalysis?.rootScope.block;if(t?.type!==`Program`)return;let n=new Map;for(let[r,i]of e.compPaths){let a=new Set;n.set(r,a),C(i.node,{enter(n,o){if(n.type!==`JSXExpressionContainer`||o?.type!==`JSXElement`&&o?.type!==`JSXFragment`)return;let s=n.expression;if(!nt(s))return;let c=Is(e,r,s);c!==null&&(Bp(i.node,t,c)||a.add(c))}});let o=e.astAnalysis?.parentByNode.get(i.node)??null;if((o?.type===`ExportNamedDeclaration`||o?.type===`ExportDefaultDeclaration`)&&!e.linkedComponentRenderProps.has(r)){let t=e.componentProps.get(r);for(let e of a)t.renderProps.includes(e)||t.renderProps.push(e)}}let r=new Map;for(let[t,i]of e.compPaths)C(i.node,{enter(a){if(a.type!==`JSXElement`)return;let o=a,s=o.openingElement.name;if(!J(s)||!e.comps.has(s.name))return;let c=e.componentProps.get(s.name),l=n.get(s.name);if(l===void 0)return;let u=r.get(s.name);u===void 0&&(u=new Map,r.set(s.name,u)),l.has(`children`)&&o.children.some(e=>!li(e)||e.value.trim()!==``)&&!c.renderProps.includes(`children`)&&(c.renderProps.push(`children`),u.set(`children`,{scalar:!1,jsx:!0,at:i}));for(let n of o.openingElement.attributes){if(!oi(n))continue;let r=n.name,a=J(r)?r.name:r.name.name;if(!l.has(a))continue;let o=u.get(a)??{scalar:!1,jsx:!1,at:i},s=n.value,c=!1;ci(s)&&nt(s.expression)&&(Vp(e,s.expression)||Is(e,t,s.expression)!==null)&&(c=!0),c?o.jsx=!0:o.scalar=!0,u.set(a,o)}}});for(let[t,n]of r){let r=e.componentProps.get(t);for(let[e,i]of n){if(i.scalar&&i.jsx){if(e===`children`){r.renderProps.includes(e)||r.renderProps.push(e);continue}throw i.at.buildCodeFrameError(`memo-dom: prop '${e}' on <${t}> is used as both scalar data and JSX content`)}i.jsx?r.renderProps.includes(e)||r.renderProps.push(e):i.scalar&&(r.renderProps=r.renderProps.filter(t=>t!==e))}}let i=!0;for(;i;){i=!1;for(let[t,n]of e.compPaths){let r=e.componentProps.get(t);C(n.node,{enter(n,a){if(n.type!==`JSXAttribute`)return;let o=n,s=o.value;if(!ci(s)||!nt(s.expression))return;let c=Is(e,t,s.expression);if(c===null||r.renderProps.includes(c)||a?.type!==`JSXOpeningElement`)return;let l=a.name;if(!J(l)||!/^[A-Z]/.test(l.name))return;let u=e.componentProps.get(l.name),d=o.name,f=J(d)?d.name:d.name.name;u?.renderProps.includes(f)===!0&&(r.renderProps.push(c),i=!0)}})}}for(let[t,n]of e.linkedComponentRenderProps){let r=e.componentProps.get(t);r!==void 0&&(r.renderProps=[...n])}}function Up(e,t){let n=e.compPaths.get(t),r=e.comps.get(t),i=e=>{throw n.buildCodeFrameError(e)},a=n=>{let r=Lo(n);if(r&&(Ro(n)||bo(e,t,r)!==null)){let t=e.astAnalysis?.parentByNode.get(n)??null,r=t?.type===`ChainExpression`?e.astAnalysis?.parentByNode.get(t)??null:t,a=r===null?null:e.astAnalysis?.parentByNode.get(r)??null;return(r?.type!==`JSXExpressionContainer`||a?.type!==`JSXElement`&&a?.type!==`JSXFragment`&&!Fp(e,r))&&i(`memo-dom: list rendering must be a direct JSX child: <ul>{items.map(item => <Row />)}</ul>`),!1}return!0};C(n.node,{enter(n){if(n.type===`JSXElement`){let a=n,o=a.openingElement,s=o.name;if(!J(s))return i(`memo-dom: namespaced or member-expression JSX tags are not supported (L1)`);for(let t of o.attributes)if(!si(t)&&J(t.name,{name:`key`})){if(go(e,n))continue;i(`memo-dom: key={...} is only meaningful on list rows: items.map(item => <Row key={item.id} />)`)}let c=s.name;if(/^[A-Z]/.test(c)){let n=e.comps.has(c);!n&&!e.importedComponents.has(c)&&i(`memo-dom: <${c} /> is not a linked component factory`),n&&e.comps.get(c).parents.add(t);let r=e.childRefCounts.get(t);r||e.childRefCounts.set(t,r=new Map),r.set(c,(r.get(c)??0)+1),(a.children.some(e=>!li(e)||e.value.trim()!==``)||o.attributes.some(t=>{if(si(t)||e.componentProps.get(c)?.renderProps.includes(J(t.name)?t.name.name:t.name.name.name)!==!0)return!1;let n=ka(t.value);return n!==null&&Na(n)}))&&e.renderSlotOwners.add(t);return}r.jsxCount++;return}if(n.type===`ConditionalExpression`&&Ro(n)){let t=e.astAnalysis?.parentByNode.get(n)??null,r=t===null?null:e.astAnalysis?.parentByNode.get(t)??null;return(t?.type!==`JSXExpressionContainer`||r?.type!==`JSXElement`&&r?.type!==`JSXFragment`&&!Fp(e,t))&&i(`memo-dom: conditional rendering must be a direct JSX child: <div>{cond ? <A/> : <B/>}</div>`),!1}if(n.type===`LogicalExpression`&&Ro(n)){let t=n;t.operator!==`&&`&&t.operator!==`||`&&i(`memo-dom: only && / || conditionals are supported (R8 L1), not ??`);let r=e.astAnalysis?.parentByNode.get(n)??null,a=r===null?null:e.astAnalysis?.parentByNode.get(r)??null;return(r?.type!==`JSXExpressionContainer`||a?.type!==`JSXElement`&&a?.type!==`JSXFragment`&&!Fp(e,r))&&i(`memo-dom: conditional rendering must be a direct JSX child: <div>{cond ? <A/> : <B/>}</div>`),!1}if(n.type===`CallExpression`||n.type===`OptionalCallExpression`)return a(n)}})}function Wp(e,t){let n=e.astAnalysis?.parentByNode.get(t)??null;return n?.type===`CallExpression`&&n.callee===t}function Gp(e,t){let n=t,r=Ca(n);if(!r||!r.includes(`.`))return null;let i=r.split(`.`)[0];if(e.state.get(i)!==`store`||Q(e,t,i)?.scope.isProgramScope!==!0)return null;let a=e.astAnalysis?.parentByNode.get(t)??null;return a?.type===`AssignmentExpression`&&a.operator===`=`&&a.left===n||Wp(e,t)?null:r}function Kp(e,t,n){let r=new Set([...e.instanceReasonIds.get(t)?.keys()??[],...n]);e.instanceReasonIds.set(t,new Map([...r].sort().map((e,t)=>[e,t])))}function qp(e,t){let n=[],r=e;for(;r=So(r),K(r);){if(n.unshift(r),Ai(r.object))return null;r=r.object}if(!W(r,{name:t}))return null;let i=n[0];if(i===void 0||!i.computed||!q(i.property)||!(W(i.property)||Nr(i.property)||G(i.property))||n.length<2)return null;let a=[];for(let e of n.slice(1))if(!e.computed&&W(e.property))a.push(e.property.name);else if(e.computed&&G(e.property))a.push(e.property.value);else return null;return a}function Jp(e,t,n){let r=!1;return Ma(e.body,e=>{if(r)return;let i=$r(e)&&K(e.left)?e.left:ei(e)&&K(e.argument)||ti(e,{operator:`delete`})&&K(e.argument)?e.argument:null;if(i===null)return;let a=qp(i,t);a!==null&&!Ta(a,n)&&(r=!0)}),r}function Yp(e,t,n,r){if(!r.sourceLocal||!W(r.sourceExpr))return;let i=r.sourceExpr.name;if(e.instanceState.get(t)?.has(i)!==!0)return;let a=wa(r.keyExpr,r.itemParam);if(a===null||a.length===0)return;let o=e.compPaths.get(t);if(o===void 0||!Jp(o.node,i,a))return;let s=`${t}\0${i}`;if(e.disabledKeyedListMutationSources.has(s))return;let c=e.keyedListMutationSources.get(t);c===void 0&&(c=new Map,e.keyedListMutationSources.set(t,c));let l=c.get(i);if(l!==void 0){e.keyedListMutations.delete(l.call),c.delete(i),e.disabledKeyedListMutationSources.add(s);return}let u={source:i,keyPath:a,keysVariable:Y(e,`${i}ChangedKeys`).name,targetedReason:`${s}\0content`,structuralReason:`${s}\0structure`,call:n};c.set(i,u),e.keyedListMutations.set(n,u),e.targetedListComponents.add(t),Kp(e,t,[i,u.targetedReason,u.structuralReason])}function Xp(e){for(let[t]of e.comps){let n=e.compPaths.get(t),r=new Set,i=new Map,a={count:0};function o(n){if(e.listSources.add(n.sourceKey),e.listComponents.add(t),n.sourceLocal)return;let r=e.componentListSources.get(t);r===void 0&&(r=new Set,e.componentListSources.set(t,r)),r.add(n.sourceKey)}function s(r,i,a){let s=Lo(r);if(s===null||!Ro(r))return!0;let c=zo(e,s,n,t,a);o(c);let l=`${i}/${c.suffix}`;if(c.form===`component`){let n=e.listedSites.get(c.rowComp)??[];n.some(e=>e.owner===t&&e.suffix===l)||n.push({owner:t,suffix:l,itemParam:c.itemParam,keyExpr:c.keyExpr,sourceKey:c.sourceKey,sourceLocal:c.sourceLocal}),e.listedSites.set(c.rowComp,n)}else d(r,c,l);return!1}function c(r,i,a){let o=r.openingElement.name;if(!J(o)||!/^[A-Z]/.test(o.name))return;if(!e.comps.has(o.name)&&!e.importedComponents.has(o.name))throw n.buildCodeFrameError(`memo-dom: <${o.name} /> is not a linked component factory`);let s=a.get(o.name)??0;a.set(o.name,s+1);let c=`${i}/${s===0?o.name:`${o.name}[${s}]`}`,l=e.conditionalComponentSites.get(o.name)??[];l.some(e=>e.owner===t&&e.suffix===c)||l.push({owner:t,suffix:c}),e.conditionalComponentSites.set(o.name,l)}function l(r,i,a){let o=r.openingElement.name;if(!J(o)||!/^[A-Z]/.test(o.name))return;if(!e.comps.has(o.name)&&!e.importedComponents.has(o.name))throw n.buildCodeFrameError(`memo-dom: <${o.name} /> is not a linked component factory`);let s=a.get(o.name)??0;a.set(o.name,s+1);let c=`${i}/Row[*]/${s===0?o.name:`${o.name}[${s}]`}`,l=e.rowComponentSites.get(o.name)??[];l.some(e=>e.owner===t&&e.suffix===c)||l.push({owner:t,suffix:c}),e.rowComponentSites.set(o.name,l)}function u(n,r){let i=e.listedSites.get(n.rowComp)??[];i.some(e=>e.owner===t&&e.suffix===r)||i.push({owner:t,suffix:r,itemParam:n.itemParam,keyExpr:n.keyExpr,sourceKey:n.sourceKey,sourceLocal:n.sourceLocal}),e.listedSites.set(n.rowComp,i)}function d(r,i,a){let s=r.arguments[0];if(s===void 0)return;let c=new Set,f=new Map,p=new Map,m=r=>{let s=r,l=Lo(s);if(l!==null&&Ro(s)){let r=zo(e,l,n,t,p,i);o(r);let c=`${a}/Row[*]/${r.suffix}`;return r.form===`component`?u(r,c):d(s,r,c),!1}let f=s.callee;if(W(f)&&(e.helpers.has(f.name)||e.importedFunctions.has(f.name))&&Q(e,r,f.name)?.scope.isProgramScope===!0){let t=e.importedFunctions.get(f.name)??ws(e,f.name);for(let e of t.reads)c.add(e)}return!0};C(s,{enter(t){if(t.type===`Identifier`){let n=t;n.name!==i.itemParam&&e.state.has(n.name)&&Q(e,t,n.name)?.scope.isProgramScope===!0&&c.add(n.name)}if(t.type===`JSXElement`&&l(t,a,f),t.type===`CallExpression`||t.type===`OptionalCallExpression`)return m(t)}}),c.size>0&&e.rowReads.set(`${t}/${a}`,{owner:t,suffix:a,vars:c})}function f(r,i=null){if(!Ro(r))return!0;let o=os(r,n,a),l=i===null?o.suffix:`${i}/${o.suffix}`,u=[];if(ri(r)){let e=r;for(;ri(e);)u.push(e.consequent),e=e.alternate;u.push(e)}else u.push(r.right);for(let e of u){let t=new Map,n=new Map;if((ri(e)||ni(e))&&Ro(e)){f(e,l);continue}ii(e)&&c(e,l,n);let r=e;C(r,{enter(e){if(e!==r){if((e.type===`ConditionalExpression`||e.type===`LogicalExpression`)&&Ro(e))return f(e,l);if(e.type===`JSXElement`&&c(e,l,n),e.type===`CallExpression`||e.type===`OptionalCallExpression`)return s(e,l,t)}}})}let d=Pa(e,r);return d.size>0&&i===null&&e.condReads.set(`${t}/${l}`,{owner:t,suffix:l,vars:d}),!1}function p(a){let s=a;if(W(s.callee,{name:`effect`})&&Q(e,a,`effect`)===void 0)return!1;let c=Lo(s);if(c&&(Ro(a)||bo(e,t,c)!==null)){let a=zo(e,c,n,t,i);o(a),Yp(e,t,c,a);let l=Uu(a,e.instanceState.get(t)??new Set);if(l.length>0&&W(a.sourceExpr)){let n=a.sourceExpr.name;e.targetedListDependencies.set(c,l.map(e=>({source:n,value:e}))),e.targetedListComponents.add(t),Kp(e,t,[n,...l])}if(a.sourceLocal||r.add(a.sourceKey),a.form===`component`){for(let t of a.jsx.openingElement.attributes){if(si(t))continue;let n=t,i=J(n.name)?n.name.name:`${n.name.namespace.name}:${n.name.name.name}`;if(i===`key`||i===`ref`||e.componentProps.get(a.rowComp)?.refProps.includes(i)===!0)continue;let o=ka(n.value);o&&Ma(o,t=>{if(W(t)&&e.state.has(t.name)&&Q(e,t,t.name)?.scope.isProgramScope===!0&&r.add(t.name),K(t)){let n=Ca(t);if(n!==null&&n.includes(`.`)){let i=n.split(`.`)[0];e.state.get(i)===`store`&&Q(e,t,i)?.scope.isProgramScope===!0&&r.add(n)}}})}let n=e.listedSites.get(a.rowComp)??[];n.some(e=>e.owner===t&&e.suffix===a.suffix)||n.push({owner:t,suffix:a.suffix,itemParam:a.itemParam,keyExpr:a.keyExpr,sourceKey:a.sourceKey,sourceLocal:a.sourceLocal}),e.listedSites.set(a.rowComp,n)}else d(s,a,a.suffix);return!1}let l=s.callee;if(W(l)&&(e.helpers.has(l.name)||e.importedFunctions.has(l.name))&&Q(e,a,l.name)?.scope.isProgramScope===!0){let t=e.importedFunctions.get(l.name)??ws(e,l.name);for(let e of t.reads)r.add(e)}return!0}C(n.node,{enter(t){if(t!==n.node&&Kr(t))return!1;if(t.type===`JSXAttribute`){let e=t.name;return J(e)&&(e.name===`ref`||/^on[A-Z]/.test(e.name))||di(e)&&e.namespace.name===`ref`?!1:void 0}if(t.type===`ConditionalExpression`||t.type===`LogicalExpression`)return f(t);if(t.type===`CallExpression`||t.type===`OptionalCallExpression`)return p(t);if(t.type===`Identifier`){let n=t;if(!e.state.has(n.name)||Q(e,t,n.name)?.scope.isProgramScope!==!0)return;let i=e.astAnalysis?.parentByNode.get(t)??null;if(i?.type===`AssignmentExpression`&&i.operator===`=`&&i.left===n)return;r.add(n.name);return}if(t.type===`MemberExpression`){let n=Gp(e,t);n!==null&&r.add(n)}}}),e.compReads.set(t,r)}}function Zp(e,t){ma(e,t.node),e.bindingTagCandidates=td(t.node),Ip(e,t),Lp(e,t),Rp(e,t),Xf(e),Rd(e),xo(e),ku(e),Cd(e,t),Hp(e),ou(e),jd(e),Mu(e),ma(e,t.node),el(e),tl(e),xl(e),Wf(e),Pc(e,t),bc(e,t,Nc),nl(e),Fl(e),Il(e),ac(e,t);for(let[t]of e.comps)Up(e,t);Xp(e),Ld(e);for(let[t]of e.comps)zl(e,t);let n=new Set([...e.listedSites.keys(),...e.linkedComponentRows.keys()]);for(let t of n){if(e.importedComponents.has(t))continue;let n=e.listedSites.get(t)??[],r=e.compPaths.get(t);if((n.length>0||e.linkedComponentRows.has(t))&&(e.comps.get(t).parents.size>0||(e.conditionalComponentSites.get(t)?.length??0)>0))throw r.buildCodeFrameError(`memo-dom: <${t}> is used both as a list row and as a static child — split it into two components (R7 L1)`)}ma(e,t.node)}function Qp(e){return e}function $p(e){return typeof e==`object`&&e&&`type`in e?e:null}function em(e,t){return $p(Qp(e)[t])}function tm(e,t){let n=Qp(e)[t];return Array.isArray(n)?n.map($p).filter(e=>e!==null):[]}function nm(e){if(e?.type!==`Identifier`)return null;let t=Qp(e).name;return typeof t==`string`?t:null}function rm(e){return S(e)}function im(e,t){return{type:`CallExpression`,callee:e,arguments:t}}function am(e,t,n){return{type:`BinaryExpression`,operator:e,left:t,right:n}}function om(e){return{type:`ReturnStatement`,argument:e}}function sm(e){return Qp(e).value}function cm(e){if(e.type===`TSAsExpression`||e.type===`TSTypeAssertion`||e.type===`TSNonNullExpression`||e.type===`TSSatisfiesExpression`||e.type===`TSInstantiationExpression`){let t=em(e,`expression`);return t!==null&&cm(t)}if(e.type===`NullLiteral`)return!0;if(e.type===`StringLiteral`||e.type===`NumericLiteral`||e.type===`BooleanLiteral`||e.type===`Literal`){let t=sm(e);return t===null||typeof t==`string`||typeof t==`number`||typeof t==`boolean`||typeof t==`bigint`}if(e.type===`UnaryExpression`&&Qp(e).operator===`-`){let t=em(e,`argument`);return t!==null&&cm(t)}if(e.type===`ObjectExpression`)return tm(e,`properties`).every(e=>{if(e.type!==`ObjectProperty`&&e.type!==`Property`||Qp(e).computed===!0)return!1;let t=em(e,`value`);return t!==null&&cm(t)});if(e.type===`ArrayExpression`){let t=Qp(e).elements;return Array.isArray(t)&&t.every(e=>{let t=$p(e);return t!==null&&cm(t)})}return!1}function lm(e,t){let n=t.identifier;for(;n!==null&&n!==t.declarationNode;){if(n.type===`VariableDeclarator`)return n;n=e.astAnalysis?.parentByNode.get(n)??null}return null}function um(e){switch(e){case`+=`:return`+`;case`-=`:return`-`;case`*=`:return`*`;case`/=`:return`/`;default:return null}}function dm(e,t,n,r){let i=Qp(e)[t];if(n===void 0)Qp(e)[t]=r;else if(Array.isArray(i))i[n]=r;else throw TypeError(`Expected array field ${e.type}.${t}`)}function fm(e,t){if(e.moduleStateCells!==!0)return;let n=t.node;ma(e,n);let r=new Map;for(let[i,a]of e.state){if(a!==`let`&&a!==`store`)continue;let o=e.stateKeys.get(i);if(o===void 0)continue;let s=Q(e,n,i);if(s===void 0)continue;let c=s.kind!==`import`;if(c){let n=lm(e,s);if(n===null)continue;let r=em(n,`init`),o=r===null?null:_a(r);if(a===`store`){if(o===null||!cm(o))throw t.buildCodeFrameError(`memo-dom: mutated store '${i}' must be initialized from a plain object/array literal to lower into request-owned state cells`)}else if(o!==null&&!cm(o))throw t.buildCodeFrameError(`memo-dom: module-state let '${i}' must be initialized from a literal to lower into request-owned state cells`);if(s.references.some(t=>e.astAnalysis?.parentByNode.get(t)?.type===`ExportSpecifier`))throw t.buildCodeFrameError(`memo-dom: cannot lower re-exported module state '${i}'`)}r.set(i,{local:i,key:o,kind:a,cellId:Y(e,`cell_${i}`).name,binding:s,owned:c})}if(r.size===0)return;for(let e of r.values()){if(e.owned)continue;let t=e.binding.declarationNode;if(t.type!==`ImportDeclaration`)continue;let n=Qp(t).specifiers;Array.isArray(n)&&(Qp(t).specifiers=n.filter(t=>{let n=$p(t);return n===null||nm(em(n,`local`))!==e.local}))}for(let t of r.values()){let n=[E(t.key)];if(t.owned){let r=lm(e,t.binding),i=r===null?null:em(r,`init`);if(i!==null){let e=rm(i);n.push(t.kind===`store`?L([],R([om(e)])):e)}}e.header.push(B(`const`,[V(T(t.cellId),im(X(e,`defineStateCell`),n))]))}let i=t=>{let n=nm(t);if(n===null)return;let i=r.get(n);if(i===void 0)return;let a=Q(e,t,n);return a===i.binding||a!==void 0&&a.declarationNode===i.binding.declarationNode||!i.owned&&a===void 0?i:void 0},a=t=>im(X(e,`readCell`),[T(t.cellId)]),o=0;C(n,{enter(e,t,n,r){if(e.type.startsWith(`TS`)){o++;return}if(e.type!==`Identifier`||t===null||n===void 0)return;let s=i(e);if(!(s===void 0||o>0)&&!(t.type===`VariableDeclarator`&&n===`id`||(t.type===`MemberExpression`||t.type===`OptionalMemberExpression`)&&n===`property`&&Qp(t).computed!==!0||t.type===`ExportSpecifier`||t.type.startsWith(`Import`)||t.type===`AssignmentExpression`&&n===`left`||t.type===`UpdateExpression`&&n===`argument`)){if((t.type===`ObjectProperty`||t.type===`Property`)&&Qp(t).shorthand===!0&&em(t,`value`)===e){Qp(t).shorthand=!1,Qp(t).value=a(s);return}(t.type!==`ObjectProperty`&&t.type!==`Property`||n!==`key`||Qp(t).computed===!0)&&dm(t,n,r,a(s))}},leave(e){e.type.startsWith(`TS`)&&o--}}),ma(e,n);let s=(t,n)=>{if(n.type===`AssignmentExpression`){let r=em(n,`right`),i=Qp(n).operator;if(i===`=`)return im(X(e,`setCell`),[T(t.cellId),rm(r)]);let a=typeof i==`string`?um(i):null;if(a===null)throw Error(`memo-dom: unsupported compound write '${String(i)}' on module state '${t.local}'`);return im(X(e,`updateCell`),[T(t.cellId),L([T(`c`)],am(a,T(`c`),rm(r)))])}let r=Qp(n).operator===`--`?`-`:`+`;return im(X(e,`updateCell`),[T(t.cellId),L([T(`c`)],am(r,T(`c`),D(1)))])};C(n,{enter(e,n,r,a){if(e.type!==`AssignmentExpression`&&e.type!==`UpdateExpression`||n===null||r===void 0)return;let o=em(e,e.type===`AssignmentExpression`?`left`:`argument`);if(o?.type!==`Identifier`)return;let c=i(o);if(c!==void 0){if(n.type!==`ExpressionStatement`)throw t.buildCodeFrameError(e.type===`AssignmentExpression`?`memo-dom: module-state write '${c.local}' must be a statement; value-producing assignments cannot lower to state cells`:`memo-dom: module-state update '${c.local}' must be a statement; its produced value cannot lower to state cells`);return dm(n,r,a,s(c,e)),!1}}}),ma(e,n)}function pm(){return{writes:new Set,structuralWrites:new Set,contentWrites:new Set,rootFallback:!1,rowLocal:!1,rowOwnerLocal:!1,instanceLocal:!1,instanceWrites:new Set,eventOrigin:null}}function mm(e,t,n=!1){e.writes.add(t),(n?e.structuralWrites:e.contentWrites).add(t)}function hm(e,t){e.instanceLocal=!0,e.instanceWrites.add(t)}function gm(e,t,n,r){let i=t.rowLocal&&r!==void 0?z(r.refreshVar===void 0?k(X(e,`markDirty`),[T(r.rowIdVar)]):k(T(r.refreshVar),[])):null,a=null;if(t.instanceLocal&&n!==null){let r=e.instanceReasonIds.get(n),i=[...t.instanceWrites].map(e=>r?.get(e)).filter(e=>e!==void 0).sort((e,t)=>e-t),o=t.instanceWrites.size>0&&i.length===t.instanceWrites.size;a=z(k(X(e,`markDirty`),[la(e,n),...o?[i.length===1?D(i[0]):xa(e,i)]:[]]))}let o=t.rowOwnerLocal&&r?.ownerIdVar!==void 0?z(k(X(e,`markDirty`),[T(r.ownerIdVar)])):null,s=e=>{let n=[];return t.eventOrigin!==null&&n.push(t.eventOrigin),i!==null&&n.push(i),o!==null&&n.push(o),a!==null&&n.push(a),e!==null&&n.push(e),n.length===0?null:n.length===1?n[0]:R(n)};if(t.rootFallback)return z(k(X(e,`markDirtySubtree`),[E(e.rootId)]));if(t.writes.size===0)return s(null);let c=(e,t)=>e===t||e.startsWith(`${t}.`)||t.startsWith(`${e}.`),l=[...t.structuralWrites].filter(e=>![...t.contentWrites].some(t=>c(e,t))),u=[...t.writes].filter(e=>!l.includes(e)),d=[];return u.length>0&&d.push(z(k(X(e,`commitWrites`),[ba(e,u.sort())]))),l.length>0&&d.push(z(k(X(e,`commitStructuralWrites`),[ba(e,l.sort())]))),s(d.length===1?d[0]:R(d))}function _m(e,t,n){if(Yr(t.body)){vm(t.body,n),t.body.body.push(n);return}let r=Y(e,`returnValue`);t.body=R([B(`const`,[V(r,t.body)]),n,ir(S(r))])}function vm(e,t){if(!Kr(e))for(let n of ht[e.type]??[]){let r=e,i=r[n];if(Array.isArray(i)){let e=i;for(let n=0;n<e.length;n++){let r=e[n];if(!r||typeof r!=`object`||!(`type`in r))continue;let i=r;Kr(i)||(Xr(i)?(e.splice(n,0,S(t)),n++):vm(i,t))}}else if(i&&typeof i==`object`&&`type`in i){let e=i;if(Kr(e))continue;Xr(e)?r[n]=R([S(t),e]):vm(e,t)}}}function ym(e,t,n,r){if(r===void 0&&n?.refreshVar!==void 0)return z(k(T(n.refreshVar),[]));let i=r??(n===void 0?t===null?E(e.rootId):la(e,t):T(n.rowIdVar));return z(k(X(e,`markDirty`),[S(i)]))}function bm(e,t,n){let r=Y(e,`event`),i=Y(e,`returnValue`);return L([r],R([B(`const`,[V(i,k(S(t),[S(r)]))]),n,ir(S(i))]))}function xm(e,t,n){if(n.key===null)return null;let r=e.componentProps.get(t);if(r===void 0)return null;let i=no(r);if(n.root===i){let[e,...t]=n.key.split(`.`).slice(1);return e===void 0?null:{name:e,path:t}}let a=io(r,n.root);return a===null?null:{name:a,path:n.key.split(`.`).slice(1)}}function Sm(e,t,n,r,i){let a=xm(e,t,r);if(a===null)return!1;n===void 0?hm(i,r.root):i.rowLocal=!0;let o=e.linkedComponentPropSources.get(t)?.get(a.name);if(o===void 0)return n?.refreshVar===void 0&&(i.rootFallback=!0),!0;i.rootFallback||=o.rootFallback;let s=a.path.length===0?``:`.${a.path.join(`.`)}`;for(let e of o.keys)mm(i,`${e}${s}`);return!0}function Cm(e){return W(e)||fi(e)||pi(e)||mi(e)||hi(e)}function wm(e){let t=e;for(;Ii(t)||Li(t)||Ri(t)||zi(t);)t=t.expression;return t}function Tm(e,t,n){if(W(t)){e.set(t.name,n);return}if(mi(t)){Cm(t.left)&&Tm(e,t.left,n);return}if(!hi(t)){if(pi(t)){for(let r=0;r<t.elements.length;r++){let i=t.elements[r];Cm(i)&&Tm(e,i,us(n,[String(r)]))}return}if(fi(t))for(let r of t.properties){if(hi(r))continue;if(r.computed||!W(r.key)&&!G(r.key)&&!Nr(r.key)){Cm(r.value)&&Tm(e,r.value,{...n,key:null});continue}let t=W(r.key)?r.key.name:String(r.key.value);Cm(r.value)&&Tm(e,r.value,us(n,[t]))}}}function Em(e,t,n,r){let i=wm(r),a=e.componentProps.get(t);if(a===void 0)return null;if(W(i)){let e=n.get(i.name);return e===void 0?no(a)===i.name?{locality:`prop`,root:i.name,key:i.name}:io(a,i.name)===null?null:{locality:`prop`,root:i.name,key:i.name}:e}if(!K(i))return null;let o=Ea(i),s=Ca(i);if(o===null)return null;let c=Em(e,t,n,T(o));return c===null?null:s===null?{...c,key:null}:us(c,s.split(`.`).slice(1))}function Dm(e,t){let n=new Map;for(let r of e.instanceDerivations.get(t)??[]){let i=Em(e,t,n,r.source);i!==null&&Tm(n,r.target,i)}return n}var Om=class extends Error{moduleId;loc;constructor(e,t,n){super(e),this.name=`MemoizedDomCompilerError`,this.moduleId=t;let r=n?.loc?.start;if(r!==void 0){let e=n?.loc?.end;this.loc={line:r.line,column:r.column,...e===void 0?{}:{endLine:e.line,endColumn:e.column}}}}};function km(e,t,n){return new Om(e,t,n)}function Am(e,t){return e.importedState.has(t)||e.importedValues.has(t)||e.importedFunctions.has(t)||e.importedComponents.has(t)}var jm=class e{analysis;moduleId;node;parentPath;shouldSkip=!1;constructor(t,n,r){this.analysis=n,this.moduleId=r,this.node=t;let i=n.parentByNode.get(t)??null;this.parentPath=i===null?null:new e(i,n,r)}get parent(){return this.parentPath?.node??null}get scope(){let e=this.analysis.nodeToScope.get(this.node);if(e===void 0)throw TypeError(`Missing handler scope for ${this.node.type}`);return e}getFunctionParent(){let e=this.parentPath;for(;e!==null;){if(Kr(e.node))return e;e=e.parentPath}return null}isExpression(){return q(this.node)}isVariableDeclarator(){return Jr(this.node)}isVariableDeclaration(){return qr(this.node)}isAssignmentExpression(e){return $r(this.node)&&(e?.operator===void 0||this.node.operator===e.operator)}replaceWith(e){jt(this.node,e)}skip(){this.shouldSkip=!0}buildCodeFrameError(e){return km(e,this.moduleId,this.node)}};function Mm(e,t,n){let r=Tt(e);return C(e,{enter(e){let i=new jm(e,r,n);return e.type===`VariableDeclarator`&&t.VariableDeclarator?.(i),Kr(e)&&t.Function?.(i),e.type===`AssignmentExpression`&&t.AssignmentExpression?.(i),e.type===`UpdateExpression`&&t.UpdateExpression?.(i),e.type===`UnaryExpression`&&t.UnaryExpression?.(i),e.type===`CallExpression`&&t.CallExpression?.(i),!i.shouldSkip&&void 0}}),r}function Nm(e,t){let n=[],r=e;for(;r=So(r),K(r);){if(n.unshift(r),Ai(r.object))return null;r=r.object}if(!W(r,{name:t.source}))return null;let i=n[0];if(i===void 0||!i.computed||!q(i.property)||!(W(i.property)||Nr(i.property)||G(i.property))||n.length<2)return null;let a=[];for(let e of n.slice(1))if(!e.computed&&W(e.property))a.push(e.property.name);else if(e.computed&&G(e.property))a.push(e.property.value);else return null;if(Ta(a,t.keyPath))return null;let o=S(i,!0);for(let e of t.keyPath)o=A(o,T(e));return o}function Pm(e,t){let n=new Set;for(let[r,i]of e.compReads)i.has(t)&&n.add(r);for(let r of e.rowReads.values())r.vars.has(t)&&n.add(`__rows__`);for(let r of e.condReads.values())r.vars.has(t)&&n.add(`__regions__`);return n}function Fm(e,t,n){if(n.sourceLocal)return!0;let r=n.sourceKey;if(r===``)return!0;for(let t of e.computeds.values())if(t.reads.has(r))return!0;let i=new Set((e.listedSites.get(t??``)??[]).map(e=>e.owner));i.size===0&&t!==null&&i.add(t);for(let t of Pm(e,r))if(t===`__rows__`||t===`__regions__`||!i.has(t))return!0;return!1}function Im(e,t,n,r,i,a,o,s,c,l,u){if(e.handlerHasRootCommit.set(t,i.has(r)),c&&!i.has(r)){let t=pm();t.eventOrigin=ym(e,o,s,l),i.set(r,t)}let d=[];if(u)for(let t of a.values()){let n=gm(e,t.writes,o,s);n!==null&&d.push({...t,commit:n})}for(let t of d)t.flag=Y(e,`didWrite`);d.sort((e,t)=>Rm(t.path)-Rm(e.path)).forEach(t=>{t.temporaries=zm(e,t.path,t.flag)});for(let[t,n]of i){let i=u&&t===r?d.length===0?null:R(d.map(e=>ar(S(e.flag),S(e.commit)))):gm(e,n,o,s);i!==null&&_m(e,t,i)}if(d.length>0){if(!Yr(n.body))throw Error(`memo-dom: execution-aware callback commit did not produce a block body`);n.body.body.unshift(B(`let`,d.flatMap(e=>[V(S(e.flag),Yn(!1)),...(e.temporaries??[]).map(e=>V(S(e)))])))}t.body=n.body}function Lm(e,t,n,r,i=!1,a,o=!1){let s=S(t),c=s,l=s,u=n===null?void 0:e.instanceState.get(n),d=n===null?void 0:e.instanceDerivedBindings.get(n),f=n===null?new Map:Dm(e,n),p=n===null?new Set:new Set(e.componentProps.get(n)?.bindings??[]),m=new Set([...p,...u??[],...d??[]]);if(n!==null)for(let t of e.compPaths.get(n)?.node.body.body??[])if(qr(t))for(let e of t.declarations)for(let{name:t}of St(e.id))m.add(t);else Ur(t)&&t.id&&m.add(t.id.name);let h=new cs((t,n)=>{if(r!==void 0&&t===r.itemParam)return{locality:`row`,root:t,key:t};if(n!==void 0&&!ss(n))return null;let i=f.get(t);if(i!==void 0)return i;if(u?.has(t)===!0)return{locality:`instance`,root:t,key:t};if(p.has(t))return{locality:`prop`,root:t,key:t};if(m.has(t))return null;if(e.transparentModuleSources.get(t)!==void 0)return ls(t,`store`);let a=e.state.get(t);return a===void 0?null:ls(t,a)}),g=t=>t.stateKind===`computed`||e.state.get(t.root)===`computed`,_=n===null?void 0:e.keyedListMutationSources.get(n),v=(e,t,n=`structural`)=>{hm(e,t);let r=_?.get(t);r!==void 0&&hm(e,n===`targeted`?r.targetedReason:r.structuralReason)},y=(e,t,n)=>{if(!e.isExpression())return;let r=S(e.node,!0);e.replaceWith(tr([k(A(T(t.keysVariable),T(`add`)),[n]),r])),e.skip()},b=new Set;for(let e of s.params)W(e)&&b.add(e.name);let ee=new Map(s.params.flatMap((e,t)=>W(e)?[[e.name,t]]:[]));Mm(l,{VariableDeclarator(e){W(e.node.id)&&(b.add(e.node.id.name),e.parentPath?.isVariableDeclaration()===!0&&h.trackDeclarator(e.scope,e.node))},Function(e){for(let t of e.node.params)W(t)&&b.add(t.name)}},e.moduleId);let te=new Map,ne=new Map,re=e=>{let t=e.getFunctionParent()?.node??c,n=te.get(t);return n||te.set(t,n=pm()),n},x=(e,t)=>{if(t(re(e)),!o||e.getFunctionParent()?.node!==c)return;let n=ne.get(e.node);n===void 0&&(n={path:e,writes:pm()},ne.set(e.node,n)),t(n.writes)},ie=e=>{x(e,e=>{r?.sourceLocal?e.rowOwnerLocal=!0:r!==void 0&&mm(e,r.sourceKey)})},ae=e=>{if(r===void 0)return null;let t=e.split(`.`).slice(1);return r.itemPath.some((e,n)=>t[n]!==e)?null:t.slice(r.itemPath.length)},oe=(t,i)=>{x(t,t=>{i!==void 0&&n!==null&&Sm(e,n,r,i,t)||(t.rowLocal=!0,t.rootFallback=!0)})},se=(t,i)=>{x(t,t=>{(n===null||!Sm(e,n,r,i,t))&&(r===void 0?(n!==null&&hm(t,i.root),t.rootFallback=!0):(t.rowLocal=!0,t.rootFallback=!0))})},ce=(t,i)=>{if(r===void 0||Ea(i)!==r.itemParam)return!1;let a=Ca(i);if(a===null)return r.itemPath.length===0?ie(t):oe(t),!0;let o=a.split(`.`).slice(1);return!r.itemPath.some((e,t)=>o[t]!==e)&&(o.splice(0,r.itemPath.length),Ta(o,r.keyPath)?ie(t):(x(t,e=>{e.rowLocal=!0}),Fm(e,n,r)&&ie(t)),!0)},le=(t,i)=>{if(i.locality===`instance`){x(t,e=>{v(e,i.root)});return}if(i.locality===`row`){if(r===void 0){x(t,e=>{e.rootFallback=!0});return}if(i.key===null){r.itemPath.length===0?ie(t):oe(t);return}let a=ae(i.key);if(a===null){oe(t,i);return}Ta(a,r.keyPath)?ie(t):(x(t,e=>{e.rowLocal=!0}),Fm(e,n,r)&&ie(t));return}if(i.locality===`prop`){se(t,i);return}if(i.stateKind===`computed`)throw t.buildCodeFrameError(`memo-dom: cannot mutate computed '${i.root}' (R13) - it is derived; write its SOURCE state instead`);if(i.stateKind!==`store`){x(t,e=>{mm(e,i.root)});return}i.key!==null&&i.key.includes(`.`)?x(t,e=>{mm(e,i.key)}):x(t,e=>{mm(e,i.root)})},ue=(t,n)=>{if(n.locality===`instance`){x(t,e=>{v(e,n.root)});return}if(n.locality===`row`){if(r===void 0){x(t,e=>{e.rootFallback=!0});return}if(n.key===null){r.itemPath.length===0?ie(t):oe(t);return}let e=ae(n.key);if(e===null){oe(t,n);return}e.length===0&&(r.keyPath===null||r.keyPath.length>0)?ie(t):le(t,n);return}if(n.locality===`prop`){se(t,n);return}if(n.stateKind===`computed`){x(t,e=>{mm(e,n.root)});return}x(t,t=>{let r=n.key??n.root;mm(t,r,e.listSources.has(r))})},de=(e,t)=>{if(!(o&&e.getFunctionParent()?.node===c))for(let n of fs(t)){if(!W(n))continue;let t=h.resolveExpression(e.scope,n);t!==null&&(g(t)||ue(e,t))}},fe=(i,a)=>{let o=Ea(a);if(o!==null&&Fo(e,o,n))throw i.buildCodeFrameError(`memo-dom: cannot mutate '${o}' - it is derived from a static source and will never change`);if(o!==void 0&&u?.has(o??``)===!0){let e=_?.get(o),t=e===void 0?null:Nm(a,e);x(i,e=>{v(e,o,t===null?`structural`:`targeted`)}),e!==void 0&&t!==null&&y(i,e,t);return}let s=W(a.object)?a.object.name:K(a.object)?Ca(a.object):null;if(s!==null&&e.listSources.has(s)){x(i,e=>{mm(e,s,!0)});return}if(o!==null&&d?.has(o)&&!f.has(o))throw i.buildCodeFrameError(`memo-dom: cannot mutate per-instance derivation '${o}' (R14) — write its source instead`);if(ce(i,a))return;if(r===void 0&&o!==null&&ee.has(o)){let n=Ca(a);if(n!==null){let r=n.split(`.`).slice(1),i=e.localParamEffects.get(t)??[],a={index:ee.get(o),path:r};i.some(e=>e.index===a.index&&e.path.join(`.`)===a.path.join(`.`))||(i.push(a),e.localParamEffects.set(t,i))}x(i,e=>{e.rootFallback=!0});return}let c=h.resolveExpression(i.scope,a);if(c!==null){le(i,c);return}if(o!==null&&p.has(o)){se(i,{locality:`prop`,root:o,key:Ca(a)});return}if(o!==null&&m.has(o)||!o||!e.state.has(o))return;let l=e.state.get(o);if(l===`computed`)throw i.buildCodeFrameError(`memo-dom: cannot mutate computed '${o}' (R13) — it is derived; write its SOURCE state instead`);x(i,e=>{if(l!==`store`){mm(e,o);return}let t=Ca(a);t!==null&&t.includes(`.`)?mm(e,t):mm(e,o)})};Mm(l,{VariableDeclarator(e){if(!W(e.node.id)&&e.node.init!==null)for(let t of h.referencedOrigins(e.scope,e.node.init))ue(e,t)},AssignmentExpression(t){let r=t.node.left;if(W(r)){if(b.has(r.name)){if(W(t.node.right)){let e=h.resolveExpression(t.scope,t.node.right);e!==null&&ue(t,e)}return}if(Fo(e,r.name,n))throw t.buildCodeFrameError(`memo-dom: cannot reassign '${r.name}' - it is derived from a static source and will never change`);if(d?.has(r.name))throw t.buildCodeFrameError(`memo-dom: cannot assign per-instance derivation '${r.name}' (R14) — write its source instead`);if(u?.has(r.name)===!0){x(t,e=>{v(e,r.name)});return}if(p.has(r.name))throw t.buildCodeFrameError(`memo-dom: cannot assign prop '${r.name}' — copy it to component-local let state first`);if(m.has(r.name))throw t.buildCodeFrameError(`memo-dom: cannot assign component-local const '${r.name}'`);if(t.scope.getBinding(r.name)?.kind===`import`||Am(e,r.name))throw t.buildCodeFrameError(`memo-dom: cannot reassign imported state '${r.name}' - ES module imports are read-only; export a mutator instead`);let i=e.state.get(r.name);if(!i)throw t.buildCodeFrameError(`memo-dom: handler assigns '${r.name}', which is neither module state nor a handler local — declare it at module level (let) or inside the handler`);if(e.importedState.has(r.name))throw t.buildCodeFrameError(`memo-dom: cannot reassign imported state '${r.name}' - ES module imports are read-only; export a mutator or mutate an imported store property`);if(i===`store`)throw t.buildCodeFrameError(`memo-dom: cannot reassign store '${r.name}' — assign a property (${r.name}.field = …) instead`);if(i===`const`)throw t.buildCodeFrameError(`memo-dom: cannot reassign mutable const root '${r.name}' - mutate the object instead`);if(i===`computed`)throw t.buildCodeFrameError(`memo-dom: cannot assign computed '${r.name}' (R13) — it is derived; write its SOURCE state instead and the derivation recomputes`);x(t,t=>{mm(t,r.name,e.listSources.has(r.name))})}else if(K(r))fe(t,r);else for(let e of h.referencedOrigins(t.scope,t.node.right))ue(t,e)},UpdateExpression(t){let r=t.node.argument;if(W(r)){if(b.has(r.name))return;if(Fo(e,r.name,n))throw t.buildCodeFrameError(`memo-dom: cannot update '${r.name}' - it is derived from a static source and will never change`);if(d?.has(r.name))throw t.buildCodeFrameError(`memo-dom: cannot update per-instance derivation '${r.name}' (R14) — write its source instead`);if(u?.has(r.name)===!0){x(t,e=>{v(e,r.name)});return}if(p.has(r.name))throw t.buildCodeFrameError(`memo-dom: cannot update prop '${r.name}' — copy it to component-local let state first`);if(m.has(r.name))throw t.buildCodeFrameError(`memo-dom: cannot update component-local const '${r.name}'`);if(t.scope.getBinding(r.name)?.kind===`import`||Am(e,r.name))throw t.buildCodeFrameError(`memo-dom: cannot update imported state '${r.name}' - ES module imports are read-only; call an exported mutator instead`);let i=e.state.get(r.name);if(!i)throw t.buildCodeFrameError(`memo-dom: handler updates '${r.name}', which is neither module state nor a handler local`);if(e.importedState.has(r.name))throw t.buildCodeFrameError(`memo-dom: cannot update imported state '${r.name}' - ES module imports are read-only; call an exported mutator instead`);if(i!==`let`)throw t.buildCodeFrameError(i===`computed`?`memo-dom: cannot update computed '${r.name}' (R13) — it is derived; write its SOURCE state instead`:`memo-dom: cannot update '${r.name}' — it is a const binding; mutate its contents instead`);x(t,e=>{mm(e,r.name)})}else K(r)&&fe(t,r)},UnaryExpression(e){e.node.operator===`delete`&&K(e.node.argument)&&fe(e,e.node.argument)},CallExpression(i){let a=i.node.callee;if(K(a)){let t=Ea(a);if(t!==null&&Fo(e,t,n))throw i.buildCodeFrameError(`memo-dom: cannot mutate '${t}' - it is derived from a static source and will never change`)}if(K(a)){if(ps(a)===`assign`&&W(a.object,{name:`Object`})){let e=i.node.arguments[0],t=e!==void 0&&q(e)?h.resolveExpression(i.scope,e):null;if(t!==null){if(t.locality===`module`&&t.stateKind===`store`){let e=ds(t,i.node.arguments.slice(1));e===null?ue(i,t):x(i,t=>{for(let n of e)mm(t,n)})}else le(i,t)}return}let n=W(a.object)?a.object.name:K(a.object)?Ea(a.object):null;if(n!==null&&d?.has(n)&&!f.has(n)){x(i,e=>{v(e,n)});return}if(r===void 0&&n!==null&&ee.has(n)){let r=K(a.object)?Ca(a.object):null,o=r===null?[]:r.split(`.`).slice(1),s=e.localParamEffects.get(t)??[],c={index:ee.get(n),path:o},l=`${c.index}:${c.path.join(`.`)}`;s.some(e=>`${e.index}:${e.path.join(`.`)}`===l)||(s.push(c),e.localParamEffects.set(t,s)),x(i,e=>{e.rootFallback=!0});return}let o=q(a.object)?h.resolveExpression(i.scope,a.object):null;o===null?de(i,i.node.arguments):ue(i,o);return}if(W(a)&&n!==null&&m.has(a.name)){let r=null;for(let t of e.compPaths.get(n)?.node.body.body??[]){if(Ur(t)&&t.id?.name===a.name){r=t;break}if(qr(t)){for(let e of t.declarations)if(W(e.id)&&e.id.name===a.name&&e.init!==null&&Kr(e.init)){r=e.init;break}if(r!==null)break}}let o=r===null?void 0:e.localParamEffects.get(r);if(o!==void 0)for(let n of o){let r=i.node.arguments[n.index];if(r===void 0||!q(r))continue;let a=h.resolveExpression(i.scope,r);if(a!==null){if(g(a))continue;ue(i,us(a,n.path));continue}if(W(r)&&ee.has(r.name)){let i=e.localParamEffects.get(t)??[],a={index:ee.get(r.name),path:n.path},o=`${a.index}:${a.path.join(`.`)}`;i.some(e=>`${e.index}:${e.path.join(`.`)}`===o)||(i.push(a),e.localParamEffects.set(t,i))}}}if(W(a)&&!m.has(a.name)&&(e.helpers.has(a.name)||e.importedFunctions.has(a.name))){let t=e.importedFunctions.get(a.name)??ws(e,a.name);x(i,e=>{for(let n of t.writes)mm(e,n);for(let n of t.boundedWrites)mm(e,n);let n=o&&i.getFunctionParent()?.node===c;t.unbounded&&!n&&(e.rootFallback=!0)});for(let e of t.parameterWrites){let t=i.node.arguments[e.index];if(t===void 0||!q(t))continue;let n=h.resolveExpression(i.scope,t);if(n!==null){if(g(n))continue;ue(i,us(n,e.path))}}return}de(i,i.node.arguments)}},e.moduleId),Im(e,t,s,c,te,ne,n,r,i,a,o)}function Rm(e){let t=0,n=e;for(;n.parentPath!==null;)t++,n=n.parentPath;return t}function zm(e,t,n){if(t.isAssignmentExpression({operator:`=`})&&(W(t.node.left)||K(t.node.left)&&!Ai(t.node.left.object)&&!ji(t.node.left.property))){let r=t.node,i=Y(e,`previousValue`),a=Y(e,`assignedValue`),o=[i,a],s,c,l;if(W(r.left))s=T(r.left.name),c=S(r,!0),l=T(r.left.name);else if(K(r.left)){let t=Y(e,`assignmentReceiver`),n=Y(e,`assignmentProperty`);o.push(t,n);let i=()=>A(S(t),S(n),!0),a=r.left.computed?S(r.left.property,!0):E(r.left.property.name);s=tr([F(`=`,S(t),S(r.left.object,!0)),F(`=`,S(n),a),i()]),c=F(`=`,i(),S(r.right,!0)),l=i()}else return[];return t.replaceWith(tr([F(`=`,S(i),s),F(`=`,S(a),c),F(`=`,S(n),P(`||`,S(n),k(X(e,`effectAssignmentChanged`),[S(i),l]))),S(a)])),o}let r=F(`=`,S(n),Yn(!0));if(t.isVariableDeclarator()){let e=t.node.init;if(e===null||!q(e))throw Error(`memo-dom: execution-aware variable site has no expression initializer`);return t.node.init=tr([r,e]),[]}if(!t.isExpression())throw Error(`memo-dom: unsupported execution-aware write site '${t.node.type}'`);return t.replaceWith(tr([r,S(t.node,!0)])),[]}const Bm=new Set([`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`,`ObjectMethod`,`ClassMethod`,`ClassPrivateMethod`]);function Vm(e){return e}function Hm(e){if(typeof e!=`object`||!e||e.type!==`Identifier`)return null;let t=e.name;return typeof t==`string`?t:null}function Um(e,t){let n=!1,r=!0;return C(e,{enter(i){if(!r||i!==e&&Bm.has(i.type))return!1;if(i.type!==`CallExpression`&&i.type!==`OptionalCallExpression`)return;n=!0;let a=Hm(Vm(i).callee);if(a===null||!t(a))return r=!1,!1}}),n&&r}function Wm(e,t){let n=t.identifier;for(;n!==null&&n!==t.declarationNode;){if(n.type===`VariableDeclarator`)return n;n=e.astAnalysis?.parentByNode.get(n)??null}return null}function Gm(e,t,n){let r=Q(e,t.node,n);if(r===void 0||r.scope.getFunctionScope()?.block!==t.node)return null;if(r.kind===`function`&&r.declarationNode.type===`FunctionDeclaration`)return r.declarationNode;let i=Wm(e,r);if(i===null)return null;let a=i.init;return a&&(Gr(a)||Wr(a))?a:null}function Km(e,t,n,r,i,a=!1){e.analyzedFunctions.has(n)||(Jm(e,t,n,r,i),e.analyzedFunctions.add(n),Lm(e,n,r,i,!1,void 0,a))}function qm(e,t,n=!1){e.analyzedFunctions.has(t)||(e.analyzedFunctions.add(t),Lm(e,t,null,void 0,!1,void 0,n))}function Jm(e,t,n,r,i){let a=new Set;Ma(n.body,e=>{Lr(e)&&W(e.callee)&&a.add(e.callee.name)});for(let n of a){let a=Gm(e,t,n);a===null||e.analyzedFunctions.has(a)||(e.analyzedFunctions.add(a),Jm(e,t,a,r,i),Lm(e,a,r,i?.refreshVar===void 0?void 0:i,!1))}}function Ym(e,t,n,r,i,a,o){let s=null,c=!1,l=e.componentProps.get(i),u=l===void 0?null:no(l);if(l!==void 0&&(W(n)&&io(l,n.name)!==null||K(n)&&u!==null&&Ea(n)===u))return bm(e,n,ym(e,i,a,o));if(Gr(n)||Wr(n))s=n;else if(W(n)){let r=e.importedFunctions.get(n.name);if(r!==void 0){let t=pm();for(let e of r.writes)mm(t,e);for(let e of r.boundedWrites)mm(t,e);return t.rootFallback=r.unbounded,bm(e,n,gm(e,t,null)??ym(e,i,a,o))}let l=Q(e,t.node,n.name),u=l===void 0?null:Wm(e,l);if(u!==null){let t=u.init;t&&(Gr(t)||Wr(t))&&(s=t,c=l?.scope.isProgramScope===!0&&e.helpers.has(n.name))}else l?.declarationNode.type===`FunctionDeclaration`&&(e.helpers.has(n.name)?(s=l.declarationNode,c=!0):s=Gm(e,t,n.name));if(!s)throw t.buildCodeFrameError(`memo-dom: cannot resolve handler '${n.name}' — use an inline arrow, a component-local const, or a module-level function (L1)`)}else throw t.buildCodeFrameError(`memo-dom: unsupported ${r} handler form — expected an arrow function or a function reference (L1)`);if(Yr(s.body)||(s.body=R([z(s.body)])),!e.analyzedFunctions.has(s)){c||Jm(e,t,s,i,a);let r=!c&&!W(n)&&Um(s,n=>{let r=Gm(e,t,n);return r!==null&&e.handlerHasRootCommit.get(r)===!0});e.analyzedFunctions.add(s);let l=W(n)&&!c&&a?.refreshVar===void 0;Lm(e,s,c?null:i,l?void 0:a,!c&&!W(n)&&!r,o)}if(c){let t=ws(e,n.name);if(s.async){let r=pm();for(let e of t.writes)mm(r,e);for(let e of t.boundedWrites)mm(r,e);return r.rootFallback=t.unbounded,bm(e,n,gm(e,r,null)??ym(e,i,a,o))}if(t.writes.size===0&&t.boundedWrites.size===0&&!t.unbounded)return bm(e,n,ym(e,i,a,o))}return W(n)&&!c&&(e.handlerHasRootCommit.get(s)===!1||s.async)?bm(e,n,ym(e,i,a,o)):W(n)?n:s}function Xm(e){if(e.length===1)return e[0];let t=[];for(let n of e){let e=t[t.length-1];e&&G(e)&&G(n)?t[t.length-1]=E(e.value+n.value):t.push(n)}if(t.length===1)return t[0];let n=t.some(e=>G(e))?t[0]:N(`+`,E(``),t[0]);for(let e=1;e<t.length;e++)n=N(`+`,n,t[e]);return n}function Zm(e,t){let n=[],r=[],i=()=>{if(r.length===0)return;let e=Xm(r);r=[],n.push({type:`node`,variable:t.emitText(e)})};for(let a of e){if(li(a)){let e=Ps(a.value);e!==``&&r.push(E(e));continue}if(ii(a)||ai(a)){i(),n.push({type:`node`,variable:t.emitNode(a)});continue}if(ci(a)||t.fail(`memo-dom: spread children are not supported`),ui(a.expression))continue;q(a.expression)||t.fail(`memo-dom: unsupported expression in JSX child position`);let e=a.expression;if(t.isForwarded(e)){i(),n.push({type:`slot`,expression:S(e)});continue}if(Fr(e)||Pr(e)||W(e,{name:`undefined`}))continue;let o=Lo(e);if(o!==null){i(),n.push({type:`list`,expression:o});continue}let s=rs(e);if(s!==null&&Na(s)){i(),n.push({type:`condition`,expression:s});continue}r.push(S(e))}return i(),n}const Qm=new Set([`innerHTML`,`checked`,`value`,`selected`,`disabled`,`hidden`,`multiple`,`required`,`readOnly`,`muted`,`open`,`controls`,`loop`,`autoFocus`,`autoPlay`,`tabIndex`]),$m={htmlFor:`for`,crossOrigin:`crossorigin`};function eh(e,t){return!t&&Qm.has(e)?e:null}function th(e,t){return!t&&e in $m}function nh(e,t,n){let r=T(e);if(t===`tabIndex`)return G(n)?z(F(`=`,A(r,T(t)),S(n))):z(I(N(`==`,S(n),O()),k(A(S(r),T(`removeAttribute`)),[E(`tabindex`)]),F(`=`,A(S(r),T(t)),S(n))));let i=t===`value`||t===`innerHTML`?E(``):Yn(!1),a=G(n)?S(n):I(N(`==`,S(n),O()),i,S(n));return z(F(`=`,A(r,T(t)),a))}function rh(e,t,n){let r=T(e),i=$m[t]??t;return G(n)?z(k(A(r,T(`setAttribute`)),[E(i),S(n)])):z(I(P(`||`,N(`==`,S(n),O()),N(`===`,S(n),Yn(!1))),k(A(S(r),T(`removeAttribute`)),[E(i)]),k(A(r,T(`setAttribute`)),[E(i),I(N(`===`,S(n),Yn(!0)),E(``),k(T(`String`),[S(n)]))])))}const ih=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`.split(`.`));function ah(e,t){return t||e===`svg`||ih.has(e)}function oh(e,t,n){return n?k(A(S(e),T(`createElementNS`)),[E(`http://www.w3.org/2000/svg`),E(t)]):k(A(S(e),T(`createElement`)),[E(t)])}function sh(e){return(Gr(e)||Wr(e))&&!uh(e.body)}function ch(e,t,n,r=`callback`){let i=Y(e,r);return t.creation.push(B(`const`,[V(S(i),S(n,!0))])),i}function lh(e,t,n,r=`callback`){let i=Y(e,r);return t.push(B(`const`,[V(S(i),S(n,!0))])),i}function uh(e){let t=!1;return C(e,{enter(e){if(t)return!1;if(ii(e)||ai(e))return t=!0,!1}}),t}function dh(e,t,n,r,i,a,o,s=!1,c=la(e,i),l=!1){let u=os(n,a,t.usedConds),d=Y(e,u.suffix).name,f=N(`+`,S(c),E(`/${u.suffix}`)),p=gf(e,n),m=L([],S(u.pickExpr)),h=u.branches.map(n=>n===null?O():fh(e,n,i,a,f,o,s,f,!1,t.usedConds,p));t.creation.push(Ns(e,S(f),S(c),L([],k(A(T(d),T(`update`)),[])))),bf(e,t,n,f),t.creation.push(B(`const`,[V(T(d),k(X(e,`createCondRegion`),[T(r),S(f),m,j(h)]))])),(l||e.volatileComponents.has(i)||ja(e,n,i))&&t.updaters.push(()=>z(k(A(T(d),T(`update`)),[]))),t.disposableRegions.push(d),t.disposableEntities.push(S(f))}function fh(e,t,n,r,i,a,o=!1,s=i,c=!1,l,u=[]){let d=Es(e,!0);for(let e of u)d.coveredTransparentSources.add(e);l!==void 0&&(d.usedConds=l);let f=a(e,d,t,n,r,c?null:`cond`,void 0,i,o,s),p=[M(T(`nodes`),k(X(e,`rootNodes`),[T(f)])),M(T(`update`),T(d.updateVar))];if(d.disposableRegions.length>0||d.disposableEntities.length>0||d.disposableCallbacks.length>0){let t=[...[...d.disposableCallbacks].reverse().map(e=>ar(N(`!==`,S(e),O()),z(k(S(e),[])))),...d.disposableRegions.map(e=>z(k(A(T(e),T(`dispose`)),[]))),...d.disposableEntities.map(t=>z(k(X(e,`unregisterSubtree`),[S(t)])))];p.push(M(T(`dispose`),L([],R(t))))}return L([],R([Os(d),...d.prelude,Ms(d),...d.creation,...d.mounts,ir(Zn(p))]))}function ph(e,t,n,r){return Br(r)?j(r.elements.map(r=>{if(r===null)return null;if(gi(r))throw t.buildCodeFrameError(`memo-dom: ref arrays must have a static shape; nested arrays are supported but array spreads are not`);return ph(e,t,n,r)})):hh(e,n,r)?S(r,!0):gh(e,t,r)||K(r)?_h(e,r):S(r,!0)}function mh(e,t,n,r,i){let a=Y(e,`refDispose`);t.mounts.push(B(`const`,[V(S(a),k(X(e,`mountRef`),[S(n,!0),S(i,!0)]))])),t.manualDisposal?t.disposableCallbacks.push(a):t.mounts.push(z(k(X(e,`cleanup`),[S(r,!0),S(a)])))}function hh(e,t,n){let r=Is(e,t,n);return r!==null&&e.componentProps.get(t)?.refProps.includes(r)===!0}function gh(e,t,n){if(!W(n)||n.name===`undefined`)return!1;let r=Q(e,t.node,n.name);if(r===void 0||r.declarationNode.type===`FunctionDeclaration`||r.declarationNode.type===`ImportDeclaration`||r.kind===`const`)return!1;let i=e.astAnalysis?.parentByNode.get(r.identifier);if(i?.type===`VariableDeclarator`){let e=i.init;if(e?.type===`FunctionExpression`||e?.type===`ArrowFunctionExpression`)return!1}return r.kind!==`param`}function _h(e,t){let n=Y(e,`refNode`);if(K(t)){let r=Y(e,`refTarget`),i=t.computed?Y(e,`refKey`):null,a=()=>A(S(r),i===null?S(t.property,!0):S(i),t.computed);return L([S(n)],R([B(`const`,[V(S(r),S(t.object,!0)),...i===null?[]:[V(S(i),S(t.property,!0))]]),z(F(`=`,a(),S(n))),ir(L([],R([ar(N(`===`,a(),S(n)),z(F(`=`,a(),T(`undefined`))))])))]))}return L([S(n)],R([z(F(`=`,S(t,!0),S(n))),ir(L([],R([ar(N(`===`,S(t,!0),S(n)),z(F(`=`,S(t,!0),T(`undefined`))))])))]))}const vh=new Set([`setClassValue`,`setStyleValue`,`setDomValue`]);function yh(e,t,n){if(t.mounts.length!==0||t.disposableRegions.length!==0||t.disposableEntities.length!==0||t.disposableCallbacks.length!==0||t.documentVar===null)return!1;let r=[],i=new Set;for(let e of t.creation){if(!qr(e))continue;let n=xh(e,t.documentVar);if(n===null)return!1;r.push(n),i.add(n.name)}if(!i.has(n)||r.length<2)return!1;let a=new Map,o=new Map;for(let e of t.creation){let t=Sh(e);if(t===null)continue;if(!i.has(t.parent)||!i.has(t.child))return!1;let n=o.get(t.parent)??0;o.set(t.parent,n+1),a.set(t.child,{parent:t.parent,index:n})}let s=new Map;for(let e of i){let t=Ch(e,n,a);if(t===null)return!1;s.set(e,t)}let c=[],l=[];for(let e of t.creation)qr(e)||Th(e,i)?c.push(S(e,!0)):l.push(e);let u=Y(e,`${n}Template`),d=Y(e,`${n}TemplateDocument`),f=Y(e,`${n}CreateTemplate`);e.header.push(B(`let`,[V(S(u)),V(S(d))]),rr(S(f),[T(t.documentVar)],R([...c,ir(T(n))])));let p=k(S(f),[T(t.documentVar)]),m=k(X(e,`canReuseTemplate`),[]),h=I(P(`&&`,S(m),P(`||`,N(`===`,S(u),er(`void`,D(0))),N(`!==`,S(d),T(t.documentVar)))),tr([F(`=`,S(d),T(t.documentVar)),F(`=`,S(u),p)]),I(S(m),S(u),p)),g=I(S(m),k(A(h,T(`cloneNode`)),[Yn(!0)]),h),_=new Set([n]);for(let e of l)Ma(e,e=>{W(e)&&i.has(e.name)&&_.add(e.name)});let v=[];return t.creation=[...r.filter(({name:e})=>_.has(e)).sort((e,t)=>s.get(e.name).length-s.get(t.name).length).map(({name:e})=>{let t=s.get(e),r;if(e===n)r=S(g,!0);else{let e=v[0];for(let n of v)n.path.length>e.path.length&&bh(n.path,t)&&(e=n);r=wh(e.name,t.slice(e.path.length))}return v.push({name:e,path:t}),B(`const`,[V(T(e),r)])}),...l],!0}function bh(e,t){return e.length<=t.length&&e.every((e,n)=>t[n]===e)}function xh(e,t){if(e.declarations.length!==1)return null;let n=e.declarations[0];if(!W(n.id)||!Lr(n.init)||!K(n.init.callee)||!W(n.init.callee.object,{name:t})||!W(n.init.callee.property))return null;let r=n.init.callee.property.name;if(r!==`createElement`&&r!==`createElementNS`&&r!==`createTextNode`)return null;let i=n.init.arguments.at(-1);return(r===`createElement`||r===`createElementNS`)&&G(i)&&i.value.includes(`-`)?null:{name:n.id.name,statement:e}}function Sh(e){return!Qr(e)||!Lr(e.expression)||!K(e.expression.callee)||!W(e.expression.callee.object)||!W(e.expression.callee.property,{name:`appendChild`})||e.expression.arguments.length!==1||!W(e.expression.arguments[0])?null:{parent:e.expression.callee.object.name,child:e.expression.arguments[0].name}}function Ch(e,t,n){if(e===t)return[];let r=[],i=new Set,a=e;for(;a!==t;){if(i.has(a))return null;i.add(a);let e=n.get(a);if(e===void 0)return null;r.push(e.index),a=e.parent}return r.reverse(),r}function wh(e,t){let n=T(e);for(let e of t){n=A(n,T(`firstChild`));for(let t=0;t<e;t++)n=A(n,T(`nextSibling`))}return n}function Th(e,t){let n=Sh(e);if(n!==null)return t.has(n.parent)&&t.has(n.child);if(!Qr(e))return!1;let r=e.expression;return!!(Lr(r)&&K(r.callee)&&(W(r.callee.object)&&t.has(r.callee.object.name)&&W(r.callee.property,{name:`setAttribute`})&&r.arguments.every(e=>q(e)&&Eh(e))||W(r.callee.object)&&W(r.callee.property)&&vh.has(r.callee.property.name)&&r.arguments.length>=2&&W(r.arguments[0])&&t.has(r.arguments[0].name)&&r.arguments.slice(1).every(e=>q(e)&&Eh(e))))}function Eh(e){return G(e)||Nr(e)||Pr(e)||Fr(e)?!0:Br(e)?e.elements.every(e=>e===null||q(e)&&Eh(e)):Vr(e)?e.properties.every(e=>Hr(e)&&!e.computed&&q(e.value)&&Eh(e.value)):!1}function Dh(e,t){let n=S(e);return t?P(`??`,n,j([])):n}function Oh(e,t,n,r,i,a,o,s,c=!1,l=la(e,i),u){let d=zo(e,n,a,i,t.usedPrefixes,u===void 0?void 0:{itemParam:u.itemParam,sourceKey:u.sourceKey,sourceLocal:u.sourceLocal??!1}),f=Y(e,`region${t.regionCounter++}`).name,p=new Map,m=d.form===`inline`?Ud(d.jsx):d.form===`component`&&Hl(e,d.rowComp)?e.importedComponents.get(d.rowComp)?.delegatedEvents??e.componentHostEvents.get(d.rowComp)??[]:[];for(let n of m){let i=Y(e,`${n}Binding`);p.set(n,i),t.creation.push(B(`const`,[V(S(i),k(X(e,`createDelegatedEventBinding`),[T(r),E(n)]))]))}let h=d.form===`callback`?Mh(e,d):d.form===`component`?Ph(e,d,i,a,s,c,l,p):Fh(e,d,i,a,o,c,l,p),g=[T(r),N(`+`,S(l),E(`/${d.suffix}`)),h];if(d.form===`callback`){let e=A(S(d.renderCallback,!0),T(`key`));g.push(L([S(d.itemPattern,!0),...d.indexParam===null?[]:[T(d.indexParam)]],I(N(`==`,S(e),O()),S(d.itemPattern,!0),k(S(e),[S(d.itemPattern,!0),...d.indexParam===null?[]:[T(d.indexParam)]]))))}else d.keyExpr!==null&&g.push(L([S(d.itemPattern,!0),...d.indexParam===null?[]:[T(d.indexParam)]],S(d.keyExpr)));d.form===`component`&&Hl(e,d.rowComp)&&(g.length===3&&g.push(T(`undefined`)),g.push(Yn(!1))),g.length===3&&g.push(T(`undefined`)),g.length===4&&g.push(Yn(!0)),g.push(Yn(d.indexParam!==null)),t.creation.push(B(`const`,[V(T(f),k(X(e,`createListRegion`),g))])),t.disposableRegions.push(f);let _=e.targetedListDependencies.get(n)??[],v=e.keyedListMutations.get(n);v!==void 0&&t.creation.push(B(`const`,[V(T(v.keysVariable),$n(T(`Set`),[]))]));let y=_.map(t=>({dependency:t,cache:Y(e,`${t.value}ListKey`).name})),b=d.sourceLocal?``:ya(e,d.sourceKey);y.length>0&&t.creation.push(B(`let`,y.map(({dependency:e,cache:t})=>V(T(t),T(e.value)))));let ee=(n=!1)=>z(k(A(T(f),T(`reconcile`)),[Dh(d.sourceExpr,d.optional),...n&&t.reasonVar!==null?[k(X(e,`isStructuralListUpdate`),[T(t.reasonVar),E(b)])]:[]]));t.creation.push(ee()),y.length===0&&v===void 0||t.reasonVar===null?t.updaters.push(()=>ee(!0)):t.updaters.push(()=>jh(e,i,t.reasonVar,f,d.sourceExpr,d.optional,y,v,b))}function kh(e,t){let n=()=>T(e),r=()=>t<0?er(`-`,D(-t),!0):D(t);return P(`||`,N(`===`,n(),r()),P(`&&`,N(`!==`,n(),O()),P(`&&`,N(`!==`,er(`typeof`,n()),E(`number`)),k(A(n(),T(`has`)),[r()]))))}function Ah(e,t){return z(k(A(T(e),T(`refreshKey`)),[t]))}function jh(e,t,n,r,i,a,o,s,c){let l=e.instanceReasonIds.get(t);if(l===void 0)return z(k(A(T(r),T(`reconcile`)),[Dh(i,a),k(X(e,`isStructuralListUpdate`),[T(n),E(c)])]));let u=s?.source??o[0]?.dependency.source,d=u===void 0?void 0:l.get(u);if(d===void 0)return z(k(A(T(r),T(`reconcile`)),[Dh(i,a),k(X(e,`isStructuralListUpdate`),[T(n),E(c)])]));let f=[z(k(A(T(r),T(`reconcile`)),[Dh(i,a),k(X(e,`isStructuralListUpdate`),[T(n),E(c)])])),...o.map(({dependency:e,cache:t})=>z(F(`=`,T(t),T(e.value)))),...s===void 0?[]:[z(k(A(T(s.keysVariable),T(`clear`)),[]))]],p=[];if(s!==void 0){let t=l.get(s.targetedReason);if(t!==void 0){let i=Y(e,`changedListKey`);p.push(ar(kh(n,t),R([or(B(`const`,[V(S(i))]),T(s.keysVariable),R([Ah(r,S(i))])),z(k(A(T(s.keysVariable),T(`clear`)),[]))])))}}for(let{dependency:t,cache:i}of o){let a=l.get(t.value);if(a===void 0)continue;let o=Y(e,`previousListKey`);p.push(ar(kh(n,a),R([B(`const`,[V(o,T(i))]),z(F(`=`,T(i),T(t.value))),Ah(r,S(o)),ar(er(`!`,k(A(T(`Object`),T(`is`)),[S(o),T(i)])),Ah(r,T(i)))])))}let m=N(`===`,T(n),O());if(m=P(`||`,m,kh(n,-1)),s!==void 0){let e=l.get(s.structuralReason),t=l.get(s.targetedReason);e!==void 0&&(m=P(`||`,m,kh(n,e))),m=P(`||`,m,t===void 0?kh(n,d):P(`&&`,kh(n,d),er(`!`,kh(n,t))))}else m=P(`||`,m,kh(n,d));return ar(m,R(f),p.length===0?void 0:R(p))}function Mh(e,t){let n=Y(e,`renderRowId`);return L([S(t.itemPattern,!0),S(n),...t.indexParam===null?[]:[T(t.indexParam)]],k(A(S(t.renderCallback,!0),T(`create`)),[S(t.itemPattern,!0),S(n),...t.indexParam===null?[]:[T(t.indexParam)]]))}function Nh({ctx:e,site:t,rowComponent:n,rowId:r,nextItem:i,nextIndex:a,rowRefresh:o,rowScope:s,result:c,lightweight:l,needsUpdateProps:u,reuseLightweightEntry:d,lightweightPushProps:f,ownerId:p,eventBindings:m,prefixStatements:h,callProps:g,updateStatements:_}){let v=l?[M(T(`nodes`),A(S(c),T(`nodes`))),M(T(`entities`),j([])),M(T(`update`),A(S(c),T(`update`))),M(T(`dispose`),A(S(c),T(`dispose`)))]:[M(T(`nodes`),k(X(e,`rootNodes`),[S(c)])),M(T(`entities`),j([S(r)]))];return u&&!d&&v.push(M(T(`updateProps`),L([S(i),...a===null?[]:[S(a)]],R(_)))),L([S(t.itemPattern,!0),S(r),...t.indexParam===null?[]:[T(t.indexParam)]],R([...s.updaters.length>0?[Os(s),Ms(s)]:[],...s.prelude,...s.creation,...s.mounts,...h,B(`const`,[V(S(c),l?k(T(n),[...g.map(e=>S(e)),S(r),...t.sourceLocal?[S(p)]:[],...[...m.values()].map(e=>S(e))]):k(T(n),[S(r),S(p),...g.length>0?[j(g)]:[]]))]),...s.updaters.length>0?[B(`const`,[V(S(o),L([],R([z(l?k(A(S(c),T(`update`)),[]):k(X(e,`markDirty`),[S(r)])),z(k(T(s.updateVar),[]))])))])]:[],...f===null?[]:[B(`const`,[V(S(f),A(S(c),T(`updateProps`)))]),z(F(`=`,A(S(c),T(`updateProps`)),L([S(i),...a===null?[]:[S(a)]],R(_))))],ir(d?S(c):Zn(v))]))}function Ph(e,t,n,r,i,a=!1,o=la(e,n),s=new Map){let c=t.rowComp,l=Y(e,`rowId`),u=Y(e,`nextItem`),d=t.indexParam===null?null:Y(e,`nextIndex`),f=Y(e,`refreshRow`),p=Es(e),m=Hl(e,c),h={itemParam:t.itemParam,itemPath:[],rowIdVar:l.name,keyPath:wa(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal&&W(o)?{ownerIdVar:o.name}:{}},g=t.jsx.openingElement.attributes.filter(e=>si(e)||Ic(e.name)!==`key`),_=g.some(e=>si(e)),v=[],y=[],b=null,ee=e.componentProps.get(c),te=m&&(e.linkedComponentRows.get(c)?.length??0)===0&&ee!==void 0?Xa(ee):null,ne=()=>{for(let{name:e}of v)if(!te.some(t=>t.name===e))throw r.buildCodeFrameError(`memo-dom: unknown prop '${e}' on <${c}> - declared props: ${te.map(e=>e.name).join(`, `)}`);let e=new Map(v.map(({name:e,value:t})=>[e,t]));return te.map(({name:t})=>S(e.get(t)??T(`undefined`)))},re=e=>te.map(({name:t})=>A(S(e),dt(t)?T(t):E(t),!dt(t))),x=t=>{let o=ii(t)||ai(t)?[t]:[mr(t)];return i(e,p,o,n,r,`row`,h,l,a,l)};if(_){b=Fc(g,{attributeValue:(t,i)=>t===`ref`||ee?.refProps.includes(t)===!0?ph(e,r,n,i):i,fail:e=>{throw r.buildCodeFrameError(e)}}).expression;for(let t of b.properties){if(!Hr(t)||t.computed||!q(t.value))continue;let i=W(t.key)?t.key.name:G(t.key)?t.key.value:null;if(i!==null){if(ee?.renderProps.includes(i)===!0){if(Ls(e,n,t.value))continue;if(!Na(t.value))throw r.buildCodeFrameError(`memo-dom: render prop '${i}' on <${c}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);t.value=x(t.value)}else if(Na(t.value))throw r.buildCodeFrameError(`memo-dom: JSX prop '${i}' on <${c}> is not rendered by the callee; interpolate that prop in <${c}> to declare a render slot`);else i!==`ref`&&ee?.refProps.includes(i)!==!0&&sh(t.value)&&(Km(e,r,t.value,n,h,!0),t.value=lh(e,y,t.value,`${i}Callback`))}}}else for(let t of g){let i=t,a=Ic(i.name),o=i.value==null?Yn(!0):ka(i.value);if(o===null)throw r.buildCodeFrameError(`memo-dom: prop '${Ic(i.name)}' on <${c}> must be an expression`);if(ee?.renderProps.includes(a)===!0){if(Ls(e,n,o)){v.push({name:a,value:S(o)});continue}if(!Na(o))throw r.buildCodeFrameError(`memo-dom: render prop '${a}' on <${c}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);v.push({name:a,value:x(o)});continue}if(a===`ref`||ee?.refProps.includes(a)===!0){v.push({name:a,value:ph(e,r,n,o)});continue}if(Na(o))throw r.buildCodeFrameError(`memo-dom: JSX prop '${a}' on <${c}> is not rendered by the callee; interpolate that prop in <${c}> to declare a render slot`);let s=sh(o);if(s)Km(e,r,o,n,h,!0);else if(W(o)){let t=Gm(e,r,o.name);t!==null&&!Na(t.body)&&Km(e,r,t,n,void 0,!0)}v.push({name:a,value:s?lh(e,y,o,`${a}Callback`):S(o)})}if(Fs(t.jsx.children)){if(g.some(e=>oi(e)&&Ic(e.name)===`children`))throw r.buildCodeFrameError(`memo-dom: <${c}> cannot use both a children prop and nested JSX children`);let o=i(e,p,t.jsx.children,n,r,`row`,h,l,a,l);b===null?v.push({name:`children`,value:S(o)}):b.properties.push(M(T(`children`),S(o)))}let ie;if(b!==null){let t=Y(e,`${c}Props`);y.push(B(`const`,[V(S(t),S(b))])),ie=te===null?Gd(e,c,t):re(t)}else ie=te===null?Wd(e,c,v):ne();let ae=[z(F(`=`,S(t.itemPattern,!0),S(u)))];d!==null&&t.indexParam!==null&&ae.push(z(F(`=`,T(t.indexParam),S(d))));let oe=ie.map(e=>S(e));if(b!==null){let t=Y(e,`next${c}Props`);ae.push(B(`const`,[V(S(t),S(b))])),oe=te===null?Gd(e,c,t):re(t)}let se=Y(e,m?`entry`:`rowElement`),ce=ie.length>0||p.updaters.length>0,le=m&&ce,ue=le?Y(e,`pushRowProps`):null;return m?ae.push(z(k(ue===null?A(S(se),T(`updateProps`)):S(ue),oe))):ae.push(z(k(X(e,`setProps`),[S(l),j(oe)])),z(k(X(e,`markDirty`),[S(l)]))),p.updaters.length>0&&ae.push(z(k(T(p.updateVar),[]))),Nh({ctx:e,site:t,rowComponent:c,rowId:l,nextItem:u,nextIndex:d,rowRefresh:f,rowScope:p,result:se,lightweight:m,needsUpdateProps:ce,reuseLightweightEntry:le,lightweightPushProps:ue,ownerId:o,eventBindings:s,prefixStatements:y,callProps:ie,updateStatements:ae})}function Fh(e,t,n,r,i,a=!1,o=la(e,n),s=new Map){t.jsx.openingElement.attributes=t.jsx.openingElement.attributes.filter(e=>si(e)||e.name.name!==`key`);let c=Es(e);for(let[e,t]of s)c.delegatedEventBindings.set(e,t.name);let l=Y(e,`rowId`).name,u=Y(e,`nextItem`),d=t.indexParam===null?null:Y(e,`nextIndex`),f={itemParam:t.itemParam,itemPath:[],rowIdVar:l,keyPath:wa(t.keyExpr,t.itemParam),sourceKey:t.sourceKey,sourceLocal:t.sourceLocal,...t.sourceLocal?{ownerIdVar:W(o)?o.name:la(e,n).name}:{}},p=i(e,c,t.jsx,n,r,`row`,f,T(l),a,T(l));yh(e,c,p);let m=[z(F(`=`,S(t.itemPattern,!0),S(u)))];return d!==null&&t.indexParam!==null&&m.push(z(F(`=`,T(t.indexParam),S(d)))),L([S(t.itemPattern,!0),T(l),...t.indexParam===null?[]:[T(t.indexParam)]],R([Os(c),Ms(c),...c.prelude,Ns(e,T(l),S(o),T(c.updateVar)),...c.creation,...c.mounts,ir(Zn([M(T(`nodes`),j([T(p)])),M(T(`entities`),j([T(l)])),M(T(`updateProps`),L([S(u),...d===null?[]:[S(d)]],R(m))),M(T(`update`),T(c.updateVar))]))]))}function Ih(e){return ii(e.body)?e.body:Yr(e.body)&&e.body.body.length===1&&Xr(e.body.body[0])&&ii(e.body.body[0].argument)?e.body.body[0].argument:null}function Lh(e,t,n,r,i,a,o,s){if(!Gr(n)&&!Wr(n)||n.async||n.generator)throw i.buildCodeFrameError(`memo-dom: render callbacks must be synchronous inline arrows or function expressions`);let c=Ih(n),l=n.params[0],u=n.params[1];if(c===null||n.params.length<1||n.params.length>2||!W(l)&&!fi(l)&&!pi(l)||u!==void 0&&!W(u))throw i.buildCodeFrameError(`memo-dom: render callbacks take an item binding pattern and optional index, then return one JSX element`);let d=Ia(l),f=St(d).map(e=>e.name);if(f.length===0)throw i.buildCodeFrameError(`memo-dom: render callback item patterns must bind at least one name`);let p=W(d)?d.name:f[0],m=u===void 0?null:u.name,h=null;c.openingElement.attributes=c.openingElement.attributes.filter(e=>{if(si(e)||!J(e.name)||e.name.name!==`key`)return!0;if(h=ka(e.value),h===null)throw i.buildCodeFrameError(`memo-dom: key={...} needs an expression`);return!1});let g=Y(e,`renderCallback`),_=Y(e,`renderRows`),v=Y(e,`renderNextUpdate`),y=Y(e,`renderRowId`),b=Y(e,`refreshRenderRow`),ee=Y(e,`renderNextItem`),te=m===null?null:Y(e,`renderNextIndex`),ne=Es(e),re=a(e,ne,c,r,i,`row`,{itemParam:p,itemPath:[],rowIdVar:y.name,keyPath:wa(h,p),sourceKey:`$render-callback`,sourceLocal:!0,...W(s)?{ownerIdVar:s.name}:{}},y,o,y);yh(e,ne,re),t.creation.push(B(`const`,[V(S(_),$n(T(`Set`),[]))])),t.updaters.push(()=>or(B(`const`,[V(S(v))]),S(_),z(k(S(v),[]))));let x=[z(F(`=`,S(d,!0),S(ee)))];te!==null&&m!==null&&x.push(z(F(`=`,T(m),S(te))));let ie=L([S(d,!0),S(y),...m===null?[]:[T(m)]],R([Os(ne),Ms(ne),B(`const`,[V(S(b),L([],R([z(k(T(ne.updateVar),[])),z(k(X(e,`renderDescendants`),[S(y)]))])))]),...ne.prelude,Ns(e,S(y),S(s,!0),S(b)),...ne.creation,...ne.mounts,z(k(A(S(_),T(`add`)),[S(b)])),ir(Zn([M(T(`nodes`),k(X(e,`rootNodes`),[T(re)])),M(T(`entities`),j([S(y)])),M(T(`updateProps`),L([S(ee),...te===null?[]:[S(te)]],R(x))),M(T(`update`),S(b)),M(T(`dispose`),L([],k(A(S(_),T(`delete`)),[S(b)])))]))])),ae=h===null?O():L([S(d,!0),...m===null?[]:[T(m)]],S(h));return t.creation.push(B(`const`,[V(S(g),Zn([M(T(`create`),ie),M(T(`key`),ae)]))])),g}function Rh(e,t,n,r,i,a,o,s,c){let l=Y(e,`routeFragment`),u=Y(e,`routeRegion`),d=Y(e,`routeUnsubscribe`),f=Y(e,`routeDispose`),p=Y(e,`currentRoute`),m=Y(e,`routeMatch`),h=t.regionCounter++,g=N(`+`,S(c),E(`/route${h}`));e.routeElements.delete(n);let _;try{_=fh(e,n,i,a,g,o,s,g,!0,t.usedConds)}finally{e.routeElements.set(n,r)}let v=L([S(p)],k(A(A(S(p),T(`matches`)),T(`some`)),[L([S(m)],N(`===`,A(S(m),T(`id`)),E(r.id)))])),y=L([],k(A(S(u),T(`update`)),[]));return t.creation.push(B(`const`,[V(S(l),k(A(Ds(e,t),T(`createDocumentFragment`)),[]))]),Ns(e,S(g),S(c),S(y)),B(`const`,[V(S(u),k(X(e,`createCondRegion`),[S(l),S(g),L([],I(k(v,[da(e,`route`)]),D(0),D(1))),j([_,O()])]))]),B(`const`,[V(S(d),k(da(e,`subscribeRouteSelected`),[S(v),S(y)]))]),B(`const`,[V(S(f),L([],R([z(k(S(d),[])),z(k(A(S(u),T(`dispose`)),[]))])))])),t.manualDisposal?(t.disposableCallbacks.push(f),t.disposableEntities.push(S(g))):t.creation.push(z(k(X(e,`cleanup`),[S(c),S(f)]))),l.name}function zh(e){return I(P(`||`,N(`==`,S(e),O()),N(`===`,er(`typeof`,S(e),!0),E(`boolean`))),E(``),k(T(`String`),[S(e)]))}function Bh(e,t,n,r){return()=>js(e,t,S(r),e=>z(F(`=`,A(T(n),T(`data`)),zh(e))))}function Vh(e,t,n,r){let i=Y(e,`text${t.textCounter++}`).name;if(G(n))return t.creation.push(B(`const`,[V(T(i),k(A(Ds(e,t),T(`createTextNode`)),[E(n.value)]))])),i;let a=ks(e,t);t.creation.push(B(`const`,[V(T(i),k(A(Ds(e,t),T(`createTextNode`)),[E(``)]))]));let o=Bh(t,a,i,n);return t.creation.push(o()),yf(e,t,gf(e,n),r,o()),t.updaters.push(o),i}function Hh(e,t){let n=!1;return C(e,{enter(e){if(e.type===`Identifier`&&e.name===t)return n=!0,!1}}),n}function Uh(e,t,n,r,i,a=null,o,s,c=!1,l=la(e,r)){return ai(n)?Wh(e,t,n,r,i,a,o,s,c,l):Jh(e,t,n,r,i,a,o,s,c,l)}function Wh(e,t,n,r,i,a,o,s,c=!1,l=la(e,r)){let u=Zm(n.children,{emitText:n=>Vh(e,t,n,l),emitNode:n=>Uh(e,t,n,r,i,a,o,s,c,l),isForwarded:t=>Ls(e,r,t),fail:e=>{throw i.buildCodeFrameError(e)}}),d=As(e,t,`fragment`);return t.creation.push(B(`const`,[V(T(d),k(A(Ds(e,t),T(`createDocumentFragment`)),[]))])),Gh(e,t,u,d,r,i,a,o,c,l),d}function Gh(e,t,n,r,i,a,o=null,s,c=!1,l=la(e,i)){for(let u of n)u.type===`node`?t.creation.push(z(k(A(T(r),T(`appendChild`)),[T(u.variable)]))):u.type===`slot`?zs(e,t,u.expression,r,l):u.type===`list`?Yh(e,t,u.expression,r,i,a,c,l,s):Xh(e,t,u.expression,r,i,a,c,l,o!==null)}function Kh(e,t,n,r,i,a,o,s,c,l){return Rs(e,t,l,(t,l,u)=>{Bs(t,n,l.name,{emitText:n=>Vh(e,t,n,u),emitNode:n=>Uh(e,t,n,r,i,a,o,s,c,u),emitList:(n,a)=>Yh(e,t,n,a,r,i,c,u,o),emitCondition:(n,o)=>Xh(e,t,n,o,r,i,c,u,a!==null),isForwarded:t=>Ls(e,r,t),emitForwarded:(n,r)=>zs(e,t,n,r,u),fail:e=>{throw i.buildCodeFrameError(e)}})})}function qh(e,t,n,r,i,a,o,s,c,l){return Kh(e,t,ii(n)||ai(n)?[n]:[mr(n)],r,i,a,o,s,c,l)}function Jh(e,t,n,r,i,a=null,o,s,c=!1,l=la(e,r)){let u=Lf(n);if(u!==null){let n=t.childCounts.get(`$dataPolicy`)??0;t.childCounts.set(`$dataPolicy`,n+1);let r=n===0?`/$dataPolicy`:`/$dataPolicy[${n}]`,i=N(`+`,S(l),E(r)),a=As(e,t,`dataPolicy`);return t.creation.push(B(`const`,[V(T(a),k(S(u.renderer),[S(i),S(l),...u.args.map(e=>S(e,!0))]))])),t.disposableEntities.push(S(i)),a}let d=e.routeElements.get(n);if(d!==void 0)return Rh(e,t,n,d,r,i,Uh,c,l);let f=n.openingElement,p=f.name.name;if(/^[A-Z]/.test(p)){let u=t.childCounts.get(p)??0;t.childCounts.set(p,u+1);let d=p.charAt(0).toLowerCase()+p.slice(1),m=Y(e,u===0?d:`${d}${u}`).name,h=u===0?`/${p}`:`/${p}[${u}]`,g=[],_=e.componentProps.get(p);if(Fs(n.children)&&f.attributes.some(e=>oi(e)&&Ic(e.name)===`children`))throw i.buildCodeFrameError(`memo-dom: <${p}> cannot use both a children prop and nested JSX children`);let v=f.attributes.some(e=>si(e)),y=null,b=!1,ee=new Set;if(v){y=Fc(f.attributes,{attributeValue:(t,n)=>t===`ref`||_?.refProps.includes(t)===!0?ph(e,i,r,n):n,fail:e=>{throw i.buildCodeFrameError(e)}}).expression;for(let n of y.properties){if(!Hr(n)||n.computed||!q(n.value))continue;let u=W(n.key)?n.key.name:G(n.key)?n.key.value:null;if(u!==null){if(_?.renderCallbacks.includes(u)===!0)n.value=Lh(e,t,n.value,r,i,Uh,c,l);else if(_?.renderProps.includes(u)===!0){if(Ls(e,r,n.value))continue;if(!Na(n.value))throw i.buildCodeFrameError(`memo-dom: render prop '${u}' on <${p}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);n.value=qh(e,t,n.value,r,i,a,o,s,c,l)}else if(Na(n.value))throw i.buildCodeFrameError(`memo-dom: JSX prop '${u}' on <${p}> is not rendered by the callee; interpolate that prop in <${p}> to declare a render slot`);else u!==`ref`&&_?.refProps.includes(u)!==!0&&sh(n.value)&&(Km(e,i,n.value,r,o,!0),n.value=ch(e,t,n.value,`${u}Callback`))}}b=Aa(e,y,r)||o!==void 0&&Hh(y,o.itemParam)}else for(let n of f.attributes){let u=n,d=Ic(u.name),f=u.value==null?Yn(!0):ka(u.value);if(f==null)throw i.buildCodeFrameError(`memo-dom: prop '${Ic(u.name)}' on <${p}> must be an expression`);if(_?.renderCallbacks.includes(d)===!0){g.push({name:d,value:Lh(e,t,f,r,i,Uh,c,l)});continue}if(d===`ref`||_?.refProps.includes(d)===!0){g.push({name:d,value:ph(e,i,r,f)});continue}if(_?.renderProps.includes(d)===!0){if(Ls(e,r,f)){g.push({name:d,value:S(f)});continue}if(!Na(f))throw i.buildCodeFrameError(`memo-dom: render prop '${d}' on <${p}> must be JSX, a JSX-bearing conditional/list, or a forwarded render prop`);g.push({name:d,value:qh(e,t,f,r,i,a,o,s,c,l)});continue}if(Na(f))throw i.buildCodeFrameError(`memo-dom: JSX prop '${d}' on <${p}> is not rendered by the callee; interpolate that prop in <${p}> to declare a render slot`);let m=sh(f);if(!m){for(let t of gf(e,f))ee.add(t);ee.size>0&&(b=!0)}if(!m&&(Aa(e,f,r)||o!==void 0&&Hh(f,o.itemParam))&&(b=!0),m)Km(e,i,f,r,o,!0);else if(W(f)){let t=Gm(e,i,f.name);t!==null&&!Na(t.body)&&Km(e,i,t,r,o,!0)}g.push({name:d,value:m?ch(e,t,f,`${d}Callback`):S(f)})}if(Fs(n.children)){if(f.attributes.some(e=>oi(e)&&Ic(e.name)===`children`))throw i.buildCodeFrameError(`memo-dom: <${p}> cannot use both a children prop and nested JSX children`);let u=Kh(e,t,n.children,r,i,a,o,s,c,l);y===null?g.push({name:`children`,value:S(u)}):y.properties.push(M(T(`children`),S(u)))}let te;if(y!==null){let n=Y(e,`${d}Props`);t.creation.push(B(`const`,[V(S(n),S(y))])),te=Gd(e,p,n)}else te=Wd(e,p,g);let ne=N(`+`,S(l),E(h)),re=Cp(e,r,n);t.creation.push(B(`const`,[V(T(m),k(T(p),[ne,S(l),...te.length>0?[j(te)]:[],...re===null?[]:[re]]))])),t.disposableEntities.push(S(ne));let x=()=>y===null?z(k(X(e,`setProps`),[N(`+`,S(l),E(h)),j(te.map(e=>S(e)))])):Kd(e,p,l,h,y);return yf(e,t,[...ee].sort(),l,x()),b&&t.updaters.push(x),m}let m=ah(p,c),h=m&&p!==`foreignObject`;if(f.attributes.find(e=>oi(e)&&Ic(e.name)===`innerHTML`)!==void 0){if(m)throw i.buildCodeFrameError(`memo-dom: innerHTML is only supported on HTML elements`);if(n.children.some(e=>!li(e)||e.value.trim()!==``))throw i.buildCodeFrameError(`memo-dom: an element using innerHTML cannot also have JSX children`)}let g=Zm(n.children,{emitText:n=>Vh(e,t,n,l),emitNode:n=>Uh(e,t,n,r,i,a,o,s,h,l),isForwarded:t=>Ls(e,r,t),fail:e=>{throw i.buildCodeFrameError(e)}}),_=As(e,t,p),v=oh(Ds(e,t),p,m);if(n.loc!==null&&n.loc!==void 0&&C(v,{enter(e){e.loc??=n.loc}}),t.creation.push(B(`const`,[V(T(_),v)])),f.attributes.some(e=>si(e))){let n=Fc(f.attributes,{attributeValue:(t,n)=>t===`ref`?ph(e,i,r,n):n,eventValue:(n,a)=>{let c=Ym(e,i,a,n,r,o,s),l=Y(e,`${n}Handler`);return t.creation.push(B(`const`,[V(S(l),c)])),l},fail:e=>{throw i.buildCodeFrameError(e)}}),a=Y(e,`${p}Props`);t.creation.push(B(`const`,[V(S(a),S(n.expression))]));let c=t=>z(k(X(e,`patchDomProps`),[T(_),S(t),E(e.rootId),j(n.safeEventKeys.map(e=>E(e)))]));t.creation.push(c(a)),mh(e,t,T(_),l,A(S(a),T(`ref`))),t.updaters.push(()=>c(n.expression))}else for(let n of f.attributes){let a=n,c=Ic(a.name);if(c===`ref`){let n=ka(a.value);if(n===null)throw i.buildCodeFrameError(`memo-dom: ref needs an expression`);mh(e,t,T(_),l,ph(e,i,r,n));continue}if(c===`key`)throw i.buildCodeFrameError(`memo-dom: key={...} is only meaningful on list rows: items.map(item => <Row key={item.id} />)`);if(/^on[A-Z]/.test(c)){let n=ka(a.value);if(n==null)throw i.buildCodeFrameError(`memo-dom: ${c} needs a handler expression (L1)`);let l=Ym(e,i,n,c,r,o,s),u=t.delegatedEventBindings.get(c);t.creation.push(z(u===void 0?F(`=`,A(T(_),T(c.toLowerCase())),l):k(X(e,`setDelegatedEvent`),[T(u),T(_),l])));continue}if(G(a.value)){c===`class`||c===`className`?t.creation.push(z(k(X(e,`setClassValue`),[T(_),E(a.value.value)]))):c===`style`?t.creation.push(z(k(X(e,`setStyleValue`),[T(_),E(a.value.value)]))):eh(c,m)===null?th(c,m)?t.creation.push(rh(_,c,E(a.value.value))):m?t.creation.push(z(k(X(e,`setDomValue`),[T(_),E(c),E(a.value.value)]))):t.creation.push(z(k(A(T(_),T(`setAttribute`)),[E(c),E(a.value.value)]))):t.creation.push(nh(_,c,E(a.value.value)));continue}let u=a.value==null?Yn(!0):ka(a.value);if(u==null)throw i.buildCodeFrameError(`memo-dom: attribute '${c}' needs a string or an expression (L1)`);let d=gf(e,u),f=S(u);if(c===`style`){let n=()=>z(k(X(e,`setStyleValue`),[T(_),S(f)]));t.creation.push(n()),yf(e,t,d,l,n()),t.updaters.push(n);continue}let p=ks(e,t),h=eh(c,m),g=()=>c===`class`||c===`className`?js(t,p,k(X(e,`classValue`),[S(f)]),t=>z(k(X(e,`setClassValue`),[T(_),t]))):h===null?th(c,m)?js(t,p,S(f),e=>rh(_,c,e)):m?js(t,p,S(f),t=>z(k(X(e,`setDomValue`),[T(_),E(c),t]))):js(t,p,S(f),e=>rh(_,c,e)):js(t,p,S(f),e=>nh(_,h,e));t.creation.push(g()),yf(e,t,d,l,g()),t.updaters.push(g)}return Gh(e,t,g,_,r,i,a,o,h,l),_}function Yh(e,t,n,r,i,a,o=!1,s=la(e,i),c){Oh(e,t,n,r,i,a,Uh,Kh,o,s,c),bf(e,t,n,s)}function Xh(e,t,n,r,i,a,o=!1,s=la(e,i),c=!1){dh(e,t,n,r,i,a,Uh,o,s,c)}function Zh(e,t,n,r,i,a=!1,o=i,s=!1,c){return fh(e,t,n,r,i,Uh,a,o,s,c)}const Qh=new Set([`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`,`ObjectMethod`,`ClassMethod`,`ClassPrivateMethod`]);function $h(e,t){return e.declarations.some(e=>St(e.id).some(e=>t.has(e.name)))}function eg(e,t,n,r,i,a=!1){let o=Gm(e,t,n);if(o!==null){Km(e,t,o,r,i,a);return}let s=Q(e,t.node,n);if(s===void 0||!s.scope.isProgramScope||!e.helpers.has(n))return;let c=e.helpers.get(n)?.node;c!==void 0&&qm(e,c,a)}function tg(e,t,n,r,i,a=!1){if(!e.compilerOwnedCallbacks.has(n)){if(Gr(n)||Wr(n)){if(Na(n.body))return;Km(e,t,n,r,i,a)}else W(n)&&eg(e,t,n.name,r,i,a)}}function ng(e,t,n,r=!1){let i=Q(e,t.node,n);if(i===void 0||!i.scope.isProgramScope||!e.helpers.has(n))return;let a=e.helpers.get(n)?.node;a!==void 0&&qm(e,a,r)}function rg(e,t,n,r=!1){if(!e.compilerOwnedCallbacks.has(n)){if(Gr(n)||Wr(n)){if(Na(n.body))return;qm(e,n,r)}else W(n)&&ng(e,t,n.name,r)}}function ig(e,t,n,r,i){let a=0,o=0,s=e.instanceDerivedBindings.get(n)??new Set;C(t.node.body,{enter(c){if(c.type===`VariableDeclaration`&&$h(c,s)&&o++,Qh.has(c.type)){a++;return}if(c.type===`CallExpression`){let s=c,l=a===0;if(l&&o>0)return!1;let u=s.callee,d=W(u,{name:`effect`})&&Q(e,c,`effect`)===void 0;if(W(u,{name:`cleanup`})&&Q(e,c,`cleanup`)===void 0){if(!l)throw t.buildCodeFrameError(`memo-dom: cleanup(disposer) must run directly during component factory initialization`);let n=s.arguments[0];if(s.arguments.length!==1||n===void 0||!q(n))throw t.buildCodeFrameError(`memo-dom: cleanup(disposer) requires exactly one disposer expression`);s.callee=X(e,`cleanup`),s.arguments.unshift(T(r))}if(!l)return;W(u)&&eg(e,t,u.name,n,i);for(let r of s.arguments)tg(e,t,r,n,i,d);return}if(c.type===`NewExpression`&&a===0){if(o>0)return!1;let r=c;for(let a of r.arguments)tg(e,t,a,n,i)}},leave(e){Qh.has(e.type)&&a--,e.type===`VariableDeclaration`&&$h(e,s)&&o--}})}function ag(e,t){let n=0;C(t.node,{enter(r){if(Qh.has(r.type)){n++;return}if(r.type===`CallExpression`&&n===0){let n=r,i=W(n.callee,{name:`effect`})&&Q(e,r,`effect`)===void 0;W(n.callee)&&ng(e,t,n.callee.name);for(let r of n.arguments)rg(e,t,r,i);return}if(r.type===`NewExpression`&&n===0){let n=r;for(let r of n.arguments)rg(e,t,r)}},leave(e){Qh.has(e.type)&&n--}})}function og(e){for(let t of e.helpers.values())t.node.async&&qm(e,t.node)}function sg(e,t){C(t.node,{enter(n){if(n.type===`CallExpression`&&W(n.callee,{name:`cleanup`})&&Q(e,n,`cleanup`)===void 0)throw t.buildCodeFrameError(`memo-dom: cleanup(disposer) is only valid directly inside a component factory`)}})}function cg(e){return e.reduce((e,t)=>P(`||`,e,t))}function lg(e,t){let n=()=>T(e),r=P(`||`,N(`===`,n(),er(`-`,D(1))),P(`&&`,N(`!==`,er(`typeof`,n()),E(`number`)),k(A(n(),T(`has`)),[er(`-`,D(1))]))),i=cg(t.map(e=>N(`===`,n(),D(e)))),a=cg(t.map(e=>k(A(n(),T(`has`)),[D(e)])));return P(`||`,N(`===`,n(),O()),P(`||`,r,I(N(`===`,er(`typeof`,n()),E(`number`)),i,a)))}function ug(e,t,n,r,i,a){let o=new Map(r.map((e,t)=>[e,t])),s=0,c=[...i.map(e=>({order:o.get(e.declaration)??2**53-1,sequence:s++,sources:e.sources,statement:eo(e)})),...a.map(e=>({order:o.get(e.statement)??2**53-1,sequence:s++,sources:e.sources,statement:R([...e.resets.map(e=>z(F(`=`,T(e.binding),S(e.source,!0)))),S(e.statement,!0)])}))].sort((e,t)=>e.order-t.order||e.sequence-t.sequence),l=e.instanceReasonIds.get(t),u=[];for(let e of c){let t=n===null||l===void 0?null:e.sources.map(e=>l.get(e)).filter(e=>e!==void 0).sort((e,t)=>e-t),r=t===null||t.length===e.sources.length?t:null,i=r?.join(` `)??`*`,a=u.at(-1),o=a?.reasons?.join(` `)??`*`;a!==void 0&&o===i?a.statements.push(e.statement):u.push({reasons:r,statements:[e.statement]})}return R(u.map(e=>e.reasons===null||n===null?R(e.statements):ar(lg(n,e.reasons),R(e.statements))))}const dg=new Set([`ArrowFunctionExpression`,`FunctionDeclaration`,`FunctionExpression`,`ObjectMethod`,`ClassMethod`,`ClassPrivateMethod`]),fg=new Set([`AwaitExpression`,`CallExpression`,`NewExpression`,`OptionalCallExpression`,`TaggedTemplateExpression`,`UpdateExpression`,`YieldExpression`]);function pg(e){return!Xr(e)||!ii(e.argument)&&!ai(e.argument)?null:{jsx:e.argument,statement:e}}function mg(e){if(e==null)return!0;let t=e;return t.type===`NullLiteral`||t.type===`BooleanLiteral`&&t.value===!1||t.type===`Literal`&&(t.value===null||t.value===!1)||t.type===`Identifier`&&t.name===`undefined`}function hg(e){return Xr(e)?mg(e.argument)?{jsx:null,statement:e}:!ii(e.argument)&&!ai(e.argument)?null:{jsx:e.argument,statement:e}:null}function gg(e){return Yr(e)?e.body.length===1?hg(e.body[0]):null:hg(e)}function _g(e){let t=[];return C(e.node.body,{enter(e){if(dg.has(e.type))return!1;e.type===`ReturnStatement`&&t.push(e)}}),t}function vg(e){if(Ur(e))return!0;if(qr(e))return e.declarations.every(e=>e.init==null||Kr(e.init)||yg(e.init));if(Ci(e)||Zr(e)){let t=!0;return C(e,{enter(e){(fg.has(e.type)||e.type===`ThrowStatement`)&&(t=!1)}}),t}return Fi(e)}function yg(e){let t=!0;return C(e,{enter(e){(fg.has(e.type)||e.type===`AssignmentExpression`)&&(t=!1)}}),t}function bg(e){if(!e.cases.some(e=>e.test==null))return null;let t=[],n=[];for(let r of e.cases){if(r.consequent.length!==1)return null;let e=hg(r.consequent[0]);if(e===null)return null;let i=t.length;t.push(e.jsx),n.push(xr(r.test==null?null:S(r.test),[ir(D(i))]))}return{pick:L([],R([Sr(S(e.discriminant),n)])),branches:t,statements:new Set([e])}}function xg(e,t){let n=e.node.body.body,r=_g(e),i=n.at(-1);if(r.length===1&&i!==void 0){let e=pg(i);if(e!==null)return e}if(i&&Zr(i)&&i.alternate!=null){let e=i.alternate,t=gg(i.consequent),n=gg(e);if(t!==null&&n!==null&&(t.jsx!==null||n.jsx!==null)&&r.length===2)return{pick:L([],I(S(i.test),D(0),D(1))),branches:[t.jsx,n.jsx],statements:new Set([i])}}if(i&&Ci(i)){let e=bg(i);if(e!==null&&e.branches.length===r.length)return e}let a=i===void 0?null:hg(i);if(a!==null){let e=[],t=[],o=new Set([i]),s=-1,c=!0;for(let r=0;r<n.length-1;r++){let i=n[r];if(Zr(i)&&i.alternate==null){let n=gg(i.consequent);if(n!==null){s===-1&&(s=r),e.push(S(i.test)),t.push(n.jsx),o.add(i);continue}}if(s!==-1&&!vg(i)){c=!1;break}}if(t.push(a.jsx),c&&t.length===r.length&&t.length>1&&t.some(e=>e!==null)){let n=D(t.length-1);for(let t=e.length-1;t>=0;t--)n=I(e[t],D(t),n);return{pick:L([],n),branches:t,statements:o}}}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 Sg(e){return e?.some(e=>e.localReads.size>0||e.localDerivationReads.size>0||e.conditionLocalReads.size>0||e.conditionLocalDerivationReads.size>0)===!0}function Cg(e,t,n,r,i,a,o,s,c){if(t.length===0&&n.length===0||e.bindings.length===0)return;let l=[...t.map(e=>wa(e.keyExpr??null,e.itemParam??``)),...n.map(e=>e.keyPath)],u=JSON.stringify(l[0]),d=l.every(e=>JSON.stringify(e)===u)?l[0]:null,f=ro(e,`item`),p=no(e);return{itemParam:f??p??e.bindings[0],itemPath:f===null&&p!==null?[`item`]:[],rowIdVar:o,...i?{refreshVar:a}:{},keyPath:d,sourceKey:t[0]?.sourceKey??n[0]?.sourceKey??``,sourceLocal:r,...r?{ownerIdVar:s??c}:{}}}function wg(e,t,n,r,i,a,o){let s=Array.from({length:i},(t,n)=>Y(e,`nextProp${n}`)),c=r===null?$a(n,s):r.map(({local:e},t)=>z(F(`=`,T(e),S(s[t]))));return ir(Zn([M(T(`nodes`),o?T(a):k(X(e,`rootNodes`),[T(a)])),M(T(`entities`),j([])),M(T(`update`),T(t.updateVar)),...i>0?[M(T(`updateProps`),L(s,R(c)))]:[],...t.disposableCallbacks.length>0?[M(T(`dispose`),L([],R([...t.disposableCallbacks].reverse().map(e=>ar(N(`!==`,S(e),O()),z(k(S(e),[])))))))]:[]]))}function Tg(e,t,n,r,i,a,o,s,c,l){return n?[...t===null?e.params.map(oo):t.map(({local:e})=>T(e)),T(i),...o===null?[]:[T(o)],...[...s.values()].map(e=>T(e))]:r>0?[T(i),T(a),T(c),...l===null?[]:[S(l)]]:[T(i),T(a),...l===null?[]:[S(l)]]}function Eg(e,t,n){let r=t.node,i=xg(t,n),a=e.componentProps.get(n),o=a.params.length,s=e.listedSites.get(n)??[],c=e.linkedComponentRows.get(n)??[],l=s.some(e=>e.sourceLocal===!0)||c.some(e=>e.sourceLocal),u=e.transparentPolicyParams.get(n)??null,d=u===null&&!e.transparentSources.has(n)&&Vl(e,n),f=d&&c.length===0?Xa(a):null,p=f?.length??o,m=Es(e,d),h=e.instanceDerivations.get(n),g=e.instanceControlFlow.get(n),_=e.effects.get(n),v=Sg(_);(e.selectiveDerivationComponents.has(n)||e.targetedListComponents.has(n)||e.listComponents.has(n)||v)&&(m.reasonVar=Y(e,`reasons`).name);let y=Y(e,`id`).name,b=d?null:Y(e,`parent`).name,ee=d&&l?Y(e,`owner`).name:null,te=new Map;if(d)for(let t of e.componentHostEvents.get(n)??[]){let n=Y(e,`${t}Binding`).name;te.set(t,n),m.delegatedEventBindings.set(t,n)}let ne=o>0&&!d?Y(e,`props`).name:null;fa(e).registerComponentId(n,y);let re=Cg(a,s,c,l,d,m.updateVar,y,ee,b);ig(e,t,n,y,re);let x=new Set(_?.map(e=>e.statement)??[]),ie=r.body.body.filter(e=>!(`jsx`in i?e===i.statement:i.statements.has(e))&&!x.has(e)),ae=`jsx`in i?Uh(e,m,i.jsx,n,t,null,re):Dg(e,m,i,n,t,y),oe=d&&`jsx`in i&&ii(i.jsx);if(d&&yh(e,m,ae),h!==void 0)for(let e of h)e.stableTarget!==!0&&(e.declaration.kind=`let`);(h!==void 0||g!==void 0)&&m.updaters.unshift(()=>ug(e,n,m.reasonVar,r.body.body,h??[],g??[])),_!==void 0&&v&&m.updaters.push(()=>lc(e,n,y,m.reasonVar,_,m)),o>0&&!d&&m.updaters.unshift(()=>R($a(a,a.params.map((e,t)=>A(T(ne),D(t),!0)))));let se=[],ce=e.eventSourceSlots.get(n);if(ce!==void 0)for(let t of ce){let n=Y(e,`${t}EventSourceSlot`).name;m.prelude.push(B(`const`,[V(T(n),k(Z(e,`createEventSourceSlot`),[]))])),m.updaters.unshift(()=>z(k(Z(e,`rebindEventSourceSlot`),[T(n),L([],T(t)),L([],k(X(e,`markDirty`),[T(y)]))]))),se.push(z(k(X(e,`cleanup`),[T(y),L([],k(Z(e,`disposeEventSourceSlot`),[T(n)]))])))}let le=[Os(m),...m.prelude];if(o>0&&!d){let e=Qa(a,a.params.map((e,t)=>A(T(ne),D(t),!0)));e!==null&&le.push(e)}le.push(...ie,Ms(m),...d?[]:[Ns(e,T(y),T(b),T(m.updateVar),e.volatileComponents.has(n))]),o>0&&!d&&le.push(z(k(X(e,`registerProps`),[T(y),T(ne)]))),le.push(...m.creation,...m.mounts),le.push(...wp(e,n,T(y)),...se),_!==void 0&&le.push(...uc(e,y,_)),e.hot&&!d&&le.push(z(k(ua(e,`registerHotComponent`),[T(n),T(y),T(b),k(X(e,`rootNodes`),[T(ae)]),ne===null?O():T(ne)]))),le.push(d?wg(e,m,a,f,p,ae,oe):ir(T(ae))),r.params=Tg(a,f,d,o,y,b,ee,te,ne,u),r.body=R(le)}function Dg(e,t,n,r,i,a){let o=Y(e,`returnRoot`).name,s=Y(e,`returnRegion`).name,c=T(a),l=N(`+`,S(c),E(`/$return`));return t.creation.push(B(`const`,[V(T(o),k(A(Ds(e,t),T(`createDocumentFragment`)),[]))])),t.creation.push(B(`const`,[V(T(s),k(X(e,`createCondRegion`),[T(o),S(l),S(n.pick),j(n.branches.map(n=>n===null?O():Zh(e,n,r,i,l,!1,c,!0,t.usedConds)))]))])),t.updaters.push(()=>z(k(A(T(s),T(`update`)),[]))),o}function Og(e){return!W(e.id)||!/^[A-Z]/.test(e.id.name)||!Gr(e.init)&&!Wr(e.init)||!Na(e.init.body)?null:e.init}function kg(e,t,n){if(t.async||t.generator)throw n.buildCodeFrameError(`memo-dom: component '${e}' must be synchronous`);if(Wr(t)&&t.id!=null&&t.id.name!==e)throw n.buildCodeFrameError(`memo-dom: named component function expression '${t.id.name}' must match binding '${e}'`);let r=rr(T(e),t.params.map(e=>S(e,!0)),Yr(t.body)?S(t.body,!0):R([ir(S(t.body,!0))]));return r.returnType=t.returnType==null?null:S(t.returnType,!0),r.typeParameters=t.typeParameters==null?null:S(t.typeParameters,!0),r.loc=t.loc,r}function Ag(e,t,n){if(e.kind!==`const`)return[t?dr(S(e,!0)):S(e,!0)];let r=[];for(let i of e.declarations){let e=Og(i),a;a=e===null?B(`const`,[S(i,!0)]):kg(i.id.name,e,n),r.push(t?dr(a):a)}return r.length>0&&Me(r[0],e),r}function jg(e){let t=[],n=!1;for(let r of e.node.body){if(qr(r)){let i=Ag(r,!1,e);n||=i.some(e=>Ur(e)),t.push(...i);continue}if(_i(r)&&qr(r.declaration)){let i=Ag(r.declaration,!0,e);n||=i.some(e=>_i(e)&&Ur(e.declaration)),t.push(...i);continue}t.push(r)}n&&(e.node.body=t,e.scope?.crawl())}const Mg=/^:([A-Za-z_$][A-Za-z0-9_$]*)$/;function Ng(e){return e}function Pg(e){return typeof e==`object`&&e&&`type`in e?e:null}function Fg(e,t){return Pg(Ng(e)[t])}function Ig(e,t){let n=Ng(e)[t];return Array.isArray(n)?n.map(Pg).filter(e=>e!==null):[]}function Lg(e){if(e?.type!==`StringLiteral`&&e?.type!==`Literal`)return null;let t=Ng(e).value;return typeof t==`string`?t:null}function Rg(e,t){return e.openingElement.attributes.find(e=>oi(e)&&Ic(e.name)===t)}function zg(e){let t=e.value;return t?.type===`JSXExpressionContainer`?Lg(Fg(t,`expression`)):Lg(t)}function Bg(e,t,n){let r=t.openingElement.loc?.start.line,i=t.openingElement.loc?.start.column;return r===void 0||i===void 0?`${e}#route:${n}`:`${e}#route:${r}:${i}`}function Vg(e){return e.split(`/`).filter(Boolean)}function Hg(e){if(!e.startsWith(`/`))throw TypeError(`route pattern '${e}' must begin with '/'`);if(e.includes(`?`)||e.includes(`#`))throw TypeError(`route pattern '${e}' must not contain a query or hash`);if(e.includes(`//`))throw TypeError(`route pattern '${e}' contains an empty path segment`);let t=e.replace(/\/+$/g,``),n=t===``?`/`:t,r=new Set,i=Vg(n);for(let t=0;t<i.length;t++){let n=i[t];if(n===`*`){if(t!==i.length-1)throw TypeError(`route wildcard must be terminal in '${e}'`);continue}if(!n.startsWith(`:`))continue;let a=Mg.exec(n);if(a===null)throw TypeError(`invalid route parameter segment '${n}' in '${e}'`);let o=a[1];if(r.has(o))throw TypeError(`duplicate route parameter '${o}' in '${e}'`);r.add(o)}return n}function Ug(e){let t=[];for(let n of Vg(e))n===`*`?t.push(`*`):n.startsWith(`:`)&&t.push(n.slice(1));return t}function Wg(e,t){if(e.endsWith(`/*`))throw TypeError(`catch-all route '${e}' cannot have child routes`);return t===`/`?e:e===`/`?t:`${e}${t}`}function Gg(e,t){let n=[],r=0,i=(e,a)=>{if(e.type===`JSXElement`){let o=e,s=a,c=Rg(o,`route`);if(c!==void 0){let e=zg(c);if(e!==null){let i=Hg(e),c=a===null?i:Wg(a.fullPattern,i),l=new Set(a===null?[]:Ug(a.fullPattern));for(let e of Ug(i))if(l.has(e))throw TypeError(`route '${c}' shadows active parameter '${e}'`);s={id:Bg(t,o,r++),moduleId:t,pattern:i,fullPattern:c,...a===null?{}:{parentId:a.id},...o.openingElement.loc?.start.line===void 0?{}:{line:o.openingElement.loc.start.line},...o.openingElement.loc?.start.column===void 0?{}:{column:o.openingElement.loc.start.column}},n.push(s)}}for(let e of o.openingElement.attributes)i(e,s);for(let e of o.children)i(e,s);return}if(e.type===`JSXFragment`){for(let t of Ig(e,`children`))i(t,a);return}for(let t of ht[e.type]??[]){let n=Ng(e)[t];if(Array.isArray(n))for(let e of n)typeof e==`object`&&e&&`type`in e&&i(e,a);else typeof n==`object`&&n&&`type`in n&&i(n,a)}};return i(e,null),n}function Kg(e,t){return Gg(e.type===`File`?e.program:e,t)}function qg(e){return Vg(e).map(e=>e===`*`?`*`:e.startsWith(`:`)?`:param`:e).join(`/`)}function Jg(e,t,n){let r=t.parentId;for(;r!==void 0;){if(r===e.id)return!0;r=n.get(r)?.parentId}return!1}function Yg(e){let t=new Map(e.map(e=>[e.id,e])),n=new Map;for(let r of e){if(r.parentId!==void 0&&!t.has(r.parentId))throw TypeError(`route '${r.fullPattern}' references a missing compiler parent`);let e=qg(r.fullPattern),i=n.get(e);if(i!==void 0&&!Jg(i,r,t)&&!Jg(r,i,t))throw TypeError(`ambiguous routes '${i.fullPattern}' and '${r.fullPattern}' share '${e}'`);n.set(e,r)}}function Xg(e){return!e.computed&&W(e.key)?e.key.name:G(e.key)?e.key.value:null}function Zg(e,t){let n=e.node,r=zg(n),i,a=null;if(r!==null)try{i=Hg(r)}catch(t){throw e.buildCodeFrameError(`memo-dom: ${t.message}`)}else if(ci(n.value)&&Vr(n.value.expression)){let t=n.value.expression;if(t.properties.some(e=>gi(e)))throw e.buildCodeFrameError(`memo-dom: route-to objects must have statically known keys; object spreads are not supported`);let r=new Map;for(let n of t.properties){if(!Hr(n))continue;let t=Xg(n);if(t===null)throw e.buildCodeFrameError(`memo-dom: route-to object keys must be static`);if(r.has(t))throw e.buildCodeFrameError(`memo-dom: route-to contains duplicate '${t}' fields`);r.set(t,n)}let o=new Set([`path`,`params`,`query`,`hash`,`replace`]);for(let t of r.keys())if(!o.has(t))throw e.buildCodeFrameError(`memo-dom: route-to does not support '${t}'`);let s=r.get(`path`);if(s===void 0||!G(s.value))throw e.buildCodeFrameError(`memo-dom: route-to requires a static string 'path'`);try{i=Hg(s.value.value)}catch(t){throw e.buildCodeFrameError(`memo-dom: ${t.message}`)}a=Zn(t.properties.filter(e=>Hr(e)&&Xg(e)!==`path`).map(e=>S(e,!0)));let c=Ug(i),l=r.get(`params`);if(c.length>0&&l===void 0)throw e.buildCodeFrameError(`memo-dom: route-to '${i}' requires params { ${c.join(`, `)} }`);if(l!==void 0){if(!Vr(l.value))throw e.buildCodeFrameError(`memo-dom: route-to params must be an object literal with static keys`);if(l.value.properties.some(e=>gi(e)))throw e.buildCodeFrameError(`memo-dom: route-to params do not support object spreads`);let t=l.value.properties.map(e=>Hr(e)?Xg(e):null);if(t.some(e=>e===null))throw e.buildCodeFrameError(`memo-dom: route-to param names must be static`);let n=t,r=n.find((e,t)=>n.indexOf(e)!==t);if(r!==void 0)throw e.buildCodeFrameError(`memo-dom: route-to params contain duplicate '${r}'`);let a=c.filter(e=>!n.includes(e)),o=n.filter(e=>!c.includes(e));if(a.length>0||o.length>0)throw e.buildCodeFrameError(`memo-dom: route-to '${i}' params mismatch`+(a.length===0?``:`; missing ${a.join(`, `)}`)+(o.length===0?``:`; unknown ${o.join(`, `)}`))}}else throw e.buildCodeFrameError(`memo-dom: route-to must be a static route string or a statically shaped destination object`);let o=t.get(i);if(o===void 0)throw e.buildCodeFrameError(`memo-dom: route-to references undeclared route '${i}'`);let s=Ug(o.fullPattern);if(r!==null&&s.length>0)throw e.buildCodeFrameError(`memo-dom: route-to '${i}' requires params { ${s.join(`, `)} }; use the object form`);return{path:i,options:a}}function Qg(e,t){if(t.options===null)return E(t.path);let n=new Map;for(let e of t.options.properties){if(!Hr(e)||!q(e.value))continue;let t=Xg(e);t!==null&&n.set(t,e.value)}let r=e=>S(n.get(e)??T(`undefined`),!0);return k(da(e,`buildRoutePath`),[E(t.path),r(`params`),r(`query`),r(`hash`)])}function $g(e,t){return k(da(e,`navigateRoute`),[E(t.path),...t.options===null?[]:[S(t.options,!0)]])}function e_(e,t,n,r){let i=t.openingElement;if(!J(i.name))throw n.buildCodeFrameError(`memo-dom: route-to currently requires a statically named JSX element`);let a=i.name.name;if(/^[A-Z]/.test(a))throw n.buildCodeFrameError(`memo-dom: route-to currently targets intrinsic elements; put it on the interactive host rendered by this component`);if(i.attributes.some(e=>si(e)))throw n.buildCodeFrameError(`memo-dom: route-to cannot be combined with JSX prop spreads because navigation ownership must be static`);if(a===`a`){if(Rg(t,`href`)!==void 0)throw n.buildCodeFrameError(`memo-dom: an anchor using route-to must not also declare href`);let a=Qg(e,r);i.attributes.push(pr(fr(`href`),G(a)?a:mr(a)));return}let o=Rg(t,`onClick`),s=Y(e,`routeEvent`),c=[],l=null;if(o!==void 0){let t=null;if(ci(o.value)&&q(o.value.expression)&&(t=o.value.expression),t===null)throw n.buildCodeFrameError(`memo-dom: onClick used with route-to must contain a handler expression`);l=Y(e,`routeClickResult`),c.push(B(`const`,[V(S(l),k(S(t,!0),[S(s)]))])),i.attributes=i.attributes.filter(e=>e!==o)}c.push(ar(er(`!`,A(S(s),T(`defaultPrevented`))),z($g(e,r)))),l!==null&&c.push(ir(S(l))),i.attributes.push(pr(fr(`onClick`),mr(L([S(s)],R(c)))))}function t_(e,t){let n=[],r=0,i=[],a=t.node;C(a,{enter(a){if(a.type!==`JSXElement`)return;let o=a,s=i.at(-1)??null,c=s,l=Rg(o,`route`);if(l===void 0){i.push(c);return}let u={node:l,buildCodeFrameError(e){return t.buildCodeFrameError(e,l)}},d=zg(l);if(d===null)throw u.buildCodeFrameError(`memo-dom: route must be a static string beginning with /`);let f;try{f=Hg(d)}catch(e){throw u.buildCodeFrameError(`memo-dom: ${e.message}`)}let p;try{p=s===null?f:Wg(s.fullPattern,f)}catch(e){throw u.buildCodeFrameError(`memo-dom: ${e.message}`)}let m=new Set(s===null?[]:Ug(s.fullPattern));for(let e of Ug(f))if(m.has(e))throw u.buildCodeFrameError(`memo-dom: route '${p}' shadows active parameter '${e}'`);let h={id:Bg(e.moduleId,o,r++),moduleId:e.moduleId,pattern:f,fullPattern:p,...s===null?{}:{parentId:s.id},...o.openingElement.loc?.start.line===void 0?{}:{line:o.openingElement.loc.start.line},...o.openingElement.loc?.start.column===void 0?{}:{column:o.openingElement.loc.start.column}};e.routeElements.set(o,h),n.push(h),e.localRoutes.push(h),e.usesRouter=!0,o.openingElement.attributes=o.openingElement.attributes.filter(e=>e!==l),c=h,i.push(c)},leave(e){e.type===`JSXElement`&&i.pop()}});let o=e.linkedRoutes??n;Yg(o);let s=new Map(o.map(e=>[e.fullPattern,e]));C(a,{enter(n){if(n.type!==`JSXElement`)return;let r=n,i=Rg(r,`route-to`);if(i===void 0)return;let a={node:i,buildCodeFrameError(e){return t.buildCodeFrameError(e,i)}},o=Zg(a,s);e.usesRouter=!0,r.openingElement.attributes=r.openingElement.attributes.filter(e=>e!==i),e_(e,r,a,o)}})}function n_(e){if(!e.emitRouteManifest)return[];let t=e.linkedRoutes??e.localRoutes;if(t.length===0)return[];e.usesRouter=!0;let n=Y(e,`routeManifest`);return[B(`const`,[V(S(n),k(da(e,`createRouteManifest`),[j(t.map(e=>Zn([M(T(`id`),E(e.id)),M(T(`pattern`),E(e.pattern)),...e.parentId===void 0?[]:[M(T(`parentId`),E(e.parentId))]])))]))]),z(k(da(e,`replaceRouteResolver`),[A(S(n),T(`resolve`))])),z(k(da(e,`ensureRouterConnected`),[]))]}function r_(e){if(!J(e.name))return null;let t=e.name.name;return t===`if`||t===`else-if`||t===`else`?t:null}function i_(e,t){let n=null;for(let r of e.openingElement.attributes){if(!oi(r))continue;let e=r_(r);if(e!==null){if(n!==null)throw t.buildCodeFrameError(`memo-dom: a JSX element may have only one of if, else-if, or else`);if(e===`else`){if(r.value!==null)throw t.buildCodeFrameError(`memo-dom: the JSX else directive does not accept a value; write <Element else>`);n={kind:e,condition:null};continue}if(!ci(r.value)||ui(r.value.expression)||!q(r.value.expression))throw t.buildCodeFrameError(`memo-dom: the JSX ${e} directive requires an expression, for example ${e}={condition}`);n={kind:e,condition:S(r.value.expression,!0)}}}return n}function a_(e){e.openingElement.attributes=e.openingElement.attributes.filter(e=>!oi(e)||r_(e)===null)}function o_(e){return li(e)&&e.value.trim()===``||ci(e)&&ui(e.expression)}function s_(e,t){let n=e.children;if(n.length===0)return;let r=[],i=0;for(;i<n.length;){let e=n[i];if(!ii(e)){r.push(e),i++;continue}let a=i_(e,t);if(a?.kind===`else-if`||a?.kind===`else`)throw t.buildCodeFrameError(`memo-dom: JSX ${a.kind} must immediately follow an if or else-if sibling`);if(a?.kind!==`if`){r.push(e),i++;continue}a_(e);let o=[{condition:a.condition,element:e}],s=null,c=i+1,l=[];for(;c<n.length;){let e=[];for(;c<n.length&&o_(n[c]);)e.push(n[c]),c++;if(c>=n.length){l=e;break}let r=n[c];if(!ii(r)){l=e;break}let i=i_(r,t);if(i?.kind===`else-if`){a_(r),o.push({condition:i.condition,element:r}),c++;continue}if(i?.kind===`else`)for(a_(r),s=r,c++;c<n.length&&o_(n[c]);)l.push(n[c]),c++;else l=e;break}let u=s??O();for(let e=o.length-1;e>=0;e--){let t=o[e];u=I(t.condition,t.element,u)}r.push(mr(u),...l),i=c}e.children=r}function c_(e,t,n,r){if(t===void 0)return;let i=e;if(n===void 0){i[t]=r;return}let a=i[t];Array.isArray(a)&&(a[n]=r)}function l_(e){C(e.node,{leave(t){(t.type===`JSXElement`||t.type===`JSXFragment`)&&s_(t,e)}}),C(e.node,{enter(t,n,r,i){if(t.type!==`JSXElement`)return;let a=t,o=i_(a,e);if(o===null)return;if(o.kind!==`if`)throw e.buildCodeFrameError(`memo-dom: JSX ${o.kind} must immediately follow an if or else-if sibling`);a_(a);let s=yr(_r(),vr(),[mr(I(o.condition,a,O()))]);return n!==null&&c_(n,r,i,s),!1}}),e.scope?.crawl()}function u_(e,t){let n=`${e.rootId}/$computed/${encodeURIComponent(e.moduleId)}#`;for(let r=0;r<t.body.length;r++){let i=t.body[r];if(_i(i)&&(i=i.declaration),!qr(i)||i.kind!==`const`)continue;let a=[];for(let t of i.declarations){if(!W(t.id)||t.init==null)continue;let r=t.id.name;if(!e.computeds.has(r))continue;i.kind=`let`;let o=S(t.init),s=Y(e,`${r}Next`),c=z(k(X(e,`register`),[Zn([M(T(`id`),E(`${n}${r}`)),M(T(`parent`),O()),M(T(`depth`),er(`-`,D(1))),M(T(`render`),L([],R([B(`const`,[V(s,o)]),ar(k(X(e,`computedChanged`),[T(r),S(s)]),R([z(F(`=`,T(r),S(s))),z(k(X(e,`commitWrites`),[ba(e,[r])]))]))])))])]));a.push(c)}a.length>0&&(t.body.splice(r+1,0,...a),r+=a.length)}}function d_(e,t){for(let n of e.moduleControlFlow){let r=t.body.indexOf(n.statement);if(r===-1)continue;let i=new Map(n.bindings.map(t=>[t,Y(e,`${t}Previous`)])),a=[B(`const`,n.bindings.map(e=>V(S(i.get(e)),T(e)))),S(n.statement,!0),...n.bindings.map(t=>ar(k(X(e,`computedChanged`),[S(i.get(t)),T(t)]),R([z(k(X(e,`commitWrites`),[ba(e,[t])]))])))];t.body.splice(r+1,0,z(k(X(e,`register`),[Zn([M(T(`id`),E(n.entityId)),M(T(`parent`),O()),M(T(`depth`),er(`-`,D(1))),M(T(`render`),L([],R(a)))])])))}}function f_(e,t){let n=e.astAnalysis;if(n===null)return;let r=e=>{let t=n.parentByNode.get(e)??null;for(;t!==null;){if(t.type===`FunctionDeclaration`){let e=t.id;if(e?.type===`Identifier`)return` in component '${e.name}'`}t=n.parentByNode.get(t)??null}return` at module scope`},i=e=>{let t=e;for(;t!==null;){if(t.loc!==null&&t.loc!==void 0)return`${t.loc.start.line}:${t.loc.start.column+1}`;t=n.parentByNode.get(t)??null}return null};C(t.node,{enter(e){if(e.type!==`JSXElement`&&e.type!==`JSXFragment`)return;let n=i(e),a=`fragment`;if(e.type===`JSXElement`){let t=e.openingElement;a=J(t.name)?`<${t.name.name}>`:`<element>`}throw t.buildCodeFrameError(`memo-dom: JSX outside a component or compile-time render helper — leftover ${a}${r(e)}${n===null?``:` near ${n}`}; components must use a supported top-level declaration`)}})}function p_(e,t){jg(t),md(e,t),l_(t),sa(e,t.node),Zd(e,t),$d(e,t),Uf(e,t),Gf(e,t),t_(e,t),Zp(e,t),Jf(e,t),Yf(e),bp(e),ag(e,t),og(e)}function m_(e,t){fm(e,t),fc(e,t),sg(e,t),pc(e,t),e.header.unshift(...n_(e)),f_(e,t);let n=Pp(e);e.computeds.size>0&&u_(e,t.node),e.moduleControlFlow.length>0&&d_(e,t.node),n&&e.header.push(n);let r=[sr([ur(T(fa(e).runtimeId))],E(e.runtimePath))];if(e.hot&&r.push(sr([ur(T(fa(e).hotRuntimeId))],E(e.hotRuntimePath))),e.usesRouter&&r.push(sr([ur(T(fa(e).routerId))],E(e.routerPath))),e.usesTransparentData&&r.push(sr([ur(T(fa(e).dataRuntimeId))],E(e.dataRuntimePath))),t.node.body.unshift(...r,...e.header),e.rootComponent!==null){let n=z(k(X(e,`registerRootFactory`),[T(e.rootComponent),Zn([M(T(`id`),E(e.rootId)),M(T(`create`),L([],k(T(e.rootComponent),[E(e.rootId),O(),j([])])))])]));t.node.body.push(n)}}function h_(e,t={}){let n=aa(t);p_(n,e);for(let[e,t]of n.compPaths)Eg(n,t,e);m_(n,e)}function g_(e,t={}){h_(e,t),It(e.node)}function __(e,t,n,r){if(r!==void 0)return{program:S(r.type===`File`?r.program:r),comments:[]};let i=Jt(n,e,{filename:t,sourceType:`module`});return{program:i.program,comments:i.comments,css:i.css}}function v_(e,t,n,r,i=Jn){let a=t.moduleId??`./component.tsx`,o=__(e,a,i,r);g_({node:o.program,buildCodeFrameError(e,t=o.program){return km(e,a,t)}},t);let s=Xt(en(o.program),{comments:o.comments,...n?{sourceMapSource:a,sourceMapContent:e}:{}});return{code:s.code,map:s.map===null?null:{...s.map,sources:s.map.sources.map(e=>e??a)},...o.css?{css:o.css}:{}}}function y_(e,t={}){let{frontend:n=Jn,...r}=t;return v_(e,r,!1,void 0,n).code}function b_(e,t,n){return v_(e,t,!1,n).code}function x_(e,t={}){let{frontend:n=Jn,...r}=t,i=v_(e,r,!0,void 0,n);if(i.map===null)throw Error(`memo-dom: compilation produced no source map`);return{code:i.code,map:i.map,...i.css?{css:i.css}:{}}}function S_(e,t,n){let r=v_(e,t,!0,n);if(r.map===null)throw Error(`memo-dom: compilation produced no source map`);return{code:r.code,map:r.map,...r.css?{css:r.css}:{}}}function C_(e,t,n){let r=e.get(t);r===void 0&&(r=new Map,e.set(t,r));let i=r.get(n);return i===void 0&&(i={keys:new Set,rootFallback:!1,transparent:!1},r.set(n,i)),i}function w_(e,t,n,r){if(n.type===`state`){r.keys.add(n.key);return}if(n.type===`transparent`){r.transparent=!0;return}if(n.type===`root`){r.rootFallback=!0;return}if(n.type===`local`)return;let i=e.get(t)?.get(n.name);if(i===void 0){r.rootFallback=!0;return}r.rootFallback||=i.rootFallback,r.transparent||=i.transparent;let a=n.path.length===0?``:`.${n.path.join(`.`)}`;for(let e of i.keys)r.keys.add(`${e}${a}`)}function T_(e,t){let n=new Map;for(let t of e.values())for(let e of t.edges)n.set(e.target,(n.get(e.target)??0)+1);let r=new Map,i=new Map(n),a=[...t];for(;a.length>0;){let t=a.shift();for(let n of e.get(t)?.edges??[]){for(let[e,i]of Object.entries(n.propSources??{})){let a=C_(r,n.target,e);for(let e of i)w_(r,t,e,a)}let e=(i.get(n.target)??1)-1;i.set(n.target,e),e===0&&a.push(n.target)}}return new Map([...r].map(([e,t])=>[e,new Map([...t].map(([e,t])=>[e,{keys:[...t.keys].sort(),rootFallback:t.rootFallback,transparent:t.transparent}]))]))}function E_(e){let t=new Set,n=new Set,r=i=>{if(n.has(i))throw Error(`memo-dom: recursive cross-module component graph at '${i}'`);if(!t.has(i)){n.add(i);for(let t of e.get(i)?.edges??[])r(t.target);n.delete(i),t.add(i)}};for(let t of e.keys())r(t)}function D_(e,t){let n=new Map(e.map(e=>[e.key,e]));E_(n);let r=new Map,i=new Map;for(let e of n.values())for(let t of e.edges){if(!n.has(t.target))throw Error(`memo-dom: component '${e.key}' references unknown factory '${t.target}'`);let a=r.get(t.target)??new Set;if(a.add(t.mode),r.set(t.target,a),t.mode===`row`){let e=i.get(t.target)??[];e.push({keyPath:t.keyPath===void 0||t.keyPath===null?null:[...t.keyPath],sourceKey:t.sourceKey??``,sourceLocal:t.sourceLocal??!1}),i.set(t.target,e)}}for(let[e,t]of r)if(t.size>1)throw Error(`memo-dom: component '${e}' is used both as a keyed row and a static child`);let a=new Map,o=[...n.keys()].filter(e=>!r.has(e)),s=t===void 0?o:[t.key];if(t!==void 0&&!n.has(t.key))throw Error(`memo-dom: mounted component '${t.key}' is missing from the linked component graph`);for(let e of s)a.set(e,new Set([t?.rootId??`App`]));let c=[...s];for(;c.length>0;){let e=c.shift(),t=a.get(e);if(t!==void 0)for(let r of n.get(e)?.edges??[]){let e=a.get(r.target)??new Set,n=e.size;for(let n of t)e.add(`${n}${r.suffix}`);a.set(r.target,e),e.size!==n&&c.push(r.target)}}let l=new Map;for(let e of n.keys())l.set(e,[...a.get(e)??[]].sort());return{paths:l,rows:i,propSources:T_(n,s)}}function O_(e){let t=e;for(;Ii(t)||Li(t)||Ri(t)||zi(t);)t=t.expression;return t}function k_(e,t){let n=O_(t);if(W(n))return!e.state.has(n.name)||Q(e,n,n.name)?.scope.isProgramScope!==!0?null:ya(e,n.name);if(!K(n))return null;let r=Ea(n);return r===null||!e.state.has(r)||Q(e,n,r)?.scope.isProgramScope!==!0?null:ya(e,Ca(n)??r)}function A_(e,t){let n=O_(t);if(W(n)){let t=io(e,n.name);return t===null?null:{type:`prop`,name:t,path:[]}}if(!K(n))return null;let r=Ea(n),i=Ca(n);if(r===null||i===null)return null;if(no(e)===r){let[e,...t]=i.split(`.`).slice(1);return e===void 0?null:{type:`prop`,name:e,path:t}}let a=io(e,r);return a===null?null:{type:`prop`,name:a,path:i.split(`.`).slice(1)}}function j_(e,t){let n=!1,r=no(e);return Ma(t,t=>{W(t)&&(t.name===r||io(e,t.name)!==null)&&(n=!0)}),n}function M_(e){return G(e)||Nr(e)||Pr(e)||Fr(e)||Ir(e)||ki(e)||e.type===`Literal`}function N_(e,t,n){let r=A_(e.componentProps.get(t),T(n));if(r!==null)return r;let i=e.compPaths.get(t)?.node,a=i===void 0?void 0:Q(e,i,n);return e.state.has(n)&&a?.scope.isProgramScope===!0?{type:`state`,key:ya(e,n)}:{type:`root`}}function P_(e,t){if(!W(t))return null;let n=e.astAnalysis?.parentByNode;if(n===void 0)return null;let r=t;for(;;){let e=n.get(r);if(e==null)return null;if(e.type===`ArrowFunctionExpression`||e.type===`FunctionExpression`||e.type===`FunctionDeclaration`){if(!e.params.some(e=>St(e).some(({name:e})=>e===t.name))){r=e;continue}let i=n.get(e);if(i===null||i?.type!==`CallExpression`&&i?.type!==`OptionalCallExpression`)return null;let a=i.callee;return!K(a)&&!zr(a)||a.computed||!W(a.property,{name:`map`})||!q(a.object)?null:a.object}r=e}}function F_(e,t,n){let r=k_(e,n);if(r!==null)return[{type:`state`,key:r}];let i=A_(e.componentProps.get(t),n);if(i!==null)return[i];if(!W(n))return[{type:`root`}];let a=(e.instanceDerivations.get(t)??[]).find(e=>e.bindings.includes(n.name));if(a===void 0)return[N_(e,t,n.name)];let o=a.sources.map(n=>N_(e,t,n));return o.length>0?o:[{type:`root`}]}function I_(e,t,n,r){if(!W(r))return null;let i=P_(e,r);if(i!==null)return F_(e,t,i);let a=[...e.listedSites?.get(n)??[],...e.rowComponentSites?.get(n)??[]].filter(e=>e.owner===t&&e.itemParam===r.name);if(a.length===0)return null;let o=[],s=e=>{let t=JSON.stringify(e);o.some(e=>JSON.stringify(e)===t)||o.push(e)};for(let n of a){let r=n.sourceKey;if(r===void 0||r===``){s({type:`root`});continue}if(n.sourceLocal!==!0){s({type:`state`,key:ya(e,r)});continue}let i=(e.instanceDerivations.get(t)??[]).find(e=>e.bindings.includes(r));if(i===void 0){s(N_(e,t,r.split(`.`)[0]));continue}for(let n of i.sources)s(N_(e,t,n))}return o}function L_(e,t,n,r){let i=O_(r),a=I_(e,t,n,i);if(a!==null)return a;let o=k_(e,i);if(o!==null)return[{type:`state`,key:o}];let s=e.componentProps.get(t),c=A_(s,i);if(c!==null)return[c];if(W(i)){let n=Q(e,i,i.name),r=e.compPaths.get(t)?.node,a=r===void 0?void 0:Q(e,r,i.name);if(n!==void 0&&n===a&&e.transparentSources.get(t)?.has(i.name)===!0)return[{type:`transparent`}]}let l=W(i)?i.name:K(i)?Ea(i):null;return l!==null&&(e.instanceState.get(t)?.has(l)===!0||e.instanceDerivedBindings.get(t)?.has(l)===!0)||Pa(e,i).size>0||j_(s,i)?[{type:`root`}]:[M_(i)?{type:`local`}:{type:`root`}]}function R_(e,t,n,r){let i=e.get(t)??{},a=i[n]??[],o=JSON.stringify(r);a.some(e=>JSON.stringify(e)===o)||(a.push(r),a.sort((e,t)=>JSON.stringify(e).localeCompare(JSON.stringify(t)))),i[n]=a,e.set(t,i)}function z_(e){return J(e.name)?e.name.name:null}function B_(e,t){let n=new Map;return Ma(e.compPaths.get(t).node,r=>{if(r.type!==`JSXOpeningElement`)return;let i=r,a=i.name;if(!J(a)||!/^[A-Z]/.test(a.name))return;let o=e.componentProps.get(a.name);for(let r of i.attributes){if(si(r)){for(let e of o?.names??[])e===`ref`||o?.refProps.includes(e)||R_(n,a.name,e,{type:`root`});continue}if(!oi(r))continue;let i=z_(r);if(i===null||i===`key`||i===`ref`||o?.refProps.includes(i)===!0)continue;let s=r.value;if(!ci(s)||s.expression.type===`JSXEmptyExpression`){R_(n,a.name,i,{type:`local`});continue}for(let r of L_(e,t,a.name,s.expression))R_(n,a.name,i,r)}}),n}function V_(e,t){let n=new Map,r=e=>e,i=e=>typeof e==`object`&&e&&typeof e.type==`string`?e:null,a=e=>Array.isArray(e)?e.filter(e=>i(e)!==null):[],o=a(r(e).body);for(let e of o){let o=e.type===`ExportNamedDeclaration`||e.type===`ExportDefaultDeclaration`?i(r(e).declaration):e;if(o?.type!==`FunctionDeclaration`)continue;let s=i(r(o).id),c=s?.type===`Identifier`?r(s).name:null;if(typeof c!=`string`||!/^[A-Z]/.test(c))continue;let l=!1;if(C(o,{enter(e){if(e.type===`JSXElement`||e.type===`JSXFragment`)return l=!0,!1}}),!l)continue;let u=Ka(a(r(o).params)),d=i(r(o).body);n.set(c,{key:`${t}#${c}`,props:[...u.names],objectProps:u.mode===`object`,acceptsUnknownProps:u.acceptsUnknown,hasWholeDefault:u.hasWholeDefault,listLightweight:!1,delegatedEvents:d===null?[]:Ud(d),renderProps:[],renderCallbacks:[],refProps:[],subtreeReads:[]})}return n}function H_(e,t,n){let r=e.componentProps.get(n);return{key:`${t}#${n}`,props:[...r.names],objectProps:r.mode===`object`,acceptsUnknownProps:r.acceptsUnknown,hasWholeDefault:r.hasWholeDefault,listLightweight:Ul(e,n),delegatedEvents:[...e.componentHostEvents.get(n)??[]],renderProps:[...r.renderProps],renderCallbacks:[...r.renderCallbacks],refProps:[...r.refProps],subtreeReads:[...Id(e,n)].map(t=>ya(e,t)).sort()}}function U_(e,t){return e.importedComponents.get(t)?.key??`${e.moduleId}#${t}`}function W_(e,t){let n=[];for(let r of t.comps.keys()){let i=[],a=B_(t,r);for(let[e,n]of t.childRefCounts.get(r)??[]){let r=U_(t,e),o=a.get(e);i.push({target:r,suffix:`/${e}`,mode:`static`,...o===void 0?{}:{propSources:o}}),n>1&&i.push({target:r,suffix:`/${e}[*]`,mode:`static`,...o===void 0?{}:{propSources:o}}),t.usesRouter&&i.push({target:r,suffix:`/**/${e}`,mode:`static`,...o===void 0?{}:{propSources:o}})}for(let[e,n]of t.conditionalComponentSites)for(let o of n){if(o.owner!==r)continue;let n=a.get(e);i.push({target:U_(t,e),suffix:`/${o.suffix}`,mode:`static`,...n===void 0?{}:{propSources:n}})}for(let[e,n]of t.rowComponentSites)for(let o of n){if(o.owner!==r)continue;let n=a.get(e);i.push({target:U_(t,e),suffix:`/${o.suffix}`,mode:`static`,...n===void 0?{}:{propSources:n}})}for(let[e,n]of t.listedSites)for(let o of n)o.owner===r&&i.push({target:U_(t,e),suffix:`/${o.suffix}/Row[*]`,mode:`row`,keyPath:wa(o.keyExpr??null,o.itemParam??``),sourceKey:o.sourceLocal===!0?o.sourceKey??``:ya(t,o.sourceKey??``),sourceLocal:o.sourceLocal??!1,...a.get(e)===void 0?{}:{propSources:a.get(e)}});n.push({key:`${e}#${r}`,moduleId:e,local:r,edges:i})}return n}function G_(e){let t=e.replace(/\\/g,`/`),n=u.normalize(t);return t.startsWith(`./`)&&!n.startsWith(`../`)?`./${n}`:n}function K_(e,t,n){let r=Jt(n,t,{filename:e,sourceType:`module`});return{ast:r.program,css:r.css}}function q_(e,t=`App`){return{...e.runtimePath===void 0?{}:{runtimePath:e.runtimePath},...e.hotRuntimePath===void 0?{}:{hotRuntimePath:e.hotRuntimePath},...e.dataRuntimePath===void 0?{}:{dataRuntimePath:e.dataRuntimePath},...e.transparentAsyncSources===void 0?{}:{transparentAsyncSources:e.transparentAsyncSources},...e.hot===void 0?{}:{hot:e.hot},...e.moduleStateCells===void 0?{}:{moduleStateCells:e.moduleStateCells},rootId:t}}function J_(e){let t=new Map,n=(e,n,r)=>{t.set(`${e}\0${n}\0${r}`,{target:e,prop:n,kind:r})};for(let[t,r]of e.compPaths)C(r.node,{enter(r){if(r.type!==`JSXElement`)return;let i=r,a=i.openingElement,o=a.name;if(!J(o)||!/^[A-Z]/.test(o.name))return;let s=e.importedComponents.get(o.name)?.key??(e.comps.has(o.name)?`${e.moduleId}#${o.name}`:null);if(s!==null){for(let r of a.attributes){if(!oi(r))continue;let i=J(r.name)?r.name.name:r.name.name.name,a=r.value;ii(a)||ai(a)||ci(a)&&q(a.expression)&&(Na(a.expression)||Ls(e,t,a.expression))?n(s,i,`jsx`):n(s,i,`scalar`)}i.children.some(e=>!li(e)||e.value.trim()!==``)&&n(s,`children`,`jsx`)}}});return[...t.values()].sort((e,t)=>e.target.localeCompare(t.target)||e.prop.localeCompare(t.prop)||e.kind.localeCompare(t.kind))}function Y_(e,t){return[...new Set(t.flatMap(t=>{let n=e.importedComponents.get(t);return n===void 0?e.comps.has(t)?[`${e.moduleId}#${t}`]:[]:[n.key]}))].sort()}function X_(e,t,n){let r=e;for(;Ii(r)||Li(r)||Ri(r);)r=r.expression;if(e=r,W(e)){t.has(e.name)&&n.add(e.name);return}if(ri(e)){X_(e.consequent,t,n),X_(e.alternate,t,n);return}if(ni(e)){X_(e.right,t,n);return}if(Vr(e)){for(let r of e.properties)Hr(r)&&q(r.value)&&X_(r.value,t,n);return}if(Br(e))for(let r of e.elements)r!=null&&!gi(r)&&X_(r,t,n)}function Z_(e,t){let n=new Set;if(q(e.body))return X_(e.body,t,n),[...n];let r=e=>{if(!Kr(e)){if(Xr(e)){q(e.argument)&&X_(e.argument,t,n);return}for(let t of ht[e.type]??[]){let n=e[t];if(Array.isArray(n))for(let e of n)typeof e==`object`&&e&&`type`in e&&r(e);else typeof n==`object`&&n&&`type`in n&&r(n)}}};for(let t of e.body.body)r(t);return[...n]}function Q_(e,t){let n=e.arguments[1];if(!Vr(n))return W(e.callee)?t.get(e.callee.name)??`GET`:`GET`;for(let e of n.properties){if(!Hr(e)||e.computed||(W(e.key)?e.key.name:G(e.key)?e.key.value:null)!==`method`||!G(e.value))continue;let t=e.value.value.toUpperCase();return t===`GET`||t===`POST`||t===`PUT`||t===`PATCH`||t===`DELETE`?t:null}return`GET`}function $_(e,t,n=new Map){let r=new Map,i=e=>{let n=Yr(e.body)?e.body.body.length===1&&Xr(e.body.body[0])?e.body.body[0].argument:null:e.body,r=n!==null&&q(n)?_a(n):null;return Lr(r)&&W(r.callee)&&t.has(r.callee.name)?r:null};for(let t of e.body){let e=_i(t)?t.declaration:t;if(Ur(e)&&e.id!==null&&i(e)!==null){r.set(e.id.name,Q_(i(e),n));continue}if(qr(e))for(let t of e.declarations){if(!W(t.id)||t.init===null)continue;let e=q(t.init)?_a(t.init):t.init;(Wr(e)||Gr(e))&&i(e)!==null&&r.set(t.id.name,Q_(i(e),n))}}return r}function ev(e){let t=[];for(let n of e.body)if(!(!bi(n)||n.importKind===`type`))for(let e of n.specifiers)if(xi(e)){if(e.importKind===`type`)continue;let r=W(e.imported)?e.imported.name:e.imported.value;t.push({local:e.local.name,imported:r,source:n.source.value})}else Si(e)?t.push({local:e.local.name,imported:`default`,source:n.source.value}):t.push({local:e.local.name,imported:`*`,source:n.source.value});return t}function tv(e,t){let n=new Set([t,`${t}/hydrate`]),r=new Set;for(let t of e.body)if(!(!bi(t)||!n.has(t.source.value)))for(let e of t.specifiers)xi(e)&&(W(e.imported,{name:`mount`})||G(e.imported,{value:`mount`})||W(e.imported,{name:`hydrate`})||G(e.imported,{value:`hydrate`}))&&r.add(e.local.name);let i=[];for(let t of e.body){if(!Qr(t))continue;let e=t.expression;if(!Lr(e)||!W(e.callee)||!r.has(e.callee.name))continue;let n=e.arguments[1];if(n===void 0||!W(n))throw Error(`memo-dom: mount() must receive a statically imported component identifier`);i.push(n.name)}return i}function nv(e){let t=new Map;for(let n of e.body){if(vi(n)){(Ur(n.declaration)||Mi(n.declaration))&&n.declaration.id!=null?t.set(`default`,n.declaration.id.name):W(n.declaration)&&t.set(`default`,n.declaration.name);continue}if(!_i(n))continue;if(n.source!==null)throw Error(`memo-dom: re-export-from declarations are not supported by compileModules(); import then export the binding explicitly`);let e=n.declaration;if(qr(e))for(let n of e.declarations)W(n.id)&&t.set(n.id.name,n.id.name);else Ur(e)&&e.id!=null&&t.set(e.id.name,e.id.name);for(let e of n.specifiers){if(!yi(e))continue;let n=e.local.name,r=G(e.exported)?e.exported.value:e.exported.name;t.set(r,n)}}return t}function rv(e,t,n,r,i){let a,o={node:S(e.ast,!0),buildCodeFrameError(t,n=e.ast){return km(t,e.id,n)}};jg(o);let s=ev(o.node),c=aa({...q_(n,r),moduleId:e.id,linkedImports:t,linkedRoutes:i});md(c,o),sa(c,o.node),Zd(c,o),$d(c,o),Uf(c,o),Gf(c,o),t_(c,o),Zp(c,o),Jf(c,o),Yf(c),Pp(c);let l={},u=id(o.node),d=$_(o.node,c.transparentSourceFactories,c.transparentSourceFactoryMethods);for(let[n,r]of nv(o.node)){if(c.comps.has(r)){l[n]={type:`component`,...H_(c,e.id,r)};continue}let i=c.state.get(r);if(i!==void 0){l[n]={type:`state`,kind:i,key:c.stateKeys.get(r)??`${e.id}#${r}`,transparentSource:t[r]?.type===`state`?t[r]?.transparentSource===!0:c.transparentModuleSources.has(r),tagCandidates:[...c.stateTagCandidates.get(r)??[]],componentCandidates:Y_(c,c.stateComponentCandidates.get(r)??[])};continue}if(c.transparentModuleSources.has(r)){l[n]={type:`state`,kind:`let`,key:c.transparentModuleSources.get(r)??`${e.id}#${r}`,transparentSource:!0,tagCandidates:[],componentCandidates:[]};continue}let a=c.importedFunctions.get(r)??(c.helpers.has(r)?ws(c,r):void 0);if(a!==void 0){l[n]={type:`function`,...d.has(r)?{transparentSourceFactory:!0,...d.get(r)===null?{}:{transparentSourceMethod:d.get(r)}}:{},tagCandidates:[...u.get(r)??c.functionTagCandidates.get(r)??[]],componentCandidates:Y_(c,c.functionComponentCandidates.get(r)??[]),reads:[...a.reads].map(e=>ya(c,e)).sort(),writes:[...a.writes].map(e=>ya(c,e)).sort(),boundedWrites:[...a.boundedWrites].map(e=>ya(c,e)).sort(),parameterWrites:a.parameterWrites.map(e=>({index:e.index,path:[...e.path]})).sort((e,t)=>e.index-t.index||e.path.join(`.`).localeCompare(t.path.join(`.`))),unbounded:a.unbounded};continue}l[n]={type:`value`}}if(a={exports:l,imports:s,mounts:tv(o.node,n.runtimePath??`@memoized-dom/runtime`),components:W_(e.id,c),componentUsages:J_(c),readers:Object.fromEntries([...c.readers.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,[...t].sort()]))},a===void 0)throw Error(`memo-dom: failed to analyze module '${e.id}'`);return a}function iv(e,t){let n,r={node:S(e.ast,!0),buildCodeFrameError(t,n=e.ast){return km(t,e.id,n)}};jg(r);let i=new Map,a=rd(r.node),o=id(r.node),s=V_(r.node,e.id),c=new Set(s.keys()),l=new Map((t.transparentAsyncSources??ia).map(e=>[e.module,e.source])),u=new Set;for(let e of r.node.body){if(!bi(e))continue;let t=l.get(e.source.value);if(t!==void 0)for(let n of e.specifiers)xi(n)&&W(n.imported)&&n.imported.name===t&&u.add(n.local.name)}let d=$_(r.node,u);for(let[e,t]of s)i.set(e,{type:`component`,...t});for(let t of r.node.body){let n=_i(t)?t.declaration:t;if(qr(n))for(let t of n.declarations){if(!W(t.id))continue;let r=t.init!==null&&q(t.init)?_a(t.init):t.init;if(Gr(r)||Wr(r)){let n=Z_(r,c).map(t=>`${e.id}#${t}`);i.set(t.id.name,{type:`function`,...d.has(t.id.name)?{transparentSourceFactory:!0,...d.get(t.id.name)===null?{}:{transparentSourceMethod:d.get(t.id.name)}}:{},tagCandidates:[...o.get(t.id.name)??[]],componentCandidates:n,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0});continue}let s;if(Lr(r)&&W(r.callee)&&u.has(r.callee.name)){i.set(t.id.name,{type:`state`,kind:`let`,key:`${e.id}#${t.id.name}`,transparentSource:!0,tagCandidates:[],componentCandidates:[]});continue}if(n.kind===`let`||n.kind===`var`?s=`let`:Da(r)?s=`store`:Oa(r)&&(s=`const`),s!==void 0){let n=new Set;q(r)&&X_(r,c,n),i.set(t.id.name,{type:`state`,kind:s,key:`${e.id}#${t.id.name}`,tagCandidates:[...a.get(t.id.name)??[]],componentCandidates:[...n].map(t=>`${e.id}#${t}`)})}}else if(Ur(n)&&n.id!=null&&!s.has(n.id.name)){let t=Z_(n,c).map(t=>`${e.id}#${t}`);i.set(n.id.name,{type:`function`,...d.has(n.id.name)?{transparentSourceFactory:!0,...d.get(n.id.name)===null?{}:{transparentSourceMethod:d.get(n.id.name)}}:{},tagCandidates:[...o.get(n.id.name)??[]],componentCandidates:t,reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0})}}let f={};for(let[e,t]of nv(r.node)){let n=i.get(t);n!==void 0&&(f[e]=n)}if(n={exports:f,imports:ev(r.node),mounts:tv(r.node,t.runtimePath??`@memoized-dom/runtime`),components:[],componentUsages:[],readers:{}},n===void 0)throw Error(`memo-dom: failed to discover module '${e.id}'`);return n}function av(e,t,n,r){let i=r.resolveImport?.(t,e);if(i===void 0){let e=Object.entries(r.aliases??{}).sort(([e],[t])=>t.length-e.length);for(let[n,r]of e)if(n.endsWith(`/`)?t.startsWith(n):t===n||t.startsWith(`${n}/`)){i=`${r}${t.slice(n.length)}`;break}}if(i===void 0){if(t.startsWith(`.`)){let n=u.normalize(u.join(u.dirname(e),t));i=e.startsWith(`./`)&&!n.startsWith(`../`)?`./${n}`:n}else i=t}let a=G_(i??t),o=[a,`${a}.ts`,`${a}.tsx`,`${a}.js`,`${a}.jsx`,`${a}/index.ts`,`${a}/index.tsx`,`${a}/index.js`,`${a}/index.jsx`];for(let e of o){let t=n.get(e);if(t!==void 0)return t}}function ov(e,t,n){let r=[];for(let i of e.values()){let a=t.get(i.id);for(let o of a.mounts){let s=a.imports.find(e=>e.local===o);if(s===void 0||s.imported===`*`)throw Error(`memo-dom: mount root '${o}' must be a statically imported component`);let c=av(i.id,s.source,e,n),l=c===void 0?void 0:t.get(c.id)?.exports[s.imported];if(c===void 0||l?.type!==`component`)throw Error(`memo-dom: mount root '${o}' does not resolve to a compiled component`);let u=l.key.slice(l.key.lastIndexOf(`#`)+1);r.push({key:l.key,moduleId:c.id,mountModuleId:i.id,local:u,rootId:u})}}if(r.length>1)throw Error(`memo-dom: one connected application graph may contain only one top-level mount() call`);return r[0]}function sv(e,t){if(!t.startsWith(`.`))return t;let n=u.relative(u.dirname(e),t);return n.startsWith(`.`)?n:`./${n}`}function cv(e,t,n){return t.map(t=>{for(let[r,i]of n)for(let[n,a]of Object.entries(i.exports))if(a.type===`component`&&a.key===t)return{key:a.key,source:sv(e.id,r),imported:n,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 Error(`memo-dom: dynamic component candidate '${t}' is not exported; export the component so consuming modules can link it`)})}function lv(e,t,n,r,i,a){let o={};for(let s of t.imports){let t=av(e.id,s.source,r,i);if(t===void 0){o[s.local]={type:`function`,tagCandidates:[],componentCandidates:[],reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}if(s.imported===`*`)throw Error(`memo-dom: namespace import '${s.local}' from '${s.source}' cannot identify a reactive export; use named imports`);let c=n.get(t.id)?.exports[s.imported];if(c===void 0){o[s.local]={type:`function`,tagCandidates:[],componentCandidates:[],reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}if(c.type===`state`)o[s.local]={type:`state`,kind:c.kind,key:c.key,transparentSource:c.transparentSource,tagCandidates:[...c.tagCandidates],componentCandidates:cv(e,c.componentCandidates,n)};else if(c.type===`component`){let e=a?.get(c.key),t=c.renderProps.filter(t=>e?.scalar.has(t)!==!0||e.jsx.has(t));o[s.local]={type:`component`,key:c.key,props:[...c.props],objectProps:c.objectProps,acceptsUnknownProps:c.acceptsUnknownProps,hasWholeDefault:c.hasWholeDefault,listLightweight:c.listLightweight,delegatedEvents:c.delegatedEvents,renderProps:t,renderCallbacks:[...c.renderCallbacks],refProps:[...c.refProps],subtreeReads:[...c.subtreeReads]}}else if(c.type===`value`){o[s.local]={type:`value`};continue}else{if(i.linkFunctionSummaries===!1){o[s.local]={type:`function`,transparentSourceFactory:c.transparentSourceFactory,transparentSourceMethod:c.transparentSourceMethod,tagCandidates:[...c.tagCandidates],componentCandidates:cv(e,c.componentCandidates,n),reads:[],writes:[],boundedWrites:[],parameterWrites:[],unbounded:!0};continue}o[s.local]={type:`function`,transparentSourceFactory:c.transparentSourceFactory,transparentSourceMethod:c.transparentSourceMethod,tagCandidates:[...c.tagCandidates],componentCandidates:cv(e,c.componentCandidates,n),reads:[...c.reads],writes:[...c.writes],boundedWrites:[...c.boundedWrites],parameterWrites:[...c.parameterWrites],unbounded:c.unbounded}}}return o}function uv(e){return JSON.stringify(e)}function dv(e,t,n){let r=new Map;for(let t of e.keys())r.set(t,new Set);for(let i of e.values()){let a=t.get(i.id);for(let t of a.imports){let a=av(i.id,t.source,e,n);a!==void 0&&r.get(a.id).add(i.id)}}return r}function fv(e,t,n,r,i){let a=new Map(t),o=dv(e,a,n),s=[...e.keys()],c=new Set(s),l=Math.max(16,e.size*e.size*4),u=0;for(;s.length>0;){let t=s.shift();c.delete(t);let d=e.get(t),f=a.get(t),p=rv(d,lv(d,f,a,e,n),n,r,i);if(u++,u>l)throw Error(`memo-dom: cross-module export summaries did not converge`);if(uv(p)!==uv(f)){a.set(t,p);for(let e of o.get(t)??[])c.has(e)||(c.add(e),s.push(e))}}return a}function pv(e,t,n){let r=t.frontend??Jn,i=new Map;for(let[t,n]of Object.entries(e)){let e=G_(t);if(i.has(e))throw Error(`memo-dom: duplicate module id after normalization: '${e}'`);let a=K_(e,n,r);i.set(e,{originalId:t,id:e,source:n,ast:a.ast,css:a.css})}let a=[...i.values()].flatMap(e=>{try{return Kg(e.ast,e.id)}catch(t){throw Error(`${e.id}: memo-dom: ${t.message}`)}});try{Yg(a)}catch(e){throw Error(`memo-dom: ${e.message}`)}let o=new Map;for(let e of i.values())o.set(e.id,iv(e,t));let s=ov(i,o,t)?.rootId??`App`,c=fv(i,o,t,s,a),l=ov(i,c,t),u=l?.moduleId??i.values().next().value?.id,d=new Map;for(let e of c.values())for(let t of e.componentUsages){let e=d.get(t.target);e===void 0&&(e={jsx:new Set,scalar:new Set},d.set(t.target,e)),e[t.kind].add(t.prop)}for(let[e,t]of d)for(let n of t.jsx)if(t.scalar.has(n))throw Error(`memo-dom: component '${e}' prop '${n}' is used as both scalar data and JSX content; split the prop or component contract`);let f=D_([...c.values()].flatMap(e=>e.components),l),p={},m={},h={},g={};for(let e of i.values()){let r=c.get(e.id);h[e.originalId]={componentExports:Object.entries(r.exports).filter(e=>e[1].type===`component`).map(([e,t])=>({exported:e,local:r.components.find(e=>e.key===t.key)?.local??t.key.slice(t.key.lastIndexOf(`#`)+1),listLightweight:t.listLightweight})).sort((e,t)=>e.local.localeCompare(t.local)),stateExports:Object.entries(r.exports).filter(e=>e[1].type===`state`).map(([e,t])=>({exported:e,kind:t.kind,key:t.key})).sort((e,t)=>e.exported.localeCompare(t.exported)),functionExports:Object.entries(r.exports).filter(e=>e[1].type===`function`).map(([e,t])=>({exported:e,...t.transparentSourceFactory===!0?{transparentSourceFactory:!0}:{},...t.transparentSourceMethod===void 0?{}:{transparentSourceMethod:t.transparentSourceMethod},reads:[...t.reads],writes:[...t.writes],boundedWrites:[...t.boundedWrites],parameterWrites:t.parameterWrites.map(e=>({index:e.index,path:[...e.path]})),unbounded:t.unbounded})).sort((e,t)=>e.exported.localeCompare(t.exported)),readers:Object.fromEntries(Object.entries(r.readers).map(([e,t])=>[e,[...t]]))};let o=lv(e,r,c,i,t,d);for(let n of r.imports){let r=av(e.id,n.source,i,t);if(r!==void 0&&c.get(r.id)?.exports[n.imported]===void 0)throw Error(`memo-dom: '${n.imported}' is not a linkable state, function, or component export of '${n.source}'`)}let _={},v={},y={},b={};for(let e of r.components){_[e.local]=[...f.paths.get(e.key)??[]];let t=f.rows.get(e.key);t!==void 0&&(v[e.local]=t.map(e=>({keyPath:e.keyPath===null?null:[...e.keyPath],sourceKey:e.sourceKey,sourceLocal:e.sourceLocal})));let n=f.propSources.get(e.key);n!==void 0&&(y[e.local]=Object.fromEntries([...n].map(([e,t])=>[e,{keys:[...t.keys],rootFallback:t.rootFallback,transparent:t.transparent}])));let i=Object.values(r.exports).find(t=>t.type===`component`&&t.key===e.key);if(i?.type===`component`){let t=d.get(e.key);b[e.local]=i.renderProps.filter(e=>t?.scalar.has(e)!==!0||t.jsx.has(e))}}let ee={...q_(t,s),moduleId:e.id,linkedImports:o,linkedComponentPaths:_,linkedComponentRows:v,linkedComponentPropSources:y,linkedComponentRenderProps:b,linkedRoutes:a,emitRouteManifest:e.id===u,...l?.moduleId===e.id?{rootComponent:l.local}:{}};if(n){let t=S_(e.source,ee,e.ast);p[e.originalId]=t.code,m[e.originalId]=t.map;let n=t.css??e.css;n&&(g[e.originalId]=n)}else p[e.originalId]=b_(e.source,ee,e.ast),e.css&&(g[e.originalId]=e.css)}return{output:p,maps:m,metadata:h,...Object.keys(g).length>0?{css:g}:{},...l===void 0?{}:{applicationRoot:l}}}function mv(e,t={}){return pv(e,t,!0)}function hv(e,t={}){return pv(e,t,!1).output}const gv=98e3,_v=`memoized-dom`,vv=/\x1B\[[0-?]*[ -/]*[@-~]/g;function yv(e){return e.replace(vv,``)}function bv(e){return e.replaceAll(`\\`,`/`).replace(/^\.\//,``)}function xv(e,t){let n=bv(e);return[...t].sort((e,t)=>t.length-e.length).find(e=>n.endsWith(bv(e)))}function Sv(e,t=[]){let n=e,r=yv(typeof n?.message==`string`?n.message:String(e)),i=r.indexOf(`: memo-dom:`),a=r.match(/\((\d+):(\d+)\)/),o=n?.loc,s=typeof o?.line==`number`?o.line:a===null?void 0:Number(a[1]),c=typeof o?.column==`number`?o.column:a===null?void 0:Number(a[2]),l=typeof o?.endLine==`number`?o.endLine:void 0,u=typeof o?.endColumn==`number`?o.endColumn:void 0,d=i===-1?``:r.slice(0,i),f=(typeof n?.moduleId==`string`?n.moduleId:void 0)??xv(d,t)??(t.length===1?t[0]:void 0),p=i===-1?r:r.slice(i+2);return{code:gv,source:_v,severity:`error`,message:p,...f===void 0?{}:{moduleId:f},...s===void 0?{}:{line:s},...c===void 0?{}:{column:c},...l===void 0?{}:{endLine:l},...u===void 0?{}:{endColumn:u}}}function Cv(e,t={}){try{return y_(e,t),[]}catch(e){return[Sv(e,[t.moduleId??`./component.tsx`])]}}function wv(e,t={}){try{return hv(e,t),[]}catch(t){return[Sv(t,Object.keys(e))]}}function Tv(e){return e}function Ev(e){return e.replaceAll(`\\`,`/`).split(/[?#]/,1)[0]}function Dv(e,t=`server/functions`){let n=Ev(e),r=t.replaceAll(`\\`,`/`).replace(/^\.\//,``).replace(/^\/+|\/+$/g,``),i=`/${r}/`,a=`/${n.replace(/^\.\//,``).replace(/^\/+/,``)}`,o=a.lastIndexOf(i);if(o===-1)throw km(`memo-dom: server function module '${e}' is outside '${r}/'`,e);let s=a.slice(o+i.length).replace(/\.(?:[cm]?[jt]sx?|tsrx)$/i,``);return s===``||s===`_middleware`?s:s.split(`/`).map(e=>encodeURIComponent(e)).join(`/`)}function Ov(e){return e.startsWith(`get`)?`GET`:e.startsWith(`post`)?`POST`:e.startsWith(`put`)?`PUT`:e.startsWith(`patch`)?`PATCH`:e.startsWith(`delete`)?`DELETE`:null}function kv(e){let t=new Map;for(let n of e.body){let e=_i(n)?n.declaration:n;if(Ur(e)&&e.id!==null){t.set(e.id.name,{local:e.id.name,node:e});continue}if(qr(e))for(let n of e.declarations){if(!W(n.id)||n.init===null)continue;let e=q(n.init)?_a(n.init):n.init;(Wr(e)||Gr(e))&&t.set(n.id.name,{local:n.id.name,node:e})}}return t}function Av(e){let t=[];for(let n of e.body){if(vi(n))throw km(`memo-dom: [MMD-S003] server/functions modules use named exports; default exports cannot cross the client boundary`,void 0,n);if(!_i(n)||Tv(n).exportKind===`type`)continue;if(n.source!==null)throw km(`memo-dom: [MMD-S003] re-export server functions through a local named binding so their endpoint and middleware ownership stay explicit`,void 0,n);let e=n.declaration;if(Ur(e)&&e.id!==null)t.push({exported:e.id.name,local:e.id.name,at:e.id});else if(qr(e))for(let n of e.declarations)W(n.id)&&t.push({exported:n.id.name,local:n.id.name,at:n.id});for(let e of n.specifiers){if(!yi(e))continue;let n=W(e.exported)?e.exported.name:e.exported.value;t.push({exported:n,local:e.local.name,at:e})}}return t}function jv(e){let t=Tv(e).typeAnnotation;if(typeof t!=`object`||!t||!(`type`in t))return null;let n=Tv(t).typeAnnotation;return typeof n==`object`&&n&&`type`in n?n:null}function Mv(e){if(e.type===`TSStringKeyword`)return`string`;if(e.type===`TSNumberKeyword`)return`number`;if(e.type===`TSBooleanKeyword`)return`boolean`;if(e.type!==`TSLiteralType`)return null;let t=Tv(e).literal;if(typeof t!=`object`||!t||!(`type`in t))return null;let n=Tv(t).value;return typeof n==`string`?`string`:typeof n==`number`?`number`:typeof n==`boolean`?`boolean`:null}function Nv(e){if(e===null)return null;let t=Mv(e);if(t!==null)return t;if(e.type===`TSArrayType`){let t=Tv(e).elementType;if(typeof t!=`object`||!t||!(`type`in t))return null;let n=Mv(t);return n===null?null:`${n}[]`}if(e.type===`TSUnionType`){let t=Tv(e).types;if(!Array.isArray(t))return null;let n=new Set;for(let e of t){if(typeof e!=`object`||!e||!(`type`in e))return null;let t=e;if(t.type===`TSUndefinedKeyword`||t.type===`TSNullKeyword`)continue;let r=Nv(t);if(r===null)return null;n.add(r)}return n.size===1?[...n][0]:null}return null}function Pv(e){return G(e)?`string`:Nr(e)?`number`:Pr(e)?`boolean`:null}function Fv(e,t,n){return e.params.map(e=>{let r=mi(e),i=r?e.left:e;if(!W(i))throw km(`memo-dom: [MMD-S013] server function parameters must be named identifiers so the HTTP query/body contract is stable`,n,e);let a=r||Tv(i).optional===!0;if(t!==`GET`)return{name:i.name,optional:a};let o=Nv(jv(i))??(r?Pv(e.right):null)??`string`;return{name:i.name,optional:a,queryKind:o}})}function Iv(e,t){let n=Jt(t.frontend??Jn,e,{filename:t.moduleId,sourceType:`module`}).program,r=Dv(t.moduleId,t.functionsRoot),i=kv(n),a=[],o=!1;for(let e of Av(n)){if(e.exported===`middleware`){o=!0;continue}let n=i.get(e.local);if(n===void 0)throw km(`memo-dom: [MMD-S003] Server function module export '${e.exported}' must be an async function; only verb-prefixed async functions and 'middleware' may cross the client boundary`,t.moduleId,e.at);let s=Ov(e.exported);if(s===null)throw km(`memo-dom: [MMD-S011] Server function '${e.exported}' must begin with get, post, put, patch, or delete`,t.moduleId,e.at);if(!n.node.async||n.node.generator)throw km(`memo-dom: [MMD-S003] Server function '${e.exported}' must be async before it can cross the client boundary`,t.moduleId,e.at);if(r===``)throw km(`memo-dom: server/functions root cannot contain endpoints; place functions in a named module`,t.moduleId,e.at);a.push({exported:e.exported,local:n.local,method:s,path:`/_fn/${r}/${encodeURIComponent(e.exported)}`,parameters:Fv(n.node,s,t.moduleId)})}return{moduleId:t.moduleId,moduleName:r,middlewareExport:o,functions:a.sort((e,t)=>e.path.localeCompare(t.path))}}function Lv(e,t=`@memoized-dom/data`){let n=[`import { $fetch as __mmd_fetch } from ${JSON.stringify(t)};`];for(let t of e.functions){let e=t.parameters.map(e=>e.name).join(`, `),r=t.parameters.map(e=>e.name).join(`, `);if(t.method===`GET`){let i=t.parameters.length===0?``:`, { query: { ${r} } }`;n.push(`export function ${t.exported}(${e}) { return __mmd_fetch(${JSON.stringify(t.path)}${i}); }`)}else{let i=t.parameters.length===0?``:`, body: { ${r} }`;n.push(`export function ${t.exported}(${e}) { return __mmd_fetch(${JSON.stringify(t.path)}, { method: ${JSON.stringify(t.method)}${i} }); }`)}}return`${n.join(`
|
|
2
|
+
`)}\n`}function Rv(e,t){let n=[`// Generated by @memoized-dom/compiler — client facade declarations for the application server functions.`,`import type { ResolvedValue } from ${JSON.stringify(t.dataModule??`@memoized-dom/data`)};`],r=new Map,i=[],a=0;for(let o of e){if(o.functions.length===0)continue;let e=`__mmd_impl_${a++}`;n.push(`import type * as ${e} from ${JSON.stringify(t.resolveImplementation(o.moduleId))};`);for(let t of o.functions){let n=r.get(t.exported);if(n!==void 0)throw km(`memo-dom: [MMD-S012] server function name '${t.exported}' is exported by both '${n}' and '${o.moduleId}'; the '#server-functions' barrel requires unique exported names`,o.moduleId);r.set(t.exported,o.moduleId);let a=`${e}.${t.exported}`;i.push(`export declare function ${t.exported}(...args: Parameters<typeof ${a}>): ResolvedValue<Awaited<ReturnType<typeof ${a}>>>;`)}}return`${[...n,...i].join(`
|
|
3
|
+
`)}\n`}export{Iv as analyzeServerFunctionModule,y_ as compile,x_ as compileDetailed,hv as compileModules,mv as compileModulesDetailed,gv as compilerDiagnosticCode,_v as compilerDiagnosticSource,Lt as createExtensionEstreeFrontend,Cv as diagnose,wv as diagnoseModules,qn as experimentalTsrxEstreeFrontend,Lv as generateServerFunctionClient,Rv as generateServerFunctionDeclarations,Jn as memoizedEstreeFrontend,Kn as parseTsrxEstree,qt as parseWithEstreeFrontend,Jt as parseWithEstreeFrontendOrThrow,Dv as serverFunctionModuleName,Sv as toCompilerDiagnostic,Kt as yukuEstreeFrontend};
|