pulse-ui-client 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{useEffect as m,useState as n,useMemo as c,createContext as JW,useContext as XW}from"react";import UW,{cloneElement as H,createElement as e,lazy as DW,Suspense as RW}from"react";var o="$$fragment",r="$$";function a(W){return typeof W==="object"&&W!==null}function t(W){return typeof W==="object"&&W!==null&&W.tag.startsWith("$$")&&W.tag!=="$$fragment"}import{jsx as p,Fragment as CW}from"react/jsx-runtime";class M{client;path;components;callbackCache;constructor(W,q,Z){this.client=W;this.path=q;this.components=Z;this.callbackCache=new Map}getCallback(W){let q=this.callbackCache.get(W);if(!q)q=(...Z)=>this.client.invokeCallback(this.path,W,Z),this.callbackCache.set(W,q);return q}renderNode(W){if(W==null||typeof W==="boolean"||typeof W==="number"||typeof W==="string")return W;if(a(W)){let{tag:q,props:Z={},children:Q=[]}=W,$={};for(let[V,z]of Object.entries(Z))if(typeof z==="string"&&z.startsWith("$$fn:")){let J=z.substring(5);$[V]=this.getCallback(J)}else $[V]=z;if(W.key)$.key=W.key;let X=[];for(let V of Q)X.push(this.renderNode(V));if(t(W)){let V=W.tag.slice(r.length),z=this.components[V];return e(z,$,...X)}return e(q===o?UW.Fragment:q,$,...X)}return null}}function L(W){let q=W.props?.children;if(q==null)return[];return Array.isArray(q)?q.slice():[q]}function AW(W,q){let Z={};for(let[Q,$]of Object.entries(q||{}))if(typeof $==="string"&&$.startsWith("$$fn:")){let X=$.substring(5);Z[Q]=W.getCallback(X)}else Z[Q]=$;return Z}function NW(W,q){return H(W,void 0,...q)}function x(W,q,Z){let Q=W;for(let $ of q){let X=$.path.split(".").filter((z)=>z.length>0).map(Number),V=(z,J)=>{if(J<X.length){K(z,X,J),z=z;let G=X[J],P=L(z),O=P[G];return P[G]=V(O,J+1),NW(z,P)}switch($.type){case"replace":return Z.renderNode($.data);case"update_props":{K(z,X,J),z=z;let G=AW(Z,$.data);return H(z,G)}case"insert":{K(z,X,J),z=z;let G=L(z);return G.splice($.idx,0,Z.renderNode($.data)),H(z,null,...G)}case"remove":{K(z,X,J),z=z;let G=L(z);return G.splice($.idx,1),H(z,null,...G)}case"move":{K(z,X,J),z=z;let G=L(z),P=G.splice($.data.from_index,1)[0];return G.splice($.data.to_index,0,P),H(z,null,...G)}default:throw Error(`[Pulse renderer] Unknown update type: ${$.type}`)}};Q=V(Q,0)}return Q}function OW(W,q){let Z=DW(W);return({children:Q,...$})=>{return p(RW,{fallback:q??p(CW,{}),children:p(Z,{...$,children:Q})})}}function K(W,q,Z){return!0}function f(){function W(q,Z){return(Q)=>{let $={};for(let X of q)$[X]=Q[X];if(Z)for(let X in Z){let V=Z[X];$[X]=V(Q)}return $}}return W}var fW=(W)=>W.tagName.toLowerCase(),IW=["id","className","tagName","localName","clientHeight","clientLeft","clientTop","clientWidth","scrollHeight","scrollLeft","scrollTop","scrollWidth","slot"],yW=["autofocus","tabIndex","nonce"],wW=["accessKey","accessKeyLabel","autocapitalize","dir","draggable","hidden","inert","lang","offsetHeight","offsetLeft","offsetTop","offsetWidth","popover","spellcheck","title","translate","writingSuggestions","contentEditable","enterKeyHint","isContentEditable","inputMode"],kW=f()(IW,{tagName:fW}),BW=f()(yW),KW=f()(wW);function I(W){return{...kW(W),...BW(W),...KW(W)}}function F(W,q){let Z=f()(W,q);return(Q)=>({...I(Q),...Z(Q)})}var HW=["hash","host","hostname","href","origin","password","pathname","port","protocol","search","target","download","rel","hreflang","type","username","ping","referrerPolicy","text"],gW=F(HW),jW=["alt","coords","download","hash","host","hostname","href","origin","password","pathname","port","protocol","rel","search","shape","target","username","ping","referrerPolicy"],YW=F(jW),LW=["autoplay","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","loop","muted","networkState","paused","playbackRate","preload","readyState","seeking","src","volume","preservesPitch"],zW=F(LW),MW=(W)=>zW(W),bW=["disabled","name","type","value","formAction","formEnctype","formMethod","formNoValidate","formTarget","popoverTargetAction"],SW=F(bW),TW=["value"],_W=F(TW),hW=["height","src","type","width","align","name"],mW=F(hW),pW=["disabled","name","type","validationMessage","willValidate"],xW=F(pW),vW=["acceptCharset","action","autocomplete","encoding","enctype","length","method","name","noValidate","target","rel"],uW=F(vW),EW=["allow","allowFullscreen","height","name","referrerPolicy","src","srcdoc","width","align","frameBorder","longDesc","marginHeight","marginWidth","scrolling","sandbox"],iW=F(EW),nW=["alt","crossOrigin","decoding","height","isMap","loading","naturalHeight","naturalWidth","referrerPolicy","sizes","src","srcset","useMap","width","align","border","complete","hspace","longDesc","lowsrc","name","vspace","x","y","fetchPriority"],cW=F(nW),dW=["accept","alt","autocomplete","checked","defaultChecked","defaultValue","dirName","disabled","height","indeterminate","max","maxLength","min","minLength","multiple","name","pattern","placeholder","readOnly","required","selectionDirection","selectionEnd","selectionStart","size","src","step","type","value","valueAsNumber","width","align","capture","formAction","formEnctype","formMethod","formNoValidate","formTarget","useMap","validationMessage","willValidate","popoverTargetAction"],sW=F(dW),lW=["htmlFor"],oW=F(lW),rW=["value","type"],aW=F(rW),tW=["as","crossOrigin","disabled","fetchPriority","href","hreflang","imageSizes","imageSrcset","integrity","media","referrerPolicy","rel","type","charset","rev","target","sizes"],eW=F(tW),W1=["name"],q1=F(W1),Z1=["high","low","max","min","optimum","value"],$1=F(Z1),z1=["cite","dateTime"],WW=F(z1),Q1=["reversed","start","type","compact"],J1=F(Q1),X1=["data","height","name","type","useMap","width","validationMessage","willValidate","align","archive","border","code","codeBase","codeType","declare","hspace","standby","vspace"],G1=F(X1),F1=["disabled","label"],V1=F(F1),P1=["defaultSelected","disabled","index","label","selected","text","value"],U1=F(P1),D1=["defaultValue","name","type","value","htmlFor","validationMessage","willValidate"],R1=F(D1),A1=["max","position","value"],N1=F(A1),O1=["cite"],qW=F(O1),C1=(W)=>I(W),f1=["async","crossOrigin","defer","fetchPriority","integrity","noModule","referrerPolicy","src","text","type","charset"],I1=f()(f1,{event:(W)=>W.event,htmlFor:(W)=>W.htmlFor}),y1=(W)=>({...I(W),...I1(W)}),w1=["autocomplete","disabled","length","multiple","name","required","selectedIndex","size","type","value","validationMessage","willValidate"],k1=F(w1),B1=["name"],K1=F(B1),H1=["height","media","sizes","src","srcset","type","width"],g1=F(H1),j1=["align"],Y1=F(j1),L1=["abbr","cellIndex","colSpan","headers","rowSpan","scope","align","axis","bgColor","ch","chOff","height","noWrap","vAlign","width"],ZW=F(L1),M1=["span","align","ch","chOff","vAlign","width"],$W=F(M1),b1=["align","bgColor","border","cellPadding","cellSpacing","frame","rules","summary","width"],S1=F(b1),T1=["rowIndex","sectionRowIndex","align","bgColor","ch","chOff","vAlign"],_1=F(T1),h1=["align","ch","chOff","vAlign"],v=F(h1),m1=(W)=>I(W),p1=["autocomplete","cols","defaultValue","dirName","disabled","maxLength","minLength","name","placeholder","readOnly","required","rows","selectionDirection","selectionEnd","selectionStart","value","wrap","textLength","validationMessage","willValidate"],x1=F(p1),v1=["dateTime"],u1=F(v1),E1=["default","kind","label","readyState","src","srclang"],i1=F(E1),n1=["height","poster","videoHeight","videoWidth","width","playsInline"],c1=f()(n1),d1=(W)=>({...zW(W),...c1(W)}),s1=["clear"],l1=F(s1),o1=["href","target"],r1=F(o1),a1=["aLink","background","bgColor","link","text","vLink"],t1=F(a1),e1=["compact"],Wq=F(e1),qq=["open"],Zq=F(qq),$q=["open","returnValue"],zq=F($q),Qq=["align"],Jq=F(Qq),Xq=(W)=>I(W),Gq=["align"],w=F(Gq),Fq=["align","color","noShade","size","width"],Vq=F(Fq),Pq=["version"],Uq=F(Pq),Dq=(W)=>I(W),Rq=["content","httpEquiv","name","scheme"],Aq=F(Rq),Nq=["align"],Oq=F(Nq),Cq=(W)=>I(W),fq=["width"],Iq=F(fq),yq=(W)=>I(W),wq=["media","type","disabled"],kq=F(wq),Bq=["text"],Kq=F(Bq),Hq=["compact","type"],gq=F(Hq),jq={A:gW,AREA:YW,AUDIO:MW,BASE:r1,BLOCKQUOTE:qW,Q:qW,BODY:t1,BR:l1,BUTTON:SW,CANVAS:I,CAPTION:Y1,CITE:C1,COL:$W,COLGROUP:$W,DATA:_W,DETAILS:Zq,DIALOG:zq,DIV:Jq,DL:Wq,EMBED:mW,FIELDSET:xW,FORM:uW,H1:w,H2:w,H3:w,H4:w,H5:w,H6:w,HEAD:Xq,HR:Vq,HTML:Uq,IFRAME:iW,IMG:cW,INPUT:sW,LABEL:oW,LI:aW,LINK:eW,MAP:q1,MENU:Dq,META:Aq,METER:$1,INS:WW,DEL:WW,OBJECT:G1,OL:J1,OPTGROUP:V1,OPTION:U1,OUTPUT:R1,P:Oq,PICTURE:Cq,PRE:Iq,PROGRESS:N1,SCRIPT:y1,SELECT:k1,SLOT:K1,SOURCE:g1,SPAN:yq,STYLE:kq,TABLE:S1,TBODY:v,THEAD:v,TFOOT:v,TD:ZW,TH:ZW,TEMPLATE:m1,TEXTAREA:x1,TIME:u1,TITLE:Kq,TR:_1,TRACK:i1,UL:gq,VIDEO:d1};function b(W){let q=W.tagName.toUpperCase(),Z=jq[q];if(Z)return Z(W);throw Error(`Unexpected HTML element tag: ${W.tagName} (update .web/custom/serialize.ts)`)}var Yq=(W)=>b(W.target),g=(W)=>W.relatedTarget?b(W.relatedTarget):null;function U(W,q){return f()(W,{target:Yq,...q||{}})}var C=["target","bubbles","cancelable","defaultPrevented","eventPhase","isTrusted","timeStamp","type"],S=[...C,"detail"],T=[...S,"altKey","button","buttons","clientX","clientY","ctrlKey","metaKey","movementX","movementY","pageX","pageY","screenX","screenY","shiftKey"],Lq=[...T,"pointerId","pressure","tangentialPressure","tiltX","tiltY","twist","width","height","pointerType","isPrimary"],Mq=U(C),bq=U(S),Sq=U(T,{relatedTarget:g}),Tq=U(C,{clipboardData:(W)=>QW(W.clipboardData)}),_q=U([...C,"data"]),hq=U(T,{relatedTarget:g,dataTransfer:(W)=>QW(W.dataTransfer)}),mq=U(Lq,{relatedTarget:g}),pq=U(C,{relatedTarget:g}),xq=U(C),vq=U(C),uq=U(C),Eq=U([...S,"altKey","ctrlKey","code","key","locale","location","metaKey","repeat","shiftKey"]),iq=U([...S,"altKey","ctrlKey","metaKey","shiftKey","changedTouches","targetTouches","touches"],{changedTouches:(W)=>u(W.changedTouches),targetTouches:(W)=>u(W.targetTouches),touches:(W)=>u(W.touches)}),nq=U([...T,"deltaMode","deltaX","deltaY","deltaZ"],{relatedTarget:g}),cq=U([...C,"animationName","elapsedTime","pseudoElement"]),dq=U([...C,"oldState","newState"]),sq=U([...C,"elapsedTime","propertyName","pseudoElement"]);function u(W){return Array.from(W).map((q)=>({target:b(q.target),identifier:q.identifier,screenX:q.screenX,screenY:q.screenY,clientX:q.clientX,clientY:q.clientY,pageX:q.pageX,pageY:q.pageY}))}function QW(W){if(!W)return null;let q=[];if(W.items)for(let Z=0;Z<W.items.length;Z++){let Q=W.items[Z];q.push({kind:Q.kind,type:Q.type})}return{drop_effect:W.dropEffect,effect_allowed:W.effectAllowed,items:q,types:Array.from(W.types||[])}}var D={};function R(W,q,Z){for(let Q of q)W[Q]=Z}R(D,["pointerdown","pointermove","pointerup","pointercancel","gotpointercapture","lostpointercapture","pointerenter","pointerleave","pointerover","pointerout"],mq);R(D,["click","contextmenu","dblclick","mousedown","mouseenter","mouseleave","mousemove","mouseout","mouseover","mouseup"],Sq);R(D,["drag","dragend","dragenter","dragexit","dragleave","dragover","dragstart","drop"],hq);R(D,["keydown","keypress","keyup"],Eq);R(D,["focus","blur"],pq);R(D,["change","input"],uq);R(D,["invalid"],vq);R(D,["reset","submit"],xq);R(D,["copy","cut","paste"],Tq);R(D,["compositionend","compositionstart","compositionupdate"],_q);R(D,["touchcancel","touchend","touchmove","touchstart"],iq);R(D,["scroll"],bq);R(D,["wheel"],nq);R(D,["animationstart","animationend","animationiteration"],cq);R(D,["transitionend"],sq);R(D,["toggle"],dq);function E(W){if(W&&typeof W==="object"&&"nativeEvent"in W&&typeof W.isDefaultPrevented==="function"){let q=W;if(typeof q.type!=="string")return W;let Z=D[q.type.toLowerCase()];if(Z)return Z(q);return Mq(q)}return W}function lq(W){return W instanceof Date}function oq(W){return typeof File<"u"&&W instanceof File}function rq(W){return typeof FormData<"u"&&W instanceof FormData}function j(W){let q=new Map,Z=1,Q=($)=>{if($===null||typeof $!=="object")return $;let X=$;if(q.has(X))return{__ref:q.get(X)};if(lq($)){let J=Z++;return q.set(X,J),{__pulse:"date",__id:J,timestamp:$.getTime()}}if(oq($)){let J=Z++;return q.set(X,J),{__pulse:"file",__id:J,name:$.name,type:$.type,size:$.size,lastModified:$.lastModified,file:$}}if(rq($)){let J=Z++;q.set(X,J);let G={};for(let[P,O]of $.entries()){let A=Q(O);if(Object.prototype.hasOwnProperty.call(G,P)){let N=G[P];if(Array.isArray(N))N.push(A);else G[P]=[N,A]}else G[P]=A}return{__pulse:"formdata",__id:J,fields:G}}let V=Z++;if(q.set(X,V),Array.isArray($))return{__pulse:"array",__id:V,items:$.map(Q)};let z={};for(let J in $){let G=$[J];if(typeof G==="function"||typeof G==="symbol"||typeof G>"u")continue;z[J]=Q(G)}return{__pulse:"object",__id:V,__data:z}};return Q(W)}function i(W){let q=new Map,Z=(Q)=>{if(Q===null||typeof Q!=="object")return Q;if(Array.isArray(Q))return Q.map(Z);let $=Q;if($.__ref!==void 0){let V=$.__ref;return q.get(V)||null}if($.__pulse==="date"){let V=$.__id,z=new Date($.timestamp);return q.set(V,z),z}if($.__pulse==="file"){let{__id:V,file:z}=$;return q.set(V,z),z}if($.__pulse==="formdata"){let{__id:V,fields:z}=$,J=new FormData;q.set(V,J);for(let[G,P]of Object.entries(z))if(Array.isArray(P))for(let O of P){let A=Z(O);J.append(G,A)}else{let O=Z(P);J.append(G,O)}return J}if($.__pulse==="array"){let V=$.__id,z=[];q.set(V,z);let J=$.items;for(let G=0;G<J.length;G++)z[G]=Z(J[G]);return z}if($.__pulse==="object"){let V=$.__id,z={};q.set(V,z);let J=$.__data;for(let[G,P]of Object.entries(J))z[G]=Z(P);return z}let X={};for(let[V,z]of Object.entries($))X[V]=Z(z);return X};return Z(W)}import{io as aq}from"socket.io-client";class _{url;renderId;frameworkNavigate;activeViews;socket=null;messageQueue;connectionListeners=new Set;serverErrors=new Map;serverErrorListeners=new Set;constructor(W,q,Z){this.url=W;this.renderId=q;this.frameworkNavigate=Z;this.socket=null,this.activeViews=new Map,this.messageQueue=[]}isConnected(){return this.socket?.connected??!1}async connect(){if(this.socket)return;return new Promise((W,q)=>{let Z=aq(this.url,{transports:["websocket","webtransport"],auth:{renderId:this.renderId}});this.socket=Z,Z.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let[Q,$]of this.activeViews)Z.emit("message",j({type:"mount",path:Q,routeInfo:$.routeInfo}));for(let Q of this.messageQueue){if(Q.type==="mount"&&this.activeViews.has(Q.path))continue;if(Q.type==="navigate")continue;Z.emit("message",j(Q))}this.messageQueue=[],this.notifyConnectionListeners(!0),W()}),Z.on("connect_error",(Q)=>{console.error("[SocketIOTransport] Connection failed:",Q),this.notifyConnectionListeners(!1),q(Q)}),Z.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),Z.on("message",(Q)=>this.handleServerMessage(i(Q)))})}onConnectionChange(W){return this.connectionListeners.add(W),W(this.isConnected()),()=>{this.connectionListeners.delete(W)}}notifyConnectionListeners(W){for(let q of this.connectionListeners)q(W)}onServerError(W){this.serverErrorListeners.add(W);for(let[q,Z]of this.serverErrors)W(q,Z);return()=>{this.serverErrorListeners.delete(W)}}notifyServerError(W,q){for(let Z of this.serverErrorListeners)Z(W,q)}async sendMessage(W){if(this.isConnected())this.socket.emit("message",j(W));else this.messageQueue.push(W)}mountView(W,q){if(this.activeViews.has(W))throw Error(`Path ${W} is already mounted`);this.activeViews.set(W,q),this.sendMessage({type:"mount",path:W,routeInfo:q.routeInfo})}async navigate(W,q){await this.sendMessage({type:"navigate",path:W,routeInfo:q})}unmount(W){this.sendMessage({type:"unmount",path:W}),this.activeViews.delete(W)}disconnect(){this.socket?.disconnect(),this.socket=null,this.messageQueue=[],this.connectionListeners.clear(),this.activeViews.clear(),this.serverErrors.clear(),this.serverErrorListeners.clear()}handleServerMessage(W){switch(W.type){case"vdom_init":{let q=this.activeViews.get(W.path);if(!q)return;if(q)q.onInit(W.vdom);if(this.serverErrors.has(W.path))this.serverErrors.delete(W.path),this.notifyServerError(W.path,null);break}case"vdom_update":{let q=this.activeViews.get(W.path);if(!q)return;if(q.onUpdate(W.ops),this.serverErrors.has(W.path))this.serverErrors.delete(W.path),this.notifyServerError(W.path,null);break}case"server_error":{if(!this.activeViews.has(W.path))return;this.serverErrors.set(W.path,W.error),this.notifyServerError(W.path,W.error);break}case"api_call":{this.performApiCall(W);break}case"navigate_to":{let q=!!W.replace,Z=W.path||"";if(Z.startsWith("//"))Z=`${window.location.protocol}${Z}`;if(/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(Z))if(Z.startsWith("http://")||Z.startsWith("https://"))try{let $=new URL(Z);if($.origin===window.location.origin){let X=`${$.pathname}${$.search}${$.hash}`;this.frameworkNavigate(X,{replace:q})}else if(q)window.location.replace(Z);else window.location.assign(Z)}catch{if(q)window.location.replace(Z);else window.location.assign(Z)}else if(q)window.location.replace(Z);else window.location.assign(Z);else this.frameworkNavigate(Z,{replace:q});break}default:console.error("Unexpected message:",W)}}async performApiCall(W){try{let q=await fetch(W.url,{method:W.method||"GET",headers:{...W.headers||{},...W.body!=null&&!("content-type"in(W.headers||{}))?{"content-type":"application/json"}:{}},body:W.body!=null?typeof W.body==="string"?W.body:JSON.stringify(W.body):void 0,credentials:W.credentials||"include"}),Z={};q.headers.forEach((V,z)=>Z[z]=V);let Q=null;if((q.headers.get("content-type")||"").includes("application/json"))Q=await q.json().catch(()=>null);else Q=await q.text().catch(()=>null);let X={type:"api_result",id:W.id,ok:q.ok,status:q.status,headers:Z,body:Q};await this.sendMessage(X)}catch(q){let Z={type:"api_result",id:W.id,ok:!1,status:0,headers:{},body:{error:String(q)}};await this.sendMessage(Z)}}async invokeCallback(W,q,Z){await this.sendMessage({type:"callback",path:W,callback:q,args:Z.map(E)})}}import{useLocation as tq,useParams as eq,useNavigate as WZ}from"react-router";import{jsx as k,jsxs as h}from"react/jsx-runtime";var GW=JW(null),FW=JW(null),VW=()=>{let W=XW(GW);if(!W)throw Error("usePulseClient must be used within a PulseProvider");return W},qZ=(W)=>{let q=XW(FW);if(!q)throw Error("usePulsePrerender must be used within a PulseProvider");let Z=q.views[W];if(!Z)throw Error(`No prerender found for '${W}'`);return Z},d=typeof window<"u";function ZZ({children:W,config:q,prerender:Z}){let[Q,$]=n(!0),X=WZ(),{renderId:V,views:z}=Z,J=c(()=>new _(q.serverAddress,V,X),[q.serverAddress,X,V]);return m(()=>J.onConnectionChange($),[J]),m(()=>{if(d)return J.connect(),()=>J.disconnect()},[J]),k(GW.Provider,{value:J,children:h(FW.Provider,{value:Z,children:[!Q&&k("div",{style:{position:"fixed",bottom:"20px",right:"20px",backgroundColor:"red",color:"white",padding:"10px",borderRadius:"5px",zIndex:1000},children:"Failed to connect to the server."}),W]})})}function $Z({externalComponents:W,path:q}){let Z=VW(),Q=qZ(q),$=c(()=>new M(Z,q,W),[Z,q,W]),[X,V]=n(()=>$.renderNode(Q)),[z,J]=n(null),G=tq(),P=eq(),O=c(()=>{let{"*":A="",...N}=P,y=new URLSearchParams(G.search);return{hash:G.hash,pathname:G.pathname,query:G.search,queryParams:Object.fromEntries(y.entries()),pathParams:N,catchall:A.length>0?A.split("/"):[]}},[G.hash,G.pathname,G.search,JSON.stringify(P)]);if(m(()=>{if(d){Z.mountView(q,{routeInfo:O,onInit:(N)=>{V($.renderNode(N))},onUpdate:(N)=>{V((y)=>y==null?y:x(y,N,$))}});let A=Z.onServerError((N,y)=>{if(N===q)J(y)});return()=>{A(),Z.unmount(q)}}},[Z]),m(()=>{if(d)Z.navigate(q,O)},[Z,q,O]),z)return k(zZ,{error:z});return X}function zZ({error:W}){return h("div",{style:{padding:16,border:"1px solid #e00",background:"#fff5f5",color:"#900",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',whiteSpace:"pre-wrap"},children:[h("div",{style:{fontWeight:700,marginBottom:8},children:["Server Error during ",W.phase]}),W.message&&k("div",{children:W.message}),W.stack&&h("details",{open:!0,style:{marginTop:8},children:[k("summary",{children:"Stack trace"}),k("pre",{style:{margin:0},children:W.stack})]})]})}import{io as QZ}from"socket.io-client";class PW{url;socket=null;listener=null;messageQueue=[];connectionListeners=new Set;constructor(W){this.url=W}connect(W){return this.listener=W,new Promise((q,Z)=>{this.socket=QZ(this.url,{transports:["websocket"]}),this.socket.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let Q of this.messageQueue)this.socket?.emit("message",Q);this.messageQueue=[],this.notifyConnectionListeners(!0),q()}),this.socket.on("connect_error",(Q)=>{console.error("[SocketIOTransport] Connection failed:",Q),this.notifyConnectionListeners(!1),Z(Q)}),this.socket.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),this.socket.on("message",(Q)=>{this.listener?.(Q)})})}disconnect(){this.socket?.disconnect(),this.socket=null,this.listener=null,this.messageQueue=[],this.connectionListeners.clear()}async sendMessage(W){if(this.isConnected())this.socket.emit("message",W);else this.messageQueue.push(W)}isConnected(){return this.socket?.connected||!1}onConnectionChange(W){return this.connectionListeners.add(W),W(this.isConnected()),()=>{this.connectionListeners.delete(W)}}notifyConnectionListeners(W){for(let q of this.connectionListeners)q(W)}}function JZ({params:W,request:q}){let{"*":Z="",...Q}=W,$=new URL(q.url);return{hash:$.hash,pathname:$.pathname,query:$.search,queryParams:Object.fromEntries($.searchParams.entries()),pathParams:Q,catchall:Z.length>1?Z.split("/"):[]}}function XZ(W){if(W===null||typeof W!=="object")return!1;let q=Object.getPrototypeOf(W);return q===Object.prototype||q===null}function s(W){return typeof W==="function"||typeof W==="symbol"||typeof W>"u"}async function GZ(W){let q=await W.arrayBuffer();return Array.from(new Uint8Array(q))}async function FZ(W){return await Y(W,{seen:new WeakMap,nextId:1})}function VZ(W,q){if(W.seen.get(q)!==void 0)return null;let Q=W.nextId++;return W.seen.set(q,Q),Q}async function Y(W,q){if(W===null||typeof W!=="object")return W;if(W instanceof Date)return{__t:"datetime",timestamp:W.getTime()};if(W instanceof FormData){let z=VZ(q,W);if(z===null)return{__t:"ref",id:q.seen.get(W)};let J={};for(let[P,O]of W.entries()){let A=await Y(O,q);if(A===void 0)continue;if(Object.prototype.hasOwnProperty.call(J,P)){let N=J[P];if(Array.isArray(N))N.push(A);else J[P]=[N,A]}else J[P]=A}return{__t:"formdata",fields:J,__id:z}}if(W instanceof File){let z=W,J=await GZ(W);return{__t:"file",name:z.name,type:z.type,size:z.size,lastModified:z.lastModified,content:J}}let Z=W,Q=q.seen.get(Z);if(Q!==void 0)return{__t:"ref",id:Q};let $=q.nextId++;if(q.seen.set(Z,$),Array.isArray(W)){let J=(await Promise.all(W.map((P)=>Y(P,q)))).filter((P)=>P!==void 0);return{__t:"array",__id:$,items:J}}let X={};if(XZ(W))for(let z of Object.keys(W)){let J=W[z];if(s(J))continue;let G=await Y(J,q);if(G!==void 0)X[z]=G}else for(let z in W){let J=W[z];if(s(J))continue;let G=await Y(J,q);if(G!==void 0)X[z]=G}return{__t:"object",__id:$,props:X}}function PZ(W){return B(W)}function B(W){if(W===null||typeof W!=="object")return W;let q=W,Z=q.__t;if(Z==="datetime"){let $=q.timestamp;return new Date($)}if(Z==="file"){let $=q.content;if(Array.isArray($))return{...q,content:new Uint8Array($)};return q}if(Z==="formdata"){let $=q.fields,X={};for(let V of Object.keys($)){let z=$[V];if(Array.isArray(z))X[V]=z.map((J)=>B(J));else X[V]=B(z)}return{__t:"formdata",fields:X}}if(Z==="array")return q.items.map((X)=>B(X));if(Z==="object"){let $=q.props,X={};for(let V of Object.keys($))X[V]=B($[V]);return X}if(Z==="ref")return q;let Q={};for(let $ of Object.keys(q))Q[$]=B(q[$]);return Q}function UZ(W){return l(W,new WeakSet)}function l(W,q){if(W===null||typeof W!=="object")return W;if(q.has(W))return;if(q.add(W),Array.isArray(W))return W.map((Q)=>l(Q,q)).filter((Q)=>Q!==void 0);let Z={};for(let Q in W){let $=W[Q];if(s($))continue;let X=l($,q);if(X!==void 0)Z[Q]=X}return Z}export{VW as usePulseClient,j as stringify,i as parse,JZ as extractServerRouteInfo,E as extractEvent,FZ as encodeForWire,PZ as decodeFromWire,UZ as cleanForSerialization,x as applyReactTreeUpdates,M as VDOMRenderer,PW as SocketIOTransport,OW as RenderLazy,$Z as PulseView,_ as PulseSocketIOClient,ZZ as PulseProvider};
1
+ import{useEffect as p,useState as c,useMemo as n,createContext as z1,useContext as G1}from"react";import D1,{cloneElement as k,createElement as e,lazy as R1,Suspense as A1}from"react";var o="$$fragment",r="$$";function a(W){return typeof W==="object"&&W!==null}function t(W){return typeof W==="object"&&W!==null&&W.tag.startsWith("$$")&&W.tag!=="$$fragment"}import{jsx as x,Fragment as f1}from"react/jsx-runtime";class M{client;path;components;callbackCache;constructor(W,q,Z){this.client=W;this.path=q;this.components=Z;this.callbackCache=new Map}getCallback(W){let q=this.callbackCache.get(W);if(!q)q=(...Z)=>this.client.invokeCallback(this.path,W,Z),this.callbackCache.set(W,q);return q}renderNode(W){if(W==null||typeof W==="boolean"||typeof W==="number"||typeof W==="string")return W;if(a(W)){let{tag:q,props:Z={},children:J=[]}=W,$={};for(let[z,Q]of Object.entries(Z))if(typeof Q==="string"&&Q.startsWith("$$fn:")){let X=Q.substring(5);$[z]=this.getCallback(X)}else $[z]=Q;if(W.key)$.key=W.key;let G=[];for(let z of J)G.push(this.renderNode(z));if(t(W)){let z=W.tag.slice(r.length),Q=this.components[z];return e(Q,$,...G)}return e(q===o?D1.Fragment:q,$,...G)}return null}}function y(W){let q=W.props?.children;if(q==null)return[];return Array.isArray(q)?q.slice():[q]}function N1(W,q){let Z={};for(let[J,$]of Object.entries(q||{}))if(typeof $==="string"&&$.startsWith("$$fn:")){let G=$.substring(5);Z[J]=W.getCallback(G)}else Z[J]=$;return Z}function O1(W,q){return k(W,void 0,...q)}function u(W,q,Z){let J=W;for(let $ of q){let G=$.path.split(".").filter((Q)=>Q.length>0).map(Number),z=(Q,X)=>{if(X<G.length){H(Q,G,X),Q=Q;let F=G[X],U=y(Q),P=U[F];return U[F]=z(P,X+1),O1(Q,U)}switch($.type){case"replace":return Z.renderNode($.data);case"update_props":{H(Q,G,X),Q=Q;let U={...Q.props??{}};console.log("update_props, data:",$.data);let P=$.data;if(P.remove&&P.remove.length>0){for(let D of P.remove)if(D in U)delete U[D]}if(P.set){let D=N1(Z,P.set);for(let[R,f]of Object.entries(D))U[R]=f}return console.log("Old props:",Q.props),console.log("New props:",U),k(Q,U)}case"insert":{H(Q,G,X),Q=Q;let F=y(Q);return F.splice($.idx,0,Z.renderNode($.data)),k(Q,null,...F)}case"remove":{H(Q,G,X),Q=Q;let F=y(Q);return F.splice($.idx,1),k(Q,null,...F)}case"move":{H(Q,G,X),Q=Q;let F=y(Q),U=F.splice($.data.from_index,1)[0];return F.splice($.data.to_index,0,U),k(Q,null,...F)}default:throw Error(`[Pulse renderer] Unknown update type: ${$.type}`)}};J=z(J,0)}return J}function C1(W,q){let Z=R1(W);return({children:J,...$})=>{return x(A1,{fallback:q??x(f1,{}),children:x(Z,{...$,children:J})})}}function H(W,q,Z){return!0}function I(){function W(q,Z){return(J)=>{let $={};for(let G of q)$[G]=J[G];if(Z)for(let G in Z){let z=Z[G];$[G]=z(J)}return $}}return W}var I1=(W)=>W.tagName.toLowerCase(),B1=["id","className","tagName","localName","clientHeight","clientLeft","clientTop","clientWidth","scrollHeight","scrollLeft","scrollTop","scrollWidth","slot"],K1=["autofocus","tabIndex","nonce"],w1=["accessKey","accessKeyLabel","autocapitalize","dir","draggable","hidden","inert","lang","offsetHeight","offsetLeft","offsetTop","offsetWidth","popover","spellcheck","title","translate","writingSuggestions","contentEditable","enterKeyHint","isContentEditable","inputMode"],g1=I()(B1,{tagName:I1}),H1=I()(K1),k1=I()(w1);function B(W){return{...g1(W),...H1(W),...k1(W)}}function V(W,q){let Z=I()(W,q);return(J)=>({...B(J),...Z(J)})}var Y1=["hash","host","hostname","href","origin","password","pathname","port","protocol","search","target","download","rel","hreflang","type","username","ping","referrerPolicy","text"],j1=V(Y1),L1=["alt","coords","download","hash","host","hostname","href","origin","password","pathname","port","protocol","rel","search","shape","target","username","ping","referrerPolicy"],y1=V(L1),M1=["autoplay","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","loop","muted","networkState","paused","playbackRate","preload","readyState","seeking","src","volume","preservesPitch"],Q1=V(M1),b1=(W)=>Q1(W),S1=["disabled","name","type","value","formAction","formEnctype","formMethod","formNoValidate","formTarget","popoverTargetAction"],_1=V(S1),T1=["value"],h1=V(T1),m1=["height","src","type","width","align","name"],p1=V(m1),x1=["disabled","name","type","validationMessage","willValidate"],u1=V(x1),E1=["acceptCharset","action","autocomplete","encoding","enctype","length","method","name","noValidate","target","rel"],v1=V(E1),i1=["allow","allowFullscreen","height","name","referrerPolicy","src","srcdoc","width","align","frameBorder","longDesc","marginHeight","marginWidth","scrolling","sandbox"],c1=V(i1),n1=["alt","crossOrigin","decoding","height","isMap","loading","naturalHeight","naturalWidth","referrerPolicy","sizes","src","srcset","useMap","width","align","border","complete","hspace","longDesc","lowsrc","name","vspace","x","y","fetchPriority"],s1=V(n1),l1=["accept","alt","autocomplete","checked","defaultChecked","defaultValue","dirName","disabled","height","indeterminate","max","maxLength","min","minLength","multiple","name","pattern","placeholder","readOnly","required","selectionDirection","selectionEnd","selectionStart","size","src","step","type","value","valueAsNumber","width","align","capture","formAction","formEnctype","formMethod","formNoValidate","formTarget","useMap","validationMessage","willValidate","popoverTargetAction"],d1=V(l1),o1=["htmlFor"],r1=V(o1),a1=["value","type"],t1=V(a1),e1=["as","crossOrigin","disabled","fetchPriority","href","hreflang","imageSizes","imageSrcset","integrity","media","referrerPolicy","rel","type","charset","rev","target","sizes"],WW=V(e1),qW=["name"],ZW=V(qW),$W=["high","low","max","min","optimum","value"],QW=V($W),JW=["cite","dateTime"],W1=V(JW),XW=["reversed","start","type","compact"],zW=V(XW),GW=["data","height","name","type","useMap","width","validationMessage","willValidate","align","archive","border","code","codeBase","codeType","declare","hspace","standby","vspace"],FW=V(GW),VW=["disabled","label"],UW=V(VW),PW=["defaultSelected","disabled","index","label","selected","text","value"],DW=V(PW),RW=["defaultValue","name","type","value","htmlFor","validationMessage","willValidate"],AW=V(RW),NW=["max","position","value"],OW=V(NW),CW=["cite"],q1=V(CW),fW=(W)=>B(W),IW=["async","crossOrigin","defer","fetchPriority","integrity","noModule","referrerPolicy","src","text","type","charset"],BW=I()(IW,{event:(W)=>W.event,htmlFor:(W)=>W.htmlFor}),KW=(W)=>({...B(W),...BW(W)}),wW=["autocomplete","disabled","length","multiple","name","required","selectedIndex","size","type","value","validationMessage","willValidate"],gW=V(wW),HW=["name"],kW=V(HW),YW=["height","media","sizes","src","srcset","type","width"],jW=V(YW),LW=["align"],yW=V(LW),MW=["abbr","cellIndex","colSpan","headers","rowSpan","scope","align","axis","bgColor","ch","chOff","height","noWrap","vAlign","width"],Z1=V(MW),bW=["span","align","ch","chOff","vAlign","width"],$1=V(bW),SW=["align","bgColor","border","cellPadding","cellSpacing","frame","rules","summary","width"],_W=V(SW),TW=["rowIndex","sectionRowIndex","align","bgColor","ch","chOff","vAlign"],hW=V(TW),mW=["align","ch","chOff","vAlign"],E=V(mW),pW=(W)=>B(W),xW=["autocomplete","cols","defaultValue","dirName","disabled","maxLength","minLength","name","placeholder","readOnly","required","rows","selectionDirection","selectionEnd","selectionStart","value","wrap","textLength","validationMessage","willValidate"],uW=V(xW),EW=["dateTime"],vW=V(EW),iW=["default","kind","label","readyState","src","srclang"],cW=V(iW),nW=["height","poster","videoHeight","videoWidth","width","playsInline"],sW=I()(nW),lW=(W)=>({...Q1(W),...sW(W)}),dW=["clear"],oW=V(dW),rW=["href","target"],aW=V(rW),tW=["aLink","background","bgColor","link","text","vLink"],eW=V(tW),Wq=["compact"],qq=V(Wq),Zq=["open"],$q=V(Zq),Qq=["open","returnValue"],Jq=V(Qq),Xq=["align"],zq=V(Xq),Gq=(W)=>B(W),Fq=["align"],K=V(Fq),Vq=["align","color","noShade","size","width"],Uq=V(Vq),Pq=["version"],Dq=V(Pq),Rq=(W)=>B(W),Aq=["content","httpEquiv","name","scheme"],Nq=V(Aq),Oq=["align"],Cq=V(Oq),fq=(W)=>B(W),Iq=["width"],Bq=V(Iq),Kq=(W)=>B(W),wq=["media","type","disabled"],gq=V(wq),Hq=["text"],kq=V(Hq),Yq=["compact","type"],jq=V(Yq),Lq={A:j1,AREA:y1,AUDIO:b1,BASE:aW,BLOCKQUOTE:q1,Q:q1,BODY:eW,BR:oW,BUTTON:_1,CANVAS:B,CAPTION:yW,CITE:fW,COL:$1,COLGROUP:$1,DATA:h1,DETAILS:$q,DIALOG:Jq,DIV:zq,DL:qq,EMBED:p1,FIELDSET:u1,FORM:v1,H1:K,H2:K,H3:K,H4:K,H5:K,H6:K,HEAD:Gq,HR:Uq,HTML:Dq,IFRAME:c1,IMG:s1,INPUT:d1,LABEL:r1,LI:t1,LINK:WW,MAP:ZW,MENU:Rq,META:Nq,METER:QW,INS:W1,DEL:W1,OBJECT:FW,OL:zW,OPTGROUP:UW,OPTION:DW,OUTPUT:AW,P:Cq,PICTURE:fq,PRE:Bq,PROGRESS:OW,SCRIPT:KW,SELECT:gW,SLOT:kW,SOURCE:jW,SPAN:Kq,STYLE:gq,TABLE:_W,TBODY:E,THEAD:E,TFOOT:E,TD:Z1,TH:Z1,TEMPLATE:pW,TEXTAREA:uW,TIME:vW,TITLE:kq,TR:hW,TRACK:cW,UL:jq,VIDEO:lW};function b(W){let q=W.tagName.toUpperCase(),Z=Lq[q];if(Z)return Z(W);throw Error(`Unexpected HTML element tag: ${W.tagName} (update .web/custom/serialize.ts)`)}var yq=(W)=>b(W.target),Y=(W)=>W.relatedTarget?b(W.relatedTarget):null;function A(W,q){return I()(W,{target:yq,...q||{}})}var C=["target","bubbles","cancelable","defaultPrevented","eventPhase","isTrusted","timeStamp","type"],S=[...C,"detail"],_=[...S,"altKey","button","buttons","clientX","clientY","ctrlKey","metaKey","movementX","movementY","pageX","pageY","screenX","screenY","shiftKey"],Mq=[..._,"pointerId","pressure","tangentialPressure","tiltX","tiltY","twist","width","height","pointerType","isPrimary"],bq=A(C),Sq=A(S),_q=A(_,{relatedTarget:Y}),Tq=A(C,{clipboardData:(W)=>J1(W.clipboardData)}),hq=A([...C,"data"]),mq=A(_,{relatedTarget:Y,dataTransfer:(W)=>J1(W.dataTransfer)}),pq=A(Mq,{relatedTarget:Y}),xq=A(C,{relatedTarget:Y}),uq=A(C),Eq=A(C),vq=A(C),iq=A([...S,"altKey","ctrlKey","code","key","locale","location","metaKey","repeat","shiftKey"]),cq=A([...S,"altKey","ctrlKey","metaKey","shiftKey","changedTouches","targetTouches","touches"],{changedTouches:(W)=>v(W.changedTouches),targetTouches:(W)=>v(W.targetTouches),touches:(W)=>v(W.touches)}),nq=A([..._,"deltaMode","deltaX","deltaY","deltaZ"],{relatedTarget:Y}),sq=A([...C,"animationName","elapsedTime","pseudoElement"]),lq=A([...C,"oldState","newState"]),dq=A([...C,"elapsedTime","propertyName","pseudoElement"]);function v(W){return Array.from(W).map((q)=>({target:b(q.target),identifier:q.identifier,screenX:q.screenX,screenY:q.screenY,clientX:q.clientX,clientY:q.clientY,pageX:q.pageX,pageY:q.pageY}))}function J1(W){if(!W)return null;let q=[];if(W.items)for(let Z=0;Z<W.items.length;Z++){let J=W.items[Z];q.push({kind:J.kind,type:J.type})}return{drop_effect:W.dropEffect,effect_allowed:W.effectAllowed,items:q,types:Array.from(W.types||[])}}var N={};function O(W,q,Z){for(let J of q)W[J]=Z}O(N,["pointerdown","pointermove","pointerup","pointercancel","gotpointercapture","lostpointercapture","pointerenter","pointerleave","pointerover","pointerout"],pq);O(N,["click","contextmenu","dblclick","mousedown","mouseenter","mouseleave","mousemove","mouseout","mouseover","mouseup"],_q);O(N,["drag","dragend","dragenter","dragexit","dragleave","dragover","dragstart","drop"],mq);O(N,["keydown","keypress","keyup"],iq);O(N,["focus","blur"],xq);O(N,["change","input"],vq);O(N,["invalid"],Eq);O(N,["reset","submit"],uq);O(N,["copy","cut","paste"],Tq);O(N,["compositionend","compositionstart","compositionupdate"],hq);O(N,["touchcancel","touchend","touchmove","touchstart"],cq);O(N,["scroll"],Sq);O(N,["wheel"],nq);O(N,["animationstart","animationend","animationiteration"],sq);O(N,["transitionend"],dq);O(N,["toggle"],lq);function i(W){if(W&&typeof W==="object"&&"nativeEvent"in W&&typeof W.isDefaultPrevented==="function"){let q=W;if(typeof q.type!=="string")return W;let Z=N[q.type.toLowerCase()];if(Z)return Z(q);return bq(q)}return W}function T(W,q){let Z=[],J=q.map(()=>[]),$=new Map,G=(z)=>{let Q=$.get(z);if(Q!==void 0)return Q;if(z==null||typeof z==="number"||typeof z==="string"||typeof z==="boolean"){let X=Z.length;return Z.push(z),$.set(z,X),X}for(let X=0;X<q.length;X++){let F=q[X];if(F.check(z)){if($.has(z))return $.get(z);let U=Z.length;Z.push([]),$.set(z,U);let P=F.encode(z,(D)=>G(D));return Z[U]=P,J[X].push(U),U}}if(z&&typeof z==="object"){if($.has(z))return $.get(z);if(Array.isArray(z)){let U=Z.length;Z.push([]),$.set(z,U);let P=[];for(let D=0;D<z.length;D++)P.push(G(z[D]));return Z[U]=P,U}let X=Z.length;Z.push({}),$.set(z,X);let F={};for(let U of Object.keys(z)){let P=z[U],D=G(P);F[U]=D}return Z[X]=F,X}throw Error(`Unsupported value in serialize(): ${String(z)} (type ${typeof z})`)};return G(W),[J,Z]}function X1(W,q){let[Z,J]=W,$=new Map;for(let Q=0;Q<Z.length;Q++)for(let X of Z[Q]??[])$.set(X,Q);let G=new Map,z=(Q)=>{if(G.has(Q))return G.get(Q);if(Q<0||Q>=J.length)throw Error(`Invalid serialized data: missing entry at index ${Q}`);let X=J[Q];if($.has(Q)){let D=q[$.get(Q)].decode(J[Q],(R)=>z(R));return G.set(Q,D),D}if(X==null||typeof X==="number"||typeof X==="string"||typeof X==="boolean")return X??=void 0,G.set(Q,X),X;if(Array.isArray(X)){let P=[];G.set(Q,P);for(let D of X)P.push(z(D));return P}let F={};G.set(Q,F);let U=X;for(let P in U)F[P]=z(U[P]);return F};if(J.length===0)throw Error("Invalid serialized data: empty entries array");return z(0)}var oq={check(W){return W instanceof Date},encode(W,q){return{t:q("date"),ts:q(W.getTime())}},decode(W,q){if(q(W.t)!=="date")throw Error("Invalid date payload");let J=q(W.ts);return new Date(J)}},rq={check(W){return typeof File<"u"&&W instanceof File},encode(W,q){return{t:q("file"),n:q(W.name),tp:q(W.type),sz:q(W.size),lm:q(W.lastModified),b:W}},decode(W,q){let Z=W;if(q(Z.t)!=="file")throw Error("Invalid file payload");let $=q(Z.n),G=q(Z.tp),z=q(Z.sz),Q=q(Z.lm),X=Z.file;if(typeof File<"u"){if(X instanceof File)return X;if(X&&(X instanceof Uint8Array||X instanceof ArrayBuffer)){let F=X instanceof Uint8Array?X:new Uint8Array(X);return new File([F],$,{type:G,lastModified:Q})}if(typeof Blob<"u"&&X instanceof Blob)return new File([X],$,{type:G,lastModified:Q})}return{name:$,type:G,size:z,lastModified:Q,file:X}}},aq={check(W){return typeof FormData<"u"&&W instanceof FormData},encode(W,q){let Z={};for(let[J,$]of W.entries()){let G=Z[J];if(G===void 0)Z[J]=$;else if(Array.isArray(G))G.push($);else Z[J]=[G,$]}return{t:q("formdata"),f:q(Z)}},decode(W,q){if(q(W.t)!=="formdata")throw Error("Invalid formdata payload");let J=q(W.f),$=new FormData;for(let[G,z]of Object.entries(J))if(Array.isArray(z))for(let Q of z)$.append(G,Q);else $.append(G,z);return $}},tq={check(W){return W instanceof Set},encode(W,q){return{t:q("set"),items:q(Array.from(W.values()))}},decode(W,q){if(q(W.t)!=="set")throw Error("Invalid set payload");let J=q(W.items);return new Set(J)}},eq={check(W){return W instanceof Map},encode(W,q){return{t:q("map"),entries:q(Array.from(W.entries()))}},decode(W,q){if(q(W.t)!=="map")throw Error("Invalid map payload");let J=q(W.entries);return new Map(J)}};function j(){return[oq,rq,aq,tq,eq]}import{io as WZ}from"socket.io-client";class h{url;renderId;frameworkNavigate;activeViews;socket=null;messageQueue;connectionListeners=new Set;serverErrors=new Map;serverErrorListeners=new Set;constructor(W,q,Z){this.url=W;this.renderId=q;this.frameworkNavigate=Z;this.socket=null,this.activeViews=new Map,this.messageQueue=[]}isConnected(){return this.socket?.connected??!1}async connect(){if(this.socket)return;return new Promise((W,q)=>{let Z=WZ(this.url,{transports:["websocket","webtransport"],auth:{renderId:this.renderId}});this.socket=Z,Z.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let[J,$]of this.activeViews)Z.emit("message",T({type:"mount",path:J,routeInfo:$.routeInfo},j()));for(let J of this.messageQueue){if(J.type==="mount"&&this.activeViews.has(J.path))continue;if(J.type==="navigate")continue;Z.emit("message",T(J,j()))}this.messageQueue=[],this.notifyConnectionListeners(!0),W()}),Z.on("connect_error",(J)=>{console.error("[SocketIOTransport] Connection failed:",J),this.notifyConnectionListeners(!1),q(J)}),Z.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),Z.on("message",(J)=>this.handleServerMessage(X1(J,j())))})}onConnectionChange(W){return this.connectionListeners.add(W),W(this.isConnected()),()=>{this.connectionListeners.delete(W)}}notifyConnectionListeners(W){for(let q of this.connectionListeners)q(W)}onServerError(W){this.serverErrorListeners.add(W);for(let[q,Z]of this.serverErrors)W(q,Z);return()=>{this.serverErrorListeners.delete(W)}}notifyServerError(W,q){for(let Z of this.serverErrorListeners)Z(W,q)}async sendMessage(W){if(this.isConnected())this.socket.emit("message",T(W,j()));else this.messageQueue.push(W)}mountView(W,q){if(this.activeViews.has(W))throw Error(`Path ${W} is already mounted`);this.activeViews.set(W,q),this.sendMessage({type:"mount",path:W,routeInfo:q.routeInfo})}async navigate(W,q){await this.sendMessage({type:"navigate",path:W,routeInfo:q})}unmount(W){this.sendMessage({type:"unmount",path:W}),this.activeViews.delete(W)}disconnect(){this.socket?.disconnect(),this.socket=null,this.messageQueue=[],this.connectionListeners.clear(),this.activeViews.clear(),this.serverErrors.clear(),this.serverErrorListeners.clear()}handleServerMessage(W){switch(W.type){case"vdom_init":{let q=this.activeViews.get(W.path);if(!q)return;if(q)q.onInit(W.vdom);if(this.serverErrors.has(W.path))this.serverErrors.delete(W.path),this.notifyServerError(W.path,null);break}case"vdom_update":{let q=this.activeViews.get(W.path);if(!q)return;if(q.onUpdate(W.ops),this.serverErrors.has(W.path))this.serverErrors.delete(W.path),this.notifyServerError(W.path,null);break}case"server_error":{if(!this.activeViews.has(W.path))return;this.serverErrors.set(W.path,W.error),this.notifyServerError(W.path,W.error);break}case"api_call":{this.performApiCall(W);break}case"navigate_to":{let q=!!W.replace,Z=W.path||"";if(Z.startsWith("//"))Z=`${window.location.protocol}${Z}`;if(/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(Z))if(Z.startsWith("http://")||Z.startsWith("https://"))try{let $=new URL(Z);if($.origin===window.location.origin){let G=`${$.pathname}${$.search}${$.hash}`;this.frameworkNavigate(G,{replace:q})}else if(q)window.location.replace(Z);else window.location.assign(Z)}catch{if(q)window.location.replace(Z);else window.location.assign(Z)}else if(q)window.location.replace(Z);else window.location.assign(Z);else this.frameworkNavigate(Z,{replace:q});break}default:console.error("Unexpected message:",W)}}async performApiCall(W){try{let q=await fetch(W.url,{method:W.method||"GET",headers:{...W.headers||{},...W.body!=null&&!("content-type"in(W.headers||{}))?{"content-type":"application/json"}:{}},body:W.body!=null?typeof W.body==="string"?W.body:JSON.stringify(W.body):void 0,credentials:W.credentials||"include"}),Z={};q.headers.forEach((z,Q)=>Z[Q]=z);let J=null;if((q.headers.get("content-type")||"").includes("application/json"))J=await q.json().catch(()=>null);else J=await q.text().catch(()=>null);let G={type:"api_result",id:W.id,ok:q.ok,status:q.status,headers:Z,body:J};await this.sendMessage(G)}catch(q){let Z={type:"api_result",id:W.id,ok:!1,status:0,headers:{},body:{error:String(q)}};await this.sendMessage(Z)}}async invokeCallback(W,q,Z){await this.sendMessage({type:"callback",path:W,callback:q,args:Z.map(i)})}}import{useLocation as qZ,useParams as ZZ,useNavigate as $Z}from"react-router";import{jsx as w,jsxs as m}from"react/jsx-runtime";var F1=z1(null),V1=z1(null),U1=()=>{let W=G1(F1);if(!W)throw Error("usePulseClient must be used within a PulseProvider");return W},QZ=(W)=>{let q=G1(V1);if(!q)throw Error("usePulsePrerender must be used within a PulseProvider");let Z=q.views[W];if(!Z)throw Error(`No prerender found for '${W}'`);return Z},s=typeof window<"u";function JZ({children:W,config:q,prerender:Z}){let[J,$]=c(!0),G=$Z(),{renderId:z,views:Q}=Z,X=n(()=>new h(q.serverAddress,z,G),[q.serverAddress,G,z]);return p(()=>X.onConnectionChange($),[X]),p(()=>{if(s)return X.connect(),()=>X.disconnect()},[X]),w(F1.Provider,{value:X,children:m(V1.Provider,{value:Z,children:[!J&&w("div",{style:{position:"fixed",bottom:"20px",right:"20px",backgroundColor:"red",color:"white",padding:"10px",borderRadius:"5px",zIndex:1000},children:"Failed to connect to the server."}),W]})})}function XZ({externalComponents:W,path:q}){let Z=U1(),J=QZ(q),$=n(()=>new M(Z,q,W),[Z,q,W]),[G,z]=c(()=>$.renderNode(J)),[Q,X]=c(null),F=qZ(),U=ZZ(),P=n(()=>{let{"*":D="",...R}=U,f=new URLSearchParams(F.search);return{hash:F.hash,pathname:F.pathname,query:F.search,queryParams:Object.fromEntries(f.entries()),pathParams:R,catchall:D.length>0?D.split("/"):[]}},[F.hash,F.pathname,F.search,JSON.stringify(U)]);if(p(()=>{if(s){Z.mountView(q,{routeInfo:P,onInit:(R)=>{z($.renderNode(R))},onUpdate:(R)=>{z((f)=>f==null?f:u(f,R,$))}});let D=Z.onServerError((R,f)=>{if(R===q)X(f)});return()=>{D(),Z.unmount(q)}}},[Z]),p(()=>{if(s)Z.navigate(q,P)},[Z,q,P]),Q)return w(zZ,{error:Q});return G}function zZ({error:W}){return m("div",{style:{padding:16,border:"1px solid #e00",background:"#fff5f5",color:"#900",fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',whiteSpace:"pre-wrap"},children:[m("div",{style:{fontWeight:700,marginBottom:8},children:["Server Error during ",W.phase]}),W.message&&w("div",{children:W.message}),W.stack&&m("details",{open:!0,style:{marginTop:8},children:[w("summary",{children:"Stack trace"}),w("pre",{style:{margin:0},children:W.stack})]})]})}import{io as GZ}from"socket.io-client";class P1{url;socket=null;listener=null;messageQueue=[];connectionListeners=new Set;constructor(W){this.url=W}connect(W){return this.listener=W,new Promise((q,Z)=>{this.socket=GZ(this.url,{transports:["websocket"]}),this.socket.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let J of this.messageQueue)this.socket?.emit("message",J);this.messageQueue=[],this.notifyConnectionListeners(!0),q()}),this.socket.on("connect_error",(J)=>{console.error("[SocketIOTransport] Connection failed:",J),this.notifyConnectionListeners(!1),Z(J)}),this.socket.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),this.socket.on("message",(J)=>{this.listener?.(J)})})}disconnect(){this.socket?.disconnect(),this.socket=null,this.listener=null,this.messageQueue=[],this.connectionListeners.clear()}async sendMessage(W){if(this.isConnected())this.socket.emit("message",W);else this.messageQueue.push(W)}isConnected(){return this.socket?.connected||!1}onConnectionChange(W){return this.connectionListeners.add(W),W(this.isConnected()),()=>{this.connectionListeners.delete(W)}}notifyConnectionListeners(W){for(let q of this.connectionListeners)q(W)}}function FZ({params:W,request:q}){let{"*":Z="",...J}=W,$=new URL(q.url);return{hash:$.hash,pathname:$.pathname,query:$.search,queryParams:Object.fromEntries($.searchParams.entries()),pathParams:J,catchall:Z.length>1?Z.split("/"):[]}}function VZ(W){if(W===null||typeof W!=="object")return!1;let q=Object.getPrototypeOf(W);return q===Object.prototype||q===null}function l(W){return typeof W==="function"||typeof W==="symbol"||typeof W>"u"}async function UZ(W){let q=await W.arrayBuffer();return Array.from(new Uint8Array(q))}async function PZ(W){return await L(W,{seen:new WeakMap,nextId:1})}function DZ(W,q){if(W.seen.get(q)!==void 0)return null;let J=W.nextId++;return W.seen.set(q,J),J}async function L(W,q){if(W===null||typeof W!=="object")return W;if(W instanceof Date)return{__t:"datetime",timestamp:W.getTime()};if(W instanceof FormData){let Q=DZ(q,W);if(Q===null)return{__t:"ref",id:q.seen.get(W)};let X={};for(let[U,P]of W.entries()){let D=await L(P,q);if(D===void 0)continue;if(Object.prototype.hasOwnProperty.call(X,U)){let R=X[U];if(Array.isArray(R))R.push(D);else X[U]=[R,D]}else X[U]=D}return{__t:"formdata",fields:X,__id:Q}}if(W instanceof File){let Q=W,X=await UZ(W);return{__t:"file",name:Q.name,type:Q.type,size:Q.size,lastModified:Q.lastModified,content:X}}let Z=W,J=q.seen.get(Z);if(J!==void 0)return{__t:"ref",id:J};let $=q.nextId++;if(q.seen.set(Z,$),Array.isArray(W)){let X=(await Promise.all(W.map((U)=>L(U,q)))).filter((U)=>U!==void 0);return{__t:"array",__id:$,items:X}}let G={};if(VZ(W))for(let Q of Object.keys(W)){let X=W[Q];if(l(X))continue;let F=await L(X,q);if(F!==void 0)G[Q]=F}else for(let Q in W){let X=W[Q];if(l(X))continue;let F=await L(X,q);if(F!==void 0)G[Q]=F}return{__t:"object",__id:$,props:G}}function RZ(W){return g(W)}function g(W){if(W===null||typeof W!=="object")return W;let q=W,Z=q.__t;if(Z==="datetime"){let $=q.timestamp;return new Date($)}if(Z==="file"){let $=q.content;if(Array.isArray($))return{...q,content:new Uint8Array($)};return q}if(Z==="formdata"){let $=q.fields,G={};for(let z of Object.keys($)){let Q=$[z];if(Array.isArray(Q))G[z]=Q.map((X)=>g(X));else G[z]=g(Q)}return{__t:"formdata",fields:G}}if(Z==="array")return q.items.map((G)=>g(G));if(Z==="object"){let $=q.props,G={};for(let z of Object.keys($))G[z]=g($[z]);return G}if(Z==="ref")return q;let J={};for(let $ of Object.keys(q))J[$]=g(q[$]);return J}function AZ(W){return d(W,new WeakSet)}function d(W,q){if(W===null||typeof W!=="object")return W;if(q.has(W))return;if(q.add(W),Array.isArray(W))return W.map((J)=>d(J,q)).filter((J)=>J!==void 0);let Z={};for(let J in W){let $=W[J];if(l($))continue;let G=d($,q);if(G!==void 0)Z[J]=G}return Z}function NZ(W){return W instanceof Date}function OZ(W){return typeof File<"u"&&W instanceof File}function CZ(W){return typeof FormData<"u"&&W instanceof FormData}function fZ(W){let q=new Map,Z=1,J=($)=>{if($===null||typeof $!=="object")return $;let G=$;if(q.has(G))return{__ref:q.get(G)};if(NZ($)){let X=Z++;return q.set(G,X),{__pulse:"date",__id:X,timestamp:$.getTime()}}if(OZ($)){let X=Z++;return q.set(G,X),{__pulse:"file",__id:X,name:$.name,type:$.type,size:$.size,lastModified:$.lastModified,file:$}}if(CZ($)){let X=Z++;q.set(G,X);let F={};for(let[U,P]of $.entries()){let D=J(P);if(Object.prototype.hasOwnProperty.call(F,U)){let R=F[U];if(Array.isArray(R))R.push(D);else F[U]=[R,D]}else F[U]=D}return{__pulse:"formdata",__id:X,fields:F}}let z=Z++;if(q.set(G,z),Array.isArray($))return{__pulse:"array",__id:z,items:$.map(J)};let Q={};for(let X in $){let F=$[X];if(typeof F==="function"||typeof F==="symbol"||typeof F>"u")continue;Q[X]=J(F)}return{__pulse:"object",__id:z,__data:Q}};return J(W)}function IZ(W){let q=new Map,Z=(J)=>{if(J===null||typeof J!=="object")return J;if(Array.isArray(J))return J.map(Z);let $=J;if($.__ref!==void 0){let z=$.__ref;return q.get(z)||null}if($.__pulse==="date"){let z=$.__id,Q=new Date($.timestamp);return q.set(z,Q),Q}if($.__pulse==="file"){let{__id:z,file:Q}=$;return q.set(z,Q),Q}if($.__pulse==="formdata"){let{__id:z,fields:Q}=$,X=new FormData;q.set(z,X);for(let[F,U]of Object.entries(Q))if(Array.isArray(U))for(let P of U){let D=Z(P);X.append(F,D)}else{let P=Z(U);X.append(F,P)}return X}if($.__pulse==="array"){let z=$.__id,Q=[];q.set(z,Q);let X=$.items;for(let F=0;F<X.length;F++)Q[F]=Z(X[F]);return Q}if($.__pulse==="object"){let z=$.__id,Q={};q.set(z,Q);let X=$.__data;for(let[F,U]of Object.entries(X))Q[F]=Z(U);return Q}let G={};for(let[z,Q]of Object.entries($))G[z]=Z(Q);return G};return Z(W)}export{U1 as usePulseClient,fZ as stringify,IZ as parse,FZ as extractServerRouteInfo,i as extractEvent,PZ as encodeForWire,RZ as decodeFromWire,AZ as cleanForSerialization,u as applyReactTreeUpdates,M as VDOMRenderer,P1 as SocketIOTransport,C1 as RenderLazy,XZ as PulseView,h as PulseSocketIOClient,JZ as PulseProvider};
2
2
 
3
- //# debugId=E18861139DDB9F6B64756E2164756E21
3
+ //# debugId=9693F40BB63A52DC64756E2164756E21