pulse-ui-client 0.0.1 → 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/README.md +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +13 -9
- package/dist/pulse.d.ts +3 -3
- package/dist/renderer.d.ts +8 -2
- package/dist/serialize/clean.d.ts +3 -0
- package/dist/serialize/clean.test.d.ts +1 -0
- package/dist/serialize/elements.d.ts +1 -0
- package/dist/serialize/events.d.ts +1 -0
- package/dist/serialize/extractor.d.ts +5 -0
- package/dist/serialize/flatted.d.ts +2 -0
- package/dist/serialize/flatted.test.d.ts +1 -0
- package/dist/vdom.d.ts +2 -0
- package/package.json +1 -1
- package/dist/serialize.d.ts +0 -2351
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,12 @@ export type { PulseConfig, PulseProviderProps } from "./pulse";
|
|
|
3
3
|
export { PulseSocketIOClient } from "./client";
|
|
4
4
|
export type { PulseClient, MountedView, VDOMListener, ConnectionStatusListener, ServerErrorListener, } from "./client";
|
|
5
5
|
export type { VDOM, VDOMNode, VDOMElement, VDOMUpdate, ComponentRegistry, } from "./vdom";
|
|
6
|
-
export { VDOMRenderer, createElementNode, createFragment, createMountPoint, applyVDOMUpdates, } from "./renderer";
|
|
6
|
+
export { VDOMRenderer, createElementNode, createFragment, createMountPoint, applyVDOMUpdates, RenderLazy, } from "./renderer";
|
|
7
7
|
export type { ServerMessage, ServerInitMessage, ServerUpdateMessage, ServerErrorMessage, ServerErrorInfo, ServerApiCallMessage, ServerNavigateToMessage, ClientMessage, ClientCallbackMessage, ClientMountMessage, ClientNavigateMessage, ClientUnmountMessage, ClientApiResultMessage, } from "./messages";
|
|
8
8
|
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 x,useMemo as v,createContext as t,useContext as e}from"react";import Qq,{memo as Wq}from"react";var p="$$fragment",j="$$";function w(q){return typeof q==="object"&&q!==null}function L(q){return typeof q==="object"&&q!==null&&q.tag.startsWith("$$")&&q.tag!=="$$fragment"}function o(q){if(!L(q))throw new Error("Node is not a mount point");return q.tag.slice(2)}import{jsxDEV as V,Fragment as c}from"react/jsx-dev-runtime";function H(q,J){if(w(q))return q.key||J;return J}var O=Wq(({node:q})=>{let{getCallback:J,getComponent:Z}=h();if(q===null||typeof q==="boolean"||q===void 0)return null;if(typeof q==="string"||typeof q==="number")return V(c,{children:q},void 0,!1,void 0,this);if(w(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,z={};for(let[W,f]of Object.entries(Q))if(typeof f==="string"&&f.startsWith("$$fn:")){let G=f.substring(5);z[W]=J(G)}else z[W]=f;if(L(q)){let W=o(q),f=Z(W),G=X.map((N,_)=>V(O,{node:N},H(N,_),!1,void 0,this));return V(f,{...z,children:G},void 0,!1,void 0,this)}if($===p)return V(c,{children:X.map((W,f)=>V(O,{node:W},H(W,f),!1,void 0,this))},void 0,!1,void 0,this);let S=X.map((W,f)=>V(O,{node:W},H(W,f),!1,void 0,this));return Qq.createElement($,z,...S)}return console.error("Unknown VDOM node type:",q),null});O.displayName="VDOMRenderer";function fq(q,J={},Z=[],$){if(q.startsWith(j))console.error(`[Pulse] Error: The tag "${q}" starts with a reserved prefix "${j}". Please use a different tag name.`);let Q={tag:q,props:J,children:Z};if($!==void 0)Q.key=$;return Q}function Xq(q=[],J){let Z={tag:p,props:{},children:q};if(J!==void 0)Z.key=J;return Z}function zq(q,J={},Z=[],$){let Q={tag:j+q,props:J,children:Z};if($!==void 0)Q.key=$;return Q}function Aq(q,J){if(J==="")return w(q)?q:null;let Z=J.split(".").map(Number),$=q;for(let Q of Z){if(!w($))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 w($)?$:null}function Gq(q){if(typeof q!=="object"||q===null)return q;return JSON.parse(JSON.stringify(q))}function u(q,J){let Z=Gq(q);for(let $ of J){let{type:Q,path:X,data:z}=$;if(X===""){switch(Q){case"replace":Z=z;break;case"update_props":if(w(Z))Z.props={...Z.props??{},...z};break;default:console.error(`[applyUpdates] Invalid root operation: ${Q}`)}continue}let S=X.substring(0,X.lastIndexOf(".")),W=parseInt(X.substring(X.lastIndexOf(".")+1),10),f=Aq(Z,S);if(!f){console.error(`[applyUpdates] Could not find parent for path: ${X}`);continue}if(!f.children)f.children=[];switch(Q){case"replace":f.children[W]=z;break;case"update_props":let G=f.children[W];if(w(G))G.props={...G.props??{},...z};break;case"insert":f.children.splice(W,0,z);break;case"remove":f.children.splice(W,1);break;case"move":{let N=f.children.splice(z.from_index,1)[0];f.children.splice(z.to_index,0,N);break}}}return Z}function Rq(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 Uq(q){return{autofocus:q.autofocus,tab_index:q.tabIndex,nonce:q.nonce}}function Y(q){return{...Rq(q),...Uq(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 Kq(q){return{...Y(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 _q(q){return{...Y(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 a(q){return{...Y(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 wq(q){return{...a(q)}}function Fq(q){return{...Y(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 Sq(q){return{...Y(q),value:q.value}}function Iq(q){return{...Y(q),height:q.height,src:q.src,type:q.type,width:q.width,align:q.align,name:q.name}}function Oq(q){return{...Y(q),disabled:q.disabled,name:q.name,type:q.type,validation_message:q.validationMessage,will_validate:q.willValidate}}function Nq(q){return{...Y(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 Cq(q){return{...Y(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 Vq(q){return{...Y(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 Pq(q){return{...Y(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 Dq(q){return{...Y(q),html_for:q.htmlFor}}function bq(q){return{...Y(q),value:q.value,type:q.type}}function jq(q){return{...Y(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 kq(q){return{...Y(q),name:q.name}}function yq(q){return{...Y(q),high:q.high,low:q.low,max:q.max,min:q.min,optimum:q.optimum,value:q.value}}function Bq(q){return{...Y(q),cite:q.cite,dateTime:q.dateTime}}function gq(q){return{...Y(q),reversed:q.reversed,start:q.start,type:q.type,compact:q.compact}}function pq(q){return{...Y(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 Lq(q){return{...Y(q),disabled:q.disabled,label:q.label}}function Hq(q){return{...Y(q),default_selected:q.defaultSelected,disabled:q.disabled,index:q.index,label:q.label,selected:q.selected,text:q.text,value:q.value}}function uq(q){return{...Y(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 hq(q){return{...Y(q),max:q.max,position:q.position,value:q.value}}function Mq(q){return{...Y(q),cite:q.cite}}function Tq(q){return{...Y(q)}}function iq(q){return{...Y(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{...Y(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 dq(q){return{...Y(q),name:q.name}}function Eq(q){return{...Y(q),height:q.height,media:q.media,sizes:q.sizes,src:q.src,srcset:q.srcset,type:q.type,width:q.width}}function xq(q){return{...Y(q),align:q.align}}function vq(q){return{...Y(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 sq(q){return{...Y(q),span:q.span,align:q.align,ch:q.ch,ch_off:q.chOff,v_align:q.vAlign,width:q.width}}function oq(q){return{...Y(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 cq(q){return{...Y(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 rq(q){return{...Y(q),align:q.align,ch:q.ch,ch_off:q.chOff,v_align:q.vAlign}}function nq(q){return{...Y(q)}}function aq(q){return{...Y(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 lq(q){return{...Y(q),datetime:q.dateTime}}function tq(q){return{...Y(q),default:q.default,kind:q.kind,label:q.label,ready_state:q.readyState,src:q.src,srclang:q.srclang}}function eq(q){return{...a(q),height:q.height,poster:q.poster,video_height:q.videoHeight,video_width:q.videoWidth,width:q.width,plays_inline:q.playsInline}}function q1(q){return{...Y(q),clear:q.clear}}function J1(q){return{...Y(q),href:q.href,target:q.target}}function Y1(q){return{...Y(q),a_link:q.aLink,background:q.background,bg_color:q.bgColor,link:q.link,text:q.text,v_link:q.vLink}}function Z1(q){return{...Y(q),compact:q.compact}}function $1(q){return{...Y(q),open:q.open}}function Q1(q){return{...Y(q),open:q.open,return_value:q.returnValue}}function W1(q){return{...Y(q),align:q.align}}function f1(q){return{...Y(q)}}function X1(q){return{...Y(q),align:q.align}}function z1(q){return{...Y(q),align:q.align,color:q.color,no_shade:q.noShade,size:q.size,width:q.width}}function A1(q){return{...Y(q),version:q.version}}function G1(q){return{...Y(q)}}function R1(q){return{...Y(q),content:q.content,http_equiv:q.httpEquiv,name:q.name,scheme:q.scheme}}function U1(q){return{...Y(q),align:q.align}}function K1(q){return{...Y(q)}}function _1(q){return{...Y(q),width:q.width}}function w1(q){return{...Y(q)}}function F1(q){return{...Y(q),media:q.media,type:q.type,disabled:q.disabled}}function S1(q){return{...Y(q),text:q.text}}function I1(q){return{...Y(q),compact:q.compact,type:q.type}}function P(q){switch(q.tagName.toUpperCase()){case"A":return Kq(q);case"AREA":return _q(q);case"AUDIO":return wq(q);case"BASE":return J1(q);case"BLOCKQUOTE":case"Q":return Mq(q);case"BODY":return Y1(q);case"BR":return q1(q);case"BUTTON":return Fq(q);case"CANVAS":return Y(q);case"CAPTION":return xq(q);case"CITE":return Tq(q);case"COL":case"COLGROUP":return sq(q);case"DATA":return Sq(q);case"DETAILS":return $1(q);case"DIALOG":return Q1(q);case"DIV":return W1(q);case"DL":return Z1(q);case"EMBED":return Iq(q);case"FIELDSET":return Oq(q);case"FORM":return Nq(q);case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":return X1(q);case"HEAD":return f1(q);case"HR":return z1(q);case"HTML":return A1(q);case"IFRAME":return Cq(q);case"IMG":return Vq(q);case"INPUT":return Pq(q);case"LABEL":return Dq(q);case"LI":return bq(q);case"LINK":return jq(q);case"MAP":return kq(q);case"MENU":return G1(q);case"META":return R1(q);case"METER":return yq(q);case"INS":case"DEL":return Bq(q);case"OBJECT":return pq(q);case"OL":return gq(q);case"OPTGROUP":return Lq(q);case"OPTION":return Hq(q);case"OUTPUT":return uq(q);case"P":return U1(q);case"PICTURE":return K1(q);case"PRE":return _1(q);case"PROGRESS":return hq(q);case"SCRIPT":return iq(q);case"SELECT":return mq(q);case"SLOT":return dq(q);case"SOURCE":return Eq(q);case"SPAN":return w1(q);case"STYLE":return F1(q);case"TABLE":return oq(q);case"TBODY":case"THEAD":case"TFOOT":return rq(q);case"TD":case"TH":return vq(q);case"TEMPLATE":return nq(q);case"TEXTAREA":return aq(q);case"TIME":return lq(q);case"TITLE":return S1(q);case"TR":return cq(q);case"TRACK":return tq(q);case"UL":return I1(q);case"VIDEO":return eq(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 A(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 M(q){return{...K(q),clipboard_data:l(q.clipboardData)}}function T(q){return{...K(q),data:q.data}}function F(q){return{...A(q),data_transfer:l(q.dataTransfer)}}function U(q){return{...A(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 r(q){return{...K(q),related_target:q.relatedTarget?P(q.relatedTarget):null}}function d(q){return K(q)}function O1(q){return K(q)}function n(q){return d(q)}function i(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 k(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 N1(q){return{...A(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 C1(q){return{...K(q),old_state:q.oldState,new_state:q.newState}}function V1(q){return{...K(q),elapsed_time:q.elapsedTime,property_name:q.propertyName,pseudo_element:q.pseudoElement}}function l(q){if(!q)return null;let J=[];if(q.items)for(let Z=0;Z<q.items.length;Z++){let $=q.items[Z];J.push({kind:$.kind,type:$.type})}return{drop_effect:q.dropEffect,effect_allowed:q.effectAllowed,items:J,types:Array.from(q.types||[])}}var P1={pointerdown:U,pointermove:U,pointerup:U,pointercancel:U,gotpointercapture:U,lostpointercapture:U,pointerenter:U,pointerleave:U,pointerover:U,pointerout:U,click:A,contextmenu:A,dblclick:A,mousedown:A,mouseenter:A,mouseleave:A,mousemove:A,mouseout:A,mouseover:A,mouseup:A,drag:F,dragend:F,dragenter:F,dragexit:F,dragleave:F,dragover:F,dragstart:F,drop:F,keydown:i,keypress:i,keyup:i,focus:r,blur:r,change:n,input:n,invalid:O1,reset:d,submit:d,copy:M,cut:M,paste:M,compositionend:T,compositionstart:T,compositionupdate:T,touchcancel:k,touchend:k,touchmove:k,touchstart:k,scroll:y,wheel:N1,animationstart:m,animationend:m,animationiteration:m,transitionend:V1,toggle:C1};function E(q){if(q&&typeof q==="object"&&"nativeEvent"in q&&typeof q.isDefaultPrevented==="function"){let J=q;if(typeof J.type!=="string")return q;let Z=P1[J.type.toLowerCase()];if(Z)return Z(J);return console.warn(`No specific extractor for event type "${J.type}". Using synthetic.`),K(J)}return q}import{io as D1}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 Z=D1(this.url,{transports:["websocket"]});this.socket=Z,Z.on("connect",()=>{console.log("[SocketIOTransport] Connected:",this.socket?.id);for(let[$,Q]of this.activeViews)Z.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;Z.emit("message",$)}this.messageQueue=[],this.notifyConnectionListeners(!0),q()}),Z.on("connect_error",($)=>{console.error("[SocketIOTransport] Connection failed:",$),this.notifyConnectionListeners(!1),J($)}),Z.on("disconnect",()=>{console.log("[SocketIOTransport] Disconnected"),this.notifyConnectionListeners(!1)}),Z.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,Z]of this.serverErrors)q(J,Z);return()=>{this.serverErrorListeners.delete(q)}}notifyServerError(q,J){for(let Z of this.serverErrorListeners)Z(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=u(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"}),Z={};J.headers.forEach((z,S)=>Z[S]=z);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:Z,body:$};await this.sendMessage(X)}catch(J){let Z={type:"api_result",id:q.id,ok:!1,status:0,headers:{},body:{error:String(J)}};await this.sendMessage(Z)}}async invokeCallback(q,J,Z){await this.sendMessage({type:"callback",path:q,callback:J,args:Z.map(E)})}}import{useLocation as b1,useParams as j1,useNavigate as k1}from"react-router";import{jsxDEV as R}from"react/jsx-dev-runtime";var qq=t(null),Jq=()=>{let q=e(qq);if(!q)throw new Error("usePulseClient must be used within a PulseProvider");return q},Yq=t(null),h=()=>{let q=e(Yq);if(!q)throw new Error("usePulseRenderHelpers must be used within a PulseRenderContext (provided by <PulseView>)");return q},s=typeof window!=="undefined";function y1({children:q,config:J}){let[Z,$]=x(!0),Q=k1(),X=v(()=>new B(`${J.serverAddress}`,Q),[J.serverAddress,Q]);return g(()=>X.onConnectionChange($),[X]),g(()=>{if(s)return X.connect(),()=>X.disconnect()},[X]),R(qq.Provider,{value:X,children:[!Z&&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 B1({initialVDOM:q,externalComponents:J,path:Z}){let $=Jq(),[Q,X]=x(q),[z,S]=x(null),W=b1(),f=j1(),G=v(()=>{let{"*":_="",...D}=f,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(f)]);g(()=>{if(s){$.mountView(Z,{vdom:q,listener:X,routeInfo:G});let _=$.onServerError((D,b)=>{if(D===Z)S(b)});return()=>{console.log("Unmounting",Z),_(),$.unmount(Z)}}},[$]),g(()=>{if(s)$.navigate(Z,G)},[$,Z,G]);let N=v(()=>{let _=new Map;return{getCallback:(C)=>{let I=_.get(C);if(!I)I=(...$q)=>$.invokeCallback(Z,C,$q),_.set(C,I);return I},getComponent:(C)=>{let I=J[C];if(!I)throw new Error(`Component with key "${C}" not found.`);return I}}},[$,J,Z]);return R(Yq.Provider,{value:N,children:z?R(g1,{error:z},void 0,!1,void 0,this):R(O,{node:Q},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function g1({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 p1}from"socket.io-client";class Zq{url;socket=null;listener=null;messageQueue=[];connectionListeners=new Set;constructor(q){this.url=q}connect(q){return this.listener=q,new Promise((J,Z)=>{this.socket=p1(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),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(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 L1({params:q,request:J}){let{"*":Z="",...$}=q,Q=new URL(J.url);return{hash:Q.hash,pathname:Q.pathname,query:Q.search,queryParams:Object.fromEntries(Q.searchParams.entries()),pathParams:$,catchall:Z.length>1?Z.split("/"):[]}}export{h as usePulseRenderHelpers,Jq as usePulseClient,L1 as extractServerRouteInfo,E as extractEvent,zq as createMountPoint,Xq as createFragment,fq as createElementNode,u as applyVDOMUpdates,O as VDOMRenderer,Zq as SocketIOTransport,B1 as PulseView,B as PulseSocketIOClient,y1 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=
|
|
3
|
+
//# debugId=3E3EE69C7B6186E564756E2164756E21
|