import{COMPONENTS as e,CURRENT_CONTEXT as t,LAST_CONTEXT as n}from"./lib/smart-symbols.js";import{objectEquals as r}from"./lib/utils.js";let o={};const c=new Set,i=new Set;function s(n,r){n[e]=new Map,c.add(n);const o=new MutationObserver((()=>a()));o.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0}),r.addEventListener("abort",(()=>{o.disconnect(),c.delete(n),n[e].forEach(((e,t)=>{e.forEach((e=>d(n,t,e)))})),delete n[e],delete n[t]}),{once:!0})}function l(t,n){i.add(t),a(),null!=n&&n.addEventListener("abort",(()=>{i.delete(t),c.forEach((n=>{(n[e].get(t)??[]).forEach((e=>d(n,t,e))),n[e].delete(t)}))}),{once:!0})}function a(){const s=[],l=[],a=[];c.forEach((t=>{i.forEach((n=>{const r=Array.from(t.querySelectorAll(n.selector)).filter((e=>{return n="cc-smart-container",e.parentElement.closest(n)===t;var n})),o=t[e].get(n)??[];t[e].set(n,r),r.filter((e=>!o.includes(e))).forEach((e=>l.push([t,n,e]))),r.filter((e=>o.includes(e))).forEach((e=>a.push([t,n,e]))),o.filter((e=>!r.includes(e))).forEach((e=>s.push([t,n,e])))}))})),s.forEach((([e,t,n])=>d(e,t,n))),l.forEach((([e,t,r])=>function(e,t,r){r[n]={},t.onConnect?.(e,r)}(e,t,r))),[...l,...a].forEach((([e,c,i])=>function(e,c,i){const s={...o,...e[t]},l=function(e,t){if(null==e)return{};if(null==t)return e;const n=Object.keys(t).map((t=>[t,e[t]])).filter((([,e])=>void 0!==e));return Object.fromEntries(n)}(s,c.params);if(r(i[n],l))return;i[n]=l,c.onContextUpdate?.(e,i,l)}(e,c,i)))}function f(e,n){e[t]=n,a()}function u(e){o=e,a()}function d(e,t,r){delete r[n],t.onDisconnect?.(e,r)}export{l as defineSmartComponentCore,s as observeContainer,f as updateContext,u as updateRootContext};
//# sourceMappingURL=smart-manager.js.map
