pulse-ui-client 0.0.15 → 0.1.26

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.d.ts CHANGED
@@ -16,4 +16,4 @@ export { extractServerRouteInfo } from "./helpers";
16
16
  export type { RouteInfo } from "./helpers";
17
17
  export { extractEvent } from "./serialize/events";
18
18
  export { encodeForWire, decodeFromWire, cleanForSerialization, } from "./serialize/clean";
19
- export { serialize as serialize, deserialize as deserialize, } from "./serialize/v3";
19
+ export { serialize as serialize, deserialize as deserialize, } from "./serialize/serializer";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{useEffect as p,useState as a,useMemo as t,createContext as NW,useContext as RW}from"react";import BW,{cloneElement as w,createElement as JW,isValidElement as KW,lazy as wW,Suspense as HW}from"react";var QW="$$fragment",qW="$$";function zW(W){return typeof W==="object"&&W!==null}function FW(W){return typeof W==="object"&&W!==null&&W.tag.startsWith("$$")&&W.tag!=="$$fragment"}import{jsx as d,Fragment as LW}from"react/jsx-runtime";class x{client;path;components;cssModules;callbackCache;callbackProps;renderPropKeys;cssProps;constructor(W,Z,$,Q,q=[],z=[],G=[]){this.client=W;this.path=Z;this.components=$;this.cssModules=Q;this.callbackCache=new Map,this.callbackProps=new Map,this.renderPropKeys=new Set(z),this.cssProps=new Set(G),this.setCallbacks(q)}setCallbacks(W){this.callbackProps.clear(),this.callbackCache.clear();for(let Z of W){let[$,Q]=this.splitPropPath(Z);if(!this.callbackProps.has($))this.callbackProps.set($,new Set);this.callbackProps.get($).add(Q)}}applyCallbackDelta(W,Z){let $=new Map,Q=(z)=>{if(!$.has(z))$.set(z,new Set(this.callbackProps.get(z)??[]))};if(W.remove)for(let z of W.remove){let[G,F]=this.splitPropPath(z);Q(G);let J=this.callbackProps.get(G);if(!J){this.callbackCache.delete(z);continue}if(this.callbackCache.delete(z),J.delete(F),J.size===0)this.callbackProps.delete(G)}if(W.add)for(let z of W.add){let[G,F]=this.splitPropPath(z);if(Q(G),!this.callbackProps.has(G))this.callbackProps.set(G,new Set);this.callbackProps.get(G).add(F)}let q=Z;for(let[z,G]of $.entries()){let F=new Set(this.callbackProps.get(z)??[]);if(this.setsEqual(G,F))continue;let J=z?z.split(".").filter((X)=>X.length>0):[];q=this.updateCallbacksOnTree(q,J,0,"",G,F)}return q}setRenderProps(W){this.renderPropKeys=new Set(W)}setCssRefs(W){this.cssProps=new Set(W)}applyRenderPropsDelta(W){if(W.remove)for(let Z of W.remove)this.renderPropKeys.delete(Z);if(W.add)for(let Z of W.add)this.renderPropKeys.add(Z)}applyCssRefsDelta(W){if(W.set)for(let Z of W.set)this.cssProps.add(Z);if(W.remove)for(let Z of W.remove)this.cssProps.delete(Z)}getCallback(W,Z){let $=this.propPath(W,Z),Q=this.callbackCache.get($);if(!Q)Q=(...q)=>this.client.invokeCallback(this.path,$,q),this.callbackCache.set($,Q);return Q}renderNode(W,Z=""){if(W==null||typeof W==="boolean"||typeof W==="number"||typeof W==="string")return W;if(zW(W)){let{tag:$,props:Q={},children:q=[]}=W,z={...Q};for(let F of this.getCallbackNames(Z))z[F]=this.getCallback(Z,F);for(let[F,J]of Object.entries(z)){let X=this.propPath(Z,F);if(this.cssProps.has(X))z[F]=this.resolveCssToken(J);if(this.renderPropKeys.has(X))z[F]=this.renderNode(J,X)}if(W.key)z.key=W.key;let G=[];for(let F=0;F<q.length;F+=1){let J=q[F],X=Z?`${Z}.${F}`:String(F);G.push(this.renderNode(J,X))}if(FW(W)){let F=W.tag.slice(qW.length),J=this.components[F];if(!J)throw Error(`Could not find component ${F}. This is a Pulse internal error.`);return JW(J,z,...G)}return JW($===QW?BW.Fragment:$,z,...G)}return null}splitPropPath(W){let Z=W.lastIndexOf(".");if(Z===-1)return["",W];return[W.slice(0,Z),W.slice(Z+1)]}propPath(W,Z){return W?`${W}.${Z}`:Z}getCallbackNames(W){let Z=this.callbackProps.get(W);return Z?Array.from(Z):[]}transformValue(W,Z,$){let Q=this.callbackProps.get(W),q=this.propPath(W,Z);if(Q&&Q.size>0&&Q.has(Z))return this.getCallback(W,Z);if(this.renderPropKeys.has(q))return this.renderNode($,q);if(this.cssProps.has(q))return this.resolveCssToken($);return $}resolveCssToken(W){let Z=W.indexOf(":");if(Z===-1)return W;let $=W.slice(0,Z),Q=W.slice(Z+1);if(!$||!Q)return W;let q=this.cssModules[$];if(!q)throw Error(`Received CSS reference for unknown module '${$}'`);let z=q[Q];if(typeof z!=="string")throw Error(`Received CSS reference for missing class '${Q}' in module '${$}'`);return z}updateCallbacksOnTree(W,Z,$,Q,q,z){if($<Z.length){M(W,Z,$);let D=W,O=Z[$],C=Number(O),V=Q?`${Q}.${O}`:O;if(!Number.isNaN(C)){let A=k(D),N=A[C],R=this.updateCallbacksOnTree(N,Z,$+1,V,q,z);if(R===N)return W;return A[C]=R,w(D,void 0,...A)}else{let A=D.props??{},N=A[O],R=this.updateCallbacksOnTree(N,Z,$+1,V,q,z);if(R===N)return W;return w(D,{...A,[O]:R})}}if(!KW(W))return W;let G=W,F=G.props??{},J=!1,X={...F};for(let D of q)if(!z.has(D)&&D in X)delete X[D],J=!0;for(let D of z){let O=this.getCallback(Q,D);if(X[D]!==O)X[D]=O,J=!0}if(!J)return W;return w(G,X)}setsEqual(W,Z){if(W.size!==Z.size)return!1;for(let $ of W)if(!Z.has($))return!1;return!0}}function k(W){let Z=W.props?.children;if(Z==null)return[];return Array.isArray(Z)?Z.slice():[Z]}function n(W,Z,$){let Q=W;for(let q of Z){if(q.type==="update_callbacks"){Q=$.applyCallbackDelta(q.data,Q);continue}if(q.type==="update_css_refs"){$.applyCssRefsDelta(q.data);continue}if(q.type==="update_render_props"){$.applyRenderPropsDelta(q.data);continue}let z=q.path.split(".").filter((F)=>F.length>0),G=(F,J,X)=>{if(J<z.length){M(F,z,J);let D=F,O=z[J],C=+O,V=X?`${X}.${O}`:O;if(!Number.isNaN(C)){let A=k(D),N=A[C];return A[C]=G(N,J+1,V),w(D,void 0,...A)}else{let A=D.props??{},N=A[O],R={...A,[O]:G(N,J+1,V)};return w(D,R)}}switch(q.type){case"replace":return $.renderNode(q.data,q.path);case"update_props":{M(F,z,J);let D=F,C={...D.props??{}},V=q.data;if(V.remove&&V.remove.length>0){for(let A of V.remove)if(A in C)delete C[A]}if(V.set)for(let[A,N]of Object.entries(V.set))C[A]=$.transformValue(X,A,N);return w(D,C)}case"insert":{M(F,z,J);let D=F,O=k(D),C=X?`${X}.${q.idx}`:String(q.idx);return O.splice(q.idx,0,$.renderNode(q.data,C)),w(D,null,...O)}case"remove":{M(F,z,J);let D=F,O=k(D);return O.splice(q.idx,1),w(D,null,...O)}case"move":{M(F,z,J);let D=F,O=k(D),C=O.splice(q.data.from_index,1)[0];return O.splice(q.data.to_index,0,C),w(D,null,...O)}default:throw Error(`[Pulse renderer] Unknown update type: ${q.type}`)}};Q=G(Q,0,"")}return Q}function YW(W,Z){let $=wW(W);return({children:Q,...q})=>{return d(HW,{fallback:Z??d(LW,{}),children:d($,{...q,children:Q})})}}function M(W,Z,$){return!0}function H(){function W(Z,$){return(Q)=>{let q={};for(let z of Z)q[z]=Q[z];if($)for(let z in $){let G=$[z];q[z]=G(Q)}return q}}return W}var MW=(W)=>W.tagName.toLowerCase(),bW=["id","className","tagName","localName","clientHeight","clientLeft","clientTop","clientWidth","scrollHeight","scrollLeft","scrollTop","scrollWidth","slot"],SW=["autofocus","tabIndex","nonce"],yW=["accessKey","accessKeyLabel","autocapitalize","dir","draggable","hidden","inert","lang","offsetHeight","offsetLeft","offsetTop","offsetWidth","popover","spellcheck","title","translate","writingSuggestions","contentEditable","enterKeyHint","isContentEditable","inputMode"],kW=H()(bW,{tagName:MW}),_W=H()(SW),TW=H()(yW);function Y(W){return{...kW(W),..._W(W),...TW(W)}}function U(W,Z){let $=H()(W,Z);return(Q)=>({...Y(Q),...$(Q)})}var gW=["hash","host","hostname","href","origin","password","pathname","port","protocol","search","target","download","rel","hreflang","type","username","ping","referrerPolicy","text"],xW=U(gW),vW=["alt","coords","download","hash","host","hostname","href","origin","password","pathname","port","protocol","rel","search","shape","target","username","ping","referrerPolicy"],mW=U(vW),hW=["autoplay","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","loop","muted","networkState","paused","playbackRate","preload","readyState","seeking","src","volume","preservesPitch"],DW=U(hW),EW=(W)=>DW(W),uW=["disabled","name","type","value","formAction","formEnctype","formMethod","formNoValidate","formTarget","popoverTargetAction"],pW=U(uW),iW=["value"],cW=U(iW),dW=["height","src","type","width","align","name"],nW=U(dW),oW=["disabled","name","type","validationMessage","willValidate"],lW=U(oW),sW=["acceptCharset","action","autocomplete","encoding","enctype","length","method","name","noValidate","target","rel"],rW=U(sW),aW=["allow","allowFullscreen","height","name","referrerPolicy","src","srcdoc","width","align","frameBorder","longDesc","marginHeight","marginWidth","scrolling","sandbox"],tW=U(aW),eW=["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"],W1=U(eW),Z1=["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"],$1=U(Z1),Q1=["htmlFor"],q1=U(Q1),z1=["value","type"],F1=U(z1),J1=["as","crossOrigin","disabled","fetchPriority","href","hreflang","imageSizes","imageSrcset","integrity","media","referrerPolicy","rel","type","charset","rev","target","sizes"],X1=U(J1),G1=["name"],U1=U(G1),V1=["high","low","max","min","optimum","value"],D1=U(V1),O1=["cite","dateTime"],XW=U(O1),A1=["reversed","start","type","compact"],C1=U(A1),N1=["data","height","name","type","useMap","width","validationMessage","willValidate","align","archive","border","code","codeBase","codeType","declare","hspace","standby","vspace"],R1=U(N1),f1=["disabled","label"],I1=U(f1),P1=["defaultSelected","disabled","index","label","selected","text","value"],j1=U(P1),B1=["defaultValue","name","type","value","htmlFor","validationMessage","willValidate"],K1=U(B1),w1=["max","position","value"],H1=U(w1),Y1=["cite"],GW=U(Y1),L1=(W)=>Y(W),M1=["async","crossOrigin","defer","fetchPriority","integrity","noModule","referrerPolicy","src","text","type","charset"],b1=H()(M1,{event:(W)=>W.event,htmlFor:(W)=>W.htmlFor}),S1=(W)=>({...Y(W),...b1(W)}),y1=["autocomplete","disabled","length","multiple","name","required","selectedIndex","size","type","value","validationMessage","willValidate"],k1=U(y1),_1=["name"],T1=U(_1),g1=["height","media","sizes","src","srcset","type","width"],x1=U(g1),v1=["align"],m1=U(v1),h1=["abbr","cellIndex","colSpan","headers","rowSpan","scope","align","axis","bgColor","ch","chOff","height","noWrap","vAlign","width"],UW=U(h1),E1=["span","align","ch","chOff","vAlign","width"],VW=U(E1),u1=["align","bgColor","border","cellPadding","cellSpacing","frame","rules","summary","width"],p1=U(u1),i1=["rowIndex","sectionRowIndex","align","bgColor","ch","chOff","vAlign"],c1=U(i1),d1=["align","ch","chOff","vAlign"],o=U(d1),n1=(W)=>Y(W),o1=["autocomplete","cols","defaultValue","dirName","disabled","maxLength","minLength","name","placeholder","readOnly","required","rows","selectionDirection","selectionEnd","selectionStart","value","wrap","textLength","validationMessage","willValidate"],l1=U(o1),s1=["dateTime"],r1=U(s1),a1=["default","kind","label","readyState","src","srclang"],t1=U(a1),e1=["height","poster","videoHeight","videoWidth","width","playsInline"],W3=H()(e1),Z3=(W)=>({...DW(W),...W3(W)}),$3=["clear"],Q3=U($3),q3=["href","target"],z3=U(q3),F3=["aLink","background","bgColor","link","text","vLink"],J3=U(F3),X3=["compact"],G3=U(X3),U3=["open"],V3=U(U3),D3=["open","returnValue"],O3=U(D3),A3=["align"],C3=U(A3),N3=(W)=>Y(W),R3=["align"],b=U(R3),f3=["align","color","noShade","size","width"],I3=U(f3),P3=["version"],j3=U(P3),B3=(W)=>Y(W),K3=["content","httpEquiv","name","scheme"],w3=U(K3),H3=["align"],Y3=U(H3),L3=(W)=>Y(W),M3=["width"],b3=U(M3),S3=(W)=>Y(W),y3=["media","type","disabled"],k3=U(y3),_3=["text"],T3=U(_3),g3=["compact","type"],x3=U(g3),v3={A:xW,AREA:mW,AUDIO:EW,BASE:z3,BLOCKQUOTE:GW,Q:GW,BODY:J3,BR:Q3,BUTTON:pW,CANVAS:Y,CAPTION:m1,CITE:L1,COL:VW,COLGROUP:VW,DATA:cW,DETAILS:V3,DIALOG:O3,DIV:C3,DL:G3,EMBED:nW,FIELDSET:lW,FORM:rW,H1:b,H2:b,H3:b,H4:b,H5:b,H6:b,HEAD:N3,HR:I3,HTML:j3,IFRAME:tW,IMG:W1,INPUT:$1,LABEL:q1,LI:F1,LINK:X1,MAP:U1,MENU:B3,META:w3,METER:D1,INS:XW,DEL:XW,OBJECT:R1,OL:C1,OPTGROUP:I1,OPTION:j1,OUTPUT:K1,P:Y3,PICTURE:L3,PRE:b3,PROGRESS:H1,SCRIPT:S1,SELECT:k1,SLOT:T1,SOURCE:x1,SPAN:S3,STYLE:k3,TABLE:p1,TBODY:o,THEAD:o,TFOOT:o,TD:UW,TH:UW,TEMPLATE:n1,TEXTAREA:l1,TIME:r1,TITLE:T3,TR:c1,TRACK:t1,UL:x3,VIDEO:Z3};function v(W){let Z=W.tagName.toUpperCase(),$=v3[Z];if($)return $(W);throw Error(`Unexpected HTML element tag: ${W.tagName} (update .web/custom/serialize.ts)`)}var m3=(W)=>v(W.target),_=(W)=>W.relatedTarget?v(W.relatedTarget):null;function I(W,Z){return H()(W,{target:m3,...Z||{}})}var K=["target","bubbles","cancelable","defaultPrevented","eventPhase","isTrusted","timeStamp","type"],m=[...K,"detail"],h=[...m,"altKey","button","buttons","clientX","clientY","ctrlKey","metaKey","movementX","movementY","pageX","pageY","screenX","screenY","shiftKey"],h3=[...h,"pointerId","pressure","tangentialPressure","tiltX","tiltY","twist","width","height","pointerType","isPrimary"],E3=I(K),u3=I(m),p3=I(h,{relatedTarget:_}),i3=I(K,{clipboardData:(W)=>OW(W.clipboardData)}),c3=I([...K,"data"]),d3=I(h,{relatedTarget:_,dataTransfer:(W)=>OW(W.dataTransfer)}),n3=I(h3,{relatedTarget:_}),o3=I(K,{relatedTarget:_}),l3=I(K),s3=I(K),r3=I(K),a3=I([...m,"altKey","ctrlKey","code","key","locale","location","metaKey","repeat","shiftKey"]),t3=I([...m,"altKey","ctrlKey","metaKey","shiftKey","changedTouches","targetTouches","touches"],{changedTouches:(W)=>l(W.changedTouches),targetTouches:(W)=>l(W.targetTouches),touches:(W)=>l(W.touches)}),e3=I([...h,"deltaMode","deltaX","deltaY","deltaZ"],{relatedTarget:_}),WZ=I([...K,"animationName","elapsedTime","pseudoElement"]),ZZ=I([...K,"oldState","newState"]),$Z=I([...K,"elapsedTime","propertyName","pseudoElement"]);function l(W){return Array.from(W).map((Z)=>({target:v(Z.target),identifier:Z.identifier,screenX:Z.screenX,screenY:Z.screenY,clientX:Z.clientX,clientY:Z.clientY,pageX:Z.pageX,pageY:Z.pageY}))}function OW(W){if(!W)return null;let Z=[];if(W.items)for(let $=0;$<W.items.length;$++){let Q=W.items[$];Z.push({kind:Q.kind,type:Q.type})}return{drop_effect:W.dropEffect,effect_allowed:W.effectAllowed,items:Z,types:Array.from(W.types||[])}}var P={};function j(W,Z,$){for(let Q of Z)W[Q]=$}j(P,["pointerdown","pointermove","pointerup","pointercancel","gotpointercapture","lostpointercapture","pointerenter","pointerleave","pointerover","pointerout"],n3);j(P,["click","contextmenu","dblclick","mousedown","mouseenter","mouseleave","mousemove","mouseout","mouseover","mouseup"],p3);j(P,["drag","dragend","dragenter","dragexit","dragleave","dragover","dragstart","drop"],d3);j(P,["keydown","keypress","keyup"],a3);j(P,["focus","blur"],o3);j(P,["change","input"],r3);j(P,["invalid"],s3);j(P,["reset","submit"],l3);j(P,["copy","cut","paste"],i3);j(P,["compositionend","compositionstart","compositionupdate"],c3);j(P,["touchcancel","touchend","touchmove","touchstart"],t3);j(P,["scroll"],u3);j(P,["wheel"],e3);j(P,["animationstart","animationend","animationiteration"],WZ);j(P,["transitionend"],$Z);j(P,["toggle"],ZZ);function s(W){if(W&&typeof W==="object"&&"nativeEvent"in W&&typeof W.isDefaultPrevented==="function"){let Z=W;if(typeof Z.type!=="string")return W;let $=P[Z.type.toLowerCase()];if($)return $(Z);return E3(Z)}return W}function T(W){let Z=new Map,$=[],Q=[],q=[],z=[],G=0;function F(X){if(X==null||typeof X==="number"||typeof X==="string"||typeof X==="boolean")return X;let D=G++,O=Z.get(X);if(O!==void 0)return $.push(D),O;if(Z.set(X,D),X instanceof Date)return Q.push(D),X.getTime();if(Array.isArray(X)){let C=X.length,V=Array(C);for(let A=0;A<C;A++)V[A]=F(X[A]);return V}if(X instanceof Map){z.push(D);let C={};for(let[V,A]of X.entries())C[String(V)]=F(A);return C}if(X instanceof Set){q.push(D);let C=X.size,V=Array(C),A=0;for(let N of X)V[A]=F(N),A+=1;return V}if(typeof X==="object"){let C={},V=Object.keys(X);for(let A=0;A<V.length;A++){let N=V[A];C[N]=F(X[N])}return C}throw Error(`Unsupported value in serialization: ${X}`)}let J=F(W);return[[$,Q,q,z],J]}function r(W,Z){let[[$,Q,q,z],G]=W,F=new Set($),J=new Set(Q),X=new Set(q),D=new Set(z),O=[];function C(V){let A=O.length;if(F.has(A))return O.push(null),O[V];if(J.has(A)){let N=new Date(V);return O.push(N),N}if(V==null||typeof V==="number"||typeof V==="string"||typeof V==="boolean"){if(Z?.coerceNullsToUndefined)return V??void 0;return V}if(Array.isArray(V)){if(X.has(A)){let f=new Set;O.push(f);for(let B=0;B<V.length;B++)f.add(C(V[B]));return f}let N=V.length,R=Array(N);O.push(R);for(let f=0;f<N;f++)R[f]=C(V[f]);return R}if(typeof V==="object"){if(D.has(A)){let f=new Map;O.push(f);let B=Object.keys(V);for(let c=0;c<B.length;c++){let $W=B[c];f.set($W,C(V[$W]))}return f}let N={};O.push(N);let R=Object.keys(V);for(let f=0;f<R.length;f++){let B=R[f];N[B]=C(V[B])}return N}throw Error(`Unsupported value in deserialization: ${V}`)}return C(G)}import{io as JZ}from"socket.io-client";class L extends Error{constructor(W){super(W);this.name="PulseChannelResetError"}}function QZ(){if(typeof crypto<"u"&&typeof crypto.randomUUID==="function")return crypto.randomUUID().replace(/-/g,"");return Math.random().toString(16).slice(2)+Math.random().toString(16).slice(2)}function qZ(W){if(W instanceof Error)return W.message;if(typeof W==="string")return W;try{return JSON.stringify(W)}catch{return String(W)}}function zZ(W){return typeof W.responseTo==="string"}function FZ(W){return typeof W.event==="string"}class AW{client;id;handlers=new Map;pending=new Map;backlog=[];closed=!1;constructor(W,Z){this.client=W;this.id=Z}emit(W,Z){this.ensureOpen(),this.client.sendChannelMessage({type:"channel_message",channel:this.id,event:W,payload:Z})}async request(W,Z){this.ensureOpen();let $=QZ();return new Promise((Q,q)=>{this.pending.set($,{resolve:Q,reject:q}),this.client.sendChannelMessage({type:"channel_message",channel:this.id,event:W,payload:Z,requestId:$}).catch((z)=>{this.pending.delete($),q(z)})})}on(W,Z){this.ensureOpen();let $=this.handlers.get(W);if(!$)$=new Set,this.handlers.set(W,$);return $.add(Z),this.flushBacklog(W),()=>{let Q=this.handlers.get(W);if(!Q)return;if(Q.delete(Z),Q.size===0)this.handlers.delete(W)}}handleServerMessage(W){if(zZ(W))return this.resolvePending(W),this.closed;if(this.closed)return!0;if(!FZ(W))return this.closed;if(W.event==="__close__")return this.close(new L("Channel closed by server")),!0;if(W.requestId)this.dispatchRequest(W);else this.dispatchEvent(W);return this.closed}handleDisconnect(W){this.close(W)}dispose(W){this.close(W)}ensureOpen(){if(this.closed)throw new L("Channel is closed")}flushBacklog(W){if(this.backlog.length===0)return;let Z=[];for(let $ of this.backlog)if($.event===W)this.dispatchEvent($);else Z.push($);this.backlog=Z}dispatchEvent(W){let Z=this.handlers.get(W.event);if(!Z||Z.size===0){this.backlog.push(W);return}for(let $ of Z)try{let Q=$(W.payload);if(Q&&typeof Q.then==="function")Q.catch((q)=>{console.error("Pulse channel handler error",q)})}catch(Q){console.error("Pulse channel handler error",Q)}}async dispatchRequest(W){let Z=this.handlers.get(W.event),$,Q;if(Z&&Z.size>0)for(let q of Z)try{let z=q(W.payload);if($=await Promise.resolve(z),$!==void 0)break}catch(z){Q=z;break}if(Q){await this.client.sendChannelMessage({type:"channel_message",channel:this.id,event:void 0,responseTo:W.requestId,error:qZ(Q)});return}await this.client.sendChannelMessage({type:"channel_message",channel:this.id,event:void 0,responseTo:W.requestId,payload:$})}resolvePending(W){let Z=W.responseTo?this.pending.get(W.responseTo):void 0;if(!Z)return;if(this.pending.delete(W.responseTo),W.error!==void 0&&W.error!==null)Z.reject(new L(String(W.error)));else Z.resolve(W.payload)}close(W){if(this.closed)return;this.closed=!0;for(let Z of this.pending.values())Z.reject(W);this.pending.clear(),this.handlers.clear(),this.backlog=[]}}function CW(W,Z){return new AW(W,Z)}class E{url;renderId;frameworkNavigate;activeViews;socket=null;messageQueue;connectionListeners=new Set;serverErrors=new Map;serverErrorListeners=new Set;channels=new Map;constructor(W,Z,$){this.url=W;this.renderId=Z;this.frameworkNavigate=$;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,Z)=>{let $=JZ(this.url,{transports:["websocket","webtransport"],auth:{renderId:this.renderId}});this.socket=$,$.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let[Q,q]of this.activeViews)$.emit("message",T({type:"mount",path:Q,routeInfo:q.routeInfo}));for(let Q of this.messageQueue){if(Q.type==="mount"&&this.activeViews.has(Q.path))continue;if(Q.type==="navigate")continue;$.emit("message",T(Q))}this.messageQueue=[],this.notifyConnectionListeners(!0),W()}),$.on("connect_error",(Q)=>{console.error("[SocketIOTransport] Connection failed:",Q),this.notifyConnectionListeners(!1),Z(Q)}),$.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.handleTransportDisconnect(),this.notifyConnectionListeners(!1)}),$.on("message",(Q)=>this.handleServerMessage(r(Q,{coerceNullsToUndefined:!0})))})}onConnectionChange(W){return this.connectionListeners.add(W),W(this.isConnected()),()=>{this.connectionListeners.delete(W)}}notifyConnectionListeners(W){for(let Z of this.connectionListeners)Z(W)}onServerError(W){this.serverErrorListeners.add(W);for(let[Z,$]of this.serverErrors)W(Z,$);return()=>{this.serverErrorListeners.delete(W)}}notifyServerError(W,Z){for(let $ of this.serverErrorListeners)$(W,Z)}async sendMessage(W){if(this.isConnected())this.socket.emit("message",T(W));else this.messageQueue.push(W)}async sendChannelMessage(W){await this.sendMessage(W)}mountView(W,Z){if(this.activeViews.has(W))throw Error(`Path ${W} is already mounted`);this.activeViews.set(W,Z),this.sendMessage({type:"mount",path:W,routeInfo:Z.routeInfo})}async navigate(W,Z){await this.sendMessage({type:"navigate",path:W,routeInfo:Z})}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();for(let{bridge:W}of this.channels.values())W.dispose(new L("Client disconnected"));this.channels.clear()}handleServerMessage(W){switch(W.type){case"vdom_init":{let Z=this.activeViews.get(W.path);if(!Z)return;if(Z)Z.onInit(W.vdom,W.callbacks,W.render_props,W.css_refs);if(this.serverErrors.has(W.path))this.serverErrors.delete(W.path),this.notifyServerError(W.path,null);break}case"vdom_update":{let Z=this.activeViews.get(W.path);if(!Z)return;if(Z.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 Z=!!W.replace,$=W.path||"";if($.startsWith("//"))$=`${window.location.protocol}${$}`;if(/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test($))if($.startsWith("http://")||$.startsWith("https://"))try{let q=new URL($);if(q.origin===window.location.origin){let z=`${q.pathname}${q.search}${q.hash}`;this.frameworkNavigate(z,{replace:Z})}else if(Z)window.location.replace($);else window.location.assign($)}catch{if(Z)window.location.replace($);else window.location.assign($)}else if(Z)window.location.replace($);else window.location.assign($);else this.frameworkNavigate($,{replace:Z});break}case"channel_message":{this.routeChannelMessage(W);break}default:console.error("Unexpected message:",W)}}async performApiCall(W){try{let Z=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.headers.forEach((G,F)=>$[F]=G);let Q=null;if((Z.headers.get("content-type")||"").includes("application/json"))Q=await Z.json().catch(()=>null);else Q=await Z.text().catch(()=>null);let z={type:"api_result",id:W.id,ok:Z.ok,status:Z.status,headers:$,body:Q};await this.sendMessage(z)}catch(Z){let $={type:"api_result",id:W.id,ok:!1,status:0,headers:{},body:{error:String(Z)}};await this.sendMessage($)}}async invokeCallback(W,Z,$){await this.sendMessage({type:"callback",path:W,callback:Z,args:$.map(s)})}acquireChannel(W){let Z=this.ensureChannelEntry(W);return Z.refCount+=1,Z.bridge}releaseChannel(W){let Z=this.channels.get(W);if(!Z)return;if(Z.refCount=Math.max(0,Z.refCount-1),Z.refCount===0)Z.bridge.dispose(new L("Channel released")),this.channels.delete(W)}ensureChannelEntry(W){let Z=this.channels.get(W);if(!Z)Z={bridge:CW(this,W),refCount:0},this.channels.set(W,Z);return Z}routeChannelMessage(W){let Z=this.ensureChannelEntry(W.channel);if(Z.bridge.handleServerMessage(W)&&Z.refCount===0)this.channels.delete(W.channel)}handleTransportDisconnect(){for(let W of this.channels.values())W.bridge.handleDisconnect(new L("Connection lost"))}}import{useLocation as XZ,useParams as GZ,useNavigate as UZ}from"react-router";import{jsx as S,jsxs as u}from"react/jsx-runtime";var fW=NW(null),IW=NW(null),i=()=>{let W=RW(fW);if(!W)throw Error("usePulseClient must be used within a PulseProvider");return W},VZ=(W)=>{let Z=RW(IW);if(!Z)throw Error("usePulsePrerender must be used within a PulseProvider");let $=Z.views[W];if(!$)throw Error(`No prerender found for '${W}'`);return $},e=typeof window<"u";function DZ({children:W,config:Z,prerender:$}){let[Q,q]=a(!0),z=UZ(),{renderId:G}=$,F=t(()=>new E(Z.serverAddress,G,z),[Z.serverAddress,z,G]);return p(()=>F.onConnectionChange(q),[F]),p(()=>{if(e)return F.connect(),()=>F.disconnect()},[F]),S(fW.Provider,{value:F,children:u(IW.Provider,{value:$,children:[!Q&&S("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 OZ({externalComponents:W,path:Z,cssModules:$}){let Q=i(),q=VZ(Z),z=q.vdom,G=t(()=>new x(Q,Z,W,$,q.callbacks,q.render_props,q.css_refs),[Q,Z,W,$,q]),[F,J]=a(()=>G.renderNode(z)),[X,D]=a(null),O=XZ(),C=GZ(),V=t(()=>{let{"*":A="",...N}=C,R=new URLSearchParams(O.search);return{hash:O.hash,pathname:O.pathname,query:O.search,queryParams:Object.fromEntries(R.entries()),pathParams:N,catchall:A.length>0?A.split("/"):[]}},[O.hash,O.pathname,O.search,JSON.stringify(C)]);if(p(()=>{if(e){Q.mountView(Z,{routeInfo:V,onInit:(N,R,f,B)=>{G.setCallbacks(R),G.setRenderProps(f),G.setCssRefs(B),J(G.renderNode(N))},onUpdate:(N)=>{J((R)=>R==null?R:n(R,N,G))}});let A=Q.onServerError((N,R)=>{if(N===Z)D(R)});return()=>{A(),Q.unmount(Z)}}},[Q]),p(()=>{if(e)Q.navigate(Z,V)},[Q,Z,V]),X)return S(AZ,{error:X});return F}function AZ({error:W}){return u("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:[u("div",{style:{fontWeight:700,marginBottom:8},children:["Server Error during ",W.phase]}),W.message&&S("div",{children:W.message}),W.stack&&u("details",{open:!0,style:{marginTop:8},children:[S("summary",{children:"Stack trace"}),S("pre",{style:{margin:0},children:W.stack})]})]})}import{useEffect as CZ,useMemo as NZ}from"react";function RZ(W){let Z=i(),$=NZ(()=>{if(!W)throw Error("usePulseChannel requires a non-empty channelId");return Z.acquireChannel(W)},[Z,W]);return CZ(()=>{return()=>{Z.releaseChannel(W)}},[Z,W]),$}import{forwardRef as fZ,useCallback as IZ}from"react";import{jsx as jZ}from"react/jsx-runtime";var PZ=fZ(function({onSubmit:Z,action:$,...Q},q){return jZ("form",{...Q,action:$,ref:q,onSubmit:IZ((z)=>PW({event:z,action:$,onSubmit:Z}),[$,Z])})});async function PW({event:W,action:Z,onSubmit:$,formData:Q,force:q}){if($?.(W),!q&&W.defaultPrevented)return;let z=W.currentTarget;W.preventDefault();let G=W.nativeEvent;if(!Q)Q=new FormData(z,G.submitter);let F=new URL(Z,window.location.href);try{await fetch(F,{method:"POST",credentials:"include",body:Q})}catch(J){throw J}}import{io as BZ}from"socket.io-client";class jW{url;socket=null;listener=null;messageQueue=[];connectionListeners=new Set;constructor(W){this.url=W}connect(W){return this.listener=W,new Promise((Z,$)=>{this.socket=BZ(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),Z()}),this.socket.on("connect_error",(Q)=>{console.error("[SocketIOTransport] Connection failed:",Q),this.notifyConnectionListeners(!1),$(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 Z of this.connectionListeners)Z(W)}}function KZ({params:W,request:Z}){let{"*":$="",...Q}=W,q=new URL(Z.url);return{hash:q.hash,pathname:q.pathname,query:q.search,queryParams:Object.fromEntries(q.searchParams.entries()),pathParams:Q,catchall:$.length>1?$.split("/"):[]}}function wZ(W){if(W===null||typeof W!=="object")return!1;let Z=Object.getPrototypeOf(W);return Z===Object.prototype||Z===null}function WW(W){return typeof W==="function"||typeof W==="symbol"||typeof W>"u"}async function HZ(W){let Z=await W.arrayBuffer();return Array.from(new Uint8Array(Z))}async function YZ(W){return await g(W,{seen:new WeakMap,nextId:1})}function LZ(W,Z){if(W.seen.get(Z)!==void 0)return null;let Q=W.nextId++;return W.seen.set(Z,Q),Q}async function g(W,Z){if(W===null||typeof W!=="object")return W;if(W instanceof Date)return{__t:"datetime",timestamp:W.getTime()};if(W instanceof FormData){let F=LZ(Z,W);if(F===null)return{__t:"ref",id:Z.seen.get(W)};let J={};for(let[D,O]of W.entries()){let C=await g(O,Z);if(C===void 0)continue;if(Object.prototype.hasOwnProperty.call(J,D)){let V=J[D];if(Array.isArray(V))V.push(C);else J[D]=[V,C]}else J[D]=C}return{__t:"formdata",fields:J,__id:F}}if(W instanceof File){let F=W,J=await HZ(W);return{__t:"file",name:F.name,type:F.type,size:F.size,lastModified:F.lastModified,content:J}}let $=W,Q=Z.seen.get($);if(Q!==void 0)return{__t:"ref",id:Q};let q=Z.nextId++;if(Z.seen.set($,q),Array.isArray(W)){let J=(await Promise.all(W.map((D)=>g(D,Z)))).filter((D)=>D!==void 0);return{__t:"array",__id:q,items:J}}let z={};if(wZ(W))for(let F of Object.keys(W)){let J=W[F];if(WW(J))continue;let X=await g(J,Z);if(X!==void 0)z[F]=X}else for(let F in W){let J=W[F];if(WW(J))continue;let X=await g(J,Z);if(X!==void 0)z[F]=X}return{__t:"object",__id:q,props:z}}function MZ(W){return y(W)}function y(W){if(W===null||typeof W!=="object")return W;let Z=W,$=Z.__t;if($==="datetime"){let q=Z.timestamp;return new Date(q)}if($==="file"){let q=Z.content;if(Array.isArray(q))return{...Z,content:new Uint8Array(q)};return Z}if($==="formdata"){let q=Z.fields,z={};for(let G of Object.keys(q)){let F=q[G];if(Array.isArray(F))z[G]=F.map((J)=>y(J));else z[G]=y(F)}return{__t:"formdata",fields:z}}if($==="array")return Z.items.map((z)=>y(z));if($==="object"){let q=Z.props,z={};for(let G of Object.keys(q))z[G]=y(q[G]);return z}if($==="ref")return Z;let Q={};for(let q of Object.keys(Z))Q[q]=y(Z[q]);return Q}function bZ(W){return ZW(W,new WeakSet)}function ZW(W,Z){if(W===null||typeof W!=="object")return W;if(Z.has(W))return;if(Z.add(W),Array.isArray(W))return W.map((Q)=>ZW(Q,Z)).filter((Q)=>Q!==void 0);let $={};for(let Q in W){let q=W[Q];if(WW(q))continue;let z=ZW(q,Z);if(z!==void 0)$[Q]=z}return $}export{i as usePulseClient,RZ as usePulseChannel,PW as submitForm,T as serialize,KZ as extractServerRouteInfo,s as extractEvent,YZ as encodeForWire,r as deserialize,MZ as decodeFromWire,bZ as cleanForSerialization,n as applyReactTreeUpdates,x as VDOMRenderer,jW as SocketIOTransport,YW as RenderLazy,OZ as PulseView,E as PulseSocketIOClient,DZ as PulseProvider,PZ as PulseForm,L as PulseChannelResetError};
1
+ import{useEffect as u,useState as a,useMemo as t,createContext as CW,useContext as RW}from"react";import BW,{cloneElement as K,createElement as XW,isValidElement as wW,lazy as KW,Suspense as HW}from"react";var QW="$$fragment",qW="$$";function FW(W){return typeof W==="object"&&W!==null}function JW(W){return typeof W==="object"&&W!==null&&W.tag.startsWith("$$")&&W.tag!=="$$fragment"}import{jsx as d,Fragment as LW}from"react/jsx-runtime";class x{client;path;components;cssModules;callbacks;callbackCache;renderPropKeys;cssProps;constructor(W,Z,$,Q,q=[],F=[],N=[]){this.client=W;this.path=Z;this.components=$;this.cssModules=Q;this.callbacks=new Set(q),this.callbackCache=new Map,this.renderPropKeys=new Set(F),this.cssProps=new Set(N),this.setCallbacks(q)}setCallbacks(W){this.callbacks=new Set(W)}setRenderProps(W){this.renderPropKeys=new Set(W)}setCssRefs(W){this.cssProps=new Set(W)}applyCallbackDelta(W){if(W.remove)for(let Z of W.remove)this.callbacks.delete(Z);if(W.add)for(let Z of W.add)this.callbacks.add(Z)}applyRenderPropsDelta(W){if(W.remove)for(let Z of W.remove)this.renderPropKeys.delete(Z);if(W.add)for(let Z of W.add)this.renderPropKeys.add(Z)}applyCssRefsDelta(W){if(W.set)for(let Z of W.set)this.cssProps.add(Z);if(W.remove)for(let Z of W.remove)this.cssProps.delete(Z)}getCallback(W,Z){let $=this.propPath(W,Z),Q=this.callbackCache.get($);if(!Q)Q=(...q)=>this.client.invokeCallback(this.path,$,q),this.callbackCache.set($,Q);return Q}renderNode(W,Z=""){if(W==null||typeof W==="boolean"||typeof W==="number"||typeof W==="string")return W;if(FW(W)){let{tag:$,props:Q={},children:q=[]}=W,F={};for(let[J,U]of Object.entries(Q))F[J]=this.transformValue(Z,J,U);if(W.key)F.key=W.key;let N=[];for(let J=0;J<q.length;J+=1){let U=q[J],G=Z?`${Z}.${J}`:String(J);N.push(this.renderNode(U,G))}if(JW(W)){let J=W.tag.slice(qW.length),U=this.components[J];if(!U)throw Error(`Could not find component ${J}. This is a Pulse internal error.`);return XW(U,F,...N)}return XW($===QW?BW.Fragment:$,F,...N)}return null}propPath(W,Z){return W?`${W}.${Z}`:Z}transformValue(W,Z,$){let Q=this.propPath(W,Z);if(this.callbacks.has(Q))return this.getCallback(W,Z);if(this.renderPropKeys.has(Q))return this.renderNode($,Q);if(this.cssProps.has(Q))return this.resolveCssToken($);return $}resolveCssToken(W){let Z=W.indexOf(":");if(Z===-1)return W;let $=W.slice(0,Z),Q=W.slice(Z+1);if(!$||!Q)return W;let q=this.cssModules[$];if(!q)throw Error(`Received CSS reference for unknown module '${$}'`);let F=q[Q];if(typeof F!=="string")throw Error(`Received CSS reference for missing class '${Q}' in module '${$}'`);return F}updateCallbacksOnTree(W,Z,$,Q,q,F){if($<Z.length){M(W,Z,$);let V=W,D=Z[$],A=Number(D),z=Q?`${Q}.${D}`:D;if(!Number.isNaN(A)){let O=S(V),C=O[A],R=this.updateCallbacksOnTree(C,Z,$+1,z,q,F);if(R===C)return W;return O[A]=R,K(V,void 0,...O)}else{let O=V.props??{},C=O[D],R=this.updateCallbacksOnTree(C,Z,$+1,z,q,F);if(R===C)return W;return K(V,{...O,[D]:R})}}if(!wW(W))return W;let N=W,J=N.props??{},U=!1,G={...J};for(let V of q)if(!F.has(V)&&V in G)delete G[V],U=!0;for(let V of F){let D=this.getCallback(Q,V);if(G[V]!==D)G[V]=D,U=!0}if(!U)return W;return K(N,G)}setsEqual(W,Z){if(W.size!==Z.size)return!1;for(let $ of W)if(!Z.has($))return!1;return!0}}function S(W){let Z=W.props?.children;if(Z==null)return[];return Array.isArray(Z)?Z.slice():[Z]}function n(W,Z,$){let Q=W;for(let q of Z){if(q.type==="update_callbacks"){$.applyCallbackDelta(q.data);continue}if(q.type==="update_css_refs"){$.applyCssRefsDelta(q.data);continue}if(q.type==="update_render_props"){$.applyRenderPropsDelta(q.data);continue}let F=q.path.split(".").filter((J)=>J.length>0),N=(J,U,G)=>{if(U<F.length){M(J,F,U);let V=J,D=F[U],A=+D,z=G?`${G}.${D}`:D;if(!Number.isNaN(A)){let O=S(V),C=O[A];return O[A]=N(C,U+1,z),K(V,void 0,...O)}else{let O=V.props??{},C=O[D],R={...O,[D]:N(C,U+1,z)};return K(V,R)}}switch(q.type){case"replace":return $.renderNode(q.data,q.path);case"update_props":{M(J,F,U);let V=J,A={...V.props??{}},z=q.data;if(z.remove&&z.remove.length>0){for(let O of z.remove)if(O in A)delete A[O]}if(z.set)for(let[O,C]of Object.entries(z.set))A[O]=$.transformValue(G,O,C);return K(V,A)}case"insert":{M(J,F,U);let V=J,D=S(V),A=G?`${G}.${q.idx}`:String(q.idx);return D.splice(q.idx,0,$.renderNode(q.data,A)),K(V,null,...D)}case"remove":{M(J,F,U);let V=J,D=S(V);return D.splice(q.idx,1),K(V,null,...D)}case"move":{M(J,F,U);let V=J,D=S(V),A=D.splice(q.data.from_index,1)[0];return D.splice(q.data.to_index,0,A),K(V,null,...D)}default:throw Error(`[Pulse renderer] Unknown update type: ${q.type}`)}};Q=N(Q,0,"")}return Q}function YW(W,Z){let $=KW(W);return({children:Q,...q})=>{return d(HW,{fallback:Z??d(LW,{}),children:d($,{...q,children:Q})})}}function M(W,Z,$){return!0}function H(){function W(Z,$){return(Q)=>{let q={};for(let F of Z)q[F]=Q[F];if($)for(let F in $){let N=$[F];q[F]=N(Q)}return q}}return W}var MW=(W)=>W.tagName.toLowerCase(),yW=["id","className","tagName","localName","clientHeight","clientLeft","clientTop","clientWidth","scrollHeight","scrollLeft","scrollTop","scrollWidth","slot"],bW=["autofocus","tabIndex","nonce"],kW=["accessKey","accessKeyLabel","autocapitalize","dir","draggable","hidden","inert","lang","offsetHeight","offsetLeft","offsetTop","offsetWidth","popover","spellcheck","title","translate","writingSuggestions","contentEditable","enterKeyHint","isContentEditable","inputMode"],SW=H()(yW,{tagName:MW}),TW=H()(bW),_W=H()(kW);function Y(W){return{...SW(W),...TW(W),..._W(W)}}function X(W,Z){let $=H()(W,Z);return(Q)=>({...Y(Q),...$(Q)})}var gW=["hash","host","hostname","href","origin","password","pathname","port","protocol","search","target","download","rel","hreflang","type","username","ping","referrerPolicy","text"],xW=X(gW),vW=["alt","coords","download","hash","host","hostname","href","origin","password","pathname","port","protocol","rel","search","shape","target","username","ping","referrerPolicy"],hW=X(vW),mW=["autoplay","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","loop","muted","networkState","paused","playbackRate","preload","readyState","seeking","src","volume","preservesPitch"],DW=X(mW),pW=(W)=>DW(W),EW=["disabled","name","type","value","formAction","formEnctype","formMethod","formNoValidate","formTarget","popoverTargetAction"],uW=X(EW),iW=["value"],cW=X(iW),dW=["height","src","type","width","align","name"],nW=X(dW),oW=["disabled","name","type","validationMessage","willValidate"],lW=X(oW),sW=["acceptCharset","action","autocomplete","encoding","enctype","length","method","name","noValidate","target","rel"],rW=X(sW),aW=["allow","allowFullscreen","height","name","referrerPolicy","src","srcdoc","width","align","frameBorder","longDesc","marginHeight","marginWidth","scrolling","sandbox"],tW=X(aW),eW=["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"],W1=X(eW),Z1=["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"],$1=X(Z1),Q1=["htmlFor"],q1=X(Q1),F1=["value","type"],J1=X(F1),X1=["as","crossOrigin","disabled","fetchPriority","href","hreflang","imageSizes","imageSrcset","integrity","media","referrerPolicy","rel","type","charset","rev","target","sizes"],z1=X(X1),G1=["name"],U1=X(G1),V1=["high","low","max","min","optimum","value"],D1=X(V1),O1=["cite","dateTime"],zW=X(O1),A1=["reversed","start","type","compact"],N1=X(A1),C1=["data","height","name","type","useMap","width","validationMessage","willValidate","align","archive","border","code","codeBase","codeType","declare","hspace","standby","vspace"],R1=X(C1),f1=["disabled","label"],P1=X(f1),I1=["defaultSelected","disabled","index","label","selected","text","value"],j1=X(I1),B1=["defaultValue","name","type","value","htmlFor","validationMessage","willValidate"],w1=X(B1),K1=["max","position","value"],H1=X(K1),Y1=["cite"],GW=X(Y1),L1=(W)=>Y(W),M1=["async","crossOrigin","defer","fetchPriority","integrity","noModule","referrerPolicy","src","text","type","charset"],y1=H()(M1,{event:(W)=>W.event,htmlFor:(W)=>W.htmlFor}),b1=(W)=>({...Y(W),...y1(W)}),k1=["autocomplete","disabled","length","multiple","name","required","selectedIndex","size","type","value","validationMessage","willValidate"],S1=X(k1),T1=["name"],_1=X(T1),g1=["height","media","sizes","src","srcset","type","width"],x1=X(g1),v1=["align"],h1=X(v1),m1=["abbr","cellIndex","colSpan","headers","rowSpan","scope","align","axis","bgColor","ch","chOff","height","noWrap","vAlign","width"],UW=X(m1),p1=["span","align","ch","chOff","vAlign","width"],VW=X(p1),E1=["align","bgColor","border","cellPadding","cellSpacing","frame","rules","summary","width"],u1=X(E1),i1=["rowIndex","sectionRowIndex","align","bgColor","ch","chOff","vAlign"],c1=X(i1),d1=["align","ch","chOff","vAlign"],o=X(d1),n1=(W)=>Y(W),o1=["autocomplete","cols","defaultValue","dirName","disabled","maxLength","minLength","name","placeholder","readOnly","required","rows","selectionDirection","selectionEnd","selectionStart","value","wrap","textLength","validationMessage","willValidate"],l1=X(o1),s1=["dateTime"],r1=X(s1),a1=["default","kind","label","readyState","src","srclang"],t1=X(a1),e1=["height","poster","videoHeight","videoWidth","width","playsInline"],WZ=H()(e1),ZZ=(W)=>({...DW(W),...WZ(W)}),$Z=["clear"],QZ=X($Z),qZ=["href","target"],FZ=X(qZ),JZ=["aLink","background","bgColor","link","text","vLink"],XZ=X(JZ),zZ=["compact"],GZ=X(zZ),UZ=["open"],VZ=X(UZ),DZ=["open","returnValue"],OZ=X(DZ),AZ=["align"],NZ=X(AZ),CZ=(W)=>Y(W),RZ=["align"],y=X(RZ),fZ=["align","color","noShade","size","width"],PZ=X(fZ),IZ=["version"],jZ=X(IZ),BZ=(W)=>Y(W),wZ=["content","httpEquiv","name","scheme"],KZ=X(wZ),HZ=["align"],YZ=X(HZ),LZ=(W)=>Y(W),MZ=["width"],yZ=X(MZ),bZ=(W)=>Y(W),kZ=["media","type","disabled"],SZ=X(kZ),TZ=["text"],_Z=X(TZ),gZ=["compact","type"],xZ=X(gZ),vZ={A:xW,AREA:hW,AUDIO:pW,BASE:FZ,BLOCKQUOTE:GW,Q:GW,BODY:XZ,BR:QZ,BUTTON:uW,CANVAS:Y,CAPTION:h1,CITE:L1,COL:VW,COLGROUP:VW,DATA:cW,DETAILS:VZ,DIALOG:OZ,DIV:NZ,DL:GZ,EMBED:nW,FIELDSET:lW,FORM:rW,H1:y,H2:y,H3:y,H4:y,H5:y,H6:y,HEAD:CZ,HR:PZ,HTML:jZ,IFRAME:tW,IMG:W1,INPUT:$1,LABEL:q1,LI:J1,LINK:z1,MAP:U1,MENU:BZ,META:KZ,METER:D1,INS:zW,DEL:zW,OBJECT:R1,OL:N1,OPTGROUP:P1,OPTION:j1,OUTPUT:w1,P:YZ,PICTURE:LZ,PRE:yZ,PROGRESS:H1,SCRIPT:b1,SELECT:S1,SLOT:_1,SOURCE:x1,SPAN:bZ,STYLE:SZ,TABLE:u1,TBODY:o,THEAD:o,TFOOT:o,TD:UW,TH:UW,TEMPLATE:n1,TEXTAREA:l1,TIME:r1,TITLE:_Z,TR:c1,TRACK:t1,UL:xZ,VIDEO:ZZ};function v(W){let Z=W.tagName.toUpperCase(),$=vZ[Z];if($)return $(W);throw Error(`Unexpected HTML element tag: ${W.tagName} (update .web/custom/serialize.ts)`)}var hZ=(W)=>v(W.target),T=(W)=>W.relatedTarget?v(W.relatedTarget):null;function P(W,Z){return H()(W,{target:hZ,...Z||{}})}var w=["target","bubbles","cancelable","defaultPrevented","eventPhase","isTrusted","timeStamp","type"],h=[...w,"detail"],m=[...h,"altKey","button","buttons","clientX","clientY","ctrlKey","metaKey","movementX","movementY","pageX","pageY","screenX","screenY","shiftKey"],mZ=[...m,"pointerId","pressure","tangentialPressure","tiltX","tiltY","twist","width","height","pointerType","isPrimary"],pZ=P(w),EZ=P(h),uZ=P(m,{relatedTarget:T}),iZ=P(w,{clipboardData:(W)=>OW(W.clipboardData)}),cZ=P([...w,"data"]),dZ=P(m,{relatedTarget:T,dataTransfer:(W)=>OW(W.dataTransfer)}),nZ=P(mZ,{relatedTarget:T}),oZ=P(w,{relatedTarget:T}),lZ=P(w),sZ=P(w),rZ=P(w),aZ=P([...h,"altKey","ctrlKey","code","key","locale","location","metaKey","repeat","shiftKey"]),tZ=P([...h,"altKey","ctrlKey","metaKey","shiftKey","changedTouches","targetTouches","touches"],{changedTouches:(W)=>l(W.changedTouches),targetTouches:(W)=>l(W.targetTouches),touches:(W)=>l(W.touches)}),eZ=P([...m,"deltaMode","deltaX","deltaY","deltaZ"],{relatedTarget:T}),W0=P([...w,"animationName","elapsedTime","pseudoElement"]),Z0=P([...w,"oldState","newState"]),$0=P([...w,"elapsedTime","propertyName","pseudoElement"]);function l(W){return Array.from(W).map((Z)=>({target:v(Z.target),identifier:Z.identifier,screenX:Z.screenX,screenY:Z.screenY,clientX:Z.clientX,clientY:Z.clientY,pageX:Z.pageX,pageY:Z.pageY}))}function OW(W){if(!W)return null;let Z=[];if(W.items)for(let $=0;$<W.items.length;$++){let Q=W.items[$];Z.push({kind:Q.kind,type:Q.type})}return{drop_effect:W.dropEffect,effect_allowed:W.effectAllowed,items:Z,types:Array.from(W.types||[])}}var I={};function j(W,Z,$){for(let Q of Z)W[Q]=$}j(I,["pointerdown","pointermove","pointerup","pointercancel","gotpointercapture","lostpointercapture","pointerenter","pointerleave","pointerover","pointerout"],nZ);j(I,["click","contextmenu","dblclick","mousedown","mouseenter","mouseleave","mousemove","mouseout","mouseover","mouseup"],uZ);j(I,["drag","dragend","dragenter","dragexit","dragleave","dragover","dragstart","drop"],dZ);j(I,["keydown","keypress","keyup"],aZ);j(I,["focus","blur"],oZ);j(I,["change","input"],rZ);j(I,["invalid"],sZ);j(I,["reset","submit"],lZ);j(I,["copy","cut","paste"],iZ);j(I,["compositionend","compositionstart","compositionupdate"],cZ);j(I,["touchcancel","touchend","touchmove","touchstart"],tZ);j(I,["scroll"],EZ);j(I,["wheel"],eZ);j(I,["animationstart","animationend","animationiteration"],W0);j(I,["transitionend"],$0);j(I,["toggle"],Z0);function s(W){if(W&&typeof W==="object"&&"nativeEvent"in W&&typeof W.isDefaultPrevented==="function"){let Z=W;if(typeof Z.type!=="string")return W;let $=I[Z.type.toLowerCase()];if($)return $(Z);return pZ(Z)}return W}function _(W){let Z=new Map,$=[],Q=[],q=[],F=[],N=0;function J(G){if(G==null||typeof G==="number"||typeof G==="string"||typeof G==="boolean")return G;let V=N++,D=Z.get(G);if(D!==void 0)return $.push(V),D;if(Z.set(G,V),G instanceof Date)return Q.push(V),G.getTime();if(Array.isArray(G)){let A=G.length,z=Array(A);for(let O=0;O<A;O++)z[O]=J(G[O]);return z}if(G instanceof Map){F.push(V);let A={};for(let[z,O]of G.entries())A[String(z)]=J(O);return A}if(G instanceof Set){q.push(V);let A=G.size,z=Array(A),O=0;for(let C of G)z[O]=J(C),O+=1;return z}if(typeof G==="object"){let A={},z=Object.keys(G);for(let O=0;O<z.length;O++){let C=z[O];A[C]=J(G[C])}return A}throw Error(`Unsupported value in serialization: ${G}`)}let U=J(W);return[[$,Q,q,F],U]}function r(W,Z){let[[$,Q,q,F],N]=W,J=new Set($),U=new Set(Q),G=new Set(q),V=new Set(F),D=[];function A(z){let O=D.length;if(J.has(O))return D.push(null),D[z];if(U.has(O)){let C=new Date(z);return D.push(C),C}if(z==null||typeof z==="number"||typeof z==="string"||typeof z==="boolean"){if(Z?.coerceNullsToUndefined)return z??void 0;return z}if(Array.isArray(z)){if(G.has(O)){let f=new Set;D.push(f);for(let B=0;B<z.length;B++)f.add(A(z[B]));return f}let C=z.length,R=Array(C);D.push(R);for(let f=0;f<C;f++)R[f]=A(z[f]);return R}if(typeof z==="object"){if(V.has(O)){let f=new Map;D.push(f);let B=Object.keys(z);for(let c=0;c<B.length;c++){let $W=B[c];f.set($W,A(z[$W]))}return f}let C={};D.push(C);let R=Object.keys(z);for(let f=0;f<R.length;f++){let B=R[f];C[B]=A(z[B])}return C}throw Error(`Unsupported value in deserialization: ${z}`)}return A(N)}import{io as X0}from"socket.io-client";class L extends Error{constructor(W){super(W);this.name="PulseChannelResetError"}}function Q0(){if(typeof crypto<"u"&&typeof crypto.randomUUID==="function")return crypto.randomUUID().replace(/-/g,"");return Math.random().toString(16).slice(2)+Math.random().toString(16).slice(2)}function q0(W){if(W instanceof Error)return W.message;if(typeof W==="string")return W;try{return JSON.stringify(W)}catch{return String(W)}}function F0(W){return typeof W.responseTo==="string"}function J0(W){return typeof W.event==="string"}class AW{client;id;handlers=new Map;pending=new Map;backlog=[];closed=!1;constructor(W,Z){this.client=W;this.id=Z}emit(W,Z){this.ensureOpen(),this.client.sendChannelMessage({type:"channel_message",channel:this.id,event:W,payload:Z})}async request(W,Z){this.ensureOpen();let $=Q0();return new Promise((Q,q)=>{this.pending.set($,{resolve:Q,reject:q}),this.client.sendChannelMessage({type:"channel_message",channel:this.id,event:W,payload:Z,requestId:$}).catch((F)=>{this.pending.delete($),q(F)})})}on(W,Z){this.ensureOpen();let $=this.handlers.get(W);if(!$)$=new Set,this.handlers.set(W,$);return $.add(Z),this.flushBacklog(W),()=>{let Q=this.handlers.get(W);if(!Q)return;if(Q.delete(Z),Q.size===0)this.handlers.delete(W)}}handleServerMessage(W){if(F0(W))return this.resolvePending(W),this.closed;if(this.closed)return!0;if(!J0(W))return this.closed;if(W.event==="__close__")return this.close(new L("Channel closed by server")),!0;if(W.requestId)this.dispatchRequest(W);else this.dispatchEvent(W);return this.closed}handleDisconnect(W){this.close(W)}dispose(W){this.close(W)}ensureOpen(){if(this.closed)throw new L("Channel is closed")}flushBacklog(W){if(this.backlog.length===0)return;let Z=[];for(let $ of this.backlog)if($.event===W)this.dispatchEvent($);else Z.push($);this.backlog=Z}dispatchEvent(W){let Z=this.handlers.get(W.event);if(!Z||Z.size===0){this.backlog.push(W);return}for(let $ of Z)try{let Q=$(W.payload);if(Q&&typeof Q.then==="function")Q.catch((q)=>{console.error("Pulse channel handler error",q)})}catch(Q){console.error("Pulse channel handler error",Q)}}async dispatchRequest(W){let Z=this.handlers.get(W.event),$,Q;if(Z&&Z.size>0)for(let q of Z)try{let F=q(W.payload);if($=await Promise.resolve(F),$!==void 0)break}catch(F){Q=F;break}if(Q){await this.client.sendChannelMessage({type:"channel_message",channel:this.id,event:void 0,responseTo:W.requestId,error:q0(Q)});return}await this.client.sendChannelMessage({type:"channel_message",channel:this.id,event:void 0,responseTo:W.requestId,payload:$})}resolvePending(W){let Z=W.responseTo?this.pending.get(W.responseTo):void 0;if(!Z)return;if(this.pending.delete(W.responseTo),W.error!==void 0&&W.error!==null)Z.reject(new L(String(W.error)));else Z.resolve(W.payload)}close(W){if(this.closed)return;this.closed=!0;for(let Z of this.pending.values())Z.reject(W);this.pending.clear(),this.handlers.clear(),this.backlog=[]}}function NW(W,Z){return new AW(W,Z)}class p{url;renderId;frameworkNavigate;activeViews;socket=null;messageQueue;connectionListeners=new Set;serverErrors=new Map;serverErrorListeners=new Set;channels=new Map;constructor(W,Z,$){this.url=W;this.renderId=Z;this.frameworkNavigate=$;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,Z)=>{let $=X0(this.url,{transports:["websocket","webtransport"],auth:{renderId:this.renderId}});this.socket=$,$.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let[Q,q]of this.activeViews)$.emit("message",_({type:"mount",path:Q,routeInfo:q.routeInfo}));for(let Q of this.messageQueue){if(Q.type==="mount"&&this.activeViews.has(Q.path))continue;if(Q.type==="navigate")continue;$.emit("message",_(Q))}this.messageQueue=[],this.notifyConnectionListeners(!0),W()}),$.on("connect_error",(Q)=>{console.error("[SocketIOTransport] Connection failed:",Q),this.notifyConnectionListeners(!1),Z(Q)}),$.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.handleTransportDisconnect(),this.notifyConnectionListeners(!1)}),$.on("message",(Q)=>this.handleServerMessage(r(Q,{coerceNullsToUndefined:!0})))})}onConnectionChange(W){return this.connectionListeners.add(W),W(this.isConnected()),()=>{this.connectionListeners.delete(W)}}notifyConnectionListeners(W){for(let Z of this.connectionListeners)Z(W)}onServerError(W){this.serverErrorListeners.add(W);for(let[Z,$]of this.serverErrors)W(Z,$);return()=>{this.serverErrorListeners.delete(W)}}notifyServerError(W,Z){for(let $ of this.serverErrorListeners)$(W,Z)}async sendMessage(W){if(this.isConnected())this.socket.emit("message",_(W));else this.messageQueue.push(W)}async sendChannelMessage(W){await this.sendMessage(W)}mountView(W,Z){if(this.activeViews.has(W))throw Error(`Path ${W} is already mounted`);this.activeViews.set(W,Z),this.sendMessage({type:"mount",path:W,routeInfo:Z.routeInfo})}async navigate(W,Z){await this.sendMessage({type:"navigate",path:W,routeInfo:Z})}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();for(let{bridge:W}of this.channels.values())W.dispose(new L("Client disconnected"));this.channels.clear()}handleServerMessage(W){switch(W.type){case"vdom_init":{let Z=this.activeViews.get(W.path);if(!Z)return;if(Z)Z.onInit(W.vdom,W.callbacks,W.render_props,W.css_refs);if(this.serverErrors.has(W.path))this.serverErrors.delete(W.path),this.notifyServerError(W.path,null);break}case"vdom_update":{let Z=this.activeViews.get(W.path);if(!Z)return;if(Z.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 Z=!!W.replace,$=W.path||"";if($.startsWith("//"))$=`${window.location.protocol}${$}`;if(/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test($))if($.startsWith("http://")||$.startsWith("https://"))try{let q=new URL($);if(q.origin===window.location.origin){let F=`${q.pathname}${q.search}${q.hash}`;this.frameworkNavigate(F,{replace:Z})}else if(Z)window.location.replace($);else window.location.assign($)}catch{if(Z)window.location.replace($);else window.location.assign($)}else if(Z)window.location.replace($);else window.location.assign($);else this.frameworkNavigate($,{replace:Z});break}case"channel_message":{this.routeChannelMessage(W);break}default:console.error("Unexpected message:",W)}}async performApiCall(W){try{let Z=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.headers.forEach((N,J)=>$[J]=N);let Q=null;if((Z.headers.get("content-type")||"").includes("application/json"))Q=await Z.json().catch(()=>null);else Q=await Z.text().catch(()=>null);let F={type:"api_result",id:W.id,ok:Z.ok,status:Z.status,headers:$,body:Q};await this.sendMessage(F)}catch(Z){let $={type:"api_result",id:W.id,ok:!1,status:0,headers:{},body:{error:String(Z)}};await this.sendMessage($)}}async invokeCallback(W,Z,$){await this.sendMessage({type:"callback",path:W,callback:Z,args:$.map(s)})}acquireChannel(W){let Z=this.ensureChannelEntry(W);return Z.refCount+=1,Z.bridge}releaseChannel(W){let Z=this.channels.get(W);if(!Z)return;if(Z.refCount=Math.max(0,Z.refCount-1),Z.refCount===0)Z.bridge.dispose(new L("Channel released")),this.channels.delete(W)}ensureChannelEntry(W){let Z=this.channels.get(W);if(!Z)Z={bridge:NW(this,W),refCount:0},this.channels.set(W,Z);return Z}routeChannelMessage(W){let Z=this.ensureChannelEntry(W.channel);if(Z.bridge.handleServerMessage(W)&&Z.refCount===0)this.channels.delete(W.channel)}handleTransportDisconnect(){for(let W of this.channels.values())W.bridge.handleDisconnect(new L("Connection lost"))}}import{useLocation as z0,useParams as G0,useNavigate as U0}from"react-router";import{jsx as b,jsxs as E}from"react/jsx-runtime";var fW=CW(null),PW=CW(null),i=()=>{let W=RW(fW);if(!W)throw Error("usePulseClient must be used within a PulseProvider");return W},V0=(W)=>{let Z=RW(PW);if(!Z)throw Error("usePulsePrerender must be used within a PulseProvider");let $=Z.views[W];if(!$)throw Error(`No prerender found for '${W}'`);return $},e=typeof window<"u";function D0({children:W,config:Z,prerender:$}){let[Q,q]=a(!0),F=U0(),{renderId:N}=$,J=t(()=>new p(Z.serverAddress,N,F),[Z.serverAddress,F,N]);return u(()=>J.onConnectionChange(q),[J]),u(()=>{if(e)return J.connect(),()=>J.disconnect()},[J]),b(fW.Provider,{value:J,children:E(PW.Provider,{value:$,children:[!Q&&b("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 O0({externalComponents:W,path:Z,cssModules:$}){let Q=i(),q=V0(Z),F=q.vdom,N=t(()=>new x(Q,Z,W,$,q.callbacks,q.render_props,q.css_refs),[Q,Z,W,$,q]),[J,U]=a(()=>N.renderNode(F)),[G,V]=a(null),D=z0(),A=G0(),z=t(()=>{let{"*":O="",...C}=A,R=new URLSearchParams(D.search);return{hash:D.hash,pathname:D.pathname,query:D.search,queryParams:Object.fromEntries(R.entries()),pathParams:C,catchall:O.length>0?O.split("/"):[]}},[D.hash,D.pathname,D.search,JSON.stringify(A)]);if(u(()=>{if(e){Q.mountView(Z,{routeInfo:z,onInit:(C,R,f,B)=>{N.setCallbacks(R),N.setRenderProps(f),N.setCssRefs(B),U(N.renderNode(C))},onUpdate:(C)=>{U((R)=>R==null?R:n(R,C,N))}});let O=Q.onServerError((C,R)=>{if(C===Z)V(R)});return()=>{O(),Q.unmount(Z)}}},[Q]),u(()=>{if(e)Q.navigate(Z,z)},[Q,Z,z]),G)return b(A0,{error:G});return J}function A0({error:W}){return E("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:[E("div",{style:{fontWeight:700,marginBottom:8},children:["Server Error during ",W.phase]}),W.message&&b("div",{children:W.message}),W.stack&&E("details",{open:!0,style:{marginTop:8},children:[b("summary",{children:"Stack trace"}),b("pre",{style:{margin:0},children:W.stack})]})]})}import{useEffect as N0,useMemo as C0}from"react";function R0(W){let Z=i(),$=C0(()=>{if(!W)throw Error("usePulseChannel requires a non-empty channelId");return Z.acquireChannel(W)},[Z,W]);return N0(()=>{return()=>{Z.releaseChannel(W)}},[Z,W]),$}import{forwardRef as f0,useCallback as P0}from"react";import{jsx as j0}from"react/jsx-runtime";var I0=f0(function({onSubmit:Z,action:$,...Q},q){return j0("form",{...Q,action:$,ref:q,onSubmit:P0((F)=>IW({event:F,action:$,onSubmit:Z}),[$,Z])})});async function IW({event:W,action:Z,onSubmit:$,formData:Q,force:q}){if($?.(W),!q&&W.defaultPrevented)return;let F=W.currentTarget;W.preventDefault();let N=W.nativeEvent;if(!Q)Q=new FormData(F,N.submitter);let J=new URL(Z,window.location.href);try{await fetch(J,{method:"POST",credentials:"include",body:Q})}catch(U){throw U}}import{io as B0}from"socket.io-client";class jW{url;socket=null;listener=null;messageQueue=[];connectionListeners=new Set;constructor(W){this.url=W}connect(W){return this.listener=W,new Promise((Z,$)=>{this.socket=B0(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),Z()}),this.socket.on("connect_error",(Q)=>{console.error("[SocketIOTransport] Connection failed:",Q),this.notifyConnectionListeners(!1),$(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 Z of this.connectionListeners)Z(W)}}function w0({params:W,request:Z}){let{"*":$="",...Q}=W,q=new URL(Z.url);return{hash:q.hash,pathname:q.pathname,query:q.search,queryParams:Object.fromEntries(q.searchParams.entries()),pathParams:Q,catchall:$.length>1?$.split("/"):[]}}function K0(W){if(W===null||typeof W!=="object")return!1;let Z=Object.getPrototypeOf(W);return Z===Object.prototype||Z===null}function WW(W){return typeof W==="function"||typeof W==="symbol"||typeof W>"u"}async function H0(W){let Z=await W.arrayBuffer();return Array.from(new Uint8Array(Z))}async function Y0(W){return await g(W,{seen:new WeakMap,nextId:1})}function L0(W,Z){if(W.seen.get(Z)!==void 0)return null;let Q=W.nextId++;return W.seen.set(Z,Q),Q}async function g(W,Z){if(W===null||typeof W!=="object")return W;if(W instanceof Date)return{__t:"datetime",timestamp:W.getTime()};if(W instanceof FormData){let J=L0(Z,W);if(J===null)return{__t:"ref",id:Z.seen.get(W)};let U={};for(let[V,D]of W.entries()){let A=await g(D,Z);if(A===void 0)continue;if(Object.prototype.hasOwnProperty.call(U,V)){let z=U[V];if(Array.isArray(z))z.push(A);else U[V]=[z,A]}else U[V]=A}return{__t:"formdata",fields:U,__id:J}}if(W instanceof File){let J=W,U=await H0(W);return{__t:"file",name:J.name,type:J.type,size:J.size,lastModified:J.lastModified,content:U}}let $=W,Q=Z.seen.get($);if(Q!==void 0)return{__t:"ref",id:Q};let q=Z.nextId++;if(Z.seen.set($,q),Array.isArray(W)){let U=(await Promise.all(W.map((V)=>g(V,Z)))).filter((V)=>V!==void 0);return{__t:"array",__id:q,items:U}}let F={};if(K0(W))for(let J of Object.keys(W)){let U=W[J];if(WW(U))continue;let G=await g(U,Z);if(G!==void 0)F[J]=G}else for(let J in W){let U=W[J];if(WW(U))continue;let G=await g(U,Z);if(G!==void 0)F[J]=G}return{__t:"object",__id:q,props:F}}function M0(W){return k(W)}function k(W){if(W===null||typeof W!=="object")return W;let Z=W,$=Z.__t;if($==="datetime"){let q=Z.timestamp;return new Date(q)}if($==="file"){let q=Z.content;if(Array.isArray(q))return{...Z,content:new Uint8Array(q)};return Z}if($==="formdata"){let q=Z.fields,F={};for(let N of Object.keys(q)){let J=q[N];if(Array.isArray(J))F[N]=J.map((U)=>k(U));else F[N]=k(J)}return{__t:"formdata",fields:F}}if($==="array")return Z.items.map((F)=>k(F));if($==="object"){let q=Z.props,F={};for(let N of Object.keys(q))F[N]=k(q[N]);return F}if($==="ref")return Z;let Q={};for(let q of Object.keys(Z))Q[q]=k(Z[q]);return Q}function y0(W){return ZW(W,new WeakSet)}function ZW(W,Z){if(W===null||typeof W!=="object")return W;if(Z.has(W))return;if(Z.add(W),Array.isArray(W))return W.map((Q)=>ZW(Q,Z)).filter((Q)=>Q!==void 0);let $={};for(let Q in W){let q=W[Q];if(WW(q))continue;let F=ZW(q,Z);if(F!==void 0)$[Q]=F}return $}export{i as usePulseClient,R0 as usePulseChannel,IW as submitForm,_ as serialize,w0 as extractServerRouteInfo,s as extractEvent,Y0 as encodeForWire,r as deserialize,M0 as decodeFromWire,y0 as cleanForSerialization,n as applyReactTreeUpdates,x as VDOMRenderer,jW as SocketIOTransport,YW as RenderLazy,O0 as PulseView,p as PulseSocketIOClient,D0 as PulseProvider,I0 as PulseForm,L as PulseChannelResetError};
2
2
 
3
- //# debugId=E15FD8696B30CE4A64756E2164756E21
3
+ //# debugId=5E6472122C1891A564756E2164756E21