pulse-ui-client 0.0.2 → 0.0.4

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
@@ -9,4 +9,6 @@ export { SocketIOTransport } from "./transport";
9
9
  export type { Transport, MessageListener } from "./transport";
10
10
  export { extractServerRouteInfo } from "./helpers";
11
11
  export type { RouteInfo } from "./helpers";
12
- export { extractEvent } from "./serialize";
12
+ export { extractEvent } from "./serialize/events";
13
+ export { encodeForWire, decodeFromWire, cleanForSerialization, } from "./serialize/clean";
14
+ export { stringify, parse } from "./serialize/flatted";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{useEffect as g,useState as v,useMemo as s,createContext as e,useContext as qq}from"react";import r,{Suspense as Wq}from"react";var p="$$fragment",k="$$";function F(q){return typeof q==="object"&&q!==null}function L(q){return typeof q==="object"&&q!==null&&q.tag.startsWith("$$")&&q.tag!=="$$fragment"}function c(q){if(!L(q))throw new Error("Node is not a mount point");return q.tag.slice(2)}import{jsxDEV as w,Fragment as u}from"react/jsx-dev-runtime";function H(q,J){if(F(q))return q.key||J;return J}var N=({node:q})=>{let{getCallback:J,getComponent:Y}=M();if(q===null||typeof q==="boolean"||q===void 0)return null;if(typeof q==="string"||typeof q==="number")return w(u,{children:q},void 0,!1,void 0,this);if(F(q)){if(!(("tag"in q)&&typeof q.tag==="string"))return console.error("Invalid VDOM element node received:",q),null;let{tag:$,props:Q={},children:X=[]}=q,A={};for(let[W,z]of Object.entries(Q))if(typeof z==="string"&&z.startsWith("$$fn:")){let f=z.substring(5);A[W]=J(f)}else A[W]=z;if(L(q)){let W=c(q),z=Y(W),f=X.map((C,_)=>w(N,{node:C},H(C,_),!1,void 0,this));return w(z,{...A,children:f},void 0,!1,void 0,this)}if($===p)return w(u,{children:X.map((W,z)=>w(N,{node:W},H(W,z),!1,void 0,this))},void 0,!1,void 0,this);let I=X.map((W,z)=>w(N,{node:W},H(W,z),!1,void 0,this));return r.createElement($,A,...I)}return console.error("Unknown VDOM node type:",q),null};N.displayName="VDOMRenderer";function zq(q,J={},Y=[],$){if(q.startsWith(k))console.error(`[Pulse] Error: The tag "${q}" starts with a reserved prefix "${k}". Please use a different tag name.`);let Q={tag:q,props:J,children:Y};if($!==void 0)Q.key=$;return Q}function Xq(q=[],J){let Y={tag:p,props:{},children:q};if(J!==void 0)Y.key=J;return Y}function Aq(q,J={},Y=[],$){let Q={tag:k+q,props:J,children:Y};if($!==void 0)Q.key=$;return Q}function Gq(q,J){if(J==="")return F(q)?q:null;let Y=J.split(".").map(Number),$=q;for(let Q of Y){if(!F($))return console.error("[findNodeByPath] Invalid path: part of it is not an element node."),null;if(!$.children||Q>=$.children.length)return console.error(`[findNodeByPath] Invalid path: index ${Q} out of bounds.`),null;$=$.children[Q]}return F($)?$:null}function fq(q){if(typeof q!=="object"||q===null)return q;return JSON.parse(JSON.stringify(q))}function h(q,J){let Y=fq(q);for(let $ of J){let{type:Q,path:X,data:A}=$;if(X===""){switch(Q){case"replace":Y=A;break;case"update_props":if(F(Y))Y.props={...Y.props??{},...A};break;default:console.error(`[applyUpdates] Invalid root operation: ${Q}`)}continue}let I=X.substring(0,X.lastIndexOf(".")),W=parseInt(X.substring(X.lastIndexOf(".")+1),10),z=Gq(Y,I);if(!z){console.error(`[applyUpdates] Could not find parent for path: ${X}`);continue}if(!z.children)z.children=[];switch(Q){case"replace":z.children[W]=A;break;case"update_props":let f=z.children[W];if(F(f))f.props={...f.props??{},...A};break;case"insert":z.children.splice(W,0,A);break;case"remove":z.children.splice(W,1);break;case"move":{let C=z.children.splice(A.from_index,1)[0];z.children.splice(A.to_index,0,C);break}}}return Y}function Rq(q,J){let Y=r.lazy(q);return({children:$,...Q})=>{return w(Wq,{fallback:J??w(u,{},void 0,!1,void 0,this),children:w(Y,{...Q,children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)}}function Uq(q){return{id:q.id,class_name:q.className,tag_name:q.tagName.toLowerCase(),local_name:q.localName,client_height:q.clientHeight,client_left:q.clientLeft,client_top:q.clientTop,client_width:q.clientWidth,scroll_height:q.scrollHeight,scroll_left:q.scrollLeft,scroll_top:q.scrollTop,scroll_width:q.scrollWidth,slot:q.slot}}function Kq(q){return{autofocus:q.autofocus,tab_index:q.tabIndex,nonce:q.nonce}}function Z(q){return{...Uq(q),...Kq(q),access_key:q.accessKey,access_key_label:q.accessKeyLabel,autocapitalize:q.autocapitalize,dir:q.dir,draggable:q.draggable,hidden:q.hidden,inert:q.inert,lang:q.lang,offset_height:q.offsetHeight,offset_left:q.offsetLeft,offset_top:q.offsetTop,offset_width:q.offsetWidth,popover:q.popover,spellcheck:q.spellcheck,title:q.title,translate:q.translate,writing_suggestions:q.writingSuggestions,content_editable:q.contentEditable,enter_key_hint:q.enterKeyHint,is_content_editable:q.isContentEditable,input_mode:q.inputMode}}function _q(q){return{...Z(q),hash:q.hash,host:q.host,hostname:q.hostname,href:q.href,origin:q.origin,password:q.password,pathname:q.pathname,port:q.port,protocol:q.protocol,search:q.search,target:q.target,download:q.download,rel:q.rel,hreflang:q.hreflang,type:q.type,username:q.username,ping:q.ping,referrer_policy:q.referrerPolicy,text:q.text}}function wq(q){return{...Z(q),alt:q.alt,coords:q.coords,download:q.download,hash:q.hash,host:q.host,hostname:q.hostname,href:q.href,origin:q.origin,password:q.password,pathname:q.pathname,port:q.port,protocol:q.protocol,rel:q.rel,search:q.search,shape:q.shape,target:q.target,username:q.username,ping:q.ping,referrer_policy:q.referrerPolicy}}function l(q){return{...Z(q),autoplay:q.autoplay,controls:q.controls,cross_origin:q.crossOrigin,current_src:q.currentSrc,current_time:q.currentTime,default_muted:q.defaultMuted,default_playback_rate:q.defaultPlaybackRate,duration:q.duration,ended:q.ended,loop:q.loop,muted:q.muted,network_state:q.networkState,paused:q.paused,playback_rate:q.playbackRate,preload:q.preload,ready_state:q.readyState,seeking:q.seeking,src:q.src,volume:q.volume,preserves_pitch:q.preservesPitch}}function Fq(q){return{...l(q)}}function Sq(q){return{...Z(q),disabled:q.disabled,name:q.name,type:q.type,value:q.value,form_action:q.formAction,form_enctype:q.formEnctype,form_method:q.formMethod,form_no_validate:q.formNoValidate,form_target:q.formTarget,popover_target_action:q.popoverTargetAction}}function Iq(q){return{...Z(q),value:q.value}}function Oq(q){return{...Z(q),height:q.height,src:q.src,type:q.type,width:q.width,align:q.align,name:q.name}}function Nq(q){return{...Z(q),disabled:q.disabled,name:q.name,type:q.type,validation_message:q.validationMessage,will_validate:q.willValidate}}function Cq(q){return{...Z(q),accept_charset:q.acceptCharset,action:q.action,autocomplete:q.autocomplete,encoding:q.encoding,enctype:q.enctype,length:q.length,method:q.method,name:q.name,no_validate:q.noValidate,target:q.target,rel:q.rel}}function Vq(q){return{...Z(q),allow:q.allow,allow_fullscreen:q.allowFullscreen,height:q.height,name:q.name,referrer_policy:q.referrerPolicy,src:q.src,srcdoc:q.srcdoc,width:q.width,align:q.align,frame_border:q.frameBorder,long_desc:q.longDesc,margin_height:q.marginHeight,margin_width:q.marginWidth,scrolling:q.scrolling,sandbox:q.sandbox}}function Pq(q){return{...Z(q),alt:q.alt,cross_origin:q.crossOrigin,decoding:q.decoding,height:q.height,is_map:q.isMap,loading:q.loading,natural_height:q.naturalHeight,natural_width:q.naturalWidth,referrer_policy:q.referrerPolicy,sizes:q.sizes,src:q.src,srcset:q.srcset,use_map:q.useMap,width:q.width,align:q.align,border:q.border,complete:q.complete,hspace:q.hspace,long_desc:q.longDesc,lowsrc:q.lowsrc,name:q.name,vspace:q.vspace,x:q.x,y:q.y,fetch_priority:q.fetchPriority}}function Dq(q){return{...Z(q),accept:q.accept,alt:q.alt,autocomplete:q.autocomplete,checked:q.checked,default_checked:q.defaultChecked,default_value:q.defaultValue,dir_name:q.dirName,disabled:q.disabled,height:q.height,indeterminate:q.indeterminate,max:q.max,max_length:q.maxLength,min:q.min,min_length:q.minLength,multiple:q.multiple,name:q.name,pattern:q.pattern,placeholder:q.placeholder,read_only:q.readOnly,required:q.required,selection_direction:q.selectionDirection,selection_end:q.selectionEnd,selection_start:q.selectionStart,size:q.size,src:q.src,step:q.step,type:q.type,value:q.value,value_as_number:q.valueAsNumber,width:q.width,align:q.align,capture:q.capture,form_action:q.formAction,form_enctype:q.formEnctype,form_method:q.formMethod,form_no_validate:q.formNoValidate,form_target:q.formTarget,use_map:q.useMap,validation_message:q.validationMessage,will_validate:q.willValidate,popover_target_action:q.popoverTargetAction}}function bq(q){return{...Z(q),html_for:q.htmlFor}}function kq(q){return{...Z(q),value:q.value,type:q.type}}function jq(q){return{...Z(q),as:q.as,cross_origin:q.crossOrigin,disabled:q.disabled,fetch_priority:q.fetchPriority,href:q.href,href_lang:q.hreflang,image_sizes:q.imageSizes,image_srcset:q.imageSrcset,integrity:q.integrity,media:q.media,referrer_policy:q.referrerPolicy,rel:q.rel,type:q.type,charset:q.charset,rev:q.rev,target:q.target,sizes:q.sizes}}function yq(q){return{...Z(q),name:q.name}}function Bq(q){return{...Z(q),high:q.high,low:q.low,max:q.max,min:q.min,optimum:q.optimum,value:q.value}}function gq(q){return{...Z(q),cite:q.cite,dateTime:q.dateTime}}function pq(q){return{...Z(q),reversed:q.reversed,start:q.start,type:q.type,compact:q.compact}}function Lq(q){return{...Z(q),data:q.data,height:q.height,name:q.name,type:q.type,use_map:q.useMap,width:q.width,validation_message:q.validationMessage,will_validate:q.willValidate,align:q.align,archive:q.archive,border:q.border,code:q.code,code_base:q.codeBase,code_type:q.codeType,declare:q.declare,hspace:q.hspace,standby:q.standby,vspace:q.vspace}}function Hq(q){return{...Z(q),disabled:q.disabled,label:q.label}}function uq(q){return{...Z(q),default_selected:q.defaultSelected,disabled:q.disabled,index:q.index,label:q.label,selected:q.selected,text:q.text,value:q.value}}function hq(q){return{...Z(q),default_value:q.defaultValue,name:q.name,type:q.type,value:q.value,html_for:q.htmlFor,validation_message:q.validationMessage,will_validate:q.willValidate}}function Mq(q){return{...Z(q),max:q.max,position:q.position,value:q.value}}function Tq(q){return{...Z(q),cite:q.cite}}function iq(q){return{...Z(q)}}function dq(q){return{...Z(q),async_:q.async,cross_origin:q.crossOrigin,defer:q.defer,fetch_priority:q.fetchPriority,integrity:q.integrity,no_module:q.noModule,referrer_policy:q.referrerPolicy,src:q.src,text:q.text,type:q.type,charset:q.charset,event:q.event,html_for:q.htmlFor}}function mq(q){return{...Z(q),autocomplete:q.autocomplete,disabled:q.disabled,length:q.length,multiple:q.multiple,name:q.name,required:q.required,selected_index:q.selectedIndex,size:q.size,type:q.type,value:q.value,validation_message:q.validationMessage,will_validate:q.willValidate}}function Eq(q){return{...Z(q),name:q.name}}function xq(q){return{...Z(q),height:q.height,media:q.media,sizes:q.sizes,src:q.src,srcset:q.srcset,type:q.type,width:q.width}}function vq(q){return{...Z(q),align:q.align}}function sq(q){return{...Z(q),abbr:q.abbr,cell_index:q.cellIndex,col_span:q.colSpan,headers:q.headers,row_span:q.rowSpan,scope:q.scope,align:q.align,axis:q.axis,bg_color:q.bgColor,ch:q.ch,ch_off:q.chOff,height:q.height,no_wrap:q.noWrap,v_align:q.vAlign,width:q.width}}function oq(q){return{...Z(q),span:q.span,align:q.align,ch:q.ch,ch_off:q.chOff,v_align:q.vAlign,width:q.width}}function cq(q){return{...Z(q),align:q.align,bg_color:q.bgColor,border:q.border,cell_padding:q.cellPadding,cell_spacing:q.cellSpacing,frame:q.frame,rules:q.rules,summary:q.summary,width:q.width}}function rq(q){return{...Z(q),row_index:q.rowIndex,section_row_index:q.sectionRowIndex,align:q.align,bg_color:q.bgColor,ch:q.ch,ch_off:q.chOff,v_align:q.vAlign}}function nq(q){return{...Z(q),align:q.align,ch:q.ch,ch_off:q.chOff,v_align:q.vAlign}}function aq(q){return{...Z(q)}}function lq(q){return{...Z(q),autocomplete:q.autocomplete,cols:q.cols,default_value:q.defaultValue,dir_name:q.dirName,disabled:q.disabled,max_length:q.maxLength,min_length:q.minLength,name:q.name,placeholder:q.placeholder,read_only:q.readOnly,required:q.required,rows:q.rows,selection_direction:q.selectionDirection,selection_end:q.selectionEnd,selection_start:q.selectionStart,value:q.value,wrap:q.wrap,text_length:q.textLength,validation_message:q.validationMessage,will_validate:q.willValidate}}function tq(q){return{...Z(q),datetime:q.dateTime}}function eq(q){return{...Z(q),default:q.default,kind:q.kind,label:q.label,ready_state:q.readyState,src:q.src,srclang:q.srclang}}function q1(q){return{...l(q),height:q.height,poster:q.poster,video_height:q.videoHeight,video_width:q.videoWidth,width:q.width,plays_inline:q.playsInline}}function J1(q){return{...Z(q),clear:q.clear}}function Y1(q){return{...Z(q),href:q.href,target:q.target}}function Z1(q){return{...Z(q),a_link:q.aLink,background:q.background,bg_color:q.bgColor,link:q.link,text:q.text,v_link:q.vLink}}function $1(q){return{...Z(q),compact:q.compact}}function Q1(q){return{...Z(q),open:q.open}}function W1(q){return{...Z(q),open:q.open,return_value:q.returnValue}}function z1(q){return{...Z(q),align:q.align}}function X1(q){return{...Z(q)}}function A1(q){return{...Z(q),align:q.align}}function G1(q){return{...Z(q),align:q.align,color:q.color,no_shade:q.noShade,size:q.size,width:q.width}}function f1(q){return{...Z(q),version:q.version}}function R1(q){return{...Z(q)}}function U1(q){return{...Z(q),content:q.content,http_equiv:q.httpEquiv,name:q.name,scheme:q.scheme}}function K1(q){return{...Z(q),align:q.align}}function _1(q){return{...Z(q)}}function w1(q){return{...Z(q),width:q.width}}function F1(q){return{...Z(q)}}function S1(q){return{...Z(q),media:q.media,type:q.type,disabled:q.disabled}}function I1(q){return{...Z(q),text:q.text}}function O1(q){return{...Z(q),compact:q.compact,type:q.type}}function P(q){switch(q.tagName.toUpperCase()){case"A":return _q(q);case"AREA":return wq(q);case"AUDIO":return Fq(q);case"BASE":return Y1(q);case"BLOCKQUOTE":case"Q":return Tq(q);case"BODY":return Z1(q);case"BR":return J1(q);case"BUTTON":return Sq(q);case"CANVAS":return Z(q);case"CAPTION":return vq(q);case"CITE":return iq(q);case"COL":case"COLGROUP":return oq(q);case"DATA":return Iq(q);case"DETAILS":return Q1(q);case"DIALOG":return W1(q);case"DIV":return z1(q);case"DL":return $1(q);case"EMBED":return Oq(q);case"FIELDSET":return Nq(q);case"FORM":return Cq(q);case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return A1(q);case"HEAD":return X1(q);case"HR":return G1(q);case"HTML":return f1(q);case"IFRAME":return Vq(q);case"IMG":return Pq(q);case"INPUT":return Dq(q);case"LABEL":return bq(q);case"LI":return kq(q);case"LINK":return jq(q);case"MAP":return yq(q);case"MENU":return R1(q);case"META":return U1(q);case"METER":return Bq(q);case"INS":case"DEL":return gq(q);case"OBJECT":return Lq(q);case"OL":return pq(q);case"OPTGROUP":return Hq(q);case"OPTION":return uq(q);case"OUTPUT":return hq(q);case"P":return K1(q);case"PICTURE":return _1(q);case"PRE":return w1(q);case"PROGRESS":return Mq(q);case"SCRIPT":return dq(q);case"SELECT":return mq(q);case"SLOT":return Eq(q);case"SOURCE":return xq(q);case"SPAN":return F1(q);case"STYLE":return S1(q);case"TABLE":return cq(q);case"TBODY":case"THEAD":case"TFOOT":return nq(q);case"TD":case"TH":return sq(q);case"TEMPLATE":return aq(q);case"TEXTAREA":return lq(q);case"TIME":return tq(q);case"TITLE":return I1(q);case"TR":return rq(q);case"TRACK":return eq(q);case"UL":return O1(q);case"VIDEO":return q1(q);default:throw new Error(`Unexpected HTML element tag: ${q.tagName} (update .web/custom/serialize.ts)`)}}function K(q){return{target:P(q.target),bubbles:q.bubbles,cancelable:q.cancelable,default_prevented:q.defaultPrevented,event_phase:q.eventPhase,is_trusted:q.isTrusted,timestamp:q.timeStamp,type:q.type}}function y(q){return{...K(q),detail:q.detail}}function G(q){return{...y(q),alt_key:q.altKey,button:q.button,buttons:q.buttons,client_x:q.clientX,client_y:q.clientY,ctrl_key:q.ctrlKey,meta_key:q.metaKey,movement_x:q.movementX,movement_y:q.movementY,page_x:q.pageX,page_y:q.pageY,related_target:q.relatedTarget?P(q.relatedTarget):null,screen_x:q.screenX,screen_y:q.screenY,shift_key:q.shiftKey}}function T(q){return{...K(q),clipboard_data:t(q.clipboardData)}}function i(q){return{...K(q),data:q.data}}function S(q){return{...G(q),data_transfer:t(q.dataTransfer)}}function U(q){return{...G(q),pointer_id:q.pointerId,pressure:q.pressure,tangential_pressure:q.tangentialPressure,tilt_x:q.tiltX,tilt_y:q.tiltY,twist:q.twist,width:q.width,height:q.height,pointer_type:q.pointerType,is_primary:q.isPrimary}}function n(q){return{...K(q),related_target:q.relatedTarget?P(q.relatedTarget):null}}function E(q){return K(q)}function N1(q){return K(q)}function a(q){return E(q)}function d(q){return{...y(q),alt_key:q.altKey,ctrl_key:q.ctrlKey,code:q.code,key:q.key,locale:q.locale,location:q.location,meta_key:q.metaKey,repeat:q.repeat,shift_key:q.shiftKey}}function j(q){return{...y(q),alt_key:q.altKey,changed_touches:Array.from(q.changedTouches).map((J)=>({target:P(J.target),identifier:J.identifier,screen_x:J.screenX,screen_y:J.screenY,client_x:J.clientX,client_y:J.clientY,page_x:J.pageX,page_y:J.pageY})),ctrl_key:q.ctrlKey,meta_key:q.metaKey,shift_key:q.shiftKey,target_touches:Array.from(q.targetTouches).map((J)=>({target:P(J.target),identifier:J.identifier,screen_x:J.screenX,screen_y:J.screenY,client_x:J.clientX,client_y:J.clientY,page_x:J.pageX,page_y:J.pageY})),touches:Array.from(q.touches).map((J)=>({target:P(J.target),identifier:J.identifier,screen_x:J.screenX,screen_y:J.screenY,client_x:J.clientX,client_y:J.clientY,page_x:J.pageX,page_y:J.pageY}))}}function C1(q){return{...G(q),delta_mode:q.deltaMode,delta_x:q.deltaX,delta_y:q.deltaY,delta_z:q.deltaZ}}function m(q){return{...K(q),animation_name:q.animationName,elapsed_time:q.elapsedTime,pseudo_element:q.pseudoElement}}function V1(q){return{...K(q),old_state:q.oldState,new_state:q.newState}}function P1(q){return{...K(q),elapsed_time:q.elapsedTime,property_name:q.propertyName,pseudo_element:q.pseudoElement}}function t(q){if(!q)return null;let J=[];if(q.items)for(let Y=0;Y<q.items.length;Y++){let $=q.items[Y];J.push({kind:$.kind,type:$.type})}return{drop_effect:q.dropEffect,effect_allowed:q.effectAllowed,items:J,types:Array.from(q.types||[])}}var D1={pointerdown:U,pointermove:U,pointerup:U,pointercancel:U,gotpointercapture:U,lostpointercapture:U,pointerenter:U,pointerleave:U,pointerover:U,pointerout:U,click:G,contextmenu:G,dblclick:G,mousedown:G,mouseenter:G,mouseleave:G,mousemove:G,mouseout:G,mouseover:G,mouseup:G,drag:S,dragend:S,dragenter:S,dragexit:S,dragleave:S,dragover:S,dragstart:S,drop:S,keydown:d,keypress:d,keyup:d,focus:n,blur:n,change:a,input:a,invalid:N1,reset:E,submit:E,copy:T,cut:T,paste:T,compositionend:i,compositionstart:i,compositionupdate:i,touchcancel:j,touchend:j,touchmove:j,touchstart:j,scroll:y,wheel:C1,animationstart:m,animationend:m,animationiteration:m,transitionend:P1,toggle:V1};function x(q){if(q&&typeof q==="object"&&"nativeEvent"in q&&typeof q.isDefaultPrevented==="function"){let J=q;if(typeof J.type!=="string")return q;let Y=D1[J.type.toLowerCase()];if(Y)return Y(J);return console.warn(`No specific extractor for event type "${J.type}". Using synthetic.`),K(J)}return q}import{io as b1}from"socket.io-client";class B{url;frameworkNavigate;activeViews;socket=null;messageQueue;connectionListeners=new Set;serverErrors=new Map;serverErrorListeners=new Set;constructor(q,J){this.url=q;this.frameworkNavigate=J;this.socket=null,this.activeViews=new Map,this.messageQueue=[]}isConnected(){return this.socket?.connected??!1}async connect(){if(this.socket)return;return new Promise((q,J)=>{let Y=b1(this.url,{transports:["websocket"]});this.socket=Y,Y.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let[$,Q]of this.activeViews)Y.emit("message",{type:"mount",path:$,routeInfo:Q.routeInfo});for(let $ of this.messageQueue){if($.type==="mount"&&this.activeViews.has($.path))continue;if($.type==="navigate")continue;Y.emit("message",$)}this.messageQueue=[],this.notifyConnectionListeners(!0),q()}),Y.on("connect_error",($)=>{console.error("[SocketIOTransport] Connection failed:",$),this.notifyConnectionListeners(!1),J($)}),Y.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),Y.on("message",($)=>this.handleServerMessage($))})}onConnectionChange(q){return this.connectionListeners.add(q),q(this.isConnected()),()=>{this.connectionListeners.delete(q)}}notifyConnectionListeners(q){for(let J of this.connectionListeners)J(q)}onServerError(q){this.serverErrorListeners.add(q);for(let[J,Y]of this.serverErrors)q(J,Y);return()=>{this.serverErrorListeners.delete(q)}}notifyServerError(q,J){for(let Y of this.serverErrorListeners)Y(q,J)}async sendMessage(q){if(this.isConnected())this.socket.emit("message",q);else this.messageQueue.push(q)}mountView(q,J){if(this.activeViews.has(q))throw new Error(`Path ${q} is already mounted`);this.activeViews.set(q,J),this.sendMessage({type:"mount",path:q,routeInfo:J.routeInfo})}async navigate(q,J){await this.sendMessage({type:"navigate",path:q,routeInfo:J})}unmount(q){this.sendMessage({type:"unmount",path:q}),this.activeViews.delete(q)}disconnect(){this.socket?.disconnect(),this.socket=null,this.messageQueue=[],this.connectionListeners.clear(),this.activeViews.clear(),this.serverErrors.clear(),this.serverErrorListeners.clear()}handleServerMessage(q){switch(q.type){case"vdom_init":{let J=this.activeViews.get(q.path);if(J)J.vdom=q.vdom,J.listener(J.vdom);if(this.serverErrors.has(q.path))this.serverErrors.delete(q.path),this.notifyServerError(q.path,null);break}case"vdom_update":{let J=this.activeViews.get(q.path);if(!J||!J.vdom){console.error(`[PulseClient] Received VDOM update for path ${q.path} before initial tree was set.`);return}if(J.vdom=h(J.vdom,q.ops),J.listener(J.vdom),this.serverErrors.has(q.path))this.serverErrors.delete(q.path),this.notifyServerError(q.path,null);break}case"server_error":{this.serverErrors.set(q.path,q.error),this.notifyServerError(q.path,q.error);break}case"api_call":{this.performApiCall(q);break}case"navigate_to":{try{let J=q.path;if(this.frameworkNavigate)this.frameworkNavigate(J);else window.history.pushState({},"",J),window.dispatchEvent(new PopStateEvent("popstate"))}catch(J){console.error("Navigation error:",J)}break}}}async performApiCall(q){try{let J=await fetch(q.url,{method:q.method||"GET",headers:{...q.headers||{},...q.body!=null&&!("content-type"in(q.headers||{}))?{"content-type":"application/json"}:{}},body:q.body!=null?typeof q.body==="string"?q.body:JSON.stringify(q.body):void 0,credentials:q.credentials||"include"}),Y={};J.headers.forEach((A,I)=>Y[I]=A);let $=null;if((J.headers.get("content-type")||"").includes("application/json"))$=await J.json().catch(()=>null);else $=await J.text().catch(()=>null);let X={type:"api_result",id:q.id,ok:J.ok,status:J.status,headers:Y,body:$};await this.sendMessage(X)}catch(J){let Y={type:"api_result",id:q.id,ok:!1,status:0,headers:{},body:{error:String(J)}};await this.sendMessage(Y)}}async invokeCallback(q,J,Y){await this.sendMessage({type:"callback",path:q,callback:J,args:Y.map(x)})}}import{useLocation as k1,useParams as j1,useNavigate as y1}from"react-router";import{jsxDEV as R}from"react/jsx-dev-runtime";var Jq=e(null),Yq=()=>{let q=qq(Jq);if(!q)throw new Error("usePulseClient must be used within a PulseProvider");return q},Zq=e(null),M=()=>{let q=qq(Zq);if(!q)throw new Error("usePulseRenderHelpers must be used within a PulseRenderContext (provided by <PulseView>)");return q},o=typeof window!=="undefined";function B1({children:q,config:J}){let[Y,$]=v(!0),Q=y1(),X=s(()=>new B(`${J.serverAddress}`,Q),[J.serverAddress,Q]);return g(()=>X.onConnectionChange($),[X]),g(()=>{if(o)return X.connect(),()=>X.disconnect()},[X]),R(Jq.Provider,{value:X,children:[!Y&&R("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."},void 0,!1,void 0,this),q]},void 0,!0,void 0,this)}function g1({initialVDOM:q,externalComponents:J,path:Y}){let $=Yq(),[Q,X]=v(q),[A,I]=v(null),W=k1(),z=j1(),f=s(()=>{let{"*":_="",...D}=z,b=new URLSearchParams(W.search);return{hash:W.hash,pathname:W.pathname,query:W.search,queryParams:Object.fromEntries(b.entries()),pathParams:D,catchall:_.length>0?_.split("/"):[]}},[W.hash,W.pathname,W.search,JSON.stringify(z)]);g(()=>{if(o){$.mountView(Y,{vdom:q,listener:X,routeInfo:f});let _=$.onServerError((D,b)=>{if(D===Y)I(b)});return()=>{console.log("Unmounting",Y),_(),$.unmount(Y)}}},[$]),g(()=>{if(o)$.navigate(Y,f)},[$,Y,f]);let C=s(()=>{let _=new Map;return{getCallback:(V)=>{let O=_.get(V);if(!O)O=(...Qq)=>$.invokeCallback(Y,V,Qq),_.set(V,O);return O},getComponent:(V)=>{let O=J[V];if(!O)throw new Error(`Component with key "${V}" not found.`);return O}}},[$,J,Y]);return R(Zq.Provider,{value:C,children:A?R(p1,{error:A},void 0,!1,void 0,this):R(N,{node:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function p1({error:q}){return R("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:[R("div",{style:{fontWeight:700,marginBottom:8},children:["Server Error during ",q.phase]},void 0,!0,void 0,this),q.message&&R("div",{children:q.message},void 0,!1,void 0,this),q.stack&&R("details",{open:!0,style:{marginTop:8},children:[R("summary",{children:"Stack trace"},void 0,!1,void 0,this),R("pre",{style:{margin:0},children:q.stack},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{io as L1}from"socket.io-client";class $q{url;socket=null;listener=null;messageQueue=[];connectionListeners=new Set;constructor(q){this.url=q}connect(q){return this.listener=q,new Promise((J,Y)=>{this.socket=L1(this.url,{transports:["websocket"]}),this.socket.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let $ of this.messageQueue)this.socket?.emit("message",$);this.messageQueue=[],this.notifyConnectionListeners(!0),J()}),this.socket.on("connect_error",($)=>{console.error("[SocketIOTransport] Connection failed:",$),this.notifyConnectionListeners(!1),Y($)}),this.socket.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),this.socket.on("message",($)=>{this.listener?.($)})})}disconnect(){this.socket?.disconnect(),this.socket=null,this.listener=null,this.messageQueue=[],this.connectionListeners.clear()}async sendMessage(q){if(this.isConnected())this.socket.emit("message",q);else this.messageQueue.push(q)}isConnected(){return this.socket?.connected||!1}onConnectionChange(q){return this.connectionListeners.add(q),q(this.isConnected()),()=>{this.connectionListeners.delete(q)}}notifyConnectionListeners(q){for(let J of this.connectionListeners)J(q)}}function H1({params:q,request:J}){let{"*":Y="",...$}=q,Q=new URL(J.url);return{hash:Q.hash,pathname:Q.pathname,query:Q.search,queryParams:Object.fromEntries(Q.searchParams.entries()),pathParams:$,catchall:Y.length>1?Y.split("/"):[]}}export{M as usePulseRenderHelpers,Yq as usePulseClient,H1 as extractServerRouteInfo,x as extractEvent,Aq as createMountPoint,Xq as createFragment,zq as createElementNode,h as applyVDOMUpdates,N as VDOMRenderer,$q as SocketIOTransport,Rq as RenderLazy,g1 as PulseView,B as PulseSocketIOClient,B1 as PulseProvider};
1
+ import{useEffect as m,useState as e,useMemo as WW,createContext as fW,useContext as VW}from"react";import QW,{Suspense as kW}from"react";var v="$$fragment",g="$$";function B(W){return typeof W==="object"&&W!==null}function u(W){return typeof W==="object"&&W!==null&&W.tag.startsWith("$$")&&W.tag!=="$$fragment"}function $W(W){if(!u(W))throw new Error("Node is not a mount point");return W.tag.slice(2)}import{jsxDEV as w,Fragment as E}from"react/jsx-dev-runtime";function x(W,q){if(B(W))return W.key||q;return q}var Y=({node:W})=>{let{getCallback:q,getComponent:z}=i();if(W===null||typeof W==="boolean"||W===void 0)return null;if(typeof W==="string"||typeof W==="number")return w(E,{children:W},void 0,!1,void 0,this);if(B(W)){if(!(("tag"in W)&&typeof W.tag==="string"))return console.error("Invalid VDOM element node received:",W),null;let{tag:$,props:Z={},children:J=[]}=W,U={};for(let[Q,X]of Object.entries(Z))if(typeof X==="string"&&X.startsWith("$$fn:")){let A=X.substring(5);U[Q]=q(A)}else U[Q]=X;if(u(W)){let Q=$W(W),X=z(Q),A=J.map((f,C)=>w(Y,{node:f},x(f,C),!1,void 0,this));return w(X,{...U,children:A},void 0,!1,void 0,this)}if($===v)return w(E,{children:J.map((Q,X)=>w(Y,{node:Q},x(Q,X),!1,void 0,this))},void 0,!1,void 0,this);let G=J.map((Q,X)=>w(Y,{node:Q},x(Q,X),!1,void 0,this));return QW.createElement($,U,...G)}return console.error("Unknown VDOM node type:",W),null};Y.displayName="VDOMRenderer";function BW(W,q={},z=[],$){if(W.startsWith(g))console.error(`[Pulse] Error: The tag "${W}" starts with a reserved prefix "${g}". Please use a different tag name.`);let Z={tag:W,props:q,children:z};if($!==void 0)Z.key=$;return Z}function KW(W=[],q){let z={tag:v,props:{},children:W};if(q!==void 0)z.key=q;return z}function yW(W,q={},z=[],$){let Z={tag:g+W,props:q,children:z};if($!==void 0)Z.key=$;return Z}function YW(W,q){if(q==="")return B(W)?W:null;let z=q.split(".").map(Number),$=W;for(let Z of z){if(!B($))return console.error("[findNodeByPath] Invalid path: part of it is not an element node."),null;if(!$.children||Z>=$.children.length)return console.error(`[findNodeByPath] Invalid path: index ${Z} out of bounds.`),null;$=$.children[Z]}return B($)?$:null}function jW(W){if(typeof W!=="object"||W===null)return W;return JSON.parse(JSON.stringify(W))}function d(W,q){let z=jW(W);for(let $ of q){let{type:Z,path:J,data:U}=$;if(J===""){switch(Z){case"replace":z=U;break;case"update_props":if(B(z))z.props={...z.props??{},...U};break;default:console.error(`[applyUpdates] Invalid root operation: ${Z}`)}continue}let G=J.substring(0,J.lastIndexOf(".")),Q=parseInt(J.substring(J.lastIndexOf(".")+1),10),X=YW(z,G);if(!X){console.error(`[applyUpdates] Could not find parent for path: ${J}`);continue}if(!X.children)X.children=[];switch(Z){case"replace":X.children[Q]=U;break;case"update_props":let A=X.children[Q];if(B(A))A.props={...A.props??{},...U};break;case"insert":X.children.splice(Q,0,U);break;case"remove":X.children.splice(Q,1);break;case"move":{let f=X.children.splice(U.from_index,1)[0];X.children.splice(U.to_index,0,f);break}}}return z}function bW(W,q){let z=QW.lazy(W);return({children:$,...Z})=>{return w(kW,{fallback:q??w(E,{},void 0,!1,void 0,this),children:w(z,{...Z,children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)}}function P(){function W(q,z){return($)=>{let Z={};for(let J of q)Z[J]=$[J];if(z)for(let J in z){let U=z[J];Z[J]=U($)}return Z}}return W}var HW=["id","className","tagName","localName","clientHeight","clientLeft","clientTop","clientWidth","scrollHeight","scrollLeft","scrollTop","scrollWidth","slot"],SW=["autofocus","tabIndex","nonce"],MW=["accessKey","accessKeyLabel","autocapitalize","dir","draggable","hidden","inert","lang","offsetHeight","offsetLeft","offsetTop","offsetWidth","popover","spellcheck","title","translate","writingSuggestions","contentEditable","enterKeyHint","isContentEditable","inputMode"],LW=P()(HW,{tagName:(W)=>W.tagName.toLowerCase()}),gW=P()(SW),_W=P()(MW);function k(W){return{...LW(W),...gW(W),..._W(W)}}function F(W,q){let z=P()(W,q);return($)=>({...k($),...z($)})}var pW=["hash","host","hostname","href","origin","password","pathname","port","protocol","search","target","download","rel","hreflang","type","username","ping","referrerPolicy","text"],TW=F(pW),hW=["alt","coords","download","hash","host","hostname","href","origin","password","pathname","port","protocol","rel","search","shape","target","username","ping","referrerPolicy"],mW=F(hW),vW=["autoplay","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","loop","muted","networkState","paused","playbackRate","preload","readyState","seeking","src","volume","preservesPitch"],UW=F(vW),uW=(W)=>UW(W),xW=["disabled","name","type","value","formAction","formEnctype","formMethod","formNoValidate","formTarget","popoverTargetAction"],EW=F(xW),dW=["value"],iW=F(dW),nW=["height","src","type","width","align","name"],sW=F(nW),lW=["disabled","name","type","validationMessage","willValidate"],cW=F(lW),oW=["acceptCharset","action","autocomplete","encoding","enctype","length","method","name","noValidate","target","rel"],rW=F(oW),aW=["allow","allowFullscreen","height","name","referrerPolicy","src","srcdoc","width","align","frameBorder","longDesc","marginHeight","marginWidth","scrolling","sandbox"],tW=F(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=F(eW),q1=["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"],z1=F(q1),Z1=["htmlFor"],$1=F(Z1),Q1=["value","type"],J1=F(Q1),X1=["as","crossOrigin","disabled","fetchPriority","href","hreflang","imageSizes","imageSrcset","integrity","media","referrerPolicy","rel","type","charset","rev","target","sizes"],F1=F(X1),G1=["name"],U1=F(G1),A1=["high","low","max","min","optimum","value"],P1=F(A1),R1=["cite","dateTime"],JW=F(R1),C1=["reversed","start","type","compact"],f1=F(C1),V1=["data","height","name","type","useMap","width","validationMessage","willValidate","align","archive","border","code","codeBase","codeType","declare","hspace","standby","vspace"],D1=F(V1),O1=["disabled","label"],N1=F(O1),I1=["defaultSelected","disabled","index","label","selected","text","value"],w1=F(I1),k1=["defaultValue","name","type","value","htmlFor","validationMessage","willValidate"],B1=F(k1),K1=["max","position","value"],y1=F(K1),Y1=["cite"],XW=F(Y1),j1=(W)=>k(W),b1=["async","crossOrigin","defer","fetchPriority","integrity","noModule","referrerPolicy","src","text","type","charset"],H1=P()(b1,{event:(W)=>W.event,htmlFor:(W)=>W.htmlFor}),S1=(W)=>({...k(W),...H1(W)}),M1=["autocomplete","disabled","length","multiple","name","required","selectedIndex","size","type","value","validationMessage","willValidate"],L1=F(M1),g1=["name"],_1=F(g1),p1=["height","media","sizes","src","srcset","type","width"],T1=F(p1),h1=["align"],m1=F(h1),v1=["abbr","cellIndex","colSpan","headers","rowSpan","scope","align","axis","bgColor","ch","chOff","height","noWrap","vAlign","width"],FW=F(v1),u1=["span","align","ch","chOff","vAlign","width"],GW=F(u1),x1=["align","bgColor","border","cellPadding","cellSpacing","frame","rules","summary","width"],E1=F(x1),d1=["rowIndex","sectionRowIndex","align","bgColor","ch","chOff","vAlign"],i1=F(d1),n1=["align","ch","chOff","vAlign"],n=F(n1),s1=(W)=>k(W),l1=["autocomplete","cols","defaultValue","dirName","disabled","maxLength","minLength","name","placeholder","readOnly","required","rows","selectionDirection","selectionEnd","selectionStart","value","wrap","textLength","validationMessage","willValidate"],c1=F(l1),o1=["dateTime"],r1=F(o1),a1=["default","kind","label","readyState","src","srclang"],t1=F(a1),e1=["height","poster","videoHeight","videoWidth","width","playsInline"],Wq=P()(e1),qq=(W)=>({...UW(W),...Wq(W)}),zq=["clear"],Zq=F(zq),$q=["href","target"],Qq=F($q),Jq=["aLink","background","bgColor","link","text","vLink"],Xq=F(Jq),Fq=["compact"],Gq=F(Fq),Uq=["open"],Aq=F(Uq),Pq=["open","returnValue"],Rq=F(Pq),Cq=["align"],fq=F(Cq),Vq=(W)=>k(W),Dq=["align"],b=F(Dq),Oq=["align","color","noShade","size","width"],Nq=F(Oq),Iq=["version"],wq=F(Iq),kq=(W)=>k(W),Bq=["content","httpEquiv","name","scheme"],Kq=F(Bq),yq=["align"],Yq=F(yq),jq=(W)=>k(W),bq=["width"],Hq=F(bq),Sq=(W)=>k(W),Mq=["media","type","disabled"],Lq=F(Mq),gq=["text"],_q=F(gq),pq=["compact","type"],Tq=F(pq),hq={A:TW,AREA:mW,AUDIO:uW,BASE:Qq,BLOCKQUOTE:XW,Q:XW,BODY:Xq,BR:Zq,BUTTON:EW,CANVAS:k,CAPTION:m1,CITE:j1,COL:GW,COLGROUP:GW,DATA:iW,DETAILS:Aq,DIALOG:Rq,DIV:fq,DL:Gq,EMBED:sW,FIELDSET:cW,FORM:rW,H1:b,H2:b,H3:b,H4:b,H5:b,H6:b,HEAD:Vq,HR:Nq,HTML:wq,IFRAME:tW,IMG:W1,INPUT:z1,LABEL:$1,LI:J1,LINK:F1,MAP:U1,MENU:kq,META:Kq,METER:P1,INS:JW,DEL:JW,OBJECT:D1,OL:f1,OPTGROUP:N1,OPTION:w1,OUTPUT:B1,P:Yq,PICTURE:jq,PRE:Hq,PROGRESS:y1,SCRIPT:S1,SELECT:L1,SLOT:_1,SOURCE:T1,SPAN:Sq,STYLE:Lq,TABLE:E1,TBODY:n,THEAD:n,TFOOT:n,TD:FW,TH:FW,TEMPLATE:s1,TEXTAREA:c1,TIME:r1,TITLE:_q,TR:i1,TRACK:t1,UL:Tq,VIDEO:qq};function R(W){let q=W.tagName.toUpperCase(),z=hq[q];if(z)return z(W);throw new Error(`Unexpected HTML element tag: ${W.tagName} (update .web/custom/serialize.ts)`)}var D=["target","bubbles","cancelable","defaultPrevented","eventPhase","isTrusted","timeStamp","type"],p=[...D,"detail"],T=[...p,"altKey","button","buttons","clientX","clientY","ctrlKey","metaKey","movementX","movementY","pageX","pageY","screenX","screenY","shiftKey"],mq=[...T,"pointerId","pressure","tangentialPressure","tiltX","tiltY","twist","width","height","pointerType","isPrimary"],vq=P()(D,{target:(W)=>R(W.target)}),uq=P()(p,{target:(W)=>R(W.target)}),N=P()(T,{target:(W)=>R(W.target),relatedTarget:(W)=>W.relatedTarget?R(W.relatedTarget):null}),s=P()(D,{target:(W)=>R(W.target),clipboardData:(W)=>CW(W.clipboardData)}),l=P()([...D,"data"],{target:(W)=>R(W.target)}),K=P()(T,{target:(W)=>R(W.target),relatedTarget:(W)=>W.relatedTarget?R(W.relatedTarget):null,dataTransfer:(W)=>CW(W.dataTransfer)}),I=P()(mq,{target:(W)=>R(W.target),relatedTarget:(W)=>W.relatedTarget?R(W.relatedTarget):null}),AW=P()(D,{target:(W)=>R(W.target),relatedTarget:(W)=>W.relatedTarget?R(W.relatedTarget):null}),PW=P()(D,{target:(W)=>R(W.target)}),xq=P()(D,{target:(W)=>R(W.target)}),RW=P()(D,{target:(W)=>R(W.target)}),c=P()([...p,"altKey","ctrlKey","code","key","locale","location","metaKey","repeat","shiftKey"],{target:(W)=>R(W.target)}),_=P()([...p,"altKey","ctrlKey","metaKey","shiftKey","changedTouches","targetTouches","touches"],{target:(W)=>R(W.target),changedTouches:(W)=>r(W.changedTouches),targetTouches:(W)=>r(W.targetTouches),touches:(W)=>r(W.touches)}),Eq=P()([...T,"deltaMode","deltaX","deltaY","deltaZ"],{target:(W)=>R(W.target),relatedTarget:(W)=>W.relatedTarget?R(W.relatedTarget):null}),o=P()([...D,"animationName","elapsedTime","pseudoElement"],{target:(W)=>R(W.target)}),dq=P()([...D,"oldState","newState"],{target:(W)=>R(W.target)}),iq=P()([...D,"elapsedTime","propertyName","pseudoElement"],{target:(W)=>R(W.target)});function r(W){return Array.from(W).map((q)=>({target:R(q.target),identifier:q.identifier,screenX:q.screenX,screenY:q.screenY,clientX:q.clientX,clientY:q.clientY,pageX:q.pageX,pageY:q.pageY}))}function CW(W){if(!W)return null;let q=[];if(W.items)for(let z=0;z<W.items.length;z++){let $=W.items[z];q.push({kind:$.kind,type:$.type})}return{drop_effect:W.dropEffect,effect_allowed:W.effectAllowed,items:q,types:Array.from(W.types||[])}}var nq={pointerdown:I,pointermove:I,pointerup:I,pointercancel:I,gotpointercapture:I,lostpointercapture:I,pointerenter:I,pointerleave:I,pointerover:I,pointerout:I,click:N,contextmenu:N,dblclick:N,mousedown:N,mouseenter:N,mouseleave:N,mousemove:N,mouseout:N,mouseover:N,mouseup:N,drag:K,dragend:K,dragenter:K,dragexit:K,dragleave:K,dragover:K,dragstart:K,drop:K,keydown:c,keypress:c,keyup:c,focus:AW,blur:AW,change:RW,input:RW,invalid:xq,reset:PW,submit:PW,copy:s,cut:s,paste:s,compositionend:l,compositionstart:l,compositionupdate:l,touchcancel:_,touchend:_,touchmove:_,touchstart:_,scroll:uq,wheel:Eq,animationstart:o,animationend:o,animationiteration:o,transitionend:iq,toggle:dq};function a(W){if(W&&typeof W==="object"&&"nativeEvent"in W&&typeof W.isDefaultPrevented==="function"){let q=W;if(console.log("React event:",q),typeof q.type!=="string")return W;let z=nq[q.type.toLowerCase()];if(z)return z(q);return vq(q)}return W}function sq(W){return W instanceof Date}function lq(W){return typeof File!=="undefined"&&W instanceof File}function cq(W){return typeof FormData!=="undefined"&&W instanceof FormData}function S(W){let q=new Map,z=1,$=(Z)=>{if(Z===null||typeof Z!=="object")return Z;let J=Z;if(q.has(J))return{__ref:q.get(J)};if(sq(Z)){let Q=z++;return q.set(J,Q),{__pulse:"date",__id:Q,timestamp:Z.getTime()}}if(lq(Z)){let Q=z++;return q.set(J,Q),{__pulse:"file",__id:Q,name:Z.name,type:Z.type,size:Z.size,lastModified:Z.lastModified,file:Z}}if(cq(Z)){let Q=z++;q.set(J,Q);let X={};for(let[A,f]of Z.entries()){let C=$(f);if(Object.prototype.hasOwnProperty.call(X,A)){let V=X[A];if(Array.isArray(V))V.push(C);else X[A]=[V,C]}else X[A]=C}return{__pulse:"formdata",__id:Q,fields:X}}let U=z++;if(q.set(J,U),Array.isArray(Z))return{__pulse:"array",__id:U,items:Z.map($)};let G={};for(let Q in Z){let X=Z[Q];if(typeof X==="function"||typeof X==="symbol"||typeof X==="undefined")continue;G[Q]=$(X)}return{__pulse:"object",__id:U,__data:G}};return $(W)}function t(W){let q=new Map,z=($)=>{if($===null||typeof $!=="object")return $;if(Array.isArray($))return $.map(z);let Z=$;if(Z.__ref!==void 0){let U=Z.__ref;return q.get(U)||null}if(Z.__pulse==="date"){let U=Z.__id,G=new Date(Z.timestamp);return q.set(U,G),G}if(Z.__pulse==="file"){let{__id:U,file:G}=Z;return q.set(U,G),G}if(Z.__pulse==="formdata"){let{__id:U,fields:G}=Z,Q=new FormData;q.set(U,Q);for(let[X,A]of Object.entries(G))if(Array.isArray(A))for(let f of A){let C=z(f);Q.append(X,C)}else{let f=z(A);Q.append(X,f)}return Q}if(Z.__pulse==="array"){let U=Z.__id,G=[];q.set(U,G);let Q=Z.items;for(let X=0;X<Q.length;X++)G[X]=z(Q[X]);return G}if(Z.__pulse==="object"){let U=Z.__id,G={};q.set(U,G);let Q=Z.__data;for(let[X,A]of Object.entries(Q))G[X]=z(A);return G}let J={};for(let[U,G]of Object.entries(Z))J[U]=z(G);return J};return z(W)}import{io as oq}from"socket.io-client";class h{url;frameworkNavigate;activeViews;socket=null;messageQueue;connectionListeners=new Set;serverErrors=new Map;serverErrorListeners=new Set;constructor(W,q){this.url=W;this.frameworkNavigate=q;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=oq(this.url,{transports:["websocket"]});this.socket=z,z.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let[$,Z]of this.activeViews)z.emit("message",S({type:"mount",path:$,routeInfo:Z.routeInfo}));for(let $ of this.messageQueue){if($.type==="mount"&&this.activeViews.has($.path))continue;if($.type==="navigate")continue;z.emit("message",S($))}this.messageQueue=[],this.notifyConnectionListeners(!0),W()}),z.on("connect_error",($)=>{console.error("[SocketIOTransport] Connection failed:",$),this.notifyConnectionListeners(!1),q($)}),z.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),z.on("message",($)=>this.handleServerMessage(t($)))})}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",S(W));else this.messageQueue.push(W)}mountView(W,q){if(this.activeViews.has(W))throw new 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)q.vdom=W.vdom,q.listener(q.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||!q.vdom){console.error(`[PulseClient] Received VDOM update for path ${W.path} before initial tree was set.`);return}if(q.vdom=d(q.vdom,W.ops),q.listener(q.vdom),this.serverErrors.has(W.path))this.serverErrors.delete(W.path),this.notifyServerError(W.path,null);break}case"server_error":{this.serverErrors.set(W.path,W.error),this.notifyServerError(W.path,W.error);break}case"api_call":{this.performApiCall(W);break}case"navigate_to":{try{let q=W.path;if(this.frameworkNavigate)this.frameworkNavigate(q);else window.history.pushState({},"",q),window.dispatchEvent(new PopStateEvent("popstate"))}catch(q){console.error("Navigation error:",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((U,G)=>z[G]=U);let $=null;if((q.headers.get("content-type")||"").includes("application/json"))$=await q.json().catch(()=>null);else $=await q.text().catch(()=>null);let J={type:"api_result",id:W.id,ok:q.ok,status:q.status,headers:z,body:$};await this.sendMessage(J)}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(a)})}}import{useLocation as rq,useParams as aq,useNavigate as tq}from"react-router";import{jsxDEV as O}from"react/jsx-dev-runtime";var DW=fW(null),OW=()=>{let W=VW(DW);if(!W)throw new Error("usePulseClient must be used within a PulseProvider");return W},NW=fW(null),i=()=>{let W=VW(NW);if(!W)throw new Error("usePulseRenderHelpers must be used within a PulseRenderContext (provided by <PulseView>)");return W},qW=typeof window!=="undefined";function eq({children:W,config:q}){let[z,$]=e(!0),Z=tq(),J=WW(()=>new h(`${q.serverAddress}`,Z),[q.serverAddress,Z]);return m(()=>J.onConnectionChange($),[J]),m(()=>{if(qW)return J.connect(),()=>J.disconnect()},[J]),O(DW.Provider,{value:J,children:[!z&&O("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."},void 0,!1,void 0,this),W]},void 0,!0,void 0,this)}function Wz({initialVDOM:W,externalComponents:q,path:z}){let $=OW(),[Z,J]=e(W),[U,G]=e(null),Q=rq(),X=aq(),A=WW(()=>{let{"*":C="",...V}=X,L=new URLSearchParams(Q.search);return{hash:Q.hash,pathname:Q.pathname,query:Q.search,queryParams:Object.fromEntries(L.entries()),pathParams:V,catchall:C.length>0?C.split("/"):[]}},[Q.hash,Q.pathname,Q.search,JSON.stringify(X)]);m(()=>{if(qW){$.mountView(z,{vdom:W,listener:J,routeInfo:A});let C=$.onServerError((V,L)=>{if(V===z)G(L)});return()=>{console.log("Unmounting",z),C(),$.unmount(z)}}},[$]),m(()=>{if(qW)$.navigate(z,A)},[$,z,A]);let f=WW(()=>{let C=new Map;return{getCallback:(j)=>{let y=C.get(j);if(!y)y=(...wW)=>$.invokeCallback(z,j,wW),C.set(j,y);return y},getComponent:(j)=>{let y=q[j];if(!y)throw new Error(`Component with key "${j}" not found.`);return y}}},[$,q,z]);return O(NW.Provider,{value:f,children:U?O(qz,{error:U},void 0,!1,void 0,this):O(Y,{node:Z},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function qz({error:W}){return O("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:[O("div",{style:{fontWeight:700,marginBottom:8},children:["Server Error during ",W.phase]},void 0,!0,void 0,this),W.message&&O("div",{children:W.message},void 0,!1,void 0,this),W.stack&&O("details",{open:!0,style:{marginTop:8},children:[O("summary",{children:"Stack trace"},void 0,!1,void 0,this),O("pre",{style:{margin:0},children:W.stack},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{io as zz}from"socket.io-client";class IW{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=zz(this.url,{transports:["websocket"]}),this.socket.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let $ of this.messageQueue)this.socket?.emit("message",$);this.messageQueue=[],this.notifyConnectionListeners(!0),q()}),this.socket.on("connect_error",($)=>{console.error("[SocketIOTransport] Connection failed:",$),this.notifyConnectionListeners(!1),z($)}),this.socket.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),this.socket.on("message",($)=>{this.listener?.($)})})}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 Zz({params:W,request:q}){let{"*":z="",...$}=W,Z=new URL(q.url);return{hash:Z.hash,pathname:Z.pathname,query:Z.search,queryParams:Object.fromEntries(Z.searchParams.entries()),pathParams:$,catchall:z.length>1?z.split("/"):[]}}function $z(W){if(W===null||typeof W!=="object")return!1;let q=Object.getPrototypeOf(W);return q===Object.prototype||q===null}function zW(W){return typeof W==="function"||typeof W==="symbol"||typeof W==="undefined"}async function Qz(W){let q=await W.arrayBuffer();return Array.from(new Uint8Array(q))}async function Jz(W){return await M(W,{seen:new WeakMap,nextId:1})}function Xz(W,q){if(W.seen.get(q)!==void 0)return null;let $=W.nextId++;return W.seen.set(q,$),$}async function M(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 G=Xz(q,W);if(G===null)return{__t:"ref",id:q.seen.get(W)};let Q={};for(let[A,f]of W.entries()){let C=await M(f,q);if(C===void 0)continue;if(Object.prototype.hasOwnProperty.call(Q,A)){let V=Q[A];if(Array.isArray(V))V.push(C);else Q[A]=[V,C]}else Q[A]=C}return{__t:"formdata",fields:Q,__id:G}}if(W instanceof File){let G=W,Q=await Qz(W);return{__t:"file",name:G.name,type:G.type,size:G.size,lastModified:G.lastModified,content:Q}}let z=W,$=q.seen.get(z);if($!==void 0)return{__t:"ref",id:$};let Z=q.nextId++;if(q.seen.set(z,Z),Array.isArray(W)){let Q=(await Promise.all(W.map((A)=>M(A,q)))).filter((A)=>A!==void 0);return{__t:"array",__id:Z,items:Q}}let J={};if($z(W))for(let G of Object.keys(W)){let Q=W[G];if(zW(Q))continue;let X=await M(Q,q);if(X!==void 0)J[G]=X}else for(let G in W){let Q=W[G];if(zW(Q))continue;let X=await M(Q,q);if(X!==void 0)J[G]=X}return{__t:"object",__id:Z,props:J}}function Fz(W){return H(W)}function H(W){if(W===null||typeof W!=="object")return W;let q=W,z=q.__t;if(z==="datetime"){let Z=q.timestamp;return new Date(Z)}if(z==="file"){let Z=q.content;if(Array.isArray(Z))return{...q,content:new Uint8Array(Z)};return q}if(z==="formdata"){let Z=q.fields,J={};for(let U of Object.keys(Z)){let G=Z[U];if(Array.isArray(G))J[U]=G.map((Q)=>H(Q));else J[U]=H(G)}return{__t:"formdata",fields:J}}if(z==="array")return q.items.map((J)=>H(J));if(z==="object"){let Z=q.props,J={};for(let U of Object.keys(Z))J[U]=H(Z[U]);return J}if(z==="ref")return q;let $={};for(let Z of Object.keys(q))$[Z]=H(q[Z]);return $}function Gz(W){return ZW(W,new WeakSet)}function ZW(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(($)=>ZW($,q)).filter(($)=>$!==void 0);let z={};for(let $ in W){let Z=W[$];if(zW(Z))continue;let J=ZW(Z,q);if(J!==void 0)z[$]=J}return z}export{i as usePulseRenderHelpers,OW as usePulseClient,S as stringify,t as parse,Zz as extractServerRouteInfo,a as extractEvent,Jz as encodeForWire,Fz as decodeFromWire,yW as createMountPoint,KW as createFragment,BW as createElementNode,Gz as cleanForSerialization,d as applyVDOMUpdates,Y as VDOMRenderer,IW as SocketIOTransport,bW as RenderLazy,Wz as PulseView,h as PulseSocketIOClient,eq as PulseProvider};
2
2
 
3
- //# debugId=6C27788B0A510EB464756E2164756E21
3
+ //# debugId=3E3EE69C7B6186E564756E2164756E21