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