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