import{a as getElement,g as getRenderingRef}from"./index-25e5af33.js";var multiverse=new Map,updateConsumer=function(e,t){var n=e.fields,a=e.updater;n.forEach((function(e){a(e,t[e])}))},Universe={create:function(e,t){var n=getElement(e),a=new Map,l={wormholes:a,state:t};multiverse.set(e,l);var o=e.connectedCallback;e.connectedCallback=function(){multiverse.set(e,l),o&&o.call(e)};var c=e.disconnectedCallback;e.disconnectedCallback=function(){multiverse.delete(e),c&&c.call(e)},n.addEventListener("openWormhole",(function(e){e.stopPropagation();var t=e.detail,n=t.consumer,o=t.onOpen;if(!a.has(n)){if("symbol"!=typeof n){var c=n.connectedCallback,r=n.disconnectedCallback;n.connectedCallback=function(){a.set(n,e.detail),c&&c.call(n)},n.disconnectedCallback=function(){a.delete(n),r&&r.call(n)}}a.set(n,e.detail),updateConsumer(e.detail,l.state),null==o||o.resolve((function(){a.delete(n)}))}})),n.addEventListener("closeWormhole",(function(e){var t=e.detail;a.delete(t)}))},Provider:function(e,t){var n=e.state,a=getRenderingRef();if(multiverse.has(a)){var l=multiverse.get(a);l.state=n,l.wormholes.forEach((function(e){updateConsumer(e,n)}))}return t}};export{Universe as U};