import{Ci as l,Ni as d,Si as a,yi as g}from"./icons-xTj2hkG8.js";function k(t,e){if(Object.is(t,e))return!0;if(typeof t!="object"||t===null||typeof e!="object"||e===null)return!1;if(t instanceof Map&&e instanceof Map){if(t.size!==e.size)return!1;for(const[n,i]of t)if(!e.has(n)||!Object.is(i,e.get(n)))return!1;return!0}if(t instanceof Set&&e instanceof Set){if(t.size!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0}if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();const s=u(t);if(s.length!==u(e).length)return!1;for(let n=0;nn,s){const n=s?.compare??v,i=a(o=>{const{unsubscribe:h}=t.subscribe(o);return h},[t]),r=a(()=>t.get(),[t]);return d(i,r,r,e,n)}var f=g(null);function S(){return l(f)?.defaultOptions??{}}function p(t){return typeof t=="function"}function O(t,...e){return p(t)?t(...e):t}var E=class{#r=!0;#e;#t;#l;#n;#a;#s;#u;#d=0;#v=5;#o=!1;#c=!1;#i=null;#g=()=>{this.debugLog("Connected to event bus"),this.#a=!0,this.#o=!1,this.debugLog("Emitting queued events",this.#n),this.#n.forEach(t=>this.emitEventToBus(t)),this.#n=[],this.stopConnectLoop(),this.#t().removeEventListener("tanstack-connect-success",this.#g)};#h=()=>{if(this.#d{this.#o||(this.#o=!0,this.#t().addEventListener("tanstack-connect-success",this.#g),this.#h())};constructor({pluginId:t,debug:e=!1,enabled:s=!0,reconnectEveryMs:n=300}){this.#e=t,this.#r=s,this.#t=this.getGlobalTarget,this.#l=e,this.debugLog(" Initializing event subscription for plugin",this.#e),this.#n=[],this.#a=!1,this.#c=!1,this.#s=null,this.#u=n}startConnectLoop(){this.#s!==null||this.#a||(this.debugLog(`Starting connect loop (every ${this.#u}ms)`),this.#s=setInterval(this.#h,this.#u))}stopConnectLoop(){this.#o=!1,this.#s!==null&&(clearInterval(this.#s),this.#s=null,this.#n=[],this.debugLog("Stopped connect loop"))}debugLog(...t){this.#l&&console.log(`🌴 [tanstack-devtools:${this.#e}-plugin]`,...t)}getGlobalTarget(){if(typeof globalThis<"u"&&globalThis.__TANSTACK_EVENT_TARGET__)return this.debugLog("Using global event target"),globalThis.__TANSTACK_EVENT_TARGET__;if(typeof window<"u"&&typeof window.addEventListener<"u")return this.debugLog("Using window as event target"),window;const t=typeof EventTarget<"u"?new EventTarget:void 0;return typeof t>"u"||typeof t.addEventListener>"u"?(this.debugLog("No event mechanism available, running in non-web environment"),{addEventListener:()=>{},removeEventListener:()=>{},dispatchEvent:()=>!1}):(this.debugLog("Using new EventTarget as fallback"),t)}getPluginId(){return this.#e}dispatchCustomEventShim(t,e){try{const s=new Event(t,{detail:e});this.#t().dispatchEvent(s)}catch{this.debugLog("Failed to dispatch shim event")}}dispatchCustomEvent(t,e){try{this.#t().dispatchEvent(new CustomEvent(t,{detail:e}))}catch{this.dispatchCustomEventShim(t,e)}}emitEventToBus(t){this.debugLog("Emitting event to client bus",t),this.dispatchCustomEvent("tanstack-dispatch-event",t)}createEventPayload(t,e){return{type:`${this.#e}:${t}`,payload:e,pluginId:this.#e}}emit(t,e){if(!this.#r){this.debugLog("Event bus client is disabled, not emitting event",t,e);return}if(this.#i&&(this.debugLog("Emitting event to internal event target",t,e),this.#i.dispatchEvent(new CustomEvent(`${this.#e}:${t}`,{detail:this.createEventPayload(t,e)}))),this.#c){this.debugLog("Previously failed to connect, not emitting to bus");return}if(!this.#a){this.debugLog("Bus not available, will be pushed as soon as connected"),this.#n.push(this.createEventPayload(t,e)),typeof CustomEvent<"u"&&!this.#o&&(this.#f(),this.startConnectLoop());return}return this.emitEventToBus(this.createEventPayload(t,e))}on(t,e,s){const n=s?.withEventTarget??!1,i=`${this.#e}:${t}`;if(n&&(this.#i||(this.#i=new EventTarget),this.#i.addEventListener(i,o=>{e(o.detail)})),!this.#r)return this.debugLog("Event bus client is disabled, not registering event",i),()=>{};const r=o=>{this.debugLog("Received event from bus",o.detail),e(o.detail)};return this.#t().addEventListener(i,r),this.debugLog("Registered event to bus",i),()=>{n&&this.#i?.removeEventListener(i,r),this.#t().removeEventListener(i,r)}}onAll(t){if(!this.#r)return this.debugLog("Event bus client is disabled, not registering event"),()=>{};const e=s=>{const n=s.detail;t(n)};return this.#t().addEventListener("tanstack-devtools-global",e),()=>this.#t().removeEventListener("tanstack-devtools-global",e)}onAllPluginEvents(t){if(!this.#r)return this.debugLog("Event bus client is disabled, not registering event"),()=>{};const e=s=>{const n=s.detail;this.#e&&n.pluginId!==this.#e||t(n)};return this.#t().addEventListener("tanstack-devtools-global",e),()=>this.#t().removeEventListener("tanstack-devtools-global",e)}},b=new Map;function m(t,e){b.set(t,e)}function c(t){if(t!==void 0)try{return JSON.parse(JSON.stringify(t))}catch{return null}}function L(t){return typeof t.get=="function"?t.get():t.state}function y(t){return{key:t.key,store:{state:c(L(t.store))},options:c(t.options)}}var C=class extends E{constructor(t){super({pluginId:"pacer",debug:t?.debug,reconnectEveryMs:1e3})}},I=(t,e)=>{const s=e.key;s&&(m(s,e),T.emit(t,y({...e,key:s})))},T=new C;export{P as a,S as i,T as n,k as o,O as r,I as t};