import{isFunction as e}from"../utils/is-function.mjs";import{waitingElementHanlders as t,handlers as n,subscriptions as r}from"../internal-state.mjs";import{errorSink as o}from"../sinks/error-sink.mjs";import{DOMSinks as s}from"../sinks/index.mjs";import{terminationSink as i}from"../sinks/termination-sink.mjs";const a=new Set(["ended","play","pause","volumechange"]),c=e=>1==e.nodeType,l=c=>{(Array.from(c.attributes)||[]).forEach((l=>{const d=l.nodeName,u=l.nodeValue,m=d.replace(/^on/,""),f=m!==d,p=/^#REF\d+$/.test(u)&&c.innerHTML.split(u)||[];let b;2==p.length&&(b=document.createTextNode(""),c.innerHTML=p[0],c.append(b),c.insertAdjacentHTML("beforeend",p[1])),(/^#REF/.test(u)||"onmount"==d||f)&&(c.removeAttribute(d),(t.get(u)||[]).forEach((t=>{const l=t.handler,u=e(l)?l.bind(c):e(l.next)?l.next.bind(l):null;if(u&&a.has(m))c.addEventListener(m,u,{capture:!0});else if("event"==t.type||"source"==t.type||"onmount"==d)Object.keys(t).length&&n.set(c,[].concat(n.get(c)||[],{...t,handler:u}));else if(s.has(t.type)){const e=s.get(t.type),n=e(b||c,t.attribute),a=t.attribute?.then||t.attribute?.subscribe?t.attribute:t.handler,l=a.then?a.then(n,t.error||o):a.subscribe?a.subscribe(n,t.error||o,t.termination||i):"function"==typeof a?a(c):"object"==typeof a?e(c)(a):()=>{};if(a.subscribe){const e=r.get(c)||[];e.push(l),r.set(c,e)}}})),t.delete(u),"onmount"==d&&setTimeout((()=>c.dispatchEvent(new CustomEvent("mount",{bubbles:!0,detail:{}}))),0))}))},d=e=>{[...e.children].forEach((e=>d(e))),r.get(e)?.forEach((e=>e.unsubscribe?.())),r.delete(e)},u=(e,t)=>{const n=e.filter((e=>"childList"===e.type));n.flatMap((e=>[...e.addedNodes])).filter(c).flatMap((e=>[e].concat(...e.querySelectorAll("[RESOLVE]")))).forEach(l),n.flatMap((e=>[...e.removedNodes])).filter(c).forEach(d)};export{u as mount,a as nonBubblingAttributes,d as removeListeners,l as transferAttributes};
//# sourceMappingURL=lifecycle-handler.mjs.map
