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